2017-11-10 15:23:02 +00:00
|
|
|
<?php
|
2017-11-15 21:07:44 +00:00
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
2017-11-10 15:23:02 +00:00
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
2017-12-04 18:20:49 +00:00
|
|
|
class Taxonomies extends TAINACAN_UnitTestCase {
|
2017-11-10 15:23:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Teste da insercao de uma taxonomia simples
|
|
|
|
*/
|
|
|
|
function test_add() {
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
2017-11-10 15:23:02 +00:00
|
|
|
|
2017-12-04 18:20:49 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
'description' => 'tipos de musica',
|
|
|
|
'allow_insert' => 'yes'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-10 15:23:02 +00:00
|
|
|
|
|
|
|
//retorna a taxonomia
|
2017-11-21 11:15:44 +00:00
|
|
|
$test = $Tainacan_Taxonomies->fetch($taxonomy->get_id());
|
2017-11-10 15:23:02 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $test->get_name(), 'genero' );
|
|
|
|
$this->assertEquals( $test->get_description(), 'tipos de musica' );
|
2017-12-01 16:06:35 +00:00
|
|
|
$this->assertEquals( $test->get_allow_insert(), 'yes' );
|
2017-11-11 22:25:54 +00:00
|
|
|
$this->assertEquals( taxonomy_exists( $test->get_db_identifier() ) , true );
|
2017-11-10 15:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_add_term_taxonomy(){
|
2018-04-11 14:18:55 +00:00
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
|
|
|
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
2017-11-10 15:23:02 +00:00
|
|
|
|
2017-12-04 18:20:49 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-10 15:23:02 +00:00
|
|
|
|
|
|
|
//retorna a taxonomia
|
2017-11-21 11:15:44 +00:00
|
|
|
$taxonomy_test = $Tainacan_Taxonomies->fetch($taxonomy->get_id());
|
2017-11-10 15:23:02 +00:00
|
|
|
|
2017-12-04 18:20:49 +00:00
|
|
|
$term = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy_test->get_db_identifier(),
|
|
|
|
'name' => 'Rock',
|
|
|
|
'user' => 56
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-11-10 15:23:02 +00:00
|
|
|
|
2017-11-10 16:39:27 +00:00
|
|
|
//retorna um objeto da classe Tainacan_Term
|
2018-03-05 16:06:01 +00:00
|
|
|
$test = $Tainacan_Terms->fetch($term->get_term_id(), $taxonomy_test);
|
2017-11-10 16:39:27 +00:00
|
|
|
$this->assertEquals( $test->get_name(), 'Rock' );
|
|
|
|
$this->assertEquals( $test->get_user(), 56 );
|
2017-11-10 15:23:02 +00:00
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
function test_terms_of_draft_taxonomy() {
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
'description' => 'tipos de musica',
|
|
|
|
'allow_insert' => 'yes',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-04-11 14:26:46 +00:00
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
|
|
|
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
2018-04-10 17:13:20 +00:00
|
|
|
|
|
|
|
$terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy->get_id());
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
$this->assertEquals(0, sizeof($terms), 'new auto draft taxonomy should return 0 terms');
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
$term = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Rock',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
$terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy->get_id());
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
$this->assertEquals(1, sizeof($terms), 'you should be able to create a term even if the taxonomy is still auto-draft');
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
function test_term_exists() {
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
'description' => 'tipos de musica',
|
|
|
|
'allow_insert' => 'yes',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
|
|
|
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$term = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Rock',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$parent = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Parent',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$child = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Child',
|
|
|
|
'parent' => $parent->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertFalse( $Tainacan_Terms->term_exists('Reggae', $taxonomy->get_db_identifier()) );
|
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists('Rock', $taxonomy->get_db_identifier()) );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
//var_dump( $Tainacan_Terms->term_exists('Rock', $taxonomy->get_db_identifier(), 0, true) );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
// test extreme case
|
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$term_2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'test 123',
|
|
|
|
'parent' => $term->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertFalse( $Tainacan_Terms->term_exists('test 123', $taxonomy->get_db_identifier(), 0) ); // parent 0
|
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists('test 123', $taxonomy->get_db_identifier(), $term->get_id()) ); // spaces in between
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
// testing passing taxonomy object
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists('Rock', $taxonomy) );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-03-28 15:05:21 +00:00
|
|
|
// testing passing taxonomy ID
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists('Rock', $taxonomy->get_id()) );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
// testing via Taxonomy object
|
|
|
|
$this->assertTrue( $taxonomy->term_exists('Rock') );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
// testing retrieving the term
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertTrue( $taxonomy->term_exists('Rock', 0, true) instanceof \WP_Term );
|
|
|
|
$this->assertEquals( $term->get_id(), $taxonomy->term_exists('Rock', 0, true)->term_taxonomy_id );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
// test parent
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier()) ); // parent null
|
|
|
|
$this->assertFalse( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier(), 0) ); // parent 0
|
2019-10-23 23:08:00 +00:00
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier(), $parent->get_id()) ); // parent
|
|
|
|
|
|
|
|
// test with ID
|
2019-03-28 15:05:21 +00:00
|
|
|
$this->assertTrue( $Tainacan_Terms->term_exists($term->get_id(), $taxonomy->get_id()) );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
// test get term
|
2019-03-28 15:05:21 +00:00
|
|
|
$test_term = $Tainacan_Terms->term_exists($term->get_id(), $taxonomy->get_id(), null, true);
|
|
|
|
$this->assertEquals($term->get_id(), $test_term->term_id);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-03-28 15:05:21 +00:00
|
|
|
$test_term = $Tainacan_Terms->term_exists('Rock', $taxonomy->get_id(), null, true);
|
|
|
|
$this->assertEquals($term->get_id(), $test_term->term_id);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-03-28 15:05:21 +00:00
|
|
|
$test_term = $Tainacan_Terms->term_exists('Parent', $taxonomy->get_id(), null, true);
|
|
|
|
$this->assertEquals($parent->get_id(), $test_term->term_id);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
// test brackets
|
|
|
|
$test_term = $Tainacan_Terms->term_exists('[Rock]', $taxonomy->get_id(), null, true);
|
|
|
|
$this->assertFalse($test_term);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
function test_term_validation() {
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
'description' => 'tipos de musica',
|
|
|
|
'allow_insert' => 'yes',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
|
|
|
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$term = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Rock',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$parent = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Parent',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$child = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Child',
|
|
|
|
'parent' => $parent->get_id()
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$newTerm = new \Tainacan\Entities\Term();
|
|
|
|
$newTerm->set_name('Child');
|
|
|
|
$newTerm->set_taxonomy($taxonomy->get_db_identifier());
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertTrue( $newTerm->validate() );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$newTerm->set_parent($parent->get_id());
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertFalse( $newTerm->validate(), 'term should not validate because it has a duplicate in the same level' );
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$child->set_description('changed');
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2018-11-13 20:21:02 +00:00
|
|
|
$this->assertTrue( $child->validate(), 'child should validate');
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-10 17:13:20 +00:00
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-01-18 21:49:59 +00:00
|
|
|
/**
|
2019-10-23 23:08:00 +00:00
|
|
|
* @group enabled
|
2019-01-18 21:49:59 +00:00
|
|
|
*/
|
|
|
|
function test_enabled_post_types(){
|
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
|
|
|
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
|
|
|
|
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
2019-01-21 12:32:22 +00:00
|
|
|
'enabled_post_types' => ['post']
|
2019-01-18 21:49:59 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-01-21 12:32:22 +00:00
|
|
|
|
2019-01-18 21:49:59 +00:00
|
|
|
$taxonomy = $Tainacan_Taxonomies->insert($taxonomy);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-01-18 21:49:59 +00:00
|
|
|
$pto = get_object_taxonomies('post');
|
|
|
|
$pages = get_object_taxonomies('page');
|
|
|
|
$this->assertContains($taxonomy->get_db_identifier(), $pto);
|
|
|
|
$this->assertNotContains($taxonomy->get_db_identifier(), $pages);
|
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
function test_brackets() {
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
'description' => 'tipos de musica',
|
|
|
|
'allow_insert' => 'yes',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
|
|
|
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$term = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => 'Rock',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$term2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'term',
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy->get_db_identifier(),
|
|
|
|
'name' => '[Rock]',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy);
|
|
|
|
$this->assertEquals(2, sizeof($terms));
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
function test_brackets_2() {
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'teste',
|
|
|
|
'description' => 'No description',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'genero',
|
|
|
|
'description' => 'tipos de musica',
|
|
|
|
'allow_insert' => 'yes',
|
|
|
|
'status' => 'publish'
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadatum = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'metadatum',
|
|
|
|
array(
|
|
|
|
'name' => 'metadado',
|
|
|
|
'description' => 'descricao',
|
|
|
|
'collection' => $collection,
|
|
|
|
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
|
|
|
|
'metadata_type_options' => [
|
2019-05-20 15:49:00 +00:00
|
|
|
'allow_new_terms' => 'yes',
|
2019-05-02 18:09:49 +00:00
|
|
|
'taxonomy_id' => $taxonomy->get_id()
|
|
|
|
],
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$i1 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'item',
|
|
|
|
array(
|
|
|
|
'title' => 'item teste',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'collection' => $collection
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$i2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'item',
|
|
|
|
array(
|
|
|
|
'title' => 'item2 teste',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
'collection' => $collection
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$itemMeta1 = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum);
|
|
|
|
$itemMeta1->set_value('Rock');
|
|
|
|
$itemMeta1->validate();
|
|
|
|
$Tainacan_Item_Metadata->insert($itemMeta1);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
//$this->assertNotFalse(term_exists( 'Rock', $taxonomy->get_db_identifier() ));
|
|
|
|
// term_exists() is not to be trusted
|
|
|
|
//$this->assertFalse(term_exists( '[Rock]', $taxonomy->get_db_identifier() ));
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$itemMeta2 = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum);
|
|
|
|
$itemMeta2->set_value('[Rock]');
|
|
|
|
$itemMeta2->validate();
|
|
|
|
$Tainacan_Item_Metadata->insert($itemMeta2);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$itemMeta1_check = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum);
|
|
|
|
$this->assertEquals('Rock', $itemMeta1_check->get_value()->get_name());
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
$itemMeta2_check = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum);
|
|
|
|
$this->assertEquals('[Rock]', $itemMeta2_check->get_value()->get_name());
|
2019-10-23 23:08:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-02 18:09:49 +00:00
|
|
|
}
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-10-23 19:48:51 +00:00
|
|
|
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',
|
2019-10-23 23:08:00 +00:00
|
|
|
array( 'name' => 'test-1', 'status' => 'publish', ),
|
2019-10-23 19:48:51 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$collection_2 = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
2019-10-23 23:08:00 +00:00
|
|
|
array( 'name' => 'test-2', 'status' => 'publish', ),
|
2019-10-23 19:48:51 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$tax = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'taxonomy',
|
|
|
|
array(
|
|
|
|
'name' => 'tax_test',
|
|
|
|
'status' => 'publish',
|
2019-10-23 19:55:27 +00:00
|
|
|
//'enabled_post_types' => [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()]
|
2019-10-23 19:48:51 +00:00
|
|
|
),
|
|
|
|
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
|
|
|
|
);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-10-23 19:48:51 +00:00
|
|
|
$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',
|
2019-10-23 23:08:00 +00:00
|
|
|
'collection' => $collection_1,
|
|
|
|
'status' => 'publish'
|
2019-10-23 19:48:51 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$itemMeta1 = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum_1);
|
|
|
|
$itemMeta1->set_value('term');
|
|
|
|
$itemMeta1->validate();
|
|
|
|
$Tainacan_Item_Metadata->insert($itemMeta1);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-10-23 19:48:51 +00:00
|
|
|
$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',
|
2019-10-23 23:08:00 +00:00
|
|
|
'collection' => $collection_2,
|
|
|
|
'status' => 'private'
|
2019-10-23 19:48:51 +00:00
|
|
|
),
|
|
|
|
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());
|
2019-10-23 23:08:00 +00:00
|
|
|
wp_update_term_count($t2->get_term_id(), $tax_repository->get_db_identifier());
|
2019-10-23 19:48:51 +00:00
|
|
|
|
|
|
|
$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()]);
|
2019-10-23 23:08:00 +00:00
|
|
|
|
2019-10-23 19:48:51 +00:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2019-10-23 23:08:00 +00:00
|
|
|
}
|