@@ -367,6 +367,31 @@ public function test_get_items_custom_tax_post_args() {
367
367
$ this ->assertEquals ( 'Cape ' , $ data [0 ]['name ' ] );
368
368
}
369
369
370
+ public function test_get_items_post_with_exclude () {
371
+ $ include = array ();
372
+ $ include [] = $ this ->factory ->category ->create ( array ( 'name ' => 'Apple ' ) );
373
+ $ include [] = $ this ->factory ->category ->create ( array ( 'name ' => 'Orange ' ) );
374
+ $ include [] = $ this ->factory ->category ->create ( array ( 'name ' => 'Banana ' ) );
375
+
376
+ // Ensure our query doesn't include this category
377
+ $ bad_milhouse = $ this ->factory ->category ->create ( array ( 'name ' => 'Grapefruit ' ) );
378
+ $ exclude = array ( $ bad_milhouse );
379
+
380
+ $ post_id = $ this ->factory ->post ->create ();
381
+ $ post_cats_meow = array_merge ( $ include , $ exclude );
382
+ wp_set_object_terms ( $ post_id , $ post_cats_meow , 'category ' );
383
+
384
+ $ request = new WP_REST_Request ( 'GET ' , '/wp/v2/categories ' );
385
+ $ request ->set_param ( 'post ' , $ post_id );
386
+ $ request ->set_param ( 'exclude ' , $ exclude );
387
+ $ response = $ this ->server ->dispatch ( $ request );
388
+ $ this ->assertEquals ( 200 , $ response ->get_status () );
389
+
390
+ $ data = $ response ->get_data ();
391
+ $ response_ids = wp_list_pluck ( $ data , 'id ' );
392
+ $ this ->assertEqualSets ( $ include , $ response_ids , 'Response should not contain excluded categories ' );
393
+ }
394
+
370
395
public function test_get_items_search_args () {
371
396
$ this ->factory ->category ->create ( array ( 'name ' => 'Apple ' ) );
372
397
$ this ->factory ->category ->create ( array ( 'name ' => 'Banana ' ) );
0 commit comments