small fixes handling auto draft taxonomies

This commit is contained in:
Leo Germani 2018-04-10 14:13:20 -03:00
parent d7aa5d663c
commit 3999690358
6 changed files with 76 additions and 28 deletions

View File

@ -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
* 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)

View File

@ -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;
}

View File

@ -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;

View File

@ -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
*

View File

@ -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');
}
}
?>

View File

@ -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');
}
}