Changeset 30277
- Timestamp:
- 11/08/2014 07:28:12 PM (10 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/bootstrap.php
r28943 r30277 91 91 require dirname( __FILE__ ) . '/testcase-xmlrpc.php'; 92 92 require dirname( __FILE__ ) . '/testcase-ajax.php'; 93 require dirname( __FILE__ ) . '/testcase-canonical.php'; 93 94 require dirname( __FILE__ ) . '/exceptions.php'; 94 95 require dirname( __FILE__ ) . '/utils.php'; -
trunk/tests/phpunit/tests/canonical.php
r29932 r30277 9 9 * @group query 10 10 */ 11 class Tests_Canonical extends WP_UnitTestCase { 12 13 // This can be defined in a subclass of this class which contains it's own data() method, those tests will be run against the specified permastruct 14 var $structure = '/%year%/%monthnum%/%day%/%postname%/'; 15 16 var $old_current_user; 17 var $author_id; 18 var $post_ids; 19 var $term_ids; 20 21 function setUp() { 22 global $wp_rewrite; 23 24 parent::setUp(); 25 26 update_option( 'page_comments', true ); 27 update_option( 'comments_per_page', 5 ); 28 update_option( 'posts_per_page', 5 ); 29 30 $wp_rewrite->init(); 31 $wp_rewrite->set_permalink_structure( $this->structure ); 32 33 create_initial_taxonomies(); 34 35 $wp_rewrite->flush_rules(); 36 37 $this->old_current_user = get_current_user_id(); 38 $this->author_id = $this->factory->user->create( array( 'user_login' => 'canonical-author' ) ); 39 wp_set_current_user( $this->author_id ); 40 41 // Already created by install defaults: 42 // $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) ); 43 44 $this->term_ids = array(); 45 46 $this->factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) ); 47 $post_id = $this->factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) ); 48 $this->factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) ); 49 50 $this->factory->post->create( array( 51 'post_title' => 'images-test', 52 'post_date' => '2008-09-03 00:00:00', 53 'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3' 54 ) ); 55 56 $post_id = $this->factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) ); 57 $this->factory->comment->create_post_comments( $post_id, 15 ); 58 59 $this->factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) ); 60 61 $this->factory->post->create( array( 'import_id' => 123 ) ); 62 $this->factory->post->create( array( 'import_id' => 1 ) ); 63 $this->factory->post->create( array( 'import_id' => 358 ) ); 64 65 $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) ); 66 $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) ); 67 $post_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) ); 68 $this->factory->post->create( 69 array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id, 70 ) ); 71 72 $this->term_ids['/category/parent/'] = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) ); 73 $this->term_ids['/category/parent/child-1/'] = $this->factory->term->create( array( 74 'taxonomy' => 'category', 'name' => 'child-1', 'parent' => $this->term_ids['/category/parent/'], 75 ) ); 76 $this->term_ids['/category/parent/child-1/child-2/'] = $this->factory->term->create( array( 77 'taxonomy' => 'category', 'name' => 'child-2', 'parent' => $this->term_ids['/category/parent/child-1/'], 78 ) ); 79 80 $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); 81 $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); 82 83 $this->factory->term->create( array( 'name' => 'post-formats' ) ); 11 class Tests_Canonical extends WP_Canonical_UnitTestCase { 12 public static function setUpBeforeClass() { 13 self::generate_shared_fixtures(); 84 14 } 85 15 86 function tearDown() { 87 global $wp_rewrite; 88 parent::tearDown(); 89 wp_set_current_user( $this->old_current_user ); 90 91 $wp_rewrite->init(); 16 public static function tearDownAfterClass() { 17 self::delete_shared_fixtures(); 92 18 } 93 19 94 // URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..95 // Return url's are full url's with the prepended home.96 function get_canonical($test_url) {97 $test_url = home_url( $test_url );20 public function setUp() { 21 parent::setUp(); 22 wp_set_current_user( self::$author_id ); 23 } 98 24 99 $can_url = redirect_canonical( $test_url, false ); 100 if ( ! $can_url ) 101 return $test_url; // No redirect will take place for this request 102 103 return $can_url; 25 public function tearDown() { 26 parent::tearDown(); 27 wp_set_current_user( self::$old_current_user ); 104 28 } 105 29 … … 108 32 */ 109 33 function test( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { 110 $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, (array) $expected_doing_it_wrong );111 112 if ( $ticket )113 $this->knownWPBug( $ticket );114 115 $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null;116 117 if ( is_string($expected) )118 $expected = array('url' => $expected);119 elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) )120 $expected = array( 'qv' => $expected );121 122 if ( !isset($expected['url']) && !isset($expected['qv']) )123 $this->markTestSkipped('No valid expected output was provided');124 34 125 35 if ( false !== strpos( $test_url, '%d' ) ) { 126 36 if ( false !== strpos( $test_url, '/?author=%d' ) ) 127 $test_url = sprintf( $test_url, $this->author_id );37 $test_url = sprintf( $test_url, self::$author_id ); 128 38 if ( false !== strpos( $test_url, '?cat=%d' ) ) 129 $test_url = sprintf( $test_url, $this->term_ids[ $expected['url'] ] );39 $test_url = sprintf( $test_url, self::$terms[ $expected['url'] ] ); 130 40 } 131 41 132 $this->go_to( home_url( $test_url ) ); 133 134 // Does the redirect match what's expected? 135 $can_url = $this->get_canonical( $test_url ); 136 $parsed_can_url = parse_url($can_url); 137 138 // Just test the Path and Query if present 139 if ( isset($expected['url']) ) 140 $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref ); 141 142 if ( ! isset($expected['qv']) ) 143 return; 144 145 // "make" that the request and check the query is correct 146 $this->go_to( $can_url ); 147 148 // Are all query vars accounted for, And correct? 149 global $wp; 150 151 $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars); 152 if ( !empty($parsed_can_url['query']) ) { 153 parse_str($parsed_can_url['query'], $_qv); 154 155 // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite) 156 $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref ); 157 158 $query_vars = array_merge($query_vars, $_qv); 159 } 160 161 $this->assertEquals( $expected['qv'], $query_vars ); 42 $this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong ); 162 43 } 163 44 … … 176 57 // Categories 177 58 178 array( '?cat=%d', '/category/parent/', 15256 ),179 array( '?cat=%d', '/category/parent/child-1/', 15256 ),180 array( '?cat=%d', '/category/parent/child-1/child-2/'), // no children59 array( '?cat=%d', array( 'url' => '/category/parent/' ), 15256 ), 60 array( '?cat=%d', array( 'url' => '/category/parent/child-1/' ), 15256 ), 61 array( '?cat=%d', array( 'url' => '/category/parent/child-1/child-2/' ) ), // no children 181 62 array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ), 182 63 array( '/category/uncategorized/page/2/', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ), -
trunk/tests/phpunit/tests/canonical/customRules.php
r25002 r30277 1 1 <?php 2 3 require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';4 2 5 3 /** … … 8 6 * @group query 9 7 */ 10 class Tests_Canonical_CustomRules extends Tests_Canonical { 8 class Tests_Canonical_CustomRules extends WP_Canonical_UnitTestCase { 9 11 10 function setUp() { 12 11 parent::setUp(); … … 15 14 $wp_rewrite->add_rule('ccr/(.+?)/sort/(asc|desc)', 'index.php?category_name=$matches[1]&order=$matches[2]', 'top'); // ccr = Custom_Cat_Rule 16 15 $wp_rewrite->flush_rules(); 16 } 17 18 /** 19 * @dataProvider data 20 */ 21 function test( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { 22 $this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong ); 17 23 } 18 24 -
trunk/tests/phpunit/tests/canonical/https.php
r30160 r30277 1 1 <?php 2 3 require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';4 2 5 3 /** … … 8 6 * @group query 9 7 */ 10 class Tests_Canonical_HTTPS extends Tests_Canonical { 8 class Tests_Canonical_HTTPS extends WP_Canonical_UnitTestCase { 9 function setUp() { 10 global $wp_rewrite; 11 11 12 function setUp() {13 12 parent::setUp(); 13 14 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 15 create_initial_taxonomies(); 16 $wp_rewrite->flush_rules(); 17 $wp_rewrite->init(); 18 14 19 $this->http = set_url_scheme( home_url( 'sample-page/' ), 'http' ); 15 20 $this->https = set_url_scheme( home_url( 'sample-page/' ), 'https' ); -
trunk/tests/phpunit/tests/canonical/noRewrite.php
r25002 r30277 8 8 * @group query 9 9 */ 10 class Tests_Canonical_NoRewrite extends Tests_Canonical { 11 12 var $structure = ''; 10 class Tests_Canonical_NoRewrite extends WP_Canonical_UnitTestCase { 13 11 14 12 // These test cases are run against the test handler in WP_Canonical 13 public static function setUpBeforeClass() { 14 self::generate_shared_fixtures(); 15 } 16 17 public static function tearDownAfterClass() { 18 self::delete_shared_fixtures(); 19 } 20 21 public function setUp() { 22 global $wp_rewrite; 23 24 parent::setUp(); 25 26 $wp_rewrite->init(); 27 $wp_rewrite->set_permalink_structure( '' ); 28 $wp_rewrite->flush_rules(); 29 $wp_rewrite->init(); 30 } 31 32 /** 33 * @dataProvider data 34 */ 35 function test( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { 36 $this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong ); 37 } 15 38 16 39 function data() { -
trunk/tests/phpunit/tests/canonical/pageOnFront.php
r28966 r30277 1 1 <?php 2 3 require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';4 2 5 3 /** … … 8 6 * @group query 9 7 */ 10 class Tests_Canonical_PageOnFront extends Tests_Canonical { 8 class Tests_Canonical_PageOnFront extends WP_Canonical_UnitTestCase { 9 public static function setUpBeforeClass() { 10 self::generate_shared_fixtures(); 11 } 12 13 public static function tearDownAfterClass() { 14 self::delete_shared_fixtures(); 15 } 16 11 17 function setUp() { 12 18 parent::setUp(); … … 23 29 parent::tearDown(); 24 30 $wp_rewrite->init(); 31 } 32 33 /** 34 * @dataProvider data 35 */ 36 function test( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { 37 $this->assertCanonical( $test_url, $expected, $ticket, $expected_doing_it_wrong ); 25 38 } 26 39
Note: See TracChangeset
for help on using the changeset viewer.