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

@ -30,61 +30,61 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase {
$this->collection = $collection; $this->collection = $collection;
$metadatum = $this->tainacan_entity_factory->create_entity( $metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'metadado', 'name' => 'metadado',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
), ),
true true
); );
$this->metadatum = $metadatum; $this->metadatum = $metadatum;
$multiple_meta = $this->tainacan_entity_factory->create_entity( $multiple_meta = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'multimetadado', 'name' => 'multimetadado',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
'multiple' => 'yes', 'multiple' => 'yes',
'required' => 'no' 'required' => 'no'
), ),
true true
); );
$this->multiple_meta = $multiple_meta; $this->multiple_meta = $multiple_meta;
$taxonomy = $this->tainacan_entity_factory->create_entity( $taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy', 'taxonomy',
array( array(
'name' => 'genero', 'name' => 'genero',
'description' => 'tipos de musica', 'description' => 'tipos de musica',
'allow_insert' => 'yes', 'allow_insert' => 'yes',
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$this->taxonomy = $taxonomy; $this->taxonomy = $taxonomy;
$category = $this->tainacan_entity_factory->create_entity( $category = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'category', 'name' => 'category',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [ 'metadata_type_options' => [
'allow_new_terms' => 'yes', 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy->get_id() 'taxonomy_id' => $taxonomy->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'
), ),
true true
); );
$this->category = $category; $this->category = $category;
@ -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);
}
} }