From 20d9fa42fede58c7ae18eaa24fde0e226f072642 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 25 Nov 2024 11:46:55 +0100 Subject: [PATCH] Add test coverage --- .../tests/rest-api/rest-tags-controller.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index 843faadea3992..cd593578a9836 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -482,6 +482,55 @@ public function test_get_items_custom_tax_post_args() { $this->assertSame( 'Cape', $data[0]['name'] ); } + /** + * @ticket 62500 + */ + public function test_get_items_custom_tax_without_post_arg_respects_tax_query_args() { + register_taxonomy( + 'batman', + 'post', + array( + 'show_in_rest' => true, + 'sort' => true, + 'args' => array( + 'order' => 'DESC', + 'orderby' => 'name', + ), + ) + ); + $controller = new WP_REST_Terms_Controller( 'batman' ); + $controller->register_routes(); + $term1 = self::factory()->term->create( + array( + 'name' => 'Cycle', + 'taxonomy' => 'batman', + ) + ); + $term2 = self::factory()->term->create( + array( + 'name' => 'Pod', + 'taxonomy' => 'batman', + ) + ); + $term3 = self::factory()->term->create( + array( + 'name' => 'Cave', + 'taxonomy' => 'batman', + ) + ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/batman' ); + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 200, $response->get_status() ); + + $data = $response->get_data(); + $this->assertCount( 3, $data ); + $this->assertSame( + array( 'Pod', 'Cycle', 'Cave' ), + array_column( $data, 'name' ) + ); + } + public function test_get_items_search_args() { $tag1 = self::factory()->tag->create( array( 'name' => 'Apple' ) ); $tag2 = self::factory()->tag->create( array( 'name' => 'Banana' ) );