From e366584fae14e758eab10c3a8f46245e6db63da6 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 24 Sep 2015 04:31:58 +0000 Subject: [PATCH] Unit Tests: after [34477], make `Tests_Link_GetPostCommentsFeedLink` more respectable. See #33693. git-svn-id: https://develop.svn.wordpress.org/trunk@34479 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/link/getPostCommentsFeedLink.php | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) 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',