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
This commit is contained in:
Sergey Biryukov 2022-08-19 16:13:38 +00:00
parent 74fa60b30a
commit 224e9ecc17
3 changed files with 7 additions and 3 deletions

View File

@ -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}",
)

View File

@ -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,

View File

@ -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++;