@@ -440,6 +440,7 @@ public function test_get_terms_pagination_headers() {
440
440
$ headers = $ response ->get_headers ();
441
441
$ this ->assertEquals ( 50 , $ headers ['X-WP-Total ' ] );
442
442
$ this ->assertEquals ( 5 , $ headers ['X-WP-TotalPages ' ] );
443
+ $ this ->assertCount ( 10 , $ response ->get_data () );
443
444
$ next_link = add_query_arg ( array (
444
445
'page ' => 2 ,
445
446
), rest_url ( '/wp/v2/categories ' ) );
@@ -455,6 +456,7 @@ public function test_get_terms_pagination_headers() {
455
456
$ headers = $ response ->get_headers ();
456
457
$ this ->assertEquals ( 51 , $ headers ['X-WP-Total ' ] );
457
458
$ this ->assertEquals ( 6 , $ headers ['X-WP-TotalPages ' ] );
459
+ $ this ->assertCount ( 10 , $ response ->get_data () );
458
460
$ prev_link = add_query_arg ( array (
459
461
'page ' => 2 ,
460
462
), rest_url ( '/wp/v2/categories ' ) );
@@ -470,6 +472,7 @@ public function test_get_terms_pagination_headers() {
470
472
$ headers = $ response ->get_headers ();
471
473
$ this ->assertEquals ( 51 , $ headers ['X-WP-Total ' ] );
472
474
$ this ->assertEquals ( 6 , $ headers ['X-WP-TotalPages ' ] );
475
+ $ this ->assertCount ( 1 , $ response ->get_data () );
473
476
$ prev_link = add_query_arg ( array (
474
477
'page ' => 5 ,
475
478
), rest_url ( '/wp/v2/categories ' ) );
@@ -482,13 +485,39 @@ public function test_get_terms_pagination_headers() {
482
485
$ headers = $ response ->get_headers ();
483
486
$ this ->assertEquals ( 51 , $ headers ['X-WP-Total ' ] );
484
487
$ this ->assertEquals ( 6 , $ headers ['X-WP-TotalPages ' ] );
488
+ $ this ->assertCount ( 0 , $ response ->get_data () );
485
489
$ prev_link = add_query_arg ( array (
486
490
'page ' => 6 ,
487
491
), rest_url ( '/wp/v2/categories ' ) );
488
492
$ this ->assertContains ( '< ' . $ prev_link . '>; rel="prev" ' , $ headers ['Link ' ] );
489
493
$ this ->assertFalse ( stripos ( $ headers ['Link ' ], 'rel="next" ' ) );
490
494
}
491
495
496
+ public function test_get_items_per_page_exceeds_number_of_items () {
497
+ // Start of the index + Uncategorized default term
498
+ for ( $ i = 0 ; $ i < 17 ; $ i ++ ) {
499
+ $ this ->factory ->category ->create ( array (
500
+ 'name ' => "Category {$ i }" ,
501
+ ) );
502
+ }
503
+ $ request = new WP_REST_Request ( 'GET ' , '/wp/v2/categories ' );
504
+ $ request ->set_param ( 'page ' , 1 );
505
+ $ request ->set_param ( 'per_page ' , 100 );
506
+ $ response = $ this ->server ->dispatch ( $ request );
507
+ $ headers = $ response ->get_headers ();
508
+ $ this ->assertEquals ( 18 , $ headers ['X-WP-Total ' ] );
509
+ $ this -
8DBD
>assertEquals ( 1 , $ headers ['X-WP-TotalPages ' ] );
510
+ $ this ->assertCount ( 18 , $ response ->get_data () );
511
+ $ request = new WP_REST_Request ( 'GET ' , '/wp/v2/categories ' );
512
+ $ request ->set_param ( 'page ' , 2 );
513
+ $ request ->set_param ( 'per_page ' , 100 );
514
+ $ response = $ this ->server ->dispatch ( $ request );
515
+ $ headers = $ response ->get_headers ();
516
+ $ this ->assertEquals ( 18 , $ headers ['X-WP-Total ' ] );
517
+ $ this ->assertEquals ( 1 , $ headers ['X-WP-TotalPages ' ] );
518
+ $ this ->assertCount ( 0 , $ response ->get_data () );
519
+ }
520
+
492
521
public function test_get_item () {
493
522
$ request = new WP_REST_Request ( 'GET ' , '/wp/v2/categories/1 ' );
494
523
$ response = $ this ->server ->dispatch ( $ request );
0 commit comments