2018-01-10 15:56:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
2018-01-19 22:39:32 +00:00
|
|
|
/**
|
2019-10-23 20:28:48 +00:00
|
|
|
* @group api
|
2018-01-19 22:39:32 +00:00
|
|
|
*/
|
2018-01-10 15:56:55 +00:00
|
|
|
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'
|
|
|
|
),
|
2018-01-31 13:06:46 +00:00
|
|
|
true,
|
2018-01-10 15:56:55 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-01-10 15:56:55 +00:00
|
|
|
array(
|
2018-01-31 13:06:46 +00:00
|
|
|
'name' => 'Metadata filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
'collection_id' => $collection->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
2019-10-11 19:53:35 +00:00
|
|
|
'status' => 'publish'
|
2018-01-31 13:06:46 +00:00
|
|
|
),
|
|
|
|
true,
|
|
|
|
true
|
2018-01-10 15:56:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$request_body = json_encode(
|
|
|
|
array(
|
2019-10-23 20:28:48 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
2018-01-10 15:56:55 +00:00
|
|
|
'filter' => [
|
|
|
|
'name' => 'Filter name',
|
2018-03-01 19:32:42 +00:00
|
|
|
'description' => 'This is CUSTOM INTERVAL!',
|
2018-01-10 15:56:55 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$request = new \WP_REST_Request('POST', $this->namespace . '/collection/' . $collection->get_id() . '/metadatum/' . $metadatum->get_id(). '/filters');
|
2018-01-10 15:56:55 +00:00
|
|
|
|
|
|
|
$request->set_body($request_body);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
2018-03-05 18:41:32 +00:00
|
|
|
$this->assertTrue(is_array($data) && array_key_exists('filter_type', $data), sprintf('cannot create a custom interval, response: %s', print_r($data, true)));
|
2019-10-23 20:28:48 +00:00
|
|
|
$this->assertEquals('Tainacan\Filter_Types\Numeric_Interval', $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
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-01-12 16:17:52 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'Metadatum filtered',
|
2018-01-15 11:15:21 +00:00
|
|
|
'description' => 'Is filtered',
|
2019-06-26 15:34:43 +00:00
|
|
|
'collection_id' => $collection->get_id(),
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
2019-10-11 19:53:35 +00:00
|
|
|
'status' => 'publish'
|
2019-06-26 15:34:43 +00:00
|
|
|
),
|
|
|
|
true
|
2018-01-12 16:17:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
2019-06-26 15:34:43 +00:00
|
|
|
'metadatum_id' => $metadatum->get_id(),
|
2019-10-23 20:28:48 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
2018-01-12 16:17:52 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-03-23 13:03:39 +00:00
|
|
|
$permanently = [ 'permanently' => false ];
|
2018-01-12 16:17:52 +00:00
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'DELETE', $this->namespace . '/filters/' . $filter->get_id());
|
|
|
|
|
2018-03-23 13:03:39 +00:00
|
|
|
$request->set_query_params($permanently);
|
2018-01-12 16:17:52 +00:00
|
|
|
|
|
|
|
$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
|
|
|
|
2018-03-23 13:03:39 +00:00
|
|
|
$permanently = [ 'permanently' => true ];
|
2018-01-12 16:17:52 +00:00
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'DELETE', $this->namespace . '/filters/' . $filter->get_id());
|
|
|
|
|
2018-03-23 13:03:39 +00:00
|
|
|
$request->set_query_params($permanently);
|
2018-01-12 16:17:52 +00:00
|
|
|
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-01-16 13:41:24 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'Metadatum filtered',
|
2018-01-16 13:41:24 +00:00
|
|
|
'description' => 'Is filtered',
|
2019-10-11 19:53:35 +00:00
|
|
|
'status' => 'publish',
|
2019-06-26 15:34:43 +00:00
|
|
|
'collection_id' => $collection->get_id(),
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
|
|
|
),
|
|
|
|
true
|
2018-01-16 13:41:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
2019-06-26 15:34:43 +00:00
|
|
|
'metadatum_id' => $metadatum->get_id(),
|
2019-10-23 20:28:48 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
2018-01-16 13:41:24 +00:00
|
|
|
),
|
|
|
|
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-17 17:48:44 +00:00
|
|
|
|
|
|
|
public function test_fetch_filters(){
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-01-17 17:48:44 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'Metadatum filtered',
|
2018-01-17 17:48:44 +00:00
|
|
|
'description' => 'Is filtered',
|
2019-10-11 19:53:35 +00:00
|
|
|
'status' => 'publish',
|
2018-03-13 16:47:31 +00:00
|
|
|
'collection_id' => $collection->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric'
|
2018-03-13 16:47:31 +00:00
|
|
|
),
|
|
|
|
true
|
2018-01-17 17:48:44 +00:00
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-01-17 17:48:44 +00:00
|
|
|
array(
|
|
|
|
'name' => 'Other filtered',
|
|
|
|
'description' => 'Is filtered',
|
2018-03-13 16:47:31 +00:00
|
|
|
'collection_id' => $collection->get_id(),
|
2019-10-11 19:53:35 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
|
|
|
'status' => 'publish'
|
2018-03-13 16:47:31 +00:00
|
|
|
),
|
|
|
|
true
|
2018-01-17 17:48:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum' => $metadatum,
|
2019-10-23 20:28:48 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
2018-01-17 17:48:44 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filter2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'filtro2',
|
|
|
|
'collection' => $collection,
|
|
|
|
'description' => 'descricao',
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum' => $metadatum2,
|
2019-10-23 20:28:48 +00:00
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
2018-01-17 17:48:44 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-03-13 13:01:53 +00:00
|
|
|
$request = new \WP_REST_Request('GET', $this->namespace . '/collection/'. $collection->get_id() .'/filters');
|
2018-01-17 17:48:44 +00:00
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$first_filter = $data[0];
|
|
|
|
$second_filter = $data[1];
|
|
|
|
|
2018-04-09 15:45:49 +00:00
|
|
|
$names = [$first_filter['name'], $second_filter['name']];
|
|
|
|
|
|
|
|
$this->assertContains($filter->get_name(), $names);
|
|
|
|
$this->assertContains($filter2->get_name(), $names);
|
2018-01-18 13:23:16 +00:00
|
|
|
|
2018-01-18 13:38:31 +00:00
|
|
|
#### FETCH A FILTER ####
|
2018-01-18 13:23:16 +00:00
|
|
|
|
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'GET', $this->namespace . '/filters/' . $filter->get_id()
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals('filtro', $data['name']);
|
2018-01-17 17:48:44 +00:00
|
|
|
}
|
2018-03-13 13:01:53 +00:00
|
|
|
|
|
|
|
public function test_create_and_fetch_filter_in_repository(){
|
2018-05-29 13:04:37 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Collection filtered',
|
|
|
|
'description' => 'Is filtered',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-05-29 13:04:37 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'Metadatum filtered',
|
2018-05-29 13:04:37 +00:00
|
|
|
'description' => 'Is filtered',
|
|
|
|
'collection_id' => $collection->get_id(),
|
2019-10-11 19:53:35 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish'
|
2018-05-29 13:04:37 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-05-29 13:04:37 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'Metadatum filtered',
|
2018-05-29 13:04:37 +00:00
|
|
|
'description' => 'Is filtered',
|
|
|
|
'collection_id' => 'default',
|
2019-10-11 19:53:35 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
'status' => 'publish'
|
2018-05-29 13:04:37 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-03-13 13:01:53 +00:00
|
|
|
$filter_attr = json_encode([
|
2019-10-16 20:09:29 +00:00
|
|
|
'filter_type' => '\Tainacan\Filter_Types\Autocomplete',
|
2018-03-13 13:01:53 +00:00
|
|
|
'filter' => [
|
|
|
|
'name' => '2x Filter',
|
|
|
|
'description' => 'Description of 2x Filter',
|
|
|
|
'status' => 'publish'
|
2018-05-29 13:04:37 +00:00
|
|
|
],
|
2019-06-03 14:41:44 +00:00
|
|
|
'metadatum_id' => $metadatum2->get_id()
|
2018-03-13 13:01:53 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$filter_attr2 = json_encode([
|
2019-10-16 20:09:29 +00:00
|
|
|
'filter_type' => '\Tainacan\Filter_Types\Autocomplete',
|
2018-03-13 13:01:53 +00:00
|
|
|
'filter' => [
|
|
|
|
'name' => '4x Filter',
|
|
|
|
'description' => 'Description of 4x Filter',
|
|
|
|
'status' => 'publish'
|
2018-05-29 13:04:37 +00:00
|
|
|
],
|
2019-06-03 14:41:44 +00:00
|
|
|
'metadatum_id' => $metadatum->get_id()
|
2018-03-13 13:01:53 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
#### CREATE A FILTER IN REPOSITORY ####
|
|
|
|
|
|
|
|
$request_create = new \WP_REST_Request('POST', $this->namespace . '/filters');
|
|
|
|
$request_create->set_body($filter_attr);
|
|
|
|
|
|
|
|
$response_create = $this->server->dispatch($request_create);
|
|
|
|
|
|
|
|
$data = $response_create->get_data();
|
|
|
|
|
2019-09-30 21:00:44 +00:00
|
|
|
$this->assertEquals('default', $data['collection_id']);
|
2018-03-13 13:01:53 +00:00
|
|
|
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
#### CREATE A FILTER IN COLLECTION WITHOUT METADATUM ASSOCIATION ####
|
2018-03-13 13:01:53 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity('collection', [], true);
|
|
|
|
|
|
|
|
$request_create2 = new \WP_REST_Request('POST', $this->namespace . '/collection/'. $collection->get_id() .'/filters');
|
|
|
|
$request_create2->set_body($filter_attr2);
|
|
|
|
|
|
|
|
$response_create2 = $this->server->dispatch($request_create2);
|
|
|
|
|
|
|
|
$data2 = $response_create2->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals($collection->get_id(), $data2['collection_id']);
|
|
|
|
|
|
|
|
#### GET A FILTER FROM A REPOSITORY CONTEXT ####
|
|
|
|
|
|
|
|
$request_get1 = new \WP_REST_Request('GET', $this->namespace . '/filters');
|
|
|
|
|
|
|
|
$response_get1 = $this->server->dispatch($request_get1);
|
|
|
|
|
|
|
|
$data3 = $response_get1->get_data();
|
|
|
|
|
|
|
|
$this->assertCount(1, $data3);
|
|
|
|
$this->assertEquals('2x Filter', $data3[0]['name']);
|
|
|
|
|
|
|
|
#### GET A FILTER FROM A COLLECTION CONTEXT ####
|
|
|
|
|
|
|
|
$request_get2 = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collection->get_id() . '/filters');
|
|
|
|
|
|
|
|
$response_get2 = $this->server->dispatch($request_get2);
|
|
|
|
|
|
|
|
$data4 = $response_get2->get_data();
|
|
|
|
|
2018-11-14 16:32:59 +00:00
|
|
|
$this->assertCount(2, $data4);
|
|
|
|
//$this->assertEquals('4x Filter', $data4[0]['name']);
|
2018-03-13 13:01:53 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
public function test_return_filter_type_options_in_get_item() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$collection1 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test_col',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$meta = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'number',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection1,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$filter_numeric = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'numeric',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection1,
|
|
|
|
'metadatum' => $meta,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
|
|
|
'filter_type_options' => [
|
|
|
|
'step' => 3,
|
|
|
|
]
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'GET',
|
|
|
|
$this->namespace . '/filters/' . $filter_numeric->get_id()
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals($filter_numeric->get_id(), $data['id']);
|
|
|
|
$this->assertEquals('numeric', $data['name']);
|
|
|
|
$this->assertEquals(3, $data['filter_type_options']['step']);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
public function test_return_filter_type_options_in_get_items() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$collection1 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test_col',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$meta = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'number',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection1,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$filter_numeric = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'numeric',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection1,
|
|
|
|
'metadatum' => $meta,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
|
|
|
'filter_type_options' => [
|
|
|
|
'step' => 3,
|
|
|
|
]
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'GET',
|
|
|
|
$this->namespace . '/collection/' . $collection1->get_id() . '/filters'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
//var_dump($data, $this->namespace . '/collection/' . $collection2->get_id() . '/metadata/');
|
|
|
|
foreach ($data as $d) {
|
|
|
|
if ($d['id'] == $filter_numeric->get_id()) {
|
|
|
|
$meta = $d;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$this->assertEquals($filter_numeric->get_id(), $meta['id']);
|
|
|
|
$this->assertEquals('numeric', $meta['name']);
|
|
|
|
$this->assertEquals(3, $meta['filter_type_options']['step']);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
public function test_return_filter_type_options_in_get_item_default_value() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$collection1 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test_col',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$meta = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'number',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection1,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$filter_numeric = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'numeric',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection1,
|
|
|
|
'metadatum' => $meta,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Numeric_Interval',
|
|
|
|
// 'filter_type_options' => [
|
|
|
|
// 'step' => 3,
|
|
|
|
// ]
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'GET',
|
|
|
|
$this->namespace . '/filters/' . $filter_numeric->get_id()
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
|
|
|
|
$this->assertEquals($filter_numeric->get_id(), $data['id']);
|
|
|
|
$this->assertEquals('numeric', $data['name']);
|
|
|
|
$this->assertEquals(1, $data['filter_type_object']['options']['step']);
|
|
|
|
$this->assertEquals(1, $data['filter_type_options']['step']);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
public function test_return_metadata_type_options_inside_metadatum_property() {
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$collection1 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test_col',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$collection2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test_col',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$core1 = $collection1->get_core_title_metadatum();
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$meta_relationship = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'relationship',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection2,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Relationship',
|
|
|
|
'metadata_type_options' => [
|
|
|
|
'repeated' => 'yes',
|
|
|
|
'collection_id' => $collection1->get_id(),
|
|
|
|
'search' => $core1->get_id()
|
|
|
|
]
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$filter = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'test',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection2,
|
|
|
|
'metadatum' => $meta_relationship,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
$request = new \WP_REST_Request(
|
|
|
|
'GET',
|
|
|
|
$this->namespace . '/filters/' . $filter->get_id()
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($request);
|
|
|
|
|
|
|
|
$data = $response->get_data();
|
|
|
|
$this->assertEquals($filter->get_id(), $data['id']);
|
|
|
|
$this->assertEquals('test', $data['name']);
|
|
|
|
$this->assertEquals('yes', $data['metadatum']['metadata_type_object']['options']['repeated']);
|
|
|
|
$this->assertEquals($collection1->get_id(), $data['metadatum']['metadata_type_object']['options']['collection_id']);
|
|
|
|
$this->assertEquals($core1->get_id(), $data['metadatum']['metadata_type_object']['options']['search']);
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2019-10-16 14:05:29 +00:00
|
|
|
}
|
2019-10-23 20:28:48 +00:00
|
|
|
|
2020-02-11 12:48:22 +00:00
|
|
|
public function test_visibility_the_filter_from_in_collection(){
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Statement',
|
|
|
|
'description' => 'No Statement'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatumA = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Data',
|
|
|
|
'description' => 'Descreve valor do campo data.',
|
|
|
|
'collection' => $collection,
|
|
|
|
'status' => 'publish',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
), true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatumB = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Data',
|
|
|
|
'description' => 'Descreve valor do campo data.',
|
|
|
|
'collection' => $collection,
|
|
|
|
'status' => 'private',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
), true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filterA = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'test',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadatum' => $metadatumA,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filterB = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'test',
|
|
|
|
'status' => 'private',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadatum' => $metadatumA,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_logout();
|
|
|
|
wp_set_current_user(0);
|
|
|
|
|
|
|
|
$requestA = new \WP_REST_Request('GET', $this->namespace . '/filters/' . $filterA->get_id());
|
|
|
|
$requestB = new \WP_REST_Request('GET', $this->namespace . '/filters/' . $filterB->get_id());
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($requestA);
|
|
|
|
$status = $response->status;
|
|
|
|
$this->assertEquals(200, $status);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($requestB);
|
|
|
|
$status = $response->status;
|
|
|
|
$this->assertEquals(401, $status);
|
|
|
|
}
|
|
|
|
|
2020-02-11 13:09:45 +00:00
|
|
|
public function test_private_filter_ids_not_in_filters_list(){
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'Statement',
|
|
|
|
'description' => 'No Statement',
|
|
|
|
'status' => 'publish',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatumA = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Data',
|
|
|
|
'description' => 'Descreve valor do campo data.',
|
|
|
|
'collection' => $collection,
|
|
|
|
'status' => 'publish',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
), true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatumB = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'Data',
|
|
|
|
'description' => 'Descreve valor do campo data.',
|
|
|
|
'collection' => $collection,
|
|
|
|
'status' => 'private',
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
|
|
|
), true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filterA = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'test',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadatum' => $metadatumA,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$filterB = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'filter',
|
|
|
|
array(
|
|
|
|
'name' => 'test',
|
|
|
|
'status' => 'private',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadatum' => $metadatumA,
|
|
|
|
'filter_type' => 'Tainacan\Filter_Types\Autocomplete',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_logout();
|
|
|
|
wp_set_current_user(0);
|
|
|
|
|
|
|
|
$requestA = new \WP_REST_Request('GET', $this->namespace . '/filters/' . $filterA->get_id());
|
|
|
|
$requestB = new \WP_REST_Request('GET', $this->namespace . '/filters/' . $filterB->get_id());
|
|
|
|
$requestC = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collection->get_id() . '/filters');
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($requestA);
|
|
|
|
$status = $response->status;
|
|
|
|
$this->assertEquals(200, $status);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($requestB);
|
|
|
|
$status = $response->status;
|
|
|
|
$this->assertEquals(401, $status);
|
|
|
|
|
|
|
|
$response = $this->server->dispatch($requestC);
|
|
|
|
$data = $response->get_data();
|
|
|
|
$this->assertEquals(1, count($data));
|
|
|
|
$this->assertEquals($filterA->get_id(), $data[0]['id']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-10 15:56:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 20:28:48 +00:00
|
|
|
?>
|