Fixes error on test api filters and changes the condition for delete a object to non strict

This commit is contained in:
weryques 2018-05-29 10:04:37 -03:00 committed by Mateus Machado Luna
parent 2dc057698e
commit 348f429d73
5 changed files with 41 additions and 7 deletions

View File

@ -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');
}

View File

@ -281,7 +281,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) {

View File

@ -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]));

View File

@ -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){

View File

@ -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 ####