From 9fa63c38ef2e03f271bd00b2d7bbfe0746f36241 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 21 Dec 2020 03:15:59 +0000 Subject: [PATCH] Tests: Use shared post fixture in comment template tests. See #51802. git-svn-id: https://develop.svn.wordpress.org/trunk@49848 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/comment/template.php | 25 +++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/comment/template.php b/tests/phpunit/tests/comment/template.php index 68f98b5c8b..22283a5c2e 100644 --- a/tests/phpunit/tests/comment/template.php +++ b/tests/phpunit/tests/comment/template.php @@ -3,9 +3,24 @@ * @group comment */ class Tests_Comment_Template extends WP_UnitTestCase { + /** + * Shared post ID. + * + * @var int + */ + public static $post_id; + + /** + * Set up shared fixtures. + * + * @param WP_UnitTest_Factory $factory Unit test factory. + */ + function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$post_id = self::factory()->post->create(); + } function test_get_comments_number() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $this->assertSame( 0, get_comments_number( 0 ) ); $this->assertSame( '0', get_comments_number( $post_id ) ); @@ -18,7 +33,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { } function test_get_comments_number_without_arg() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $permalink = get_permalink( $post_id ); $this->go_to( $permalink ); @@ -34,7 +49,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { * @ticket 48772 */ function test_get_comments_number_text_with_post_id() { - $post_id = $this->factory->post->create(); + $post_id = self::$post_id; $this->factory->comment->create_post_comments( $post_id, 6 ); $comments_number_text = get_comments_number_text( false, false, false, $post_id ); @@ -53,7 +68,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { * @ticket 13651 */ function test_get_comments_number_text_declension_with_default_args() { - $post_id = $this->factory->post->create(); + $post_id = self::$post_id; $permalink = get_permalink( $post_id ); $this->go_to( $permalink ); @@ -76,7 +91,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { * @dataProvider data_get_comments_number_text_declension */ function test_get_comments_number_text_declension_with_custom_args( $number, $input, $output ) { - $post_id = $this->factory->post->create(); + $post_id = self::$post_id; $permalink = get_permalink( $post_id ); $this->factory->comment->create_post_comments( $post_id, $number );