diff --git a/tests/test-compound-metadatum-types.php b/tests/test-compound-metadatum-types.php index cf0811154..4cd03302f 100644 --- a/tests/test-compound-metadatum-types.php +++ b/tests/test-compound-metadatum-types.php @@ -8,7 +8,7 @@ namespace Tainacan\Tests; * @package Test_Tainacan */ -use Tainacan\Entities; +use Tainacan\Entities\Item_Metadata_Entity; /** * Compound Metadatum Types test case. @@ -17,10 +17,7 @@ use Tainacan\Entities; class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { function test_compound_metadata_types() { - - $Tainacan_Metadata = \Tainacan\Repositories\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', @@ -79,23 +76,21 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { 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->validate(); $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->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); - - global $wpdb; + $compoundItem = new Item_Metadata_Entity($i, $metadatum); $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_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_child2->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'Second 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 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( 'Blue', $compoundValue[$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' ); } function test_multiple_compound_metadata_types() { - $Tainacan_Metadata = \Tainacan\Repositories\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', @@ -175,32 +168,30 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { true ); - global $wpdb; - // 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->validate(); $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->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); // 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->validate(); $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->validate(); $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(); $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[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[1][$metadatum_child2->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'Second 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 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( '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' ); $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(); $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( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' ); - } function test_validations_taxonomy_in_multiple() { - - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -306,9 +293,6 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { } function test_validations_multiple_metadata() { - - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -341,14 +325,10 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $newMetadatum->set_multiple('no'); $this->assertTrue($newMetadatum->validate()); - - } function test_validations_metadada_order() { - $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index f023b8499..06c6e739c 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -416,7 +416,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertTrue($item_metadata_text->has_value()); } - function test_numeric_metadata_html() { + function test_numeric_metadata_html() { // Simple numeric metadata $metadatum_numeric = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -620,7 +620,6 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ); $expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title()); $expected_return2 = $this->relationship_expected_return($disappear->get_id(), $disappear->get_title()); - #$separator = ' | '; $relationship_metadata = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -713,6 +712,44 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); } + 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(), "