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());
|
|
|
|
|
|
|
|
$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-06-11 15:10:07 +00:00
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2017-12-11 14:25:28 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-11 14:25:28 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2017-12-11 14:25:28 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado2',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-11 14:25:28 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadatum3 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
2017-12-11 14:25:28 +00:00
|
|
|
array(
|
|
|
|
'name' => 'metadado3',
|
|
|
|
'status' => 'publish',
|
|
|
|
'collection' => $collection,
|
2018-06-11 17:57:50 +00:00
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
2017-12-11 14:25:28 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
2017-12-11 14:25:28 +00:00
|
|
|
|
|
|
|
$i = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'item',
|
|
|
|
array(
|
|
|
|
'title' => 'orange',
|
|
|
|
'collection' => $collection,
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2018-02-08 18:28:30 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_1');
|
2018-02-08 18:28:30 +00:00
|
|
|
|
|
|
|
$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-06-11 15:10:07 +00:00
|
|
|
$test = get_post($metadatum->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertEquals($metadatum->get_db_identifier(), $entity->get_db_identifier());
|
2017-12-11 14:25:28 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$test = get_post($metadatum2->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertEquals($metadatum2->get_db_identifier(), $entity->get_db_identifier());
|
2017-12-11 14:25:28 +00:00
|
|
|
|
2018-06-11 15:10:07 +00:00
|
|
|
$metadata = $i->get_metadata();
|
|
|
|
$item_metadata = array_pop($metadata);
|
|
|
|
$test = get_post($item_metadata->get_metadatum()->get_id());
|
2017-12-11 14:25:28 +00:00
|
|
|
$entity = Repository::get_entity_by_post($test);
|
2018-06-11 15:10:07 +00:00
|
|
|
$this->assertEquals($item_metadata->get_metadatum()->get_db_identifier(), $entity->get_db_identifier());
|
2017-12-11 14:25:28 +00:00
|
|
|
}
|
2018-02-09 18:04:39 +00:00
|
|
|
|
|
|
|
function test_delete_attributes() {
|
|
|
|
|
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'test title',
|
|
|
|
'description' => 'test description',
|
|
|
|
'status' => 'draft'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection->set_name('');
|
|
|
|
$this->assertEquals('', $collection->get_name());
|
|
|
|
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
2018-02-09 18:04:39 +00:00
|
|
|
$this->assertTrue($collection->validate());
|
|
|
|
$newCol = $Tainacan_Collections->insert($collection);
|
|
|
|
$this->assertEquals('', $newCol->get_name());
|
|
|
|
|
|
|
|
|
2018-05-30 18:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_fetch_one() {
|
|
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection3 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste3',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
|
|
|
|
|
|
|
$one = $Tainacan_Collections->fetch_one(['name' => 'teste2']);
|
|
|
|
|
|
|
|
$this->assertTrue( $one instanceof \Tainacan\Entities\Collection );
|
|
|
|
$this->assertEquals( 'teste2', $one->get_name() );
|
|
|
|
|
|
|
|
}
|
2017-12-11 14:25:28 +00:00
|
|
|
}
|