diff --git a/docs/garbage-collector.md b/docs/garbage-collector.md index 41396fea6..bc93979a4 100644 --- a/docs/garbage-collector.md +++ b/docs/garbage-collector.md @@ -1,4 +1,5 @@ * everything auto draft * post_meta of deleted fields -* post_meta of deleted instaces of a multiple compound Field. post_meta of a field that is child of a compound field, but which the ID does not appear in any array of a compound field meta_value \ No newline at end of file +* post_meta of deleted instaces of a multiple compound Field. post_meta of a field that is child of a compound field, but which the ID does not appear in any array of a compound field meta_value +* orphan terms (with taxonomy that does not exist) \ No newline at end of file diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 28cd11899..c98742a19 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -209,7 +209,7 @@ class Term extends Entity { $name_match = null; if ( $name_matches ) { foreach ( $name_matches as $_match ) { - if ( strtolower( $name ) === strtolower( $_match->name ) ) { + if ( is_object($_match) && isset($_match) && strtolower( $name ) === strtolower( $_match->name ) ) { $name_match = $_match; break; } diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 8e8f14c78..6bd40a839 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -146,7 +146,7 @@ class Items extends Repository { $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $collections = $Tainacan_Collections->fetch( [], 'OBJECT' ); - $taxonomies = $Tainacan_Taxonomies->fetch( [], 'OBJECT' ); + $taxonomies = $Tainacan_Taxonomies->fetch( ['status' => ['auto-draft', 'draft', 'publish', 'private']], 'OBJECT' ); if ( ! is_array( $collections ) ) { return; diff --git a/src/classes/repositories/class-tainacan-taxonomies.php b/src/classes/repositories/class-tainacan-taxonomies.php index 82556ce73..13ec64ed2 100644 --- a/src/classes/repositories/class-tainacan-taxonomies.php +++ b/src/classes/repositories/class-tainacan-taxonomies.php @@ -139,31 +139,6 @@ class Taxonomies extends Repository { return $new_taxonomy; } - public function tainacan_taxonomy( $taxonomy_name ){ - $labels = array( - 'name' => __( 'Taxonomies', 'textdomain' ), - 'singular_name' => __( 'Taxonomy','textdomain' ), - 'search_items' => __( 'Search taxonomies', 'textdomain' ), - 'all_items' => __( 'All taxonomies', 'textdomain' ), - 'parent_item' => __( 'Parent taxonomy', 'textdomain' ), - 'parent_item_colon' => __( 'Parent taxonomy:', 'textdomain' ), - 'edit_item' => __( 'Edit taxonomy', 'textdomain' ), - 'update_item' => __( 'Update taxonomy', 'textdomain' ), - 'add_new_item' => __( 'Add New taxonomy', 'textdomain' ), - 'new_item_name' => __( 'New Genre taxonomy', 'textdomain' ), - 'menu_name' => __( 'Genre', 'textdomain' ), - ); - - $args = array( - 'hierarchical' => true, - 'labels' => $labels, - 'show_ui' => tnc_enable_dev_wp_interface(), - 'show_admin_column' => tnc_enable_dev_wp_interface(), - ); - - register_taxonomy( $taxonomy_name, array( ), $args ); - } - /** * fetch taxonomies based on ID or WP_Query args * diff --git a/tests/test-api-terms.php b/tests/test-api-terms.php index cb1d8711f..f3f06bd50 100644 --- a/tests/test-api-terms.php +++ b/tests/test-api-terms.php @@ -179,6 +179,41 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase { $this->assertEquals('Trap', $data['name']); } + + + function test_terms_of_draft_taxonomy() { + + $taxonomy = $this->tainacan_entity_factory->create_entity( + 'taxonomy', + array( + 'name' => 'genero', + 'description' => 'tipos de musica', + 'allow_insert' => 'yes', + 'status' => 'auto-draft' + ), + true + ); + + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); + $Tainacan_Terms = \Tainacan\Repositories\Terms::getInstance(); + + $new_attributes = [ + 'hideempty' => false, + ]; + $request = new \WP_REST_Request( + 'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms' + ); + + $request->set_query_params($new_attributes); + + $response = $this->server->dispatch($request); + + $data = $response->get_data(); + + $this->assertEquals(0, sizeof($data), 'new auto draft taxonomy should return 0 terms'); + + } + } ?> \ No newline at end of file diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index 1dd48a49d..93efd646f 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -69,4 +69,41 @@ class Taxonomies extends TAINACAN_UnitTestCase { $this->assertEquals( $test->get_name(), 'Rock' ); $this->assertEquals( $test->get_user(), 56 ); } + + function test_terms_of_draft_taxonomy() { + + $taxonomy = $this->tainacan_entity_factory->create_entity( + 'taxonomy', + array( + 'name' => 'genero', + 'description' => 'tipos de musica', + 'allow_insert' => 'yes', + 'status' => 'publish' + ), + true + ); + + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); + $Tainacan_Terms = \Tainacan\Repositories\Terms::getInstance(); + + $terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy->get_id()); + + $this->assertEquals(0, sizeof($terms), 'new auto draft taxonomy should return 0 terms'); + + $term = $this->tainacan_entity_factory->create_entity( + 'term', + array( + 'taxonomy' => $taxonomy->get_db_identifier(), + 'name' => 'Rock', + ), + true + ); + + + + $terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy->get_id()); + + $this->assertEquals(1, sizeof($terms), 'you should be able to create a term even if the taxonomy is still auto-draft'); + + } } \ No newline at end of file