From 5b5eba1b543428f23d83b8653773d99f31a111d4 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Thu, 22 Oct 2020 00:17:10 +0000 Subject: [PATCH] Tests: Use shared fixtures in XML-RPC new comment unit tests. See #51344. git-svn-id: https://develop.svn.wordpress.org/trunk@49268 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase-xmlrpc.php | 2 +- tests/phpunit/tests/xmlrpc/wp/newComment.php | 29 ++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/includes/testcase-xmlrpc.php b/tests/phpunit/includes/testcase-xmlrpc.php index f529dfa93a..a2341db1c4 100644 --- a/tests/phpunit/includes/testcase-xmlrpc.php +++ b/tests/phpunit/includes/testcase-xmlrpc.php @@ -22,7 +22,7 @@ class WP_XMLRPC_UnitTestCase extends WP_UnitTestCase { parent::tearDown(); } - protected function make_user_by_role( $role ) { + protected static function make_user_by_role( $role ) { return self::factory()->user->create( array( 'user_login' => $role, diff --git a/tests/phpunit/tests/xmlrpc/wp/newComment.php b/tests/phpunit/tests/xmlrpc/wp/newComment.php index 82dcc5b9a0..5534099097 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newComment.php +++ b/tests/phpunit/tests/xmlrpc/wp/newComment.php @@ -5,16 +5,25 @@ */ class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase { - function test_valid_comment() { - $this->make_user_by_role( 'administrator' ); - $post = self::factory()->post->create_and_get(); + /** + * Post object for shared fixture. + * + * @var WP_Post + */ + public static $post; + public static function wpSetUpBeforeClass( $factory ) { + self::make_user_by_role( 'administrator' ); + self::$post = $factory->post->create_and_get(); + } + + function test_valid_comment() { $result = $this->myxmlrpcserver->wp_newComment( array( 1, 'administrator', 'administrator', - $post->ID, + self::$post->ID, array( 'content' => rand_str( 100 ), ), @@ -25,15 +34,12 @@ class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase { } function test_empty_comment() { - $this->make_user_by_role( 'administrator' ); - $post = self::factory()->post->create_and_get(); - $result = $this->myxmlrpcserver->wp_newComment( array( 1, 'administrator', 'administrator', - $post->ID, + self::$post->ID, array( 'content' => '', ), @@ -45,7 +51,6 @@ class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase { } function test_new_comment_post_closed() { - $this->make_user_by_role( 'administrator' ); $post = self::factory()->post->create_and_get( array( 'comment_status' => 'closed', @@ -71,14 +76,11 @@ class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase { } function test_new_comment_duplicated() { - $this->make_user_by_role( 'administrator' ); - $post = self::factory()->post->create_and_get(); - $comment_args = array( 1, 'administrator', 'administrator', - $post->ID, + self::$post->ID, array( 'content' => rand_str( 100 ), ), @@ -94,5 +96,4 @@ class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase { $this->assertIXRError( $result ); $this->assertSame( 403, $result->code ); } - }