2018-01-10 15:56:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
|
|
|
class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|
|
|
|
|
|
|
public function test_create_filter(){
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadata = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadata',
|
|
|
|
array(
|
|
|
|
'name' => 'Metadata filtered',
|
|
|
|
'description' => 'Is filtered'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$request_body = json_encode(
|
|
|
|
array(
|
|
|
|
'collection_id' => $collection->get_id(),
|
|
|
|
'metadata_id' => $metadata->get_id(),
|
2018-01-12 16:17:52 +00:00
|
|
|
'filter_type' => 'range',
|
2018-01-10 15:56:55 +00:00
|
|
|
'filter' => [
|
|
|
|
'name' => 'Filter name',
|
|
|
|
'description' => 'This is RANGE!',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$request = new \WP_REST_Request('POST', $this->namespace . '/filters');
|
|
|
|
|
|
|
|
$request->set_body($request_body);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
2018-01-12 16:17:52 +00:00
|
|
|
$this->assertEquals('Tainacan\Filter_Types\Range', $data['filter_type']);
|
2018-01-10 15:56:55 +00:00
|
|
|
$this->assertEquals('Filter name', $data['name']);
|
|
|
|
}
|
|
|
|
|
2018-01-12 16:17:52 +00:00
|
|
|
public function test_delete_or_trash_filter(){
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
2018-01-15 11:15:21 +00:00
|
|
|
'description' => 'Is filtered',
|
2018-01-12 16:17:52 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadata = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadata',
|
|
|
|
array(
|
|
|
|
'name' => 'Metadata filtered',
|
2018-01-15 11:15:21 +00:00
|
|
|
'description' => 'Is filtered',
|
2018-01-12 16:17:52 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$filter_type = $this->tainacan_filter_factory->create_filter('range');
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'metadata' => $metadata,
|
2018-01-15 11:15:21 +00:00
|
|
|
'filter_type' => $filter_type,
|
2018-01-12 16:17:52 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$is_permanently = json_encode([
|
2018-01-15 11:15:21 +00:00
|
|
|
'is_permanently' => false
|
2018-01-12 16:17:52 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'DELETE', $this->namespace . '/filters/' . $filter->get_id());
|
|
|
|
|
|
|
|
$request->set_body($is_permanently);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals('filtro', $data['name']);
|
|
|
|
|
|
|
|
$filter_status = get_post($filter->get_id())->post_status;
|
|
|
|
|
|
|
|
$this->assertEquals('trash', $filter_status);
|
|
|
|
|
2018-01-15 11:15:21 +00:00
|
|
|
##### DELETE #####
|
2018-01-12 16:17:52 +00:00
|
|
|
|
|
|
|
$is_permanently = json_encode([
|
2018-01-15 11:15:21 +00:00
|
|
|
'is_permanently' => true
|
2018-01-12 16:17:52 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'DELETE', $this->namespace . '/filters/' . $filter->get_id());
|
|
|
|
|
|
|
|
$request->set_body($is_permanently);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals('filtro', $data['name']);
|
|
|
|
$this->assertNull(get_post($filter->get_id()));
|
|
|
|
}
|
|
|
|
|
2018-01-16 13:41:24 +00:00
|
|
|
public function test_update_filter(){
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadata = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadata',
|
|
|
|
array(
|
|
|
|
'name' => 'Metadata filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$filter_type = $this->tainacan_filter_factory->create_filter('range');
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
|
|
|
'metadata' => $metadata,
|
|
|
|
'filter_type' => $filter_type,
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$new_attributes = json_encode([
|
|
|
|
'name' => 'Faceta',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'PATCH', $this->namespace . '/filters/' . $filter->get_id()
|
|
|
|
);
|
|
|
|
|
|
|
|
$request->set_body($new_attributes);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertNotEquals('filtro', $data['name']);
|
|
|
|
$this->assertEquals('Faceta', $data['name']);
|
|
|
|
}
|
2018-01-10 15:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|