Merge branch 'develop' into release/0.13

This commit is contained in:
Mateus Machado Luna 2019-10-16 11:24:39 -03:00
commit 3f0bb33091
6 changed files with 418 additions and 128 deletions

View File

@ -366,7 +366,7 @@ class Entity {
$attributes = [];
foreach($map as $prop => $content) {
$attributes[$prop] = $this->get_mapped_property($prop);
$attributes[$prop] = $this->get($prop);
}
$hook_prefix = self::get_post_type();

View File

@ -152,7 +152,7 @@ class Filter extends Entity {
}
$object_type = new $class_name();
$object_type->set_options( $this->get_filter_type_options() );
$object_type->set_options( $this->get_mapped_property('filter_type_options') );
return $object_type;
}
@ -171,6 +171,10 @@ class Filter extends Entity {
* @return array Configurations for the filter type object
*/
function get_filter_type_options(){
$object = $this->get_filter_type_object();
if ($object) {
return $object->get_options(); // merge with dedault filter type options
}
return $this->get_mapped_property('filter_type_options');
}

View File

@ -178,7 +178,7 @@ class Metadatum extends Entity {
}
$object_type = new $class_name();
$object_type->set_options( $this->get_metadata_type_options() );
$object_type->set_options( $this->get_mapped_property('metadata_type_options') );
return $object_type;
}
@ -197,6 +197,10 @@ class Metadatum extends Entity {
* @return array Configurations for the metadatum type object
*/
function get_metadata_type_options(){
$object = $this->get_metadata_type_object();
if ($object) {
return $object->get_options(); // merge with dedault metadata type options
}
return $this->get_mapped_property('metadata_type_options');
}

View File

@ -366,6 +366,238 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$this->assertCount(2, $data4);
//$this->assertEquals('4x Filter', $data4[0]['name']);
}
public function test_return_filter_type_options_in_get_item() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'number',
'status' => 'publish',
'collection' => $collection1,
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
),
true
);
$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
);
$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']);
}
public function test_return_filter_type_options_in_get_items() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'number',
'status' => 'publish',
'collection' => $collection1,
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
),
true
);
$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
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/collection/' . $collection1->get_id() . '/filters'
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
//var_dump($data, $this->namespace . '/collection/' . $collection2->get_id() . '/metadata/');
foreach ($data as $d) {
if ($d['id'] == $filter_numeric->get_id()) {
$meta = $d;
break;
}
}
$this->assertEquals($filter_numeric->get_id(), $meta['id']);
$this->assertEquals('numeric', $meta['name']);
$this->assertEquals(3, $meta['filter_type_options']['step']);
}
public function test_return_filter_type_options_in_get_item_default_value() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'number',
'status' => 'publish',
'collection' => $collection1,
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
),
true
);
$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
);
$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']);
}
public function test_return_metadata_type_options_inside_metadatum_property() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$collection2 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$core1 = $collection1->get_core_title_metadatum();
$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
);
$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
);
$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']);
}
}
?>

View File

@ -13,6 +13,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
array(
'name' => 'Javascript Frameworks',
'description' => 'The best framework to javascript',
'status' => 'publish'
),
true
);

View File

