Introduces compound meta render tests
This commit is contained in:
parent
e394dadde0
commit
1cd3a3052b
|
@ -8,7 +8,7 @@ namespace Tainacan\Tests;
|
||||||
* @package Test_Tainacan
|
* @package Test_Tainacan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Tainacan\Entities;
|
use Tainacan\Entities\Item_Metadata_Entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compound Metadatum Types test case.
|
* Compound Metadatum Types test case.
|
||||||
|
@ -17,10 +17,7 @@ use Tainacan\Entities;
|
||||||
class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
|
|
||||||
function test_compound_metadata_types() {
|
function test_compound_metadata_types() {
|
||||||
|
|
||||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
||||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
|
||||||
|
|
||||||
$collection = $this->tainacan_entity_factory->create_entity(
|
$collection = $this->tainacan_entity_factory->create_entity(
|
||||||
'collection',
|
'collection',
|
||||||
|
@ -79,23 +76,21 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$item_metadata1 = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child1);
|
$item_metadata1 = new Item_Metadata_Entity($i, $metadatum_child1);
|
||||||
$item_metadata1->set_value('Red');
|
$item_metadata1->set_value('Red');
|
||||||
|
|
||||||
$item_metadata1->validate();
|
$item_metadata1->validate();
|
||||||
|
|
||||||
$item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1);
|
$item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1);
|
||||||
|
|
||||||
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id());
|
$item_metadata = new Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id());
|
||||||
$item_metadata->set_value('Blue');
|
$item_metadata->set_value('Blue');
|
||||||
|
|
||||||
$item_metadata->validate();
|
$item_metadata->validate();
|
||||||
|
|
||||||
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
||||||
|
|
||||||
$compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum);
|
$compoundItem = new Item_Metadata_Entity($i, $metadatum);
|
||||||
|
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$compoundValue = $compoundItem->get_value();
|
$compoundValue = $compoundItem->get_value();
|
||||||
|
|
||||||
|
@ -105,17 +100,15 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
$this->assertTrue( isset($compoundValue[$metadatum_child1->get_id()]), 'First element of value must be set' );
|
$this->assertTrue( isset($compoundValue[$metadatum_child1->get_id()]), 'First element of value must be set' );
|
||||||
$this->assertTrue( isset($compoundValue[$metadatum_child2->get_id()]), 'Second element of value must be set' );
|
$this->assertTrue( isset($compoundValue[$metadatum_child2->get_id()]), 'Second element of value must be set' );
|
||||||
|
|
||||||
$this->assertTrue( $compoundValue[$metadatum_child1->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'First element of value should be an item metadata entity' );
|
$this->assertTrue( $compoundValue[$metadatum_child1->get_id()] instanceof Item_Metadata_Entity , 'First element of value should be an item metadata entity' );
|
||||||
$this->assertTrue( $compoundValue[$metadatum_child2->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'Second element of value should be an item metadata entity' );
|
$this->assertTrue( $compoundValue[$metadatum_child2->get_id()] instanceof Item_Metadata_Entity , 'Second element of value should be an item metadata entity' );
|
||||||
|
|
||||||
$this->assertEquals( 'Red', $compoundValue[$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' );
|
$this->assertEquals( 'Red', $compoundValue[$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' );
|
||||||
$this->assertEquals( 'Blue', $compoundValue[$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
$this->assertEquals( 'Blue', $compoundValue[$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_multiple_compound_metadata_types() {
|
function test_multiple_compound_metadata_types() {
|
||||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
||||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
|
||||||
|
|
||||||
$collection = $this->tainacan_entity_factory->create_entity(
|
$collection = $this->tainacan_entity_factory->create_entity(
|
||||||
'collection',
|
'collection',
|
||||||
|
@ -175,32 +168,30 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
// First Instance
|
// First Instance
|
||||||
$item_metadata1 = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child1);
|
$item_metadata1 = new Item_Metadata_Entity($i, $metadatum_child1);
|
||||||
$item_metadata1->set_value('Red');
|
$item_metadata1->set_value('Red');
|
||||||
$item_metadata1->validate();
|
$item_metadata1->validate();
|
||||||
$item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1);
|
$item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1);
|
||||||
|
|
||||||
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id());
|
$item_metadata = new Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id());
|
||||||
$item_metadata->set_value('Blue');
|
$item_metadata->set_value('Blue');
|
||||||
$item_metadata->validate();
|
$item_metadata->validate();
|
||||||
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
||||||
|
|
||||||
// Second Instance
|
// Second Instance
|
||||||
$item_metadata3 = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child1);
|
$item_metadata3 = new Item_Metadata_Entity($i, $metadatum_child1);
|
||||||
$item_metadata3->set_value('Green');
|
$item_metadata3->set_value('Green');
|
||||||
$item_metadata3->validate();
|
$item_metadata3->validate();
|
||||||
$item_metadata3 = $Tainacan_Item_Metadata->insert($item_metadata3);
|
$item_metadata3 = $Tainacan_Item_Metadata->insert($item_metadata3);
|
||||||
|
|
||||||
|
|
||||||
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata3->get_parent_meta_id());
|
$item_metadata = new Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata3->get_parent_meta_id());
|
||||||
$item_metadata->set_value('Yellow');
|
$item_metadata->set_value('Yellow');
|
||||||
$item_metadata->validate();
|
$item_metadata->validate();
|
||||||
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
||||||
|
|
||||||
$compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum);
|
$compoundItem = new Item_Metadata_Entity($i, $metadatum);
|
||||||
$compoundValue = $compoundItem->get_value();
|
$compoundValue = $compoundItem->get_value();
|
||||||
|
|
||||||
$this->assertTrue( is_array($compoundValue), 'value of a compound should return array' );
|
$this->assertTrue( is_array($compoundValue), 'value of a compound should return array' );
|
||||||
|
@ -212,8 +203,8 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
$this->assertTrue( isset($compoundValue[0][$metadatum_child1->get_id()]), 'First element of value must be set' );
|
$this->assertTrue( isset($compoundValue[0][$metadatum_child1->get_id()]), 'First element of value must be set' );
|
||||||
$this->assertTrue( isset($compoundValue[1][$metadatum_child2->get_id()]), 'Second element of value must be set' );
|
$this->assertTrue( isset($compoundValue[1][$metadatum_child2->get_id()]), 'Second element of value must be set' );
|
||||||
|
|
||||||
$this->assertTrue( $compoundValue[0][$metadatum_child1->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'First element of value should be an item metadata entity' );
|
$this->assertTrue( $compoundValue[0][$metadatum_child1->get_id()] instanceof Item_Metadata_Entity , 'First element of value should be an item metadata entity' );
|
||||||
$this->assertTrue( $compoundValue[1][$metadatum_child2->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'Second element of value should be an item metadata entity' );
|
$this->assertTrue( $compoundValue[1][$metadatum_child2->get_id()] instanceof Item_Metadata_Entity , 'Second element of value should be an item metadata entity' );
|
||||||
|
|
||||||
$this->assertEquals( 'Red', $compoundValue[0][$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' );
|
$this->assertEquals( 'Red', $compoundValue[0][$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' );
|
||||||
$this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
$this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
||||||
|
@ -222,7 +213,7 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
$this->assertEquals( 'Yellow', $compoundValue[1][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
$this->assertEquals( 'Yellow', $compoundValue[1][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
||||||
|
|
||||||
$item_metadata_removed = $Tainacan_Item_Metadata->remove_compound_value($i, $metadatum, $item_metadata3->get_parent_meta_id());
|
$item_metadata_removed = $Tainacan_Item_Metadata->remove_compound_value($i, $metadatum, $item_metadata3->get_parent_meta_id());
|
||||||
$compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum);
|
$compoundItem = new Item_Metadata_Entity($i, $metadatum);
|
||||||
$compoundValue = $compoundItem->get_value();
|
$compoundValue = $compoundItem->get_value();
|
||||||
|
|
||||||
$this->assertTrue( is_array($compoundValue), 'value of a compound should return array' );
|
$this->assertTrue( is_array($compoundValue), 'value of a compound should return array' );
|
||||||
|
@ -230,13 +221,9 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
|
|
||||||
$this->assertEquals( 'Red', $compoundValue[0][$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' );
|
$this->assertEquals( 'Red', $compoundValue[0][$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' );
|
||||||
$this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
$this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_validations_taxonomy_in_multiple() {
|
function test_validations_taxonomy_in_multiple() {
|
||||||
|
|
||||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
||||||
|
|
||||||
$collection = $this->tainacan_entity_factory->create_entity(
|
$collection = $this->tainacan_entity_factory->create_entity(
|
||||||
'collection',
|
'collection',
|
||||||
array(
|
array(
|
||||||
|
@ -306,9 +293,6 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_validations_multiple_metadata() {
|
function test_validations_multiple_metadata() {
|
||||||
|
|
||||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
|
||||||
|
|
||||||
$collection = $this->tainacan_entity_factory->create_entity(
|
$collection = $this->tainacan_entity_factory->create_entity(
|
||||||
'collection',
|
'collection',
|
||||||
array(
|
array(
|
||||||
|
@ -341,15 +325,11 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
$newMetadatum->set_multiple('no');
|
$newMetadatum->set_multiple('no');
|
||||||
|
|
||||||
$this->assertTrue($newMetadatum->validate());
|
$this->assertTrue($newMetadatum->validate());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_validations_metadada_order() {
|
function test_validations_metadada_order() {
|
||||||
|
|
||||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||||
|
|
||||||
|
|
||||||
$collection = $this->tainacan_entity_factory->create_entity(
|
$collection = $this->tainacan_entity_factory->create_entity(
|
||||||
'collection',
|
'collection',
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -620,7 +620,6 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
|
||||||
);
|
);
|
||||||
$expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title());
|
$expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title());
|
||||||
$expected_return2 = $this->relationship_expected_return($disappear->get_id(), $disappear->get_title());
|
$expected_return2 = $this->relationship_expected_return($disappear->get_id(), $disappear->get_title());
|
||||||
#$separator = '<span class="multivalue-separator"> | </span>';
|
|
||||||
|
|
||||||
$relationship_metadata = $this->tainacan_entity_factory->create_entity(
|
$relationship_metadata = $this->tainacan_entity_factory->create_entity(
|
||||||
'metadatum',
|
'metadatum',
|
||||||
|
@ -713,6 +712,44 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
|
||||||
$this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "<a data-linkto='term' data-id='2' href='http://example.org/?tnc_tax_273=first-term-from-my-tax'>first term from my tax</a><span class=\"multivalue-separator\"> | </span><a data-linkto='term' data-id='3' href='http://example.org/?tnc_tax_273=second-term-from-my-tax'>Second term from my tax</a>");
|
$this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "<a data-linkto='term' data-id='2' href='http://example.org/?tnc_tax_273=first-term-from-my-tax'>first term from my tax</a><span class=\"multivalue-separator\"> | </span><a data-linkto='term' data-id='3' href='http://example.org/?tnc_tax_273=second-term-from-my-tax'>Second term from my tax</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_compound_metadata_html() {
|
||||||
|
$coumpound_meta = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'metadatum',
|
||||||
|
array(
|
||||||
|
'name' => 'My compound Meta',
|
||||||
|
'status' => 'publish',
|
||||||
|
'collection' => $this->collection,
|
||||||
|
'metadata_type' => 'Tainacan\Metadata_Types\Compound',
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$text_meta = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'metadatum',
|
||||||
|
array(
|
||||||
|
'name' => 'My Text meta',
|
||||||
|
'status' => 'publish',
|
||||||
|
'collection' => $this->collection,
|
||||||
|
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||||
|
'parent' => $coumpound_meta->get_id()
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$textarea_meta = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'metadatum',
|
||||||
|
array(
|
||||||
|
'name' => 'My Textarea meta!',
|
||||||
|
'status' => 'publish',
|
||||||
|
'collection' => $this->collection,
|
||||||
|
'metadata_type' => 'Tainacan\Metadata_Types\Textarea',
|
||||||
|
'parent' => $coumpound_meta->get_id()
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$item_compound_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $coumpound_meta);
|
||||||
|
$item_compound_metadata->set_value(['invalid meta value!']);
|
||||||
|
$this->assertEquals($item_compound_metadata->get_value_as_html(), "<div class='tainacan-compound-group'> </div>");
|
||||||
|
}
|
||||||
|
|
||||||
private function relationship_expected_return($id, $title) {
|
private function relationship_expected_return($id, $title) {
|
||||||
$URL = get_permalink($id);
|
$URL = get_permalink($id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue