From 224e9ecc17e6a2703f7142d2b4cd7e517b90142d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 19 Aug 2022 16:13:38 +0000 Subject: [PATCH] Tests: Assign created fixtures to the dedicated class properties in some test classes. This affects: * `WP_Test_REST_Categories_Controller` * `WP_Test_REST_Comments_Controller` * `WP_Test_REST_Tags_Controller` and brings consistency with: * `WP_Test_REST_Posts_Controller` * `WP_Test_REST_Users_Controller` These test classes were previously updated to improve performance by creating less fixtures and reusing them where possible. While the pagination tests for categories and comments still passed due to enough items being created, the pagination test for tags did not work as expected and did not perform any assertions due to trying to iterate over an empty array of results. This is now corrected by assigning the properties as intended and adding more assertions to the affected test. Follow-up to [46657]. Props johnregan3, costdev, johnbillion. See #54662. git-svn-id: https://develop.svn.wordpress.org/trunk@53909 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/rest-api/rest-categories-controller.php | 2 +- tests/phpunit/tests/rest-api/rest-comments-controller.php | 2 +- tests/phpunit/tests/rest-api/rest-tags-controller.php | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index 01bddd3738..ef72b6f8fa 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -38,7 +38,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas // Set up categories for pagination tests. for ( $i = 0; $i < self::$total_categories - 1; $i++ ) { - $category_ids[] = $factory->category->create( + self::$category_ids[] = $factory->category->create( array( 'name' => "Category {$i}", ) diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 99986a8037..bf5d112d4e 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -117,7 +117,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase // Set up comments for pagination tests. for ( $i = 0; $i < self::$total_comments - 1; $i++ ) { - $comment_ids[] = $factory->comment->create( + self::$comment_ids[] = $factory->comment->create( array( 'comment_content' => "Comment {$i}", 'comment_post_ID' => self::$post_id, diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index b9ac20cf71..788d6901f2 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -54,7 +54,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { // Set up tags for pagination tests. for ( $i = 0; $i < self::$total_tags; $i++ ) { - $tag_ids[] = $factory->tag->create( + self::$tag_ids[] = $factory->tag->create( array( 'name' => "Tag {$i}", ) @@ -412,6 +412,8 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $response = rest_get_server()->dispatch( $request ); $tags = $response->get_data(); + $this->assertNotEmpty( $tags ); + $i = 0; foreach ( $tags as $tag ) { $this->assertSame( $tag['name'], "Tag {$i}" ); @@ -426,6 +428,8 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $response = rest_get_server()->dispatch( $request ); $tags = $response->get_data(); + $this->assertNotEmpty( $tags ); + foreach ( $tags as $tag ) { $this->assertSame( $tag['name'], "Tag {$i}" ); $i++;