refactor taxonomy metadata_type_options allow_new_terms to yes/no

This commit is contained in:
leogermani 2019-05-20 12:49:00 -03:00
parent 2141edeeab
commit af2e0b2f9f
8 changed files with 28 additions and 28 deletions

View File

@ -19,7 +19,7 @@ class Taxonomy extends Metadata_Type {
$this->set_primitive_type('term'); $this->set_primitive_type('term');
$this->set_default_options([ $this->set_default_options([
'allow_new_terms' => false 'allow_new_terms' => 'no'
]); ]);
$this->set_form_component('tainacan-form-taxonomy'); $this->set_form_component('tainacan-form-taxonomy');
@ -166,7 +166,7 @@ class Taxonomy extends Metadata_Type {
$valid = true; $valid = true;
if (false === $this->get_option('allow_new_terms')) { if ('no' === $this->get_option('allow_new_terms') || false === $this->get_option('allow_new_terms')) { //support legacy bug when it was saved as false
$terms = $item_metadata->get_value(); $terms = $item_metadata->get_value();
if (false === $terms) if (false === $terms)

View File

@ -366,7 +366,7 @@ class Test_Importer extends Importer {
'type' => 'Tainacan\Metadata_Types\Taxonomy', 'type' => 'Tainacan\Metadata_Types\Taxonomy',
'options' => [ 'options' => [
'taxonomy_id' => $this->get_transient('tax_1_id'), 'taxonomy_id' => $this->get_transient('tax_1_id'),
'allow_new_terms' => true 'allow_new_terms' => 'yes'
] ]
], $col1 ); ], $col1 );
@ -584,7 +584,7 @@ class Test_Importer extends Importer {
$metadatum1 = $this->metadata_repo->fetch( $this->get_transient('tax_1_metadatum') ); $metadatum1 = $this->metadata_repo->fetch( $this->get_transient('tax_1_metadatum') );
if ($metadatum1) { if ($metadatum1) {
$options = $metadatum1->get_metadata_type_options(); $options = $metadatum1->get_metadata_type_options();
$options['allow_new_terms'] = false; $options['allow_new_terms'] = 'no';
$metadatum1->set_metadata_type_options($options); $metadatum1->set_metadata_type_options($options);
if ($metadatum1->validate()) { if ($metadatum1->validate()) {
$this->metadata_repo->insert($metadatum1); $this->metadata_repo->insert($metadatum1);

View File

@ -149,7 +149,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase {
'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' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy_public->get_id() 'taxonomy_id' => $taxonomy_public->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'
@ -165,7 +165,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase {
'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' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy_private->get_id() 'taxonomy_id' => $taxonomy_private->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'

View File

@ -78,7 +78,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
'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' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy->get_id() 'taxonomy_id' => $taxonomy->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'
@ -1229,7 +1229,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
'collection' => $this->collection, 'collection' => $this->collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [ 'metadata_type_options' => [
'allow_new_terms' => false, 'allow_new_terms' => 'no',
'taxonomy_id' => $taxonomy2->get_id() 'taxonomy_id' => $taxonomy2->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'

View File

@ -50,7 +50,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -187,7 +187,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -202,7 +202,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
$metadatum->set_metadata_type_options([ $metadatum->set_metadata_type_options([
'taxonomy_id' => $tax2->get_id(), 'taxonomy_id' => $tax2->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
]); ]);
$metadatum->validate(); $metadatum->validate();
@ -230,7 +230,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax3->get_id(), 'taxonomy_id' => $tax3->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -302,7 +302,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -318,7 +318,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax2->get_id(), 'taxonomy_id' => $tax2->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -334,7 +334,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax2->get_id(), 'taxonomy_id' => $tax2->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -350,7 +350,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax3->get_id(), 'taxonomy_id' => $tax3->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -469,7 +469,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -486,7 +486,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax2->get_id(), 'taxonomy_id' => $tax2->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -502,7 +502,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax3->get_id(), 'taxonomy_id' => $tax3->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -519,7 +519,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax4->get_id(), 'taxonomy_id' => $tax4->get_id(),
'allow_new_terms' => false 'allow_new_terms' => 'no'
] ]
), ),
true true
@ -582,7 +582,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'status' => 'publish', 'status' => 'publish',
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => true 'allow_new_terms' => 'yes'
] ]
), ),
true true
@ -638,7 +638,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
$meta->set_collection($collection); $meta->set_collection($collection);
$meta->set_metadata_type_options([ $meta->set_metadata_type_options([
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => true 'allow_new_terms' => 'yes'
]); ]);
$this->assertFalse($meta->validate(), 'Metadatum should not validate because taxonomy is private'); $this->assertFalse($meta->validate(), 'Metadatum should not validate because taxonomy is private');

View File

@ -298,7 +298,7 @@ class Facets extends TAINACAN_UnitApiTestCase {
'collection' => $collection1, 'collection' => $collection1,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [ 'metadata_type_options' => [
'allow_new_terms' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy->get_id() 'taxonomy_id' => $taxonomy->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'
@ -317,7 +317,7 @@ class Facets extends TAINACAN_UnitApiTestCase {
'collection' => $collection2, 'collection' => $collection2,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [ 'metadata_type_options' => [
'allow_new_terms' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy->get_id() 'taxonomy_id' => $taxonomy->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'
@ -335,7 +335,7 @@ class Facets extends TAINACAN_UnitApiTestCase {
'collection' => $collection1, 'collection' => $collection1,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [ 'metadata_type_options' => [
'allow_new_terms' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy2->get_id() 'taxonomy_id' => $taxonomy2->get_id()
], ],
'multiple' => 'yes' 'multiple' => 'yes'
@ -379,7 +379,7 @@ class Facets extends TAINACAN_UnitApiTestCase {
'collection' => $collection2, 'collection' => $collection2,
'metadata_type' => 'Tainacan\Metadata_Types\Relationship', 'metadata_type' => 'Tainacan\Metadata_Types\Relationship',
'metadata_type_options' => [ 'metadata_type_options' => [
'allow_new_terms' => true, 'allow_new_terms' => 'yes',
'collection_id' => $collection1->get_id(), 'collection_id' => $collection1->get_id(),
'search' => [] 'search' => []
] ]

View File

@ -344,7 +344,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
array( array(
'name' => 'taxonomia', 'name' => 'taxonomia',
'collection_id' => $collection->get_id(), 'collection_id' => $collection->get_id(),
'metadata_type_options' => ['taxonomy_id' => $taxonomy->get_id(), 'allow_new_terms' => true ], 'metadata_type_options' => ['taxonomy_id' => $taxonomy->get_id(), 'allow_new_terms' => 'yes' ],
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'status' => 'publish' 'status' => 'publish'
), ),

View File

@ -365,7 +365,7 @@ class Taxonomies extends TAINACAN_UnitTestCase {
'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' => true, 'allow_new_terms' => 'yes',
'taxonomy_id' => $taxonomy->get_id() 'taxonomy_id' => $taxonomy->get_id()
], ],
), ),