From 453cc4b8a1485074ec60cf0f9b1ca347dbce7dbb Mon Sep 17 00:00:00 2001 From: leogermani Date: Wed, 11 Dec 2019 19:11:21 -0300 Subject: [PATCH] fix capablities list in roles retunr #274 --- .../class-tainacan-rest-roles-controller.php | 2 +- tests/test-api-roles.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/api/endpoints/class-tainacan-rest-roles-controller.php b/src/api/endpoints/class-tainacan-rest-roles-controller.php index 7e92eb7bb..306b609a5 100644 --- a/src/api/endpoints/class-tainacan-rest-roles-controller.php +++ b/src/api/endpoints/class-tainacan-rest-roles-controller.php @@ -350,7 +350,7 @@ class REST_Roles_Controller extends REST_Controller { */ public function _prepare_item_for_response( $slug, $name, $caps, $request ) { $caps = array_filter($caps, function($el) { - return in_array($el, \tainacan_roles()->get_all_caps_slugs()); + return in_array( \tainacan_roles()->get_cap_generic_name($el), \tainacan_roles()->get_all_caps_slugs() ); }, ARRAY_FILTER_USE_KEY); $return = [ diff --git a/tests/test-api-roles.php b/tests/test-api-roles.php index 60c3a9cb2..3a17cee6c 100644 --- a/tests/test-api-roles.php +++ b/tests/test-api-roles.php @@ -382,7 +382,7 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { ]); $create = $this->server->dispatch($request); -//var_dump($create); + $this->assertEquals( 201, $create->get_status() ); $request = new \WP_REST_Request('GET', $this->namespace . '/roles'); @@ -410,7 +410,8 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { 'capabilities' => [ 'tnc_rep_edit_collections' => true, 'tnc_rep_delete_collections' => true, - 'tnc_rep_edit_taxonomies' => true + 'tnc_rep_edit_taxonomies' => true, + 'manage_tainacan_collection_123' => true ] ]); @@ -432,6 +433,8 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertTrue($data['capabilities']['tnc_rep_delete_collections']); $this->assertArrayHasKey('tnc_rep_edit_taxonomies', $data['capabilities']); $this->assertTrue($data['capabilities']['tnc_rep_edit_taxonomies']); + $this->assertArrayHasKey('manage_tainacan_collection_123', $data['capabilities']); + $this->assertTrue($data['capabilities']['manage_tainacan_collection_123']); @@ -444,7 +447,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { 'capabilities' => [ 'tnc_rep_edit_collections' => true, 'tnc_rep_delete_collections' => true, + 'tnc_col_12_edit_items' => true, 'tnc_rep_edit_metadata' => true // replaced tnc_rep_edit_taxonomies by tnc_rep_edit_metadata + // removed manage_tainacan_collection_123 ] ] ); @@ -468,8 +473,11 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertTrue($data['capabilities']['tnc_rep_delete_collections']); $this->assertArrayHasKey('tnc_rep_edit_metadata', $data['capabilities']); $this->assertTrue($data['capabilities']['tnc_rep_edit_metadata']); + $this->assertArrayHasKey('tnc_col_12_edit_items', $data['capabilities']); + $this->assertTrue($data['capabilities']['tnc_col_12_edit_items']); $this->assertArrayNotHasKey('tnc_rep_edit_taxonomies', $data['capabilities']); + $this->assertArrayNotHasKey('manage_tainacan_collection_123', $data['capabilities']);