8000 Add test for exclude support for post terms · WP-API/WP-API@006c181 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Commit 006c181

Browse files
committed
Add test for exclude support for post terms
1 parent a872a86 commit 006c181

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test-rest-categories-controller.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,31 @@ public function test_get_items_custom_tax_post_args() {
367367
$this->assertEquals( 'Cape', $data[0]['name'] );
368368
}
369369

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+
370395
public function test_get_items_search_args() {
371396
$this->factory->category->create( array( 'name' => 'Apple' ) );
372397
$this->factory->category->create( array( 'name' => 'Banana' ) );

0 commit comments

Comments
 (0)
0