Skip to content

Commit 7092cde

Browse files
committed
1 parent aae3ac3 commit 7092cde

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

src/wp-includes/rest-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function create_initial_rest_routes() {
485485
$font_collections_controller->register_routes();
486486

487487
// Abilities.
488-
$abilities_categories_controller = new WP_REST_Abilities_V1_Categories_Controller();
488+
$abilities_categories_controller = new WP_REST_Abilities_V1_Abilities_Categories_Controller();
489489
$abilities_categories_controller->register_routes();
490490
$abilities_run_controller = new WP_REST_Abilities_V1_Run_Controller();
491491
$abilities_run_controller->register_routes();

src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-categories-controller.php renamed to src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-abilities-categories-controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @see WP_REST_Controller
1818
*/
19-
class WP_REST_Abilities_V1_Categories_Controller extends WP_REST_Controller {
19+
class WP_REST_Abilities_V1_Abilities_Categories_Controller extends WP_REST_Controller {
2020

2121
/**
2222
* REST API namespace.
@@ -32,7 +32,7 @@ class WP_REST_Abilities_V1_Categories_Controller extends WP_REST_Controller {
3232
* @since 6.9.0
3333
* @var string
3434
*/
35-
protected $rest_base = 'categories';
35+
protected $rest_base = 'abilities-categories';
3636

3737
/**
3838
* Registers the routes for ability categories.
@@ -212,7 +212,7 @@ public function prepare_item_for_response( $category, $request ) {
212212
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
213213
),
214214
'abilities' => array(
215-
'href' => rest_url( sprintf( '%s/abilities?category=%s', $this->namespace, $category->get_slug() ) ),
215+
'href' => rest_url( sprintf( '%s/abilities?ability_category=%s', $this->namespace, $category->get_slug() ) ),
216216
),
217217
);
218218

src/wp-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-families-controller.php';
337337
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-faces-controller.php';
338338
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-collections-controller.php';
339-
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-categories-controller.php';
339+
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-abilities-categories-controller.php';
340340
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php';
341341
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php';
342342
require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php';

tests/phpunit/tests/rest-api/rest-schema-setup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ public function test_expected_routes_in_schema() {
204204
'/wp/v2/font-families/(?P<font_family_id>[\d]+)/font-faces/(?P<id>[\d]+)',
205205
'/wp/v2/font-families/(?P<id>[\d]+)',
206206
'/wp-abilities/v1',
207-
'/wp-abilities/v1/categories',
208-
'/wp-abilities/v1/categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)',
207+
'/wp-abilities/v1/abilities-categories',
208+
'/wp-abilities/v1/abilities-categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)',
209209
'/wp-abilities/v1/abilities/(?P<name>[a-zA-Z0-9\-\/]+?)/run',
210210
'/wp-abilities/v1/abilities/(?P<name>[a-zA-Z0-9\-\/]+)',
211211
'/wp-abilities/v1/abilities',

tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php renamed to tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesAbilitiesController.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*
88
* @group abilities-api
99
* @group rest-api
10+
* @group abilities-categories
1011
*/
11-
class Tests_REST_API_WpRestAbilitiesV1CategoriesController extends WP_UnitTestCase {
12+
class Tests_REST_API_WpRestAbilitiesV1AblitiesCategoriesController extends WP_UnitTestCase {
1213

1314
/**
1415
* REST Server instance.
@@ -138,7 +139,7 @@ public function register_test_ability_categories(): void {
138139
* @ticket 64098
139140
*/
140141
public function test_get_items(): void {
141-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
142+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
142143
$response = $this->server->dispatch( $request );
143144

144145
$this->assertEquals( 200, $response->get_status() );
@@ -161,7 +162,7 @@ public function test_get_items(): void {
161162
* @ticket 64098
162163
*/
163164
public function test_get_item(): void {
164-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
165+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
165166
$response = $this->server->dispatch( $request );
166167

167168
$this->assertEquals( 200, $response->get_status() );
@@ -179,7 +180,7 @@ public function test_get_item(): void {
179180
* @ticket 64098
180181
*/
181182
public function test_get_item_with_meta(): void {
182-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-communication' );
183+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-communication' );
183184
$response = $this->server->dispatch( $request );
184185

185186
$this->assertEquals( 200, $response->get_status() );
@@ -197,7 +198,7 @@ public function test_get_item_with_meta(): void {
197198
* @ticket 64098
198199
*/
199200
public function test_get_item_with_selected_fields(): void {
200-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
201+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
201202
$request->set_param( '_fields', 'slug,label' );
202203
$response = $this->server->dispatch( $request );
203204
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
@@ -220,7 +221,7 @@ public function test_get_item_with_selected_fields(): void {
220221
* @expectedIncorrectUsage WP_Ability_Categories_Registry::get_registered
221222
*/
222223
public function test_get_item_not_found(): void {
223-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/non-existent' );
224+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/non-existent' );
224225
$response = $this->server->dispatch( $request );
225226

226227
$this->assertEquals( 404, $response->get_status() );
@@ -237,7 +238,7 @@ public function test_get_item_not_found(): void {
237238
public function test_get_items_permission_denied(): void {
238239
wp_set_current_user( 0 );
239240

240-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
241+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
241242
$response = $this->server->dispatch( $request );
242243

243244
$this->assertEquals( 401, $response->get_status() );
@@ -251,7 +252,7 @@ public function test_get_items_permission_denied(): void {
251252
public function test_get_item_permission_denied(): void {
252253
wp_set_current_user( 0 );
253254

254-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
255+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
255256
$response = $this->server->dispatch( $request );
256257

257258
$this->assertEquals( 401, $response->get_status() );
@@ -263,7 +264,7 @@ public function test_get_item_permission_denied(): void {
263264
* @ticket 64098
264265
*/
265266
public function test_pagination_headers(): void {
266-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
267+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
267268
$request->set_param( 'per_page', 10 );
268269
$response = $this->server->dispatch( $request );
269270

@@ -284,7 +285,7 @@ public function test_pagination_headers(): void {
284285
* @ticket 64098
285286
*/
286287
public function test_head_request(): void {
287-
$request = new WP_REST_Request( 'HEAD', '/wp-abilities/v1/categories' );
288+
$request = new WP_REST_Request( 'HEAD', '/wp-abilities/v1/abilities-categories' );
288289
$response = $this->server->dispatch( $request );
289290

290291
$data = $response->get_data();
@@ -301,7 +302,7 @@ public function test_head_request(): void {
301302
* @ticket 64098
302303
*/
303304
public function test_pagination_links(): void {
304-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
305+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
305306
$request->set_param( 'per_page', 10 );
306307
$request->set_param( 'page', 1 );
307308
$response = $this->server->dispatch( $request );
@@ -339,7 +340,7 @@ public function test_pagination_links(): void {
339340
* @ticket 64098
340341
*/
341342
public function test_collection_params(): void {
342-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
343+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
343344
$request->set_param( 'per_page', 5 );
344345
$response = $this->server->dispatch( $request );
345346

@@ -352,7 +353,7 @@ public function test_collection_params(): void {
352353
$data = $response->get_data();
353354
$this->assertCount( 5, $data );
354355

355-
$page1_request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
356+
$page1_request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
356357
$page1_request->set_param( 'per_page', 5 );
357358
$page1_request->set_param( 'page', 1 );
358359
$page1_response = $this->server->dispatch( $page1_request );
@@ -368,7 +369,7 @@ public function test_collection_params(): void {
368369
* @ticket 64098
369370
*/
370371
public function test_ability_category_response_links(): void {
371-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
372+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
372373
$response = $this->server->dispatch( $request );
373374

374375
$links = $response->get_links();
@@ -377,13 +378,13 @@ public function test_ability_category_response_links(): void {
377378
$this->assertArrayHasKey( 'abilities', $links );
378379

379380
$self_link = $links['self'][0]['href'];
380-
$this->assertStringContainsString( '/wp-abilities/v1/categories/test-data-retrieval', $self_link );
381+
$this->assertStringContainsString( '/wp-abilities/v1/abilities-categories/test-data-retrieval', $self_link );
381382

382383
$collection_link = $links['collection'][0]['href'];
383-
$this->assertStringContainsString( '/wp-abilities/v1/categories', $collection_link );
384+
$this->assertStringContainsString( '/wp-abilities/v1/abilities-categories', $collection_link );
384385

385386
$abilities_link = $links['abilities'][0]['href'];
386-
$this->assertStringContainsString( '/wp-abilities/v1/abilities?category=test-data-retrieval', $abilities_link );
387+
$this->assertStringContainsString( '/wp-abilities/v1/abilities?ability_category=test-data-retrieval', $abilities_link );
387388
}
388389

389390
/**
@@ -392,7 +393,7 @@ public function test_ability_category_response_links(): void {
392393
* @ticket 64098
393394
*/
394395
public function test_context_parameter(): void {
395-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
396+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
396397
$request->set_param( 'context', 'view' );
397398
$response = $this->server->dispatch( $request );
398399

@@ -413,7 +414,7 @@ public function test_context_parameter(): void {
413414
* @ticket 64098
414415
*/
415416
public function test_get_schema(): void {
416-
$request = new WP_REST_Request( 'OPTIONS', '/wp-abilities/v1/categories' );
417+
$request = new WP_REST_Request( 'OPTIONS', '/wp-abilities/v1/abilities-categories' );
417418
$response = $this->server->dispatch( $request );
418419
$data = $response->get_data();
419420

@@ -444,7 +445,7 @@ public function test_get_schema(): void {
444445
* @ticket 64098
445446
*/
446447
public function test_ability_category_slug_with_valid_format(): void {
447-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
448+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
448449
$response = $this->server->dispatch( $request );
449450
$this->assertEquals( 200, $response->get_status() );
450451
}
@@ -475,7 +476,7 @@ public function data_invalid_ability_category_slugs_provider(): array {
475476
* @param string $slug Invalid ability category slug to test.
476477
*/
477478
public function test_ability_category_slug_with_invalid_format( string $slug ): void {
478-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/' . $slug );
479+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/' . $slug );
479480
$response = $this->server->dispatch( $request );
480481

481482
$this->assertContains( $response->get_status(), array( 400, 404 ) );
@@ -508,7 +509,7 @@ public function data_invalid_pagination_params_provider(): array {
508509
* @param array<string, mixed> $params Invalid pagination parameters.
509510
*/
510511
public function test_invalid_pagination_parameters( array $params ): void {
511-
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
512+
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
512513
$request->set_query_params( $params );
513514

514515
$response = $this->server->dispatch( $request );

tests/qunit/fixtures/wp-api-generated.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13513,7 +13513,7 @@ mockedApiResponse.Schema = {
1351313513
]
1351413514
}
1351513515
},
13516-
"/wp-abilities/v1/categories": {
13516+
"/wp-abilities/v1/abilities-categories": {
1351713517
"namespace": "wp-abilities/v1",
1351813518
"methods": [
1351913519
"GET"
@@ -13556,12 +13556,12 @@ mockedApiResponse.Schema = {
1355613556
"_links": {
1355713557
"self": [
1355813558
{
13559-
"href": "http://example.org/index.php?rest_route=/wp-abilities/v1/categories"
13559+
"href": "http://example.org/index.php?rest_route=/wp-abilities/v1/abilities-categories"
1356013560
}
1356113561
]
1356213562
}
1356313563
},
13564-
"/wp-abilities/v1/categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)": {
13564+
"/wp-abilities/v1/abilities-categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)": {
1356513565
"namespace": "wp-abilities/v1",
1356613566
"methods": [
1356713567
"GET"

0 commit comments

Comments
 (0)