diff --git a/tests/phpunit/includes/testcase-canonical.php b/tests/phpunit/includes/testcase-canonical.php index 35a2d9728e..4fc7565b9b 100644 --- a/tests/phpunit/includes/testcase-canonical.php +++ b/tests/phpunit/includes/testcase-canonical.php @@ -16,17 +16,18 @@ class WP_Canonical_UnitTestCase extends WP_UnitTestCase { public $structure = '/%year%/%monthnum%/%day%/%postname%/'; public function setUp() { - global $wp_rewrite; - parent::setUp(); update_option( 'page_comments', true ); update_option( 'comments_per_page', 5 ); update_option( 'posts_per_page', 5 ); + global $wp_rewrite; $wp_rewrite->init(); $wp_rewrite->set_permalink_structure( $this->structure ); + create_initial_taxonomies(); + $wp_rewrite->flush_rules(); } diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index e660e958c1..ec4640f008 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -16,6 +16,8 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { protected $db_version; + public static $default_permalink_structure; + /** * @var WP_UnitTest_Factory */ @@ -70,6 +72,10 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { if ( is_multisite() ) { add_filter( 'pre_option_db_version', array( $this, 'db_version' ) ); } + + self::$default_permalink_structure = get_option( 'permalink_structure' ); + + $this->reset_permalinks(); } /** @@ -99,6 +105,8 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); $this->_restore_hooks(); wp_set_current_user( 0 ); + + $this->reset_permalinks( $restore = true ); } function clean_up_global_scope() { @@ -645,4 +653,30 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { public function db_version() { return $this->db_version; } + + /** + * Utility method that resets permalinks and flushes rewrites. + * + * Collects the current permalink structure and stores it in a class property for use + * by sub-classes. + * + * @since 4.4.0 + * + * @global WP_Rewrite $wp_rewrite + * + * @param bool $restore_default Optional. Whether to restore the default permalink structure. + * Default false. + */ + public function reset_permalinks( $restore_default = false ) { + global $wp_rewrite; + + if ( ! $restore_default ) { + $wp_rewrite->init(); + $wp_rewrite->set_permalink_structure( '' ); + } else { + $wp_rewrite->set_permalink_structure( self::$default_permalink_structure ); + } + + $wp_rewrite->flush_rules(); + } } diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index 5f1d6c4b25..1b3686ebcd 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -447,4 +447,4 @@ function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { } return $i; -} \ No newline at end of file +} diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 1336305c1c..56156acee9 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -253,7 +253,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { public function test_get_sample_permalink_should_return_pretty_permalink_for_posts_with_post_status_future() { global $wp_rewrite; - $old_permalink_structure = get_option( 'permalink_structure' ); $permalink_structure = '%postname%'; $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); flush_rewrite_rules(); @@ -265,9 +264,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $expected = trailingslashit( home_url( $permalink_structure ) ); $this->assertSame( $expected, $found[0] ); - - $wp_rewrite->set_permalink_structure( $old_permalink_structure ); - flush_rewrite_rules(); } /** @@ -275,11 +271,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { * @ticket 18306 */ public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() { - global $wp_rewrite; - $old_permalink_structure = get_option( 'permalink_structure' ); - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); $future_date = date( 'Y-m-d H:i:s', time() + 100 ); @@ -287,9 +278,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink_html( $p ); $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found ); - - $wp_rewrite->set_permalink_structure( $old_permalink_structure ); - flush_rewrite_rules(); } /** @@ -298,7 +286,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { */ public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_link_when_pretty_permalinks_are_enabled() { global $wp_rewrite; - $old_permalink_structure = get_option( 'permalink_structure' ); $permalink_structure = '%postname%'; $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); flush_rewrite_rules(); @@ -311,9 +298,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink_html( $p ); $post = get_post( $p ); $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found ); - - $wp_rewrite->set_permalink_structure( $old_permalink_structure ); - flush_rewrite_rules(); } /** @@ -322,7 +306,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { */ public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_link_when_changing_slug() { global $wp_rewrite; - $old_permalink_structure = get_option( 'permalink_structure' ); $permalink_structure = '%postname%'; $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); flush_rewrite_rules(); @@ -357,9 +340,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $preview_link = add_query_arg( 'preview', 'true', $preview_link ); $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message ); - - $wp_rewrite->set_permalink_structure( $old_permalink_structure ); - flush_rewrite_rules(); } /** @@ -377,9 +357,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '2015-2', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -397,9 +374,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '2015', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -417,9 +391,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '11-2', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -437,9 +408,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '13', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -457,9 +425,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '30-2', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -481,9 +446,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '30-3', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -501,9 +463,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '32', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -521,9 +480,6 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $found = get_sample_permalink( $p ); $this->assertEquals( '30', $found[1] ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } public function test_post_exists_should_match_title() { diff --git a/tests/phpunit/tests/comment/commentsTemplate.php b/tests/phpunit/tests/comment/commentsTemplate.php index b00256c3a7..a63f4b2fb2 100644 --- a/tests/phpunit/tests/comment/commentsTemplate.php +++ b/tests/phpunit/tests/comment/commentsTemplate.php @@ -6,13 +6,6 @@ * Testing items that are only testable by grabbing the markup of `comments_template()` from the output buffer. */ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { - public function setUp() { - parent::setUp(); - - global $wp_rewrite; - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); - } /** * @ticket 8071 diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php index 73b224e71e..37ace0ff50 100644 --- a/tests/phpunit/tests/feed/rss2.php +++ b/tests/phpunit/tests/feed/rss2.php @@ -9,8 +9,6 @@ * @group feed */ class Tests_Feed_RSS2 extends WP_UnitTestCase { - private $permalink_structure = ''; - static $user; static $posts; @@ -40,11 +38,6 @@ class Tests_Feed_RSS2 extends WP_UnitTestCase { } public function setUp() { - global $wp_rewrite; - $this->permalink_structure = get_option( 'permalink_structure' ); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - parent::setUp(); $this->post_count = get_option('posts_per_rss'); @@ -53,12 +46,6 @@ class Tests_Feed_RSS2 extends WP_UnitTestCase { update_option('use_smilies', false); } - public function tearDown() { - global $wp_rewrite; - $wp_rewrite->set_permalink_structure( $this->permalink_structure ); - $wp_rewrite->flush_rules(); - } - function do_rss2() { ob_start(); // nasty hack diff --git a/tests/phpunit/tests/general/paginateLinks.php b/tests/phpunit/tests/general/paginateLinks.php index ba0b77b87e..b2ad0a0426 100644 --- a/tests/phpunit/tests/general/paginateLinks.php +++ b/tests/phpunit/tests/general/paginateLinks.php @@ -3,21 +3,11 @@ class Tests_Paginate_Links extends WP_UnitTestCase { private $i18n_count = 0; - private $permalink_structure = ''; function setUp() { parent::setUp(); - global $wp_rewrite; $this->go_to( home_url( '/' ) ); - - $this->permalink_structure = $wp_rewrite->permalink_structure; - $wp_rewrite->set_permalink_structure( get_option( 'permalink_structure' ) ); - } - - function tearDown() { - global $wp_rewrite; - $wp_rewrite->set_permalink_structure( $this->permalink_structure ); } function test_defaults() { diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index f4b7011424..436fddd89d 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -40,10 +40,6 @@ class Tests_Link extends WP_UnitTestCase { $post_id = $this->factory->post->create(); $post_id2 = $this->factory->post->create(); - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - // Basic case $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); diff --git a/tests/phpunit/tests/link/getNextCommentsLink.php b/tests/phpunit/tests/link/getNextCommentsLink.php index 4b8162b416..4459fa6359 100644 --- a/tests/phpunit/tests/link/getNextCommentsLink.php +++ b/tests/phpunit/tests/link/getNextCommentsLink.php @@ -6,14 +6,6 @@ * @covers ::get_next_comments_link */ class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase { - public function setUp() { - global $wp_rewrite; - - parent::setUp(); - - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - } public function test_page_should_respect_value_of_cpage_query_var() { $p = $this->factory->post->create(); diff --git a/tests/phpunit/tests/link/getPostCommentsFeedLink.php b/tests/phpunit/tests/link/getPostCommentsFeedLink.php index 824a58c7d1..094d70787d 100644 --- a/tests/phpunit/tests/link/getPostCommentsFeedLink.php +++ b/tests/phpunit/tests/link/getPostCommentsFeedLink.php @@ -3,39 +3,8 @@ * @group link */ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { - private static $rewrite; - private static $permalink_structure; - - static function setUpBeforeClass() { - global $wp_rewrite; - - parent::setUpBeforeClass(); - - self::$rewrite = $wp_rewrite; - self::$permalink_structure = get_option( 'permalink_structure' ); - } - - public static function tearDownAfterClass() { - parent::tearDownAfterClass(); - - self::$rewrite->init(); - self::$rewrite->set_permalink_structure( self::$permalink_structure ); - self::$rewrite->flush_rules(); - } - - public function setUp() { - parent::setUp(); - self::$rewrite->init(); - } - - private function set_permalink_structure( $structure ) { - self::$rewrite->set_permalink_structure( $structure ); - self::$rewrite->flush_rules(); - } public function test_post_link() { - $this->set_permalink_structure( '' ); - $post_id = $this->factory->post->create(); $link = get_post_comments_feed_link( $post_id ); @@ -48,7 +17,10 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_post_pretty_link() { - $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + global $wp_rewrite; + $wp_rewrite->init(); + $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + $wp_rewrite->flush_rules(); $post_id = $this->factory->post->create(); @@ -59,8 +31,6 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_attachment_link() { - $this->set_permalink_structure( '' ); - $post_id = $this->factory->post->create(); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array( 'post_mime_type' => 'image/jpeg', @@ -77,7 +47,10 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_attachment_pretty_link() { - $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + global $wp_rewrite; + $wp_rewrite->init(); + $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + $wp_rewrite->flush_rules(); $post_id = $this->factory->post->create( array( 'post_status' => 'publish' @@ -97,7 +70,10 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_attachment_no_name_pretty_link() { - $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + global $wp_rewrite; + $wp_rewrite->init(); + $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + $wp_rewrite->flush_rules(); $post_id = $this->factory->post->create(); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array( @@ -112,8 +88,6 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_unattached_link() { - $this->set_permalink_structure( '' ); - $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( 'post_mime_type' => 'image/jpeg', 'post_type' => 'attachment' @@ -129,7 +103,10 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_unattached_pretty_link() { - $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + global $wp_rewrite; + $wp_rewrite->init(); + $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); + $wp_rewrite->flush_rules(); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( 'post_mime_type' => 'image/jpeg', diff --git a/tests/phpunit/tests/link/getPreviousCommentsLink.php b/tests/phpunit/tests/link/getPreviousCommentsLink.php index 4737bad2ab..4aa336dd9c 100644 --- a/tests/phpunit/tests/link/getPreviousCommentsLink.php +++ b/tests/phpunit/tests/link/getPreviousCommentsLink.php @@ -6,14 +6,6 @@ * @covers ::get_previous_comments_link */ class Tests_Link_GetPreviousCommentsLink extends WP_UnitTestCase { - public function setUp() { - global $wp_rewrite; - - parent::setUp(); - - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - } public function test_page_should_respect_value_of_cpage_query_var() { $p = $this->factory->post->create(); diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 403258e796..614f30586c 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -429,7 +429,7 @@ class Tests_Post extends WP_UnitTestCase { $post = get_post( $p ); - $wp_rewrite->set_permalink_structure( '' ); + $this->reset_permalinks(); $this->assertEquals( "$p-2", $post->post_name ); } @@ -525,8 +525,6 @@ class Tests_Post extends WP_UnitTestCase { // permalink should include the post ID at the end $this->assertEquals(get_option('siteurl').'/2007/10/31/'.$id.'/', $plink); - - $wp_rewrite->set_permalink_structure(''); } /** diff --git a/tests/phpunit/tests/post/wpUniquePostSlug.php b/tests/phpunit/tests/post/wpUniquePostSlug.php index a7c306065b..7d7755b346 100644 --- a/tests/phpunit/tests/post/wpUniquePostSlug.php +++ b/tests/phpunit/tests/post/wpUniquePostSlug.php @@ -181,9 +181,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); $this->assertEquals( '2015-2', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -203,9 +200,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); $this->assertEquals( '2015-2', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -224,9 +218,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); $this->assertEquals( '2015', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -245,9 +236,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 ); $this->assertEquals( '11-2', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -266,9 +254,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 ); $this->assertEquals( '11', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -287,9 +272,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 ); $this->assertEquals( '13', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -308,9 +290,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 ); $this->assertEquals( '30-2', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -329,9 +308,6 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 ); $this->assertEquals( '30', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } /** @@ -350,8 +326,5 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 ); $this->assertEquals( '32', $found ); - - $wp_rewrite->set_permalink_structure( '' ); - flush_rewrite_rules(); } } diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 8fed88ada1..e7a5354001 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -683,12 +683,6 @@ class Tests_Query_Results extends WP_UnitTestCase { * @ticket 29615 */ function test_child_post_in_hierarchical_post_type_with_default_permalinks() { - global $wp_rewrite; - - $old_permastruct = get_option( 'permalink_structure' ); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - register_post_type( 'handbook', array( 'hierarchical' => true ) ); $post_1 = $this->factory->post->create( array( 'post_title' => 'Contributing to the WordPress Codex', 'post_type' => 'handbook' ) ); @@ -698,9 +692,6 @@ class Tests_Query_Results extends WP_UnitTestCase { $result = $this->q->query( array( 'handbook' => 'contributing-to-the-wordpress-codex/getting-started', 'post_type' => 'handbook' ) ); $this->assertCount( 1, $result ); - - $wp_rewrite->set_permalink_structure( $old_permastruct ); - $wp_rewrite->flush_rules(); } function test_title() { diff --git a/tests/phpunit/tests/rewrite/numericSlugs.php b/tests/phpunit/tests/rewrite/numericSlugs.php index 769c65c482..5d8745904d 100644 --- a/tests/phpunit/tests/rewrite/numericSlugs.php +++ b/tests/phpunit/tests/rewrite/numericSlugs.php @@ -47,8 +47,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( '2015' ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_year_segment_collision_without_title() { @@ -77,8 +75,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ); $this->assertEquals( '2015', url_to_postid( get_permalink( '2015' ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_year_segment_collision_with_title() { @@ -98,8 +94,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_year_segment_collision_with_title() { @@ -117,8 +111,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_month_segment_collision_without_title() { @@ -139,8 +131,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_month_segment_collision_without_title() { @@ -159,8 +149,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_month_segment_collision_without_title_no_leading_zero() { @@ -181,8 +169,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_month_segment_collision_without_title_no_leading_zero() { @@ -201,8 +187,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_month_segment_collision_with_title() { @@ -222,8 +206,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_month_segment_collision_with_title() { @@ -241,8 +223,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_month_segment_collision_with_title_no_leading_zero() { @@ -262,8 +242,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_month_segment_collision_with_title_no_leading_zero() { @@ -281,8 +259,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_day_segment_collision_without_title() { @@ -303,8 +279,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_day_segment_collision_without_title() { @@ -323,8 +297,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_go_to_day_segment_collision_with_title() { @@ -344,8 +316,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->go_to( get_permalink( $id ) ); $this->assertQueryTrue( 'is_single', 'is_singular' ); - - $wp_rewrite->set_permalink_structure(''); } public function test_url_to_postid_day_segment_collision_with_title() { @@ -363,8 +333,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); - - $wp_rewrite->set_permalink_structure(''); } public function test_numeric_slug_permalink_conflicts_should_only_be_resolved_for_the_main_query() { @@ -389,8 +357,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { $this->assertTrue( $q->is_day ); $this->assertFalse( $q->is_single ); - - $wp_rewrite->set_permalink_structure(''); } public function test_month_slug_collision_should_resolve_to_date_archive_when_year_does_not_match_post_year() { diff --git a/tests/phpunit/tests/rewrite/oldSlugRedirect.php b/tests/phpunit/tests/rewrite/oldSlugRedirect.php index 5e8cdda2ab..8497c90c49 100644 --- a/tests/phpunit/tests/rewrite/oldSlugRedirect.php +++ b/tests/phpunit/tests/rewrite/oldSlugRedirect.php @@ -34,11 +34,6 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { $this->old_slug_redirect_url = null; remove_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10 ); - - global $wp_rewrite; - - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->init(); } public function test_old_slug_redirect() { diff --git a/tests/phpunit/tests/term/getTermLink.php b/tests/phpunit/tests/term/getTermLink.php index 748b8e48c9..932c638e59 100644 --- a/tests/phpunit/tests/term/getTermLink.php +++ b/tests/phpunit/tests/term/getTermLink.php @@ -4,28 +4,13 @@ * @group taxonomy */ class Tests_Term_GetTermLink extends WP_UnitTestCase { - private $permalink_structure; public function setUp() { parent::setUp(); - // Assume no pretty permalinks. - global $wp_rewrite; - $this->permalink_structure = get_option( 'permalink_structure' ); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - register_taxonomy( 'wptests_tax', 'post' ); } - public function tearDown() { - global $wp_rewrite; - $wp_rewrite->set_permalink_structure( $this->permalink_structure ); - $wp_rewrite->flush_rules(); - - parent::tearDown(); - } - public function test_integer_should_be_interpreted_as_term_id() { $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', @@ -101,7 +86,7 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() { global $wp_rewrite; - $permalink_structure = get_option( 'permalink_structure' ); + $wp_rewrite->init(); $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $wp_rewrite->flush_rules(); @@ -126,9 +111,6 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { $actual = get_term_link( $t2, 'wptests_tax2' ); - $wp_rewrite->set_permalink_structure( $permalink_structure ); - $wp_rewrite->flush_rules(); - $this->assertContains( '/foo/term1/term2/', $actual ); } @@ -159,9 +141,6 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { $actual = get_term_link( $t2, 'wptests_tax2' ); - $wp_rewrite->set_permalink_structure( $permalink_structure ); - $wp_rewrite->flush_rules(); - $this->assertContains( '/foo/term2/', $actual ); } } diff --git a/tests/phpunit/tests/user/author.php b/tests/phpunit/tests/user/author.php index 8a0b8e1f65..09dadf5743 100644 --- a/tests/phpunit/tests/user/author.php +++ b/tests/phpunit/tests/user/author.php @@ -15,11 +15,6 @@ class Tests_User_Author_Template extends WP_UnitTestCase { function setUp() { parent::setUp(); - global $wp_rewrite; - $this->permalink_structure = get_option( 'permalink_structure' ); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); - $this->author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'test_author', @@ -42,10 +37,6 @@ class Tests_User_Author_Template extends WP_UnitTestCase { } function tearDown() { - global $wp_rewrite; - $wp_rewrite->set_permalink_structure( $this->permalink_structure ); - $wp_rewrite->flush_rules(); - wp_reset_postdata(); parent::tearDown(); }