add test to methd `copy_value` of bulkedit #354

This commit is contained in:
vnmedeiros 2020-04-21 11:22:23 -03:00
parent 9dd62bac6a
commit 80f429e8b4
1 changed files with 182 additions and 29 deletions

View File

@ -1771,4 +1771,157 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase {
$this->assertEquals(20, $items->found_posts); $this->assertEquals(20, $items->found_posts);
} }
/**
* @group bulkedit-copy
*/
function test_copy_meta() {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$metadatum_copy = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadado_copy',
'status' => 'publish',
'collection' => $this->collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text',
),
true
);
$metadatum_owner = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadado_owner',
'status' => 'publish',
'collection' => $this->collection,
'metadata_type' => 'Tainacan\Metadata_Types\User',
'metadata_type_options' => [
'default_author' => 'no'
]
),
true
);
$query = [
'meta_query' => [
[
'key' => $this->metadatum->get_id(),
'value' => 'even'
]
],
'posts_per_page' => -1
];
$process = $this->new_process(
[
'query' => $query,
'collection_id' => $this->collection->get_id()
],
[
"method" => 'copy_value',
"metadatum_id" => $metadatum_copy->get_id(),
"metadatum_id_copy_from" => $this->metadatum->get_id(),
]
);
$this->assertInternalType('int', $this->run_process($process));
$query = [
'meta_query' => [
[
'key' => $metadatum_copy->get_id(),
'value' => 'even'
]
],
'posts_per_page' => -1
];
$items = $Tainacan_Items->fetch($query);
$this->assertEquals(20, $items->found_posts);
$process = $this->new_process(
[
'query' => $query,
'collection_id' => $this->collection->get_id()
],
[
"method" => 'copy_value',
"metadatum_id" => $metadatum_owner->get_id(),
"metadatum_id_copy_from" => 'create_by',
]
);
$this->assertInternalType('int', $this->run_process($process));
$query = [
'meta_query' => [
[
'key' => $metadatum_owner->get_id(),
'value' => get_current_user_id()
]
],
'posts_per_page' => -1
];
$items = $Tainacan_Items->fetch($query);
$this->assertEquals(20, $items->found_posts);
$taxonomy_copy = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'genero_copy',
'description' => 'tipos de musica',
'allow_insert' => 'yes',
'status' => 'publish'
),
true
);
$multiple_meta_copy = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'multiple_meta_copy',
'status' => 'publish',
'collection' => $this->collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [
'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy_copy->get_id()
],
'multiple' => 'yes'
),
true
);
$process = $this->new_process(
[
'items_ids' => $this->items_ids, // all
'collection_id' => $this->collection->get_id()
],
[
"method" => 'copy_value',
"metadatum_id" => $multiple_meta_copy->get_id(),
"metadatum_id_copy_from" => $this->category->get_id()
]
);
$this->assertInternalType('int', $this->run_process($process));
$query = [
'taxquery' => [
[
'taxonomy' => $this->taxonomy->get_db_identifier(),
'terms' => 'good'
]
],
'posts_per_page' => -1
];
$items = $Tainacan_Items->fetch($query);
print_r($items->found_posts);
$query = [
'taxquery' => [
[
'taxonomy' => $taxonomy_copy->get_db_identifier(),
'terms' => 'good'
]
],
'posts_per_page' => -1
];
$items_copy = $Tainacan_Items->fetch($query);
$this->assertEquals($items_copy->found_posts, $items->found_posts);
}
} }