@ -149,7 +149,8 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
'collection',
array(
'name' => 'Statement',
'description' => 'No Statement'
'description' => 'No Statement',
'status' => 'publish'
),
true
);
@ -222,7 +223,8 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
'collection',
array(
'name' => 'Statement',
'description' => 'No Statement'
'description' => 'No Statement',
'status' => 'publish'
),
true
);
@ -404,128 +406,175 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals('No name', $data['name']);
}
// public function test_fetch_all_metadatum_values(){
// $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
//
// $collection = $this->tainacan_entity_factory->create_entity(
// 'collection',
// array(
// 'name' => 'Statement',
// 'description' => 'No Statement',
// 'status' => 'publish'
// ),
// true
// );
//
// $item1 = $this->tainacan_entity_factory->create_entity(
// 'item',
// array(
// 'title' => 'No name1',
// 'description' => 'No description1',
// 'status' => 'publish',
// 'collection' => $collection
// ),
// true
// );
//
// $item2 = $this->tainacan_entity_factory->create_entity(
// 'item',
// array(
// 'title' => 'No name2',
// 'description' => 'No description2',
// 'status' => 'private',
// 'collection' => $collection
// ),
// true
// );
//
// $item3 = $this->tainacan_entity_factory->create_entity(
// 'item',
// array(
// 'title' => 'No name3',
// 'description' => 'No description3',
// 'status' => 'private',
// 'collection' => $collection
// ),
// true
// );
//
// $metadatum = $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
// );
//
// $item_metadata1 = new \Tainacan\Entities\Item_Metadata_Entity($item1, $metadatum);
// $item_metadata1->set_value('12/12/2017');
//
// $item_metadata1->validate();
// $Tainacan_Item_Metadata->insert($item_metadata1);
//
// $item_metadata2 = new \Tainacan\Entities\Item_Metadata_Entity($item2, $metadatum);
// $item_metadata2->set_value('02/03/2018');
//
// $item_metadata2->validate();
// $Tainacan_Item_Metadata->insert($item_metadata2);
//
// // Is repeated for test return of duplicates
// $item_metadata3 = new \Tainacan\Entities\Item_Metadata_Entity($item3, $metadatum);
// $item_metadata3->set_value('12/12/2017');
//
// $item_metadata3->validate();
// $Tainacan_Item_Metadata->insert($item_metadata3);
//
// //=======================
//
// $request = new \WP_REST_Request(
// 'GET',
// $this->namespace . '/collection/' . $collection->get_id() . '/facets/' . $metadatum->get_id()
// );
//
// //=======================
//
// // Set no one user
// wp_set_current_user(0);
//
// $response1 = $this->server->dispatch($request);
//
// $data1 = $response1->get_data();
//
// $this->assertCount(1, $data1);
// $this->assertEquals('12/12/2017', $data1[0]['value']);
//
// //=======================
//
// $new_user1 = $this->factory()->user->create(array( 'role' => 'subscriber' ));
// wp_set_current_user($new_user1);
//
// $response1 = $this->server->dispatch($request);
//
// $data1 = $response1->get_data();
//
// $this->assertCount(1, $data1);
// $this->assertEquals('12/12/2017', $data1[0]['value']);
//
// //=======================
//
// $new_user2 = $this->factory()->user->create(array( 'role' => 'administrator' ));
// wp_set_current_user($new_user2);
//
// $response2 = $this->server->dispatch($request);
//
// $data2 = $response2->get_data();
//
// // Only two without duplicates
// //$this->assertCount(2, $data2);
// //$this->assertEquals('12/12/2017', $data2[0]['value']);
// //$this->assertEquals('02/03/2018', $data2[1]['value']);
// }
public function test_return_metadata_type_options_in_get_item() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$collection2 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$core1 = $collection1->get_core_title_metadatum();
$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
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/metadata/' . $meta_relationship->get_id()
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals($meta_relationship->get_id(), $data['id']);
$this->assertEquals('relationship', $data['name']);
$this->assertEquals('yes', $data['metadata_type_options']['repeated']);
$this->assertEquals($collection1->get_id(), $data['metadata_type_options']['collection_id']);
$this->assertEquals($core1->get_id(), $data['metadata_type_options']['search']);
}
public function test_return_metadata_type_options_in_get_items() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$collection2 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$core1 = $collection1->get_core_title_metadatum();
$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
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/collection/' . $collection2->get_id() . '/metadata'
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
//var_dump($data, $this->namespace . '/collection/' . $collection2->get_id() . '/metadata/');
foreach ($data as $d) {
if ($d['id'] == $meta_relationship->get_id()) {
$meta = $d;
break;
}
}
$this->assertEquals($meta_relationship->get_id(), $meta['id']);
$this->assertEquals('relationship', $meta['name']);
$this->assertEquals('yes', $meta['metadata_type_options']['repeated']);
$this->assertEquals($collection1->get_id(), $meta['metadata_type_options']['collection_id']);
$this->assertEquals($core1->get_id(), $meta['metadata_type_options']['search']);
}
public function test_return_metadata_type_options_in_get_item_default_option() {
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$tax = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax_test',
'collections' => [$collection1],
'status' => 'publish'
),
true
);
$meta = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'tax',
'status' => 'publish',
'collection' => $collection1,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(),
]
),
true
);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/metadata/' . $meta->get_id()
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals($meta->get_id(), $data['id']);
$this->assertEquals('tax', $data['name']);
$this->assertEquals($tax->get_id(), $data['metadata_type_options']['taxonomy_id']);
$this->assertEquals('no', $data['metadata_type_options']['allow_new_terms']);
}
}
?>