2017-12-11 14:25:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
use Tainacan\Repositories\Repository;
|
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
* @group architecture
|
|
|
|
*/
|
|
|
|
class Objects extends TAINACAN_UnitTestCase {
|
2017-12-12 11:59:50 +00:00
|
|
|
function test_object_transformation() {
|
2017-12-11 14:25:28 +00:00
|
|
|
$x = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'testeT',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'default_order' => 'DESC'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$test = get_post($x->get_id());
|
|
|
|
$entity = Repository::get_entity_by_post($test);
|
|
|
|
$this->assertEquals($x->get_db_identifier(), $entity->get_db_identifier());
|
|
|
|
|
|
|
|
$type = $this->tainacan_field_factory->create_field('text');
|
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste2',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-01-31 14:47:59 +00:00
|
|
|
$field = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'field',
|
2017-12-11 14:25:28 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
|
|
|
'field_type' => $type
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-01-31 14:47:59 +00:00
|
|
|
$field2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'field',
|
2017-12-11 14:25:28 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado2',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
|
|
|
'field_type' => $type
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-01-31 14:47:59 +00:00
|
|
|
$field3 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'field',
|
2017-12-11 14:25:28 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado3',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
|
|
|
'field_type' => $type
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
global $Tainacan_Items;
|
|
|
|
|
|
|
|
$i = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'item',
|
|
|
|
array(
|
|
|
|
'title' => 'orange',
|
|
|
|
'collection' => $collection,
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2018-02-08 18:28:30 +00:00
|
|
|
|
|
|
|
$this->tainacan_item_metadata_factory->create_item_metadata($i, $field, 'value_1');
|
|
|
|
|
|
|
|
$test = get_post($i->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
|
|
|
$this->assertEquals($i->get_db_identifier(), $entity->get_db_identifier());
|
|
|
|
|
2018-01-31 14:47:59 +00:00
|
|
|
$test = get_post($field->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
2018-01-31 14:47:59 +00:00
|
|
|
$this->assertEquals($field->get_db_identifier(), $entity->get_db_identifier());
|
2017-12-11 14:25:28 +00:00
|
|
|
|
2018-01-31 14:47:59 +00:00
|
|
|
$test = get_post($field2->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
2018-01-31 14:47:59 +00:00
|
|
|
$this->assertEquals($field2->get_db_identifier(), $entity->get_db_identifier());
|
2017-12-11 14:25:28 +00:00
|
|
|
|
2018-02-08 13:15:44 +00:00
|
|
|
$fields = $i->get_fields();
|
2018-01-31 14:47:59 +00:00
|
|
|
$item_metadata = array_pop($fields);
|
|
|
|
$test = get_post($item_metadata->get_field()->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
2018-01-31 14:47:59 +00:00
|
|
|
$this->assertEquals($item_metadata->get_field()->get_db_identifier(), $entity->get_db_identifier());
|
2017-12-11 14:25:28 +00:00
|
|
|
}
|
|
|
|
}
|