diff --git a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php index 7a4a3584f..dcdcd621f 100644 --- a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -117,6 +117,16 @@ class Taxonomy extends Metadata_Type { $Tainacan_Metadata = Metadata::get_instance(); + // Check taxonomy visibility + $status = get_post_status( $this->get_option('taxonomy_id') ); + $post_status_obj = get_post_status_object($status); + if ( ! $post_status_obj->public ) { + $meta_status_obj = get_post_status_object($metadatum->get_status()); + if ( $meta_status_obj->public ) { + return ['taxonomy_id' => __('This metadatum can not be public because chosen taxonomy is not.', 'tainacan')]; + } + } + $taxonomy_metadata = $Tainacan_Metadata->fetch([ 'collection_id' => $metadatum->get_collection_id(), 'metadata_type' => 'Tainacan\\Metadata_Types\\Taxonomy' diff --git a/tests/test-api-visibility-objects.php b/tests/test-api-visibility-objects.php index a93f7c583..cb55c442f 100644 --- a/tests/test-api-visibility-objects.php +++ b/tests/test-api-visibility-objects.php @@ -161,7 +161,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase { 'metadatum', array( 'name' => 'metadata-private', - 'status' => 'publish', + 'status' => 'private', 'collection' => $collection, 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', 'metadata_type_options' => [ diff --git a/tests/test-bulkedit.php b/tests/test-bulkedit.php index 8d404b4b2..80f8b1514 100644 --- a/tests/test-bulkedit.php +++ b/tests/test-bulkedit.php @@ -62,7 +62,8 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { array( 'name' => 'genero', 'description' => 'tipos de musica', - 'allow_insert' => 'yes' + 'allow_insert' => 'yes', + 'status' => 'publish' ), true ); @@ -1214,7 +1215,8 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { array( 'name' => 'tax2', 'description' => 'tipos de musica', - 'allow_insert' => 'yes' + 'allow_insert' => 'yes', + 'status' => 'publish' ), true ); diff --git a/tests/test-category-metadatum-types.php b/tests/test-category-metadatum-types.php index 6cc95fce2..e04809b84 100644 --- a/tests/test-category-metadatum-types.php +++ b/tests/test-category-metadatum-types.php @@ -35,6 +35,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { array( 'name' => 'tax_test', 'collections' => [$collection], + 'status' => 'publish' ), true ); @@ -556,6 +557,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { 'taxonomy', array( 'name' => 'tax_test', + 'status' => 'publish' ), true ); @@ -604,5 +606,51 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { } + + function test_validate_private_taxonomy() { + + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); + $Tainacan_ItemMetadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'test', + ), + true + ); + + $tax = $this->tainacan_entity_factory->create_entity( + 'taxonomy', + array( + 'name' => 'tax_test', + 'status' => 'private' + ), + true + ); + + $meta = new \Tainacan\Entities\Metadatum(); + + $meta->set_name('test meta'); + $meta->set_status('publish'); + $meta->set_metadata_type('Tainacan\Metadata_Types\Taxonomy'); + $meta->set_collection($collection); + $meta->set_metadata_type_options([ + 'taxonomy_id' => $tax->get_id(), + 'allow_new_terms' => true + ]); + + $this->assertFalse($meta->validate(), 'Metadatum should not validate because taxonomy is private'); + + $meta->set_status('private'); + + $this->assertTrue($meta->validate(), 'Metadatum should validate because it is private now'); + + + + + + } } \ No newline at end of file diff --git a/tests/test-importer.php b/tests/test-importer.php index c33db64b0..5c3835d6b 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -335,6 +335,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { 'taxonomy', array( 'name' => 'genero', + 'status' => 'publish' ), true );