From 2c8def795d9001022ca26706534390135df3ca37 Mon Sep 17 00:00:00 2001 From: weryques Date: Tue, 29 May 2018 10:04:37 -0300 Subject: [PATCH] Fixes error on test api filters and changes the condition for delete a object to non strict --- ...class-tainacan-rest-filters-controller.php | 4 +- .../class-tainacan-collections.php | 2 +- .../repositories/class-tainacan-filters.php | 2 +- .../class-tainacan-taxonomies.php | 2 +- tests/test-api-filters.php | 38 ++++++++++++++++++- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php index adbe4a39b..ccabd6a5f 100644 --- a/src/api/endpoints/class-tainacan-rest-filters-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php @@ -142,7 +142,7 @@ class REST_Filters_Controller extends REST_Controller { $filter_obj->set_collection_id( $collection_id ); - if(!$body['field']){ + if(!isset($body['field'])){ throw new \InvalidArgumentException('You need provide a field id'); } @@ -150,7 +150,7 @@ class REST_Filters_Controller extends REST_Controller { } else { $filter_obj->set_collection_id( 'filter_in_repository' ); - if(!$body['field']){ + if(!isset($body['field'])){ throw new \InvalidArgumentException('You need provide a field id'); } diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index bbb0adb36..d93ec7ea0 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -272,7 +272,7 @@ class Collections extends Repository { * @return mixed|Collection */ public function delete( $args ) { - if ( ! empty( $args[1] ) && $args[1] === true ) { + if ( ! empty( $args[1] ) && $args[1] == true ) { $deleted = new Entities\Collection( wp_delete_post( $args[0], $args[1] ) ); if($deleted) { diff --git a/src/classes/repositories/class-tainacan-filters.php b/src/classes/repositories/class-tainacan-filters.php index e85b6d0b2..ece28938d 100644 --- a/src/classes/repositories/class-tainacan-filters.php +++ b/src/classes/repositories/class-tainacan-filters.php @@ -185,7 +185,7 @@ class Filters extends Repository { * */ public function delete($args){ - if(!empty($args[1]) && $args[1] === true){ + if(!empty($args[1]) && $args[1] == true){ $deleted = new Entities\Filter(wp_delete_post($args[0], $args[1])); diff --git a/src/classes/repositories/class-tainacan-taxonomies.php b/src/classes/repositories/class-tainacan-taxonomies.php index 83f9383e9..45844c37c 100644 --- a/src/classes/repositories/class-tainacan-taxonomies.php +++ b/src/classes/repositories/class-tainacan-taxonomies.php @@ -186,7 +186,7 @@ class Taxonomies extends Repository { $taxonomy_name = $args[1]; $permanently = $args[2]; - if($permanently === true){ + if($permanently == true){ $unregistered = unregister_taxonomy($taxonomy_name); if($unregistered instanceof \WP_Error){ diff --git a/tests/test-api-filters.php b/tests/test-api-filters.php index 15d9bc9a3..a0a4b57ee 100644 --- a/tests/test-api-filters.php +++ b/tests/test-api-filters.php @@ -257,13 +257,46 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase { } public function test_create_and_fetch_filter_in_repository(){ + + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'Collection filtered', + 'description' => 'Is filtered', + ), + true + ); + + $field = $this->tainacan_entity_factory->create_entity( + 'field', + array( + 'name' => 'Field filtered', + 'description' => 'Is filtered', + 'collection_id' => $collection->get_id(), + 'field_type' => 'Tainacan\Field_Types\Text' + ), + true + ); + + $field2 = $this->tainacan_entity_factory->create_entity( + 'field', + array( + 'name' => 'Field filtered', + 'description' => 'Is filtered', + 'collection_id' => 'default', + 'field_type' => 'Tainacan\Field_Types\Text' + ), + true + ); + $filter_attr = json_encode([ 'filter_type' => 'autocomplete', 'filter' => [ 'name' => '2x Filter', 'description' => 'Description of 2x Filter', 'status' => 'publish' - ] + ], + 'field' => $field2->get_id() ]); $filter_attr2 = json_encode([ @@ -272,7 +305,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase { 'name' => '4x Filter', 'description' => 'Description of 4x Filter', 'status' => 'publish' - ] + ], + 'field' => $field->get_id() ]); #### CREATE A FILTER IN REPOSITORY ####