Delete filter

This commit is contained in:
weryques 2018-01-15 09:15:21 -02:00
parent 43b15b55ba
commit a2d6c38c13
3 changed files with 19 additions and 11 deletions

View File

@ -147,7 +147,8 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller {
}
public function delete_item_permissions_check( $request ) {
return parent::delete_item_permissions_check( $request ); // TODO: Change the autogenerated stub
$filter = $this->filter_repository->fetch($request['filter_id']);
return $this->filter_repository->can_delete($filter);
}
}

View File

@ -139,9 +139,9 @@ class Filters extends Repository {
update_post_meta($id, $prop, $metadata->get_mapped_property($prop));
} elseif ($mapped['map'] == 'meta_multi') {
$values = $metadata->get_mapped_property($prop);
delete_post_meta($id, $prop);
if (is_array($values)){
foreach ($values as $value){
add_post_meta($id, $prop, $value);
@ -154,8 +154,17 @@ class Filters extends Repository {
return new Entities\Filter($metadata->WP_Post);
}*/
/**
* @param array $args
* @return Entities\Filter
*
*/
public function delete($args){
if(!empty($args[1]) && $args[1]['is_permanently'] === true){
return new Entities\Filter(wp_delete_post($args[0], $args[1]['is_permanently']));
}
return new Entities\Filter(wp_trash_post($args[0]));
}
public function update($object){

View File

@ -51,7 +51,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'collection',
array(
'name' => 'Collection filtered',
'description' => 'Is filtered'
'description' => 'Is filtered',
),
true
);
@ -60,7 +60,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'metadata',
array(
'name' => 'Metadata filtered',
'description' => 'Is filtered'
'description' => 'Is filtered',
)
);
@ -73,13 +73,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata,
'filter_type' => $filter_type
'filter_type' => $filter_type,
),
true
);
$is_permanently = json_encode([
'is_permanently' => true
'is_permanently' => false
]);
$request = new \WP_REST_Request(
@ -91,18 +91,16 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$data = $response->get_data();
$this->markTestIncomplete('Incomplete');
$this->assertEquals('filtro', $data['name']);
$filter_status = get_post($filter->get_id())->post_status;
$this->assertEquals('trash', $filter_status);
##### TRASH #####
##### DELETE #####
$is_permanently = json_encode([
'is_permanently' => false
'is_permanently' => true
]);
$request = new \WP_REST_Request(