Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function create_initial_rest_routes() {
$font_collections_controller->register_routes();

// Abilities.
$abilities_categories_controller = new WP_REST_Abilities_V1_Categories_Controller();
$abilities_categories_controller = new WP_REST_Abilities_V1_Abilities_Categories_Controller();
$abilities_categories_controller->register_routes();
$abilities_run_controller = new WP_REST_Abilities_V1_Run_Controller();
$abilities_run_controller->register_routes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @see WP_REST_Controller
*/
class WP_REST_Abilities_V1_Categories_Controller extends WP_REST_Controller {
class WP_REST_Abilities_V1_Abilities_Categories_Controller extends WP_REST_Controller {

/**
* REST API namespace.
Expand All @@ -32,7 +32,7 @@ class WP_REST_Abilities_V1_Categories_Controller extends WP_REST_Controller {
* @since 6.9.0
* @var string
*/
protected $rest_base = 'categories';
protected $rest_base = 'abilities-categories';

/**
* Registers the routes for ability categories.
Expand Down Expand Up @@ -212,7 +212,7 @@ public function prepare_item_for_response( $category, $request ) {
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
),
'abilities' => array(
'href' => rest_url( sprintf( '%s/abilities?category=%s', $this->namespace, $category->get_slug() ) ),
'href' => rest_url( sprintf( '%s/abilities?ability_category=%s', $this->namespace, $category->get_slug() ) ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this parameter already get changed in another PR? I'm not seeing this change in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay as category param here, unless you also want to change the filtering in the list controller.

),
);

Expand Down
2 changes: 1 addition & 1 deletion src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-families-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-faces-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-collections-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-categories-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-abilities-categories-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php';
require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php';
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/rest-api/rest-schema-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public function test_expected_routes_in_schema() {
'/wp/v2/font-families/(?P<font_family_id>[\d]+)/font-faces/(?P<id>[\d]+)',
'/wp/v2/font-families/(?P<id>[\d]+)',
'/wp-abilities/v1',
'/wp-abilities/v1/categories',
'/wp-abilities/v1/categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)',
'/wp-abilities/v1/abilities-categories',
'/wp-abilities/v1/abilities-categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)',
'/wp-abilities/v1/abilities/(?P<name>[a-zA-Z0-9\-\/]+?)/run',
'/wp-abilities/v1/abilities/(?P<name>[a-zA-Z0-9\-\/]+)',
'/wp-abilities/v1/abilities',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*
* @group abilities-api
* @group rest-api
* @group abilities-categories
*/
class Tests_REST_API_WpRestAbilitiesV1CategoriesController extends WP_UnitTestCase {
class Tests_REST_API_WpRestAbilitiesV1AblitiesCategoriesController extends WP_UnitTestCase {

/**
* REST Server instance.
Expand Down Expand Up @@ -142,7 +143,7 @@ public function register_test_ability_categories(): void {
* @ticket 64098
*/
public function test_get_items(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
$response = $this->server->dispatch( $request );

$this->assertEquals( 200, $response->get_status() );
Expand All @@ -165,7 +166,7 @@ public function test_get_items(): void {
* @ticket 64098
*/
public function test_get_item(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
$response = $this->server->dispatch( $request );

$this->assertEquals( 200, $response->get_status() );
Expand All @@ -183,7 +184,7 @@ public function test_get_item(): void {
* @ticket 64098
*/
public function test_get_item_with_meta(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-communication' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-communication' );
$response = $this->server->dispatch( $request );

$this->assertEquals( 200, $response->get_status() );
Expand All @@ -201,7 +202,7 @@ public function test_get_item_with_meta(): void {
* @ticket 64098
*/
public function test_get_item_with_selected_fields(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
$request->set_param( '_fields', 'slug,label' );
$response = $this->server->dispatch( $request );
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
Expand All @@ -224,7 +225,7 @@ public function test_get_item_with_selected_fields(): void {
* @expectedIncorrectUsage WP_Ability_Categories_Registry::get_registered
*/
public function test_get_item_not_found(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/non-existent' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/non-existent' );
$response = $this->server->dispatch( $request );

$this->assertEquals( 404, $response->get_status() );
Expand All @@ -241,7 +242,7 @@ public function test_get_item_not_found(): void {
public function test_get_items_permission_denied(): void {
wp_set_current_user( 0 );

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

$this->assertEquals( 401, $response->get_status() );
Expand All @@ -255,7 +256,7 @@ public function test_get_items_permission_denied(): void {
public function test_get_item_permission_denied(): void {
wp_set_current_user( 0 );

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

$this->assertEquals( 401, $response->get_status() );
Expand All @@ -267,7 +268,7 @@ public function test_get_item_permission_denied(): void {
* @ticket 64098
*/
public function test_pagination_headers(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
$request->set_param( 'per_page', 10 );
$response = $this->server->dispatch( $request );

Expand All @@ -288,7 +289,7 @@ public function test_pagination_headers(): void {
* @ticket 64098
*/
public function test_head_request(): void {
$request = new WP_REST_Request( 'HEAD', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'HEAD', '/wp-abilities/v1/abilities-categories' );
$response = $this->server->dispatch( $request );

$data = $response->get_data();
Expand All @@ -305,7 +306,7 @@ public function test_head_request(): void {
* @ticket 64098
*/
public function test_pagination_links(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
$request->set_param( 'per_page', 10 );
$request->set_param( 'page', 1 );
$response = $this->server->dispatch( $request );
Expand Down Expand Up @@ -343,7 +344,7 @@ public function test_pagination_links(): void {
* @ticket 64098
*/
public function test_collection_params(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
$request->set_param( 'per_page', 5 );
$response = $this->server->dispatch( $request );

Expand All @@ -356,7 +357,7 @@ public function test_collection_params(): void {
$data = $response->get_data();
$this->assertCount( 5, $data );

$page1_request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
$page1_request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
$page1_request->set_param( 'per_page', 5 );
$page1_request->set_param( 'page', 1 );
$page1_response = $this->server->dispatch( $page1_request );
Expand All @@ -372,7 +373,7 @@ public function test_collection_params(): void {
* @ticket 64098
*/
public function test_ability_category_response_links(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
$response = $this->server->dispatch( $request );

$links = $response->get_links();
Expand All @@ -381,13 +382,13 @@ public function test_ability_category_response_links(): void {
$this->assertArrayHasKey( 'abilities', $links );

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

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

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

/**
Expand All @@ -396,7 +397,7 @@ public function test_ability_category_response_links(): void {
* @ticket 64098
*/
public function test_context_parameter(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
$request->set_param( 'context', 'view' );
$response = $this->server->dispatch( $request );

Expand All @@ -417,7 +418,7 @@ public function test_context_parameter(): void {
* @ticket 64098
*/
public function test_get_schema(): void {
$request = new WP_REST_Request( 'OPTIONS', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'OPTIONS', '/wp-abilities/v1/abilities-categories' );
$response = $this->server->dispatch( $request );
$data = $response->get_data();

Expand Down Expand Up @@ -448,7 +449,7 @@ public function test_get_schema(): void {
* @ticket 64098
*/
public function test_ability_category_slug_with_valid_format(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/test-data-retrieval' );
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
Expand Down Expand Up @@ -479,7 +480,7 @@ public function data_invalid_ability_category_slugs_provider(): array {
* @param string $slug Invalid ability category slug to test.
*/
public function test_ability_category_slug_with_invalid_format( string $slug ): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/' . $slug );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories/' . $slug );
$response = $this->server->dispatch( $request );

$this->assertContains( $response->get_status(), array( 400, 404 ) );
Expand Down Expand Up @@ -512,7 +513,7 @@ public function data_invalid_pagination_params_provider(): array {
* @param array<string, mixed> $params Invalid pagination parameters.
*/
public function test_invalid_pagination_parameters( array $params ): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities-categories' );
$request->set_query_params( $params );

$response = $this->server->dispatch( $request );
Expand Down
6 changes: 3 additions & 3 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12423,7 +12423,7 @@ mockedApiResponse.Schema = {
]
}
},
"/wp-abilities/v1/categories": {
"/wp-abilities/v1/abilities-categories": {
"namespace": "wp-abilities/v1",
"methods": [
"GET"
Expand Down Expand Up @@ -12466,12 +12466,12 @@ mockedApiResponse.Schema = {
"_links": {
"self": [
{
"href": "http://example.org/index.php?rest_route=/wp-abilities/v1/categories"
"href": "http://example.org/index.php?rest_route=/wp-abilities/v1/abilities-categories"
}
]
}
},
"/wp-abilities/v1/categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)": {
"/wp-abilities/v1/abilities-categories/(?P<slug>[a-z0-9]+(?:-[a-z0-9]+)*)": {
"namespace": "wp-abilities/v1",
"methods": [
"GET"
Expand Down
Loading