ads html tests for numeric meta type

This commit is contained in:
Rodrigo de Oliveira 2021-04-05 11:57:23 -03:00
parent c0df4dde06
commit 4ce2c9491b
2 changed files with 49 additions and 4 deletions

View File

@ -37,5 +37,4 @@ class Numeric extends Metadata_Type {
] ]
]; ];
} }
} }

View File

@ -9,7 +9,7 @@ namespace Tainacan\Tests;
*/ */
/** /**
* Sample test case. * Item_Metadata test case.
*/ */
class Item_Metadata extends TAINACAN_UnitTestCase { class Item_Metadata extends TAINACAN_UnitTestCase {
@ -247,8 +247,6 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
} }
function test_metadata_text_textarea() { function test_metadata_text_textarea() {
$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(
@ -395,4 +393,52 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$this->assertTrue($item_metadata_text->has_value()); $this->assertTrue($item_metadata_text->has_value());
} }
function test_metadata_numeric_html() {
$collection = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true);
$item = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'My test item',
'description' => 'item description',
'collection' => $collection,
'status' => 'publish'
),
true
);
$metadatum_numeric = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Numeric important meta',
'description' => 'and its description',
'collection_id' => $collection->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
'status' => 'publish'
),
true
);
$metadatum_numeric_multiple = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Numeric important meta',
'description' => 'and its description',
'collection_id' => $collection->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
'status' => 'publish',
'multiple' => 'yes'
),
true
);
$item_metadata_numeric = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_numeric);
$item_metadata_numeric->set_value(10);
$item_metadata_numeric->validate();
$this->assertEquals($item_metadata_numeric->get_value_as_html(), 10);
$item_metadata_numeric_mult = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_numeric_multiple);
$item_metadata_numeric_mult->set_value([10,22,4]);
$item_metadata_numeric_mult->validate();
$this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10<span class="multivalue-separator"> | </span>22<span class="multivalue-separator"> | </span>4');
}
} }