diff --git a/tests/phpunit/tests/link/getPostCommentsFeedLink.php b/tests/phpunit/tests/link/getPostCommentsFeedLink.php index ff424cbc18..824a58c7d1 100644 --- a/tests/phpunit/tests/link/getPostCommentsFeedLink.php +++ b/tests/phpunit/tests/link/getPostCommentsFeedLink.php @@ -3,12 +3,38 @@ * @group link */ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { - public function test_post_link() { + private static $rewrite; + private static $permalink_structure; + + static function setUpBeforeClass() { global $wp_rewrite; - $permalink_structure = get_option( 'permalink_structure' ); - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); + + 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(); @@ -22,11 +48,7 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_post_pretty_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(); + $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $post_id = $this->factory->post->create(); @@ -37,10 +59,7 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_attachment_link() { - global $wp_rewrite; - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); + $this->set_permalink_structure( '' ); $post_id = $this->factory->post->create(); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array( @@ -58,10 +77,7 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_attachment_pretty_link() { - global $wp_rewrite; - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); - $wp_rewrite->flush_rules(); + $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $post_id = $this->factory->post->create( array( 'post_status' => 'publish' @@ -81,10 +97,7 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_attachment_no_name_pretty_link() { - global $wp_rewrite; - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); - $wp_rewrite->flush_rules(); + $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $post_id = $this->factory->post->create(); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array( @@ -94,15 +107,12 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { $link = get_post_comments_feed_link( $attachment_id ); $expected = get_permalink( $post_id ) . 'attachment/' . $attachment_id . '/feed/'; - + $this->assertEquals( $expected, $link ); } public function test_unattached_link() { - global $wp_rewrite; - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '' ); - $wp_rewrite->flush_rules(); + $this->set_permalink_structure( '' ); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( 'post_mime_type' => 'image/jpeg', @@ -119,10 +129,7 @@ class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { } public function test_unattached_pretty_link() { - global $wp_rewrite; - $wp_rewrite->init(); - $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); - $wp_rewrite->flush_rules(); + $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array( 'post_mime_type' => 'image/jpeg',