diff --git tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php
index b9ac20cf71..8f9272790e 100644
|
|
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
54 | 54 | |
55 | 55 | // Set up tags for pagination tests. |
56 | 56 | for ( $i = 0; $i < self::$total_tags; $i++ ) { |
57 | | $tag_ids[] = $factory->tag->create( |
| 57 | self::$tag_ids[] = $factory->tag->create( |
58 | 58 | array( |
59 | 59 | 'name' => "Tag {$i}", |
60 | 60 | ) |
… |
… |
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
400 | 400 | } |
401 | 401 | |
402 | 402 | public function test_get_terms_post_args_paging() { |
403 | | $post_id = $this->factory->post->create(); |
| 403 | // Numbers based on self::$total_tags being 30. |
| 404 | $per_page = 7; |
| 405 | $last_page = 5; |
| 406 | $tags_on_last_page = 2; |
404 | 407 | |
| 408 | // Create post and assign all Tags to it. |
| 409 | $post_id = $this->factory->post->create(); |
405 | 410 | wp_set_object_terms( $post_id, self::$tag_ids, 'post_tag' ); |
406 | 411 | |
407 | 412 | $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); |
408 | 413 | $request->set_param( 'post', $post_id ); |
409 | | $request->set_param( 'page', 1 ); |
410 | | $request->set_param( 'per_page', 15 ); |
411 | | $request->set_param( 'orderby', 'id' ); |
412 | | $response = rest_get_server()->dispatch( $request ); |
413 | | $tags = $response->get_data(); |
414 | | |
415 | | $i = 0; |
416 | | foreach ( $tags as $tag ) { |
417 | | $this->assertSame( $tag['name'], "Tag {$i}" ); |
418 | | $i++; |
419 | | } |
| 414 | $request->set_param( 'per_page', $per_page ); |
420 | 415 | |
421 | | $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); |
422 | | $request->set_param( 'post', $post_id ); |
423 | | $request->set_param( 'page', 2 ); |
424 | | $request->set_param( 'per_page', 15 ); |
425 | | $request->set_param( 'orderby', 'id' ); |
426 | | $response = rest_get_server()->dispatch( $request ); |
427 | | $tags = $response->get_data(); |
| 416 | // Get first page of results. |
| 417 | $request->set_param( 'page', 1 ); |
| 418 | $response = rest_get_server()->dispatch( $request ); |
| 419 | $found_tags = $response->get_data(); |
| 420 | $this->assertSame( $per_page, count( $found_tags ) ); |
428 | 421 | |
429 | | foreach ( $tags as $tag ) { |
430 | | $this->assertSame( $tag['name'], "Tag {$i}" ); |
431 | | $i++; |
432 | | } |
| 422 | // Get last page of results (by modifying the last Request). |
| 423 | $request->set_param( 'page', $last_page ); |
| 424 | $response = rest_get_server()->dispatch( $request ); |
| 425 | $found_tags = $response->get_data(); |
| 426 | $this->assertSame( $tags_on_last_page, count( $found_tags ) ); |
433 | 427 | } |
434 | 428 | |
435 | 429 | public function test_get_items_post_empty() { |