Merge branch 'develop' of github.com:tainacan/tainacan into develop

This commit is contained in:
Mateus Machado Luna 2019-04-12 20:47:22 -03:00
commit 0284945a35
2 changed files with 45 additions and 5 deletions

View File

@ -313,7 +313,7 @@ class Item_Metadata_Entity extends Entity {
return $this->has_value;
$value = $this->get_value();
$this->has_value = !empty($value);
$this->has_value = (is_array($value)) ? !empty(array_filter($value)) : !empty($value);
return $this->has_value;
}

View File

@ -306,9 +306,9 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
}
/**
* @group test_item_metadata_multiple_has_value
* @group test_item_metadata_has_value
*/
function test_item_metadata_multiple_has_value() {
function test_item_metadata_has_value() {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
@ -330,6 +330,33 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true
);
$metadatum_textarea = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadadoTextarea',
'description' => 'descricao',
'collection_id' => $collection->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Textarea',
),
true
);
$value_textarea = '';
$item_metadata_textarea = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_textarea);
$item_metadata_textarea->set_value($value_textarea);
$item_metadata_textarea->validate();
$item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea);
$this->assertFalse($item_metadata_textarea->has_value());
$item_metadata_textarea->set_value('has_value');
$item_metadata_textarea->validate();
$item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea);
$this->assertTrue($item_metadata_textarea->has_value());
$metadatum_text = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
@ -350,7 +377,20 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$item_metadata_text->validate();
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata_text);
$this->assertTrue($item_metadata->has_value());
$this->assertFalse($item_metadata->has_value());
$item_metadata_text->set_value([
''
]);
$item_metadata_text->validate();
$item_metadata_text = $Tainacan_Item_Metadata->insert($item_metadata_text);
$item_metadata_text->set_value([
'has_value'
]);
$this->assertTrue($item_metadata_text->has_value());
}
}