add tests for submission metadata types #388

This commit is contained in:
vnmedeiros 2020-09-22 11:08:17 -03:00
parent 847c616698
commit deaa630d89
1 changed files with 223 additions and 18 deletions

View File

@ -40,29 +40,197 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase {
} }
private function create_metadatum(&$collection) { private function create_metadatum(&$collection) {
$tax = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax_test',
'collections' => [$collection],
'status' => 'publish'
),
true
);
$this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $tax->get_db_identifier(),
'name' => 'term-1',
),
true
);
$this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $tax->get_db_identifier(),
'name' => 'term-2',
),
true
);
$metadatum_compound = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum_compound',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Compound',
),
true
);
$metadatum_child1 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum_child1',
'status' => 'publish',
'collection' => $collection,
'parent' => $metadatum_compound->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Text',
),
true
);
$metadatum_child2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum_child2',
'status' => 'publish',
'collection' => $collection,
'parent' => $metadatum_compound->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Text',
),
true
);
$metadatum_compound_multiple = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum_compound_multiple',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Compound',
'multiple' => 'yes'
),
true
);
$metadatum_child1_multiple = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum_child1_multiple',
'status' => 'publish',
'collection' => $collection,
'parent' => $metadatum_compound_multiple->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Text',
),
true
);
$metadatum_child2_multiple = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum_child2_multiple',
'status' => 'publish',
'collection' => $collection,
'parent' => $metadatum_compound_multiple->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Text',
),
true
);
$metadatum = array( $metadatum = array(
'text' => $this->tainacan_entity_factory->create_entity( 'text' => $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'text', 'name' => 'text',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
), ),
true true
)->get_id(), )->get_id(),
'textarea' => $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'textarea',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Textarea',
),
true
)->get_id(),
'numeric' => $this->tainacan_entity_factory->create_entity( 'numeric' => $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'numeric', 'name' => 'numeric',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Numeric', 'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
), ),
true true
)->get_id() )->get_id(),
'date' => $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'date',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Date',
),
true
)->get_id(),
'selectbox' => $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'selectbox',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Selectbox',
'metadata_type_options' => [
'options' => ['op1', 'op2', 'op3']
]
),
true
)->get_id(),
'taxonomy' => $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'taxonomy',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => 'no'
],
),
true
)->get_id(),
'compound' => [
'parent' => $metadatum_compound->get_id(),
'childrens' => [
$metadatum_child1->get_id(),
$metadatum_child2->get_id()
]
],
'compound_multiple' => [
'parent' => $metadatum_compound_multiple->get_id(),
'childrens' => [
$metadatum_child1_multiple->get_id(),
$metadatum_child2_multiple->get_id()
]
]
); );
//relationship?
//user?
return $metadatum; return $metadatum;
} }
@ -81,9 +249,46 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase {
'metadatum_id' => $metadatums['text'], 'metadatum_id' => $metadatums['text'],
'value' => 'Text submission' 'value' => 'Text submission'
], ],
[
'metadatum_id' => $metadatums['textarea'],
'value' => 'textarea submission'
],
[
'metadatum_id' => $metadatums['date'],
'value' => '2020-12-31'
],
[ [
'metadatum_id' => $metadatums['numeric'], 'metadatum_id' => $metadatums['numeric'],
'value' => 10 'value' => 10
],
[
'metadatum_id' => $metadatums['selectbox'],
'value' => 'op2'
],
[
'metadatum_id' => $metadatums['taxonomy'],
'value' => 'term-1'
],
[
'metadatum_id' => $metadatums['compound']['parent'],
'value' => [
['metadatum_id' => $metadatums['compound']['childrens'][0], 'value' => 'metadatum_child1'],
['metadatum_id' => $metadatums['compound']['childrens'][1], 'value' => 'metadatum_child2']
]
],
[
'metadatum_id' => $metadatums['compound_multiple']['parent'],
'value' => [
[
['metadatum_id' => $metadatums['compound_multiple']['childrens'][0], 'value' => 'metadatum_child1_multiple_row_1'],
['metadatum_id' => $metadatums['compound_multiple']['childrens'][1], 'value' => 'metadatum_child2_multiple_row_1']
],
[
['metadatum_id' => $metadatums['compound_multiple']['childrens'][0], 'value' => 'metadatum_child1_multiple_row_2'],
['metadatum_id' => $metadatums['compound_multiple']['childrens'][1], 'value' => 'metadatum_child2_multiple_row_2']
]
]
] ]
) )
]); ]);