2017-11-09 11:01:11 +00:00
|
|
|
<?php
|
2017-11-15 18:50:11 +00:00
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
2018-06-11 17:57:50 +00:00
|
|
|
use Tainacan\Metadata_Types;
|
2017-11-09 11:01:11 +00:00
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* Class Metadatum
|
2017-11-09 11:01:11 +00:00
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* Metadatum test case.
|
|
|
|
* @group metadata
|
2017-11-09 11:01:11 +00:00
|
|
|
*/
|
2018-06-11 15:10:07 +00:00
|
|
|
class Metadata extends TAINACAN_UnitTestCase {
|
2017-11-09 11:01:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* Test insert a regular metadatum with type
|
2017-11-09 11:01:11 +00:00
|
|
|
*/
|
|
|
|
function test_add() {
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2017-12-04 18:20:49 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2017-12-04 18:20:49 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'description' => 'descricao',
|
|
|
|
'collection' => $collection,
|
2018-02-22 20:11:01 +00:00
|
|
|
'accept_suggestion' => true,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-04 18:20:49 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-09 11:01:11 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$test = $Tainacan_Metadata->fetch($metadatum->get_id());
|
2017-11-09 11:01:11 +00:00
|
|
|
|
2017-11-09 15:51:16 +00:00
|
|
|
$this->assertEquals($test->get_name(), 'metadado');
|
|
|
|
$this->assertEquals($test->get_description(), 'descricao');
|
2017-11-12 23:14:47 +00:00
|
|
|
$this->assertEquals($test->get_collection_id(), $collection->get_id());
|
2018-02-14 00:35:12 +00:00
|
|
|
$this->assertTrue((bool) $test->get_accept_suggestion());
|
2017-11-09 11:01:11 +00:00
|
|
|
}
|
2017-11-09 15:51:16 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* Test insert a regular metadatum with type
|
2017-11-09 15:51:16 +00:00
|
|
|
*/
|
2017-11-30 13:44:29 +00:00
|
|
|
function test_add_type(){
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2017-12-04 18:20:49 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2017-12-04 18:20:49 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'description' => 'descricao',
|
|
|
|
'collection_id' => $collection->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-04 18:20:49 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-09 15:51:16 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$test = $Tainacan_Metadata->fetch($metadatum->get_id());
|
2017-11-09 15:51:16 +00:00
|
|
|
|
|
|
|
$this->assertEquals($test->get_name(), 'metadado');
|
2017-11-12 23:14:47 +00:00
|
|
|
$this->assertEquals($test->get_collection_id(), $collection->get_id());
|
2018-06-11 17:57:50 +00:00
|
|
|
$this->assertEquals('Tainacan\Metadata_Types\Text', $test->get_metadata_type());
|
|
|
|
$this->assertEquals($test->get_metadata_type(), 'Tainacan\Metadata_Types\Text');
|
2017-11-09 15:51:16 +00:00
|
|
|
}
|
2017-11-30 13:44:29 +00:00
|
|
|
|
2017-12-04 18:30:54 +00:00
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* test if parent metadatum are visible for children collection
|
2017-12-04 18:30:54 +00:00
|
|
|
*/
|
2017-11-30 13:44:29 +00:00
|
|
|
function test_hierarchy_metadata(){
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2017-12-04 18:20:49 +00:00
|
|
|
|
|
|
|
$this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2017-12-04 18:20:49 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum default',
|
|
|
|
'collection_id' => $Tainacan_Metadata->get_default_metadata_attribute(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-04 18:20:49 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_grandfather = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'collection grandfather'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2017-12-04 18:20:49 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum grandfather',
|
2017-12-04 18:20:49 +00:00
|
|
|
'collection_id' => $collection_grandfather->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-04 18:20:49 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_father = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'collection father',
|
|
|
|
'parent' => $collection_grandfather->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2017-12-04 18:20:49 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum father',
|
2017-12-04 18:20:49 +00:00
|
|
|
'collection_id' => $collection_father->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-04 18:20:49 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_son = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'collection son',
|
|
|
|
'parent' => $collection_father->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-30 13:44:29 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $collection_grandfather->get_id(), $collection_father->get_parent() );
|
|
|
|
$this->assertEquals( $collection_father->get_id(), $collection_son->get_parent() );
|
|
|
|
|
2017-12-04 18:20:49 +00:00
|
|
|
$this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2017-12-04 18:20:49 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum son',
|
2017-12-04 18:20:49 +00:00
|
|
|
'collection_id' => $collection_son->get_id(),
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-04 18:20:49 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-30 13:44:29 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$retrieve_metadata = $Tainacan_Metadata->fetch_by_collection( $collection_son, [], 'OBJECT' );
|
2018-08-06 17:55:08 +00:00
|
|
|
|
|
|
|
$retrieve_metadata_ids = $Tainacan_Metadata->fetch_ids_by_collection( $collection_son, [] );
|
2018-02-15 18:29:33 +00:00
|
|
|
|
|
|
|
// should return 6
|
|
|
|
$this->assertEquals( 6, sizeof( $retrieve_metadata ) );
|
2018-08-06 17:55:08 +00:00
|
|
|
$this->assertEquals( 6, sizeof( $retrieve_metadata_ids ) );
|
2018-02-15 18:29:33 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 17:50:24 +00:00
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* test remove core metadata
|
2018-02-16 17:50:24 +00:00
|
|
|
*/
|
2018-06-11 15:10:07 +00:00
|
|
|
function test_core_metadata(){
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2018-02-15 18:29:33 +00:00
|
|
|
|
2018-02-16 17:35:24 +00:00
|
|
|
$collection_grandfather = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'collection metadatum'
|
2018-02-16 17:35:24 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$core_metadata = $Tainacan_Metadata->get_core_metadata( $collection_grandfather );
|
2018-02-16 17:35:24 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
if( $core_metadata ){
|
|
|
|
foreach( $core_metadata as $core_metadatum ){
|
|
|
|
$this->assertFalse(wp_trash_post( $core_metadatum->get_id() ) );
|
2018-02-15 18:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 13:44:29 +00:00
|
|
|
}
|
2017-12-04 18:30:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test if the defaults types are registered
|
|
|
|
*/
|
2018-06-11 17:57:50 +00:00
|
|
|
function test_metadata_metadata_type(){
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2018-07-14 16:16:05 +00:00
|
|
|
$this->assertEquals( 7, sizeof( $Tainacan_Metadata->fetch_metadata_types() ) );
|
2017-12-05 10:37:50 +00:00
|
|
|
}
|
2018-02-19 14:20:17 +00:00
|
|
|
|
2018-02-23 12:00:45 +00:00
|
|
|
|
2018-02-19 14:20:17 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-06-11 15:10:07 +00:00
|
|
|
function test_ordenation_metadata(){
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2018-02-19 14:20:17 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum1 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-02-19 14:20:17 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum1',
|
2018-02-19 14:20:17 +00:00
|
|
|
'description' => 'descricao',
|
|
|
|
'collection' => $collection,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-19 14:20:17 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-02-19 14:20:17 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum2',
|
|
|
|
'description' => 'metadatum2',
|
2018-02-19 14:20:17 +00:00
|
|
|
'collection' => $collection,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-19 14:20:17 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum3 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2018-02-19 14:20:17 +00:00
|
|
|
array(
|
2018-06-11 15:10:07 +00:00
|
|
|
'name' => 'metadatum3',
|
|
|
|
'description' => 'metadatum3',
|
2018-02-19 14:20:17 +00:00
|
|
|
'collection' => $collection,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-19 14:20:17 +00:00
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$collection->set_metadata_order(
|
2018-02-19 14:20:17 +00:00
|
|
|
[
|
2018-06-11 15:10:07 +00:00
|
|
|
array( 'id' => $metadatum3->get_id(), 'enabled' => false ),
|
|
|
|
array( 'id' => $metadatum2->get_id(), 'enabled' => true ),
|
|
|
|
array( 'id' => $metadatum1->get_id(), 'enabled' => true )
|
2018-02-19 14:20:17 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$update_collection = $Tainacan_Collections->update( $collection );
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadata_ordinate = $Tainacan_Metadata->fetch_by_collection( $update_collection, [], 'OBJECT' );
|
|
|
|
$this->assertEquals( 'metadatum2', $metadata_ordinate[0]->get_name() );
|
2018-03-12 13:44:20 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadata_ordinate_enabled = $Tainacan_Metadata->fetch_by_collection( $update_collection, [ 'include_disabled' => true ], 'OBJECT' );
|
|
|
|
$this->assertEquals( 'metadatum3', $metadata_ordinate_enabled[0]->get_name() );
|
2018-03-12 13:44:20 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertFalse($metadata_ordinate_enabled[0]->get_enabled_for_collection());
|
|
|
|
$this->assertTrue($metadata_ordinate_enabled[1]->get_enabled_for_collection());
|
|
|
|
$this->assertTrue($metadata_ordinate_enabled[2]->get_enabled_for_collection());
|
2018-02-19 14:20:17 +00:00
|
|
|
}
|
2018-02-21 17:04:25 +00:00
|
|
|
|
|
|
|
function test_unique_slugs() {
|
|
|
|
$x = $this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2018-02-21 17:04:25 +00:00
|
|
|
array(
|
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'slug' => 'duplicated_slug',
|
|
|
|
'status' => 'publish',
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-21 17:04:25 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$y = $this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2018-02-21 17:04:25 +00:00
|
|
|
array(
|
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'slug' => 'duplicated_slug',
|
|
|
|
'status' => 'publish',
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-21 17:04:25 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertNotEquals($x->get_slug(), $y->get_slug());
|
|
|
|
|
|
|
|
// Create as draft and publish later
|
|
|
|
$x = $this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2018-02-21 17:04:25 +00:00
|
|
|
array(
|
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'slug' => 'duplicated_slug',
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-21 17:04:25 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$y = $this->tainacan_entity_factory->create_entity(
|
2018-06-11 15:10:07 +00:00
|
|
|
'metadatum',
|
2018-02-21 17:04:25 +00:00
|
|
|
array(
|
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'slug' => 'duplicated_slug',
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2018-02-21 17:04:25 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($x->get_slug(), $y->get_slug());
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2018-02-21 17:04:25 +00:00
|
|
|
$x->set_status('publish');
|
|
|
|
$x->validate();
|
2018-06-11 15:10:07 +00:00
|
|
|
$x = $Tainacan_Metadata->insert($x);
|
2018-02-21 17:04:25 +00:00
|
|
|
$y->set_status('private'); // or publish shoud behave the same
|
|
|
|
$y->validate();
|
2018-06-11 15:10:07 +00:00
|
|
|
$y = $Tainacan_Metadata->insert($y);
|
2018-02-21 17:04:25 +00:00
|
|
|
|
|
|
|
$this->assertNotEquals($x->get_slug(), $y->get_slug());
|
|
|
|
|
|
|
|
}
|
2018-02-22 20:26:57 +00:00
|
|
|
|
2018-06-11 17:57:50 +00:00
|
|
|
function test_validation_of_metadata_types() {
|
2018-06-11 15:10:07 +00:00
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
2018-02-22 20:26:57 +00:00
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$validMetadatum = new \Tainacan\Entities\Metadatum();
|
|
|
|
$validMetadatum->set_name('test');
|
|
|
|
$validMetadatum->set_description('test');
|
|
|
|
$validMetadatum->set_collection($collection);
|
2018-06-11 17:57:50 +00:00
|
|
|
$validMetadatum->set_metadata_type('Tainacan\Metadata_Types\Relationship');
|
|
|
|
$validMetadatum->set_metadata_type_options(['collection_id' => 12]);
|
2018-02-22 20:26:57 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertTrue($validMetadatum->validate());
|
2018-02-22 20:26:57 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$invalidMetadatum = new \Tainacan\Entities\Metadatum();
|
|
|
|
$invalidMetadatum->set_name('test');
|
|
|
|
$invalidMetadatum->set_description('test');
|
|
|
|
$invalidMetadatum->set_collection($collection);
|
|
|
|
$invalidMetadatum->set_status('publish');
|
2018-06-11 17:57:50 +00:00
|
|
|
$invalidMetadatum->set_metadata_type('Tainacan\Metadata_Types\Relationship');
|
|
|
|
$invalidMetadatum->set_metadata_type_options(['collection_id' => 'string']);
|
2018-02-22 20:26:57 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertFalse($invalidMetadatum->validate());
|
2018-02-22 20:26:57 +00:00
|
|
|
|
2019-07-30 21:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_metadata_type_option_index() {
|
|
|
|
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$tax = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'tax_test',
|
|
|
|
'collections' => [$collection],
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'meta',
|
|
|
|
'description' => 'description',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
|
|
|
|
'status' => 'publish',
|
|
|
|
'metadata_type_options' => [
|
|
|
|
'taxonomy_id' => $tax->get_id(),
|
|
|
|
'allow_new_terms' => 'no'
|
|
|
|
]
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$test_meta = get_post_meta($metadatum->get_id(), '_option_taxonomy_id', true);
|
|
|
|
$this->assertEquals( $tax->get_id(), $test_meta );
|
|
|
|
|
|
|
|
$fetch = $Tainacan_Metadata->fetch([
|
|
|
|
'meta_query' => [
|
|
|
|
[
|
|
|
|
'key' => '_option_taxonomy_id',
|
|
|
|
'value' => $tax->get_id()
|
|
|
|
]
|
|
|
|
]
|
|
|
|
], 'OBJECT');
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($fetch));
|
|
|
|
|
|
|
|
$this->assertEquals($metadatum->get_id(), $fetch[0]->get_id());
|
|
|
|
|
2018-02-22 20:26:57 +00:00
|
|
|
}
|
2019-07-30 21:37:27 +00:00
|
|
|
|
|
|
|
function test_relatioship_get_collection_method() {
|
|
|
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste2'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'meta',
|
|
|
|
'description' => 'description',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Relationship',
|
|
|
|
'status' => 'publish',
|
|
|
|
'metadata_type_options' => [
|
|
|
|
'collection_id' => $collection2->get_id(),
|
|
|
|
'search' => [$collection2->get_core_title_metadatum()->get_id()]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$object = $metadatum->get_metadata_type_object();
|
|
|
|
|
|
|
|
$colCheck = $object->get_collection();
|
|
|
|
|
|
|
|
$this->assertTrue( $colCheck instanceof \Tainacan\Entities\Collection );
|
|
|
|
$this->assertEquals($collection2->get_id(), $colCheck->get_id());
|
|
|
|
|
|
|
|
}
|
2017-12-05 10:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* Class TainacanMetadatumType
|
2017-12-05 10:37:50 +00:00
|
|
|
*/
|
2018-06-11 17:57:50 +00:00
|
|
|
class RandomType extends Metadata_Types\Metadata_Type {
|
2017-12-05 10:37:50 +00:00
|
|
|
|
|
|
|
function __construct(){
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-11 15:10:07 +00:00
|
|
|
* @param $metadatum
|
2017-12-05 10:37:50 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
public function render( $metadatum ){}
|
2017-11-09 11:01:11 +00:00
|
|
|
}
|