Merge branch 'release/0.13' of https://github.com/tainacan/tainacan into release/0.13

This commit is contained in:
Mateus Machado Luna 2019-10-25 10:49:44 -03:00
commit 872c4ef130
4 changed files with 279 additions and 109 deletions

View File

@ -267,7 +267,7 @@ class REST_Importers_Controller extends REST_Controller {
if ( method_exists($importer, 'get_source_special_fields') ) {
$response['source_special_fields'] = $importer->get_source_special_fields();
}
$Tainacan_Importer_Handler->save_importer_instance($importer);
return new \WP_REST_Response( $response, 200 );
}

View File

@ -81,6 +81,7 @@ class Taxonomy extends Entity {
'rewrite' => [
'slug' => $this->get_slug()
],
'update_count_callback' => '_update_generic_term_count'
);
if (taxonomy_exists($this->get_db_identifier())){

View File

@ -148,7 +148,7 @@ class Relationship extends Metadata_Type {
}
} catch (Exception $e) {
} catch (\Exception $e) {
// item not found
}
@ -164,7 +164,7 @@ class Relationship extends Metadata_Type {
$return .= $this->get_item_html($item);
}
} catch (Exception $e) {
} catch (\Exception $e) {
// item not found
}

View File

@ -416,4 +416,173 @@ class Taxonomies extends TAINACAN_UnitTestCase {
}
function test_metadata_taxonomy_term_count() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection_1 = $this->tainacan_entity_factory->create_entity(
'collection',
array( 'name' => 'test-1', 'status' => 'publish', ),
true
);
$collection_2 = $this->tainacan_entity_factory->create_entity(
'collection',
array( 'name' => 'test-2', 'status' => 'publish', ),
true
);
$tax = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax_test',
'status' => 'publish',
//'enabled_post_types' => [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()]
),
true
);
$tax_repository = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax_test_repository',
'status' => 'publish'
),
true
);
$t1 = $this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $tax->get_db_identifier(),
'name' => 'term',
'user' => get_current_user_id(),
),
true
);
$t2 = $this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $tax_repository->get_db_identifier(),
'name' => 'term_repository'
),
true
);
$metadatum_1 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'meta-1',
'description' => 'description-1',
'collection' => $collection_1,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'status' => 'publish',
'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => 'no'
]
),
true
);
$metadatum_2 = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'meta-2',
'description' => 'description-2',
'collection' => $collection_2,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'status' => 'publish',
'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => 'no'
]
),
true
);
$metadatum_repository = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'meta-1',
'description' => 'description-1',
'collection_id' => $Tainacan_Metadata->get_default_metadata_attribute(),
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'status' => 'publish',
'metadata_type_options' => [
'taxonomy_id' => $tax_repository->get_id(),
'allow_new_terms' => 'no'
]
),
true
);
$i1 = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'item teste',
'description' => 'adasdasdsa',
'collection' => $collection_1,
'status' => 'publish'
),
true
);
$itemMeta1 = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum_1);
$itemMeta1->set_value('term');
$itemMeta1->validate();
$Tainacan_Item_Metadata->insert($itemMeta1);
$itemMeta1_repo = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum_repository);
$itemMeta1_repo->set_value('term_repository');
$itemMeta1_repo->validate();
$Tainacan_Item_Metadata->insert($itemMeta1_repo);
$i2 = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'item teste',
'description' => 'adasdasdsa',
'collection' => $collection_2,
'status' => 'private'
),
true
);
$itemMeta2 = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum_2);
$itemMeta2->set_value('term');
$itemMeta2->validate();
$Tainacan_Item_Metadata->insert($itemMeta2);
$itemMeta2_repo = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum_repository);
$itemMeta2_repo->set_value('term_repository');
$itemMeta2_repo->validate();
$Tainacan_Item_Metadata->insert($itemMeta2_repo);
$terms = get_terms([
'taxonomy' => $tax->get_db_identifier(),
//'hide_empty' => false,
]);
$this->assertEquals(1, count($terms));
wp_update_term_count($t1->get_term_id(), $tax->get_db_identifier());
wp_update_term_count($t2->get_term_id(), $tax_repository->get_db_identifier());
$term = get_term($t1->get_term_id());
$term_repo = get_term($t2->get_term_id());
$tax_used = get_object_taxonomies( [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()]);
$tax = get_taxonomy($tax->get_db_identifier());
$tax_repository = get_taxonomy($tax_repository->get_db_identifier());
$this->assertContains($collection_1->get_db_identifier(), $tax->object_type);
$this->assertContains($collection_2->get_db_identifier(), $tax->object_type);
$this->assertContains($collection_1->get_db_identifier(), $tax_repository->object_type);
$this->assertContains($collection_2->get_db_identifier(), $tax_repository->object_type);
$this->assertEquals(2, $term->count);
$this->assertEquals(2, $term_repo->count);
}
}