fix item_metadata validation on bulk edit #69

This commit is contained in:
Leo Germani 2018-08-29 15:54:23 -03:00
parent a569a87ed6
commit 09e0ca0f54
2 changed files with 76 additions and 3 deletions

View File

@ -190,6 +190,7 @@ class Bulk_Edit {
}
$dummyItem = new Entities\Item();
$dummyItem->set_status('publish');
$checkItemMetadata = new Entities\Item_Metadata_Entity($dummyItem, $metadatum);
$checkItemMetadata->set_value([$value]);
@ -221,6 +222,7 @@ class Bulk_Edit {
}
$dummyItem = new Entities\Item();
$dummyItem->set_status('publish');
$checkItemMetadata = new Entities\Item_Metadata_Entity($dummyItem, $metadatum);
$checkItemMetadata->set_value( $metadatum->is_multiple() ? [$value] : $value );
@ -276,6 +278,7 @@ class Bulk_Edit {
}
$dummyItem = new Entities\Item();
$dummyItem->set_status('publish');
$checkItemMetadata = new Entities\Item_Metadata_Entity($dummyItem, $metadatum);
$checkItemMetadata->set_value( $metadatum->is_multiple() ? [$new_value] : $new_value );

View File

@ -1006,9 +1006,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
}
/**
* @group testt
*/
function test_repeated_terms() {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
@ -1066,5 +1063,78 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
}
function test_allow_new_terms() {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$taxonomy2 = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax2',
'description' => 'tipos de musica',
'allow_insert' => 'yes'
),
true
);
$category2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'category_2',
'status' => 'publish',
'collection' => $this->collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [
'allow_new_terms' => false,
'taxonomy_id' => $taxonomy2->get_id()
],
'multiple' => 'yes'
),
true
);
$bulk = new \Tainacan\Bulk_Edit([
'items_ids' => $this->items_ids,
]);
$bulk->add_value($category2, 'test_new_value');
$items = $Tainacan_Items->fetch([
'tax_query' => [
[
'taxonomy' => $taxonomy2->get_db_identifier(),
'field' => 'name',
'terms' => 'test_new_value'
]
],
'posts_per_page' => -1
]);
$this->assertEquals(0, $items->found_posts);
$bulk->set_value($category2, 'test_new_value');
$items = $Tainacan_Items->fetch([
'tax_query' => [
[
'taxonomy' => $taxonomy2->get_db_identifier(),
'field' => 'name',
'terms' => 'test_new_value'
]
],
'posts_per_page' => -1
]);
$this->assertEquals(0, $items->found_posts);
}
}