Changeset 34802
- Timestamp:
- 10/03/2015 05:14:12 PM (9 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase-canonical.php
r32918 r34802 17 17 18 18 public function setUp() { 19 global $wp_rewrite;20 21 19 parent::setUp(); 22 20 … … 25 23 update_option( 'posts_per_page', 5 ); 26 24 25 global $wp_rewrite; 27 26 $wp_rewrite->init(); 28 27 $wp_rewrite->set_permalink_structure( $this->structure ); 28 29 29 create_initial_taxonomies(); 30 30 31 $wp_rewrite->flush_rules(); 31 32 } -
trunk/tests/phpunit/includes/testcase.php
r34720 r34802 16 16 17 17 protected $db_version; 18 19 public static $default_permalink_structure; 18 20 19 21 /** … … 71 73 add_filter( 'pre_option_db_version', array( $this, 'db_version' ) ); 72 74 } 75 76 self::$default_permalink_structure = get_option( 'permalink_structure' ); 77 78 $this->reset_permalinks(); 73 79 } 74 80 … … 100 106 $this->_restore_hooks(); 101 107 wp_set_current_user( 0 ); 108 109 $this->reset_permalinks( $restore = true ); 102 110 } 103 111 … … 646 654 return $this->db_version; 647 655 } 656 657 /** 658 * Utility method that resets permalinks and flushes rewrites. 659 * 660 * Collects the current permalink structure and stores it in a class property for use 661 * by sub-classes. 662 * 663 * @since 4.4.0 664 * 665 * @global WP_Rewrite $wp_rewrite 666 * 667 * @param bool $restore_default Optional. Whether to restore the default permalink structure. 668 * Default false. 669 */ 670 public function reset_permalinks( $restore_default = false ) { 671 global $wp_rewrite; 672 673 if ( ! $restore_default ) { 674 $wp_rewrite->init(); 675 $wp_rewrite->set_permalink_structure( '' ); 676 } else { 677 $wp_rewrite->set_permalink_structure( self::$default_permalink_structure ); 678 } 679 680 $wp_rewrite->flush_rules(); 681 } 648 682 } -
trunk/tests/phpunit/tests/admin/includesPost.php
r34680 r34802 254 254 global $wp_rewrite; 255 255 256 $old_permalink_structure = get_option( 'permalink_structure' );257 256 $permalink_structure = '%postname%'; 258 257 $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); … … 266 265 267 266 $this->assertSame( $expected, $found[0] ); 268 269 $wp_rewrite->set_permalink_structure( $old_permalink_structure );270 flush_rewrite_rules();271 267 } 272 268 … … 276 272 */ 277 273 public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() { 278 global $wp_rewrite;279 $old_permalink_structure = get_option( 'permalink_structure' );280 $wp_rewrite->set_permalink_structure( '' );281 flush_rewrite_rules();282 283 274 wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 284 275 … … 288 279 $found = get_sample_permalink_html( $p ); 289 280 $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found ); 290 291 $wp_rewrite->set_permalink_structure( $old_permalink_structure );292 flush_rewrite_rules();293 281 } 294 282 … … 299 287 public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_link_when_pretty_permalinks_are_enabled() { 300 288 global $wp_rewrite; 301 $old_permalink_structure = get_option( 'permalink_structure' );302 289 $permalink_structure = '%postname%'; 303 290 $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); … … 312 299 $post = get_post( $p ); 313 300 $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found ); 314 315 $wp_rewrite->set_permalink_structure( $old_permalink_structure );316 flush_rewrite_rules();317 301 } 318 302 … … 323 307 public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_link_when_changing_slug() { 324 308 global $wp_rewrite; 325 $old_permalink_structure = get_option( 'permalink_structure' );326 309 $permalink_structure = '%postname%'; 327 310 $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); … … 358 341 359 342 $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message ); 360 361 $wp_rewrite->set_permalink_structure( $old_permalink_structure );362 flush_rewrite_rules();363 343 } 364 344 … … 378 358 $found = get_sample_permalink( $p ); 379 359 $this->assertEquals( '2015-2', $found[1] ); 380 381 $wp_rewrite->set_permalink_structure( '' );382 flush_rewrite_rules();383 360 } 384 361 … … 398 375 $found = get_sample_permalink( $p ); 399 376 $this->assertEquals( '2015', $found[1] ); 400 401 $wp_rewrite->set_permalink_structure( '' );402 flush_rewrite_rules();403 377 } 404 378 … … 418 392 $found = get_sample_permalink( $p ); 419 393 $this->assertEquals( '11-2', $found[1] ); 420 421 $wp_rewrite->set_permalink_structure( '' );422 flush_rewrite_rules();423 394 } 424 395 … … 438 409 $found = get_sample_permalink( $p ); 439 410 $this->assertEquals( '13', $found[1] ); 440 441 $wp_rewrite->set_permalink_structure( '' );442 flush_rewrite_rules();443 411 } 444 412 … … 458 426 $found = get_sample_permalink( $p ); 459 427 $this->assertEquals( '30-2', $found[1] ); 460 461 $wp_rewrite->set_permalink_structure( '' );462 flush_rewrite_rules();463 428 } 464 429 … … 482 447 $found = get_sample_permalink( $p ); 483 448 $this->assertEquals( '30-3', $found[1] ); 484 485 $wp_rewrite->set_permalink_structure( '' );486 flush_rewrite_rules();487 449 } 488 450 … … 502 464 $found = get_sample_permalink( $p ); 503 465 $this->assertEquals( '32', $found[1] ); 504 505 $wp_rewrite->set_permalink_structure( '' );506 flush_rewrite_rules();507 466 } 508 467 … … 522 481 $found = get_sample_permalink( $p ); 523 482 $this->assertEquals( '30', $found[1] ); 524 525 $wp_rewrite->set_permalink_structure( '' );526 flush_rewrite_rules();527 483 } 528 484 -
trunk/tests/phpunit/tests/comment/commentsTemplate.php
r34741 r34802 7 7 */ 8 8 class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 9 public function setUp() {10 parent::setUp();11 12 global $wp_rewrite;13 $wp_rewrite->set_permalink_structure( '' );14 flush_rewrite_rules();15 }16 9 17 10 /** -
trunk/tests/phpunit/tests/feed/rss2.php
r34092 r34802 10 10 */ 11 11 class Tests_Feed_RSS2 extends WP_UnitTestCase { 12 private $permalink_structure = '';13 14 12 static $user; 15 13 static $posts; … … 41 39 42 40 public function setUp() { 43 global $wp_rewrite;44 $this->permalink_structure = get_option( 'permalink_structure' );45 $wp_rewrite->set_permalink_structure( '' );46 $wp_rewrite->flush_rules();47 48 41 parent::setUp(); 49 42 … … 52 45 // this seems to break something 53 46 update_option('use_smilies', false); 54 }55 56 public function tearDown() {57 global $wp_rewrite;58 $wp_rewrite->set_permalink_structure( $this->permalink_structure );59 $wp_rewrite->flush_rules();60 47 } 61 48 -
trunk/tests/phpunit/tests/general/paginateLinks.php
r32359 r34802 4 4 5 5 private $i18n_count = 0; 6 private $permalink_structure = '';7 6 8 7 function setUp() { 9 8 parent::setUp(); 10 global $wp_rewrite;11 9 12 10 $this->go_to( home_url( '/' ) ); 13 14 $this->permalink_structure = $wp_rewrite->permalink_structure;15 $wp_rewrite->set_permalink_structure( get_option( 'permalink_structure' ) );16 }17 18 function tearDown() {19 global $wp_rewrite;20 $wp_rewrite->set_permalink_structure( $this->permalink_structure );21 11 } 22 12 -
trunk/tests/phpunit/tests/link.php
r34690 r34802 40 40 $post_id = $this->factory->post->create(); 41 41 $post_id2 = $this->factory->post->create(); 42 43 $wp_rewrite->init();44 $wp_rewrite->set_permalink_structure( '' );45 $wp_rewrite->flush_rules();46 42 47 43 // Basic case -
trunk/tests/phpunit/tests/link/getNextCommentsLink.php
r34561 r34802 7 7 */ 8 8 class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase { 9 public function setUp() {10 global $wp_rewrite;11 12 parent::setUp();13 14 $wp_rewrite->set_permalink_structure( '' );15 $wp_rewrite->flush_rules();16 }17 9 18 10 public function test_page_should_respect_value_of_cpage_query_var() { -
trunk/tests/phpunit/tests/link/getPostCommentsFeedLink.php
r34479 r34802 4 4 */ 5 5 class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 6 private static $rewrite;7 private static $permalink_structure;8 9 static function setUpBeforeClass() {10 global $wp_rewrite;11 12 parent::setUpBeforeClass();13 14 self::$rewrite = $wp_rewrite;15 self::$permalink_structure = get_option( 'permalink_structure' );16 }17 18 public static function tearDownAfterClass() {19 parent::tearDownAfterClass();20 21 self::$rewrite->init();22 self::$rewrite->set_permalink_structure( self::$permalink_structure );23 self::$rewrite->flush_rules();24 }25 26 public function setUp() {27 parent::setUp();28 self::$rewrite->init();29 }30 31 private function set_permalink_structure( $structure ) {32 self::$rewrite->set_permalink_structure( $structure );33 self::$rewrite->flush_rules();34 }35 6 36 7 public function test_post_link() { 37 $this->set_permalink_structure( '' );38 39 8 $post_id = $this->factory->post->create(); 40 9 … … 49 18 50 19 public function test_post_pretty_link() { 51 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 20 global $wp_rewrite; 21 $wp_rewrite->init(); 22 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 23 $wp_rewrite->flush_rules(); 52 24 53 25 $post_id = $this->factory->post->create(); … … 60 32 61 33 public function test_attachment_link() { 62 $this->set_permalink_structure( '' );63 64 34 $post_id = $this->factory->post->create(); 65 35 $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array( … … 78 48 79 49 public function test_attachment_pretty_link() { 80 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 50 global $wp_rewrite; 51 $wp_rewrite->init(); 52 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 53 $wp_rewrite->flush_rules(); 81 54 82 55 $post_id = $this->factory->post->create( array( … … 98 71 99 72 public function test_attachment_no_name_pretty_link() { 100 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 73 global $wp_rewrite; 74 $wp_rewrite->init(); 75 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 76 $wp_rewrite->flush_rules(); 101 77 102 78 $post_id = $this->factory->post->create(); … … 113 89 114 90 public function test_unattached_link() { 115 $this->set_permalink_structure( '' );116 117 91 $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( 118 92 'post_mime_type' => 'image/jpeg', … … 130 104 131 105 public function test_unattached_pretty_link() { 132 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 106 global $wp_rewrite; 107 $wp_rewrite->init(); 108 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 109 $wp_rewrite->flush_rules(); 133 110 134 111 $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( -
trunk/tests/phpunit/tests/link/getPreviousCommentsLink.php
r34561 r34802 7 7 */ 8 8 class Tests_Link_GetPreviousCommentsLink extends WP_UnitTestCase { 9 public function setUp() {10 global $wp_rewrite;11 12 parent::setUp();13 14 $wp_rewrite->set_permalink_structure( '' );15 $wp_rewrite->flush_rules();16 }17 9 18 10 public function test_page_should_respect_value_of_cpage_query_var() { -
trunk/tests/phpunit/tests/post.php
r34762 r34802 430 430 $post = get_post( $p ); 431 431 432 $ wp_rewrite->set_permalink_structure( '');432 $this->reset_permalinks(); 433 433 434 434 $this->assertEquals( "$p-2", $post->post_name ); … … 526 526 // permalink should include the post ID at the end 527 527 $this->assertEquals(get_option('siteurl').'/2007/10/31/'.$id.'/', $plink); 528 529 $wp_rewrite->set_permalink_structure('');530 528 } 531 529 -
trunk/tests/phpunit/tests/post/wpUniquePostSlug.php
r33262 r34802 182 182 $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); 183 183 $this->assertEquals( '2015-2', $found ); 184 185 $wp_rewrite->set_permalink_structure( '' );186 flush_rewrite_rules();187 184 } 188 185 … … 204 201 $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); 205 202 $this->assertEquals( '2015-2', $found ); 206 207 $wp_rewrite->set_permalink_structure( '' );208 flush_rewrite_rules();209 203 } 210 204 … … 225 219 $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); 226 220 $this->assertEquals( '2015', $found ); 227 228 $wp_rewrite->set_permalink_structure( '' );229 flush_rewrite_rules();230 221 } 231 222 … … 246 237 $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 ); 247 238 $this->assertEquals( '11-2', $found ); 248 249 $wp_rewrite->set_permalink_structure( '' );250 flush_rewrite_rules();251 239 } 252 240 … … 267 255 $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 ); 268 256 $this->assertEquals( '11', $found ); 269 270 $wp_rewrite->set_permalink_structure( '' );271 flush_rewrite_rules();272 257 } 273 258 … … 288 273 $found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 ); 289 274 $this->assertEquals( '13', $found ); 290 291 $wp_rewrite->set_permalink_structure( '' );292 flush_rewrite_rules();293 275 } 294 276 … … 309 291 $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 ); 310 292 $this->assertEquals( '30-2', $found ); 311 312 $wp_rewrite->set_permalink_structure( '' );313 flush_rewrite_rules();314 293 } 315 294 … … 330 309 $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 ); 331 310 $this->assertEquals( '30', $found ); 332 333 $wp_rewrite->set_permalink_structure( '' );334 flush_rewrite_rules();335 311 } 336 312 … … 351 327 $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 ); 352 328 $this->assertEquals( '32', $found ); 353 354 $wp_rewrite->set_permalink_structure( '' );355 flush_rewrite_rules();356 329 } 357 330 } -
trunk/tests/phpunit/tests/query/results.php
r33706 r34802 684 684 */ 685 685 function test_child_post_in_hierarchical_post_type_with_default_permalinks() { 686 global $wp_rewrite;687 688 $old_permastruct = get_option( 'permalink_structure' );689 $wp_rewrite->set_permalink_structure( '' );690 $wp_rewrite->flush_rules();691 692 686 register_post_type( 'handbook', array( 'hierarchical' => true ) ); 693 687 … … 699 693 $result = $this->q->query( array( 'handbook' => 'contributing-to-the-wordpress-codex/getting-started', 'post_type' => 'handbook' ) ); 700 694 $this->assertCount( 1, $result ); 701 702 $wp_rewrite->set_permalink_structure( $old_permastruct );703 $wp_rewrite->flush_rules();704 695 } 705 696 -
trunk/tests/phpunit/tests/rewrite/numericSlugs.php
r32648 r34802 48 48 49 49 $this->assertQueryTrue( 'is_single', 'is_singular' ); 50 51 $wp_rewrite->set_permalink_structure('');52 50 } 53 51 … … 78 76 79 77 $this->assertEquals( '2015', url_to_postid( get_permalink( '2015' ) ) ); 80 81 $wp_rewrite->set_permalink_structure('');82 78 } 83 79 … … 99 95 100 96 $this->assertQueryTrue( 'is_single', 'is_singular' ); 101 102 $wp_rewrite->set_permalink_structure('');103 97 } 104 98 … … 118 112 119 113 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 120 121 $wp_rewrite->set_permalink_structure('');122 114 } 123 115 … … 140 132 141 133 $this->assertQueryTrue( 'is_single', 'is_singular' ); 142 143 $wp_rewrite->set_permalink_structure('');144 134 } 145 135 … … 160 150 161 151 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 162 163 $wp_rewrite->set_permalink_structure('');164 152 } 165 153 … … 182 170 183 171 $this->assertQueryTrue( 'is_single', 'is_singular' ); 184 185 $wp_rewrite->set_permalink_structure('');186 172 } 187 173 … … 202 188 203 189 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 204 205 $wp_rewrite->set_permalink_structure('');206 190 } 207 191 … … 223 207 224 208 $this->assertQueryTrue( 'is_single', 'is_singular' ); 225 226 $wp_rewrite->set_permalink_structure('');227 209 } 228 210 … … 242 224 243 225 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 244 245 $wp_rewrite->set_permalink_structure('');246 226 } 247 227 … … 263 243 264 244 $this->assertQueryTrue( 'is_single', 'is_singular' ); 265 266 $wp_rewrite->set_permalink_structure('');267 245 } 268 246 … … 282 260 283 261 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 284 285 $wp_rewrite->set_permalink_structure('');286 262 } 287 263 … … 304 280 305 281 $this->assertQueryTrue( 'is_single', 'is_singular' ); 306 307 $wp_rewrite->set_permalink_structure('');308 282 } 309 283 … … 324 298 325 299 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 326 327 $wp_rewrite->set_permalink_structure('');328 300 } 329 301 … … 345 317 346 318 $this->assertQueryTrue( 'is_single', 'is_singular' ); 347 348 $wp_rewrite->set_permalink_structure('');349 319 } 350 320 … … 364 334 365 335 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 366 367 $wp_rewrite->set_permalink_structure('');368 336 } 369 337 … … 390 358 $this->assertTrue( $q->is_day ); 391 359 $this->assertFalse( $q->is_single ); 392 393 $wp_rewrite->set_permalink_structure('');394 360 } 395 361 -
trunk/tests/phpunit/tests/rewrite/oldSlugRedirect.php
r34685 r34802 35 35 36 36 remove_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10 ); 37 38 global $wp_rewrite;39 40 $wp_rewrite->set_permalink_structure( '' );41 $wp_rewrite->init();42 37 } 43 38 -
trunk/tests/phpunit/tests/term/getTermLink.php
r33022 r34802 5 5 */ 6 6 class Tests_Term_GetTermLink extends WP_UnitTestCase { 7 private $permalink_structure;8 7 9 8 public function setUp() { 10 9 parent::setUp(); 11 10 12 // Assume no pretty permalinks.13 global $wp_rewrite;14 $this->permalink_structure = get_option( 'permalink_structure' );15 $wp_rewrite->set_permalink_structure( '' );16 $wp_rewrite->flush_rules();17 18 11 register_taxonomy( 'wptests_tax', 'post' ); 19 }20 21 public function tearDown() {22 global $wp_rewrite;23 $wp_rewrite->set_permalink_structure( $this->permalink_structure );24 $wp_rewrite->flush_rules();25 26 parent::tearDown();27 12 } 28 13 … … 102 87 public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() { 103 88 global $wp_rewrite; 104 $ permalink_structure = get_option( 'permalink_structure');89 $wp_rewrite->init(); 105 90 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 106 91 $wp_rewrite->flush_rules(); … … 126 111 127 112 $actual = get_term_link( $t2, 'wptests_tax2' ); 128 129 $wp_rewrite->set_permalink_structure( $permalink_structure );130 $wp_rewrite->flush_rules();131 113 132 114 $this->assertContains( '/foo/term1/term2/', $actual ); … … 160 142 $actual = get_term_link( $t2, 'wptests_tax2' ); 161 143 162 $wp_rewrite->set_permalink_structure( $permalink_structure );163 $wp_rewrite->flush_rules();164 165 144 $this->assertContains( '/foo/term2/', $actual ); 166 145 } -
trunk/tests/phpunit/tests/user/author.php
r34687 r34802 15 15 function setUp() { 16 16 parent::setUp(); 17 18 global $wp_rewrite;19 $this->permalink_structure = get_option( 'permalink_structure' );20 $wp_rewrite->set_permalink_structure( '' );21 $wp_rewrite->flush_rules();22 17 23 18 $this->author_id = $this->factory->user->create( array( … … 43 38 44 39 function tearDown() { 45 global $wp_rewrite;46 $wp_rewrite->set_permalink_structure( $this->permalink_structure );47 $wp_rewrite->flush_rules();48 49 40 wp_reset_postdata(); 50 41 parent::tearDown();
Note: See TracChangeset
for help on using the changeset viewer.