From af2e0b2f9fda892878d612809221b71bb254fc34 Mon Sep 17 00:00:00 2001 From: leogermani Date: Mon, 20 May 2019 12:49:00 -0300 Subject: [PATCH] refactor taxonomy metadata_type_options allow_new_terms to yes/no --- .../taxonomy/class-tainacan-taxonomy.php | 4 +-- src/importer/class-tainacan-test-importer.php | 4 +-- tests/test-api-visibility-objects.php | 4 +-- tests/test-bulkedit.php | 4 +-- tests/test-category-metadatum-types.php | 28 +++++++++---------- tests/test-facets.php | 8 +++--- tests/test-importer.php | 2 +- tests/test-taxonomies.php | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php index dcdcd621f..c1e016b2d 100644 --- a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -19,7 +19,7 @@ class Taxonomy extends Metadata_Type { $this->set_primitive_type('term'); $this->set_default_options([ - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ]); $this->set_form_component('tainacan-form-taxonomy'); @@ -166,7 +166,7 @@ class Taxonomy extends Metadata_Type { $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(); if (false === $terms) diff --git a/src/importer/class-tainacan-test-importer.php b/src/importer/class-tainacan-test-importer.php index 28f265c1d..19d3f8f0b 100644 --- a/src/importer/class-tainacan-test-importer.php +++ b/src/importer/class-tainacan-test-importer.php @@ -366,7 +366,7 @@ class Test_Importer extends Importer { 'type' => 'Tainacan\Metadata_Types\Taxonomy', 'options' => [ 'taxonomy_id' => $this->get_transient('tax_1_id'), - 'allow_new_terms' => true + 'allow_new_terms' => 'yes' ] ], $col1 ); @@ -584,7 +584,7 @@ class Test_Importer extends Importer { $metadatum1 = $this->metadata_repo->fetch( $this->get_transient('tax_1_metadatum') ); if ($metadatum1) { $options = $metadatum1->get_metadata_type_options(); - $options['allow_new_terms'] = false; + $options['allow_new_terms'] = 'no'; $metadatum1->set_metadata_type_options($options); if ($metadatum1->validate()) { $this->metadata_repo->insert($metadatum1); diff --git a/tests/test-api-visibility-objects.php b/tests/test-api-visibility-objects.php index e2841a22e..47e4f996a 100644 --- a/tests/test-api-visibility-objects.php +++ b/tests/test-api-visibility-objects.php @@ -149,7 +149,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase { 'collection' => $collection, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy_public->get_id() ], 'multiple' => 'yes' @@ -165,7 +165,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase { 'collection' => $collection, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy_private->get_id() ], 'multiple' => 'yes' diff --git a/tests/test-bulkedit.php b/tests/test-bulkedit.php index 80f8b1514..55f35805a 100644 --- a/tests/test-bulkedit.php +++ b/tests/test-bulkedit.php @@ -78,7 +78,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { 'collection' => $collection, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy->get_id() ], 'multiple' => 'yes' @@ -1229,7 +1229,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { 'collection' => $this->collection, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => false, + 'allow_new_terms' => 'no', 'taxonomy_id' => $taxonomy2->get_id() ], 'multiple' => 'yes' diff --git a/tests/test-category-metadatum-types.php b/tests/test-category-metadatum-types.php index e04809b84..110ba71b9 100644 --- a/tests/test-category-metadatum-types.php +++ b/tests/test-category-metadatum-types.php @@ -50,7 +50,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -187,7 +187,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -202,7 +202,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $metadatum->set_metadata_type_options([ 'taxonomy_id' => $tax2->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ]); $metadatum->validate(); @@ -230,7 +230,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax3->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -302,7 +302,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -318,7 +318,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax2->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -334,7 +334,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax2->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -350,7 +350,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax3->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -469,7 +469,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -486,7 +486,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax2->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -502,7 +502,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax3->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -519,7 +519,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax4->get_id(), - 'allow_new_terms' => false + 'allow_new_terms' => 'no' ] ), true @@ -582,7 +582,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'status' => 'publish', 'metadata_type_options' => [ 'taxonomy_id' => $tax->get_id(), - 'allow_new_terms' => true + 'allow_new_terms' => 'yes' ] ), true @@ -638,7 +638,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $meta->set_collection($collection); $meta->set_metadata_type_options([ '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'); diff --git a/tests/test-facets.php b/tests/test-facets.php index 92f562453..5dcb5584c 100644 --- a/tests/test-facets.php +++ b/tests/test-facets.php @@ -298,7 +298,7 @@ class Facets extends TAINACAN_UnitApiTestCase { 'collection' => $collection1, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy->get_id() ], 'multiple' => 'yes' @@ -317,7 +317,7 @@ class Facets extends TAINACAN_UnitApiTestCase { 'collection' => $collection2, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy->get_id() ], 'multiple' => 'yes' @@ -335,7 +335,7 @@ class Facets extends TAINACAN_UnitApiTestCase { 'collection' => $collection1, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy2->get_id() ], 'multiple' => 'yes' @@ -379,7 +379,7 @@ class Facets extends TAINACAN_UnitApiTestCase { 'collection' => $collection2, 'metadata_type' => 'Tainacan\Metadata_Types\Relationship', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'collection_id' => $collection1->get_id(), 'search' => [] ] diff --git a/tests/test-importer.php b/tests/test-importer.php index 74d05f052..19e94455b 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -344,7 +344,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { array( 'name' => 'taxonomia', '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', 'status' => 'publish' ), diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index 9c454cd8b..6d13b6070 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -365,7 +365,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { 'collection' => $collection, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ - 'allow_new_terms' => true, + 'allow_new_terms' => 'yes', 'taxonomy_id' => $taxonomy->get_id() ], ),