From 7e2dd2c1990ada55b7a94e223b5ba6660d7e73ab Mon Sep 17 00:00:00 2001 From: Eduardo humberto Date: Fri, 10 Nov 2017 13:23:02 -0200 Subject: [PATCH] =?UTF-8?q?criando=20testes=20para=20cria=C3=A7=C3=A3o=20d?= =?UTF-8?q?e=20taxonomias=20e=20termos=20destas=20taxonomias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Entities/Taxonomy.php | 63 +++++++++++++++++++ .../{Entities => FieldTypes}/FieldType.php | 0 .../TextFieldType.php | 0 src/classes/Repositories/Taxonomies.php | 25 +++++++- src/test-tainacan.php | 6 +- tests/test-taxonomies.php | 60 ++++++++++++++++++ 6 files changed, 150 insertions(+), 4 deletions(-) rename src/classes/{Entities => FieldTypes}/FieldType.php (100%) rename src/classes/{Entities => FieldTypes}/TextFieldType.php (100%) create mode 100644 tests/test-taxonomies.php diff --git a/src/classes/Entities/Taxonomy.php b/src/classes/Entities/Taxonomy.php index 4e49cd06f..5d8e84c58 100644 --- a/src/classes/Entities/Taxonomy.php +++ b/src/classes/Entities/Taxonomy.php @@ -22,4 +22,67 @@ class Tainacan_Taxonomy extends Entity { } } + + // Getters + + function get_id() { + return $this->get_mapped_property('ID'); + } + + + function get_name() { + return $this->get_mapped_property('name'); + } + + function get_parent() { + return $this->get_mapped_property('parent'); + } + + + function get_description() { + return $this->get_mapped_property('description'); + } + + function get_allow_insert() { + return ( boolean ) $this->get_mapped_property('allow_insert'); + } + + function get_taxonomy_name() { + return $this->get_mapped_property('taxonomy_name'); + } + + + + + function get_collection() { + return new TainacanCollection( $this->get_mapped_property('collection') ); + } + + // Setters + + + function set_name($value) { + return $this->set_mapped_property('name', $value); + } + + function set_parent($value) { + return $this->set_mapped_property('parent', $value); + } + + + function set_description($value) { + return $this->set_mapped_property('description', $value); + } + + function set_allow_insert($value) { + return $this->set_mapped_property('allow_insert', $value); + } + + /** + * @param TainacanCollection + */ + function set_collection($value) { + $ID = ($value instanceof TainacanCollection ) ? $value->get_id() : $value; + return $this->set_mapped_property('collection', $ID); + } } \ No newline at end of file diff --git a/src/classes/Entities/FieldType.php b/src/classes/FieldTypes/FieldType.php similarity index 100% rename from src/classes/Entities/FieldType.php rename to src/classes/FieldTypes/FieldType.php diff --git a/src/classes/Entities/TextFieldType.php b/src/classes/FieldTypes/TextFieldType.php similarity index 100% rename from src/classes/Entities/TextFieldType.php rename to src/classes/FieldTypes/TextFieldType.php diff --git a/src/classes/Repositories/Taxonomies.php b/src/classes/Repositories/Taxonomies.php index 8065f0418..e15a3c2b3 100644 --- a/src/classes/Repositories/Taxonomies.php +++ b/src/classes/Repositories/Taxonomies.php @@ -16,6 +16,7 @@ class Tainacan_Taxonomies { 'name' => 'post_title', 'parent' => 'parent', 'description' => 'post_content', + 'taxonomy_name' => 'post_name', 'allow_insert' => 'meta', 'collection' => 'meta', ]; @@ -107,7 +108,7 @@ class Tainacan_Taxonomies { if (!get_post_meta($id, self::DB_IDENTIFIER_META, true)) { $p = get_post($id); add_post_meta($id, self::DB_IDENTIFIER_META, $p->post_name); - registerTainacanTaxonomy( $p->post_name ); + $this->registerTainacanTaxonomy( $p->post_name ); } return $id; @@ -137,4 +138,24 @@ class Tainacan_Taxonomies { register_taxonomy( $taxonomy_name, array( ), $args ); } -} \ No newline at end of file + + function get_taxonomy_by_id($id) { + return new Tainacan_Taxonomy($id); + } + + function insert_term( $name, $taxonomy, $args = array() ){ + $term = wp_insert_term( $name, $taxonomy, $args ); + return $term['term_id']; + } + + function get_terms( $taxonomies, $args ){ + return get_terms( $taxonomies, $args ); + } + + function get_term_by($field,$value,$taxonomy){ + return get_term_by($field,$value,$taxonomy); + } +} + +global $Tainacan_Taxonomies; +$Tainacan_Taxonomies = new Tainacan_Taxonomies(); \ No newline at end of file diff --git a/src/test-tainacan.php b/src/test-tainacan.php index e5d4efca3..fd1e9a63b 100644 --- a/src/test-tainacan.php +++ b/src/test-tainacan.php @@ -10,12 +10,14 @@ Version: 10.9.8.7.6.5.4 include('classes/Repositories/Collections.php'); include('classes/Repositories/Items.php'); include('classes/Repositories/Metatadas.php'); +include('classes/Repositories/Taxonomies.php'); include('classes/Entity.php'); include('classes/Entities/Collection.php'); include('classes/Entities/Item.php'); include('classes/Entities/Metadata.php'); -include('classes/Entities/FieldType.php'); -include('classes/Entities/TextFieldType.php'); +include('classes/Entities/Taxonomy.php'); +include('classes/FieldTypes/FieldType.php'); +include('classes/FieldTypes/TextFieldType.php'); require_once('tainacan-api-controllers/class-tainacan-api.php'); $tainacan_api = new Tainacan_API(); diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php new file mode 100644 index 000000000..eddcef75c --- /dev/null +++ b/tests/test-taxonomies.php @@ -0,0 +1,60 @@ +set_name('genero'); + $taxonomy->set_description('tipos de musica'); + $taxonomy->set_allow_insert(true); + + //inserindo + $taxonomy_id = $Tainacan_Taxonomies->insert($taxonomy); + + //retorna a taxonomia + $test = $Tainacan_Taxonomies->get_taxonomy_by_id($taxonomy_id); + + $this->assertEquals( $test->get_name(), 'genero' ); + $this->assertEquals( $test->get_description(), 'tipos de musica' ); + $this->assertEquals( $test->get_allow_insert(), true ); + $this->assertEquals( taxonomy_exists( $test->get_taxonomy_name() ) , true ); + } + + function test_add_term_taxonomy(){ + global $Tainacan_Taxonomies; + $taxonomy = new Tainacan_Taxonomy(); + + //setando os valores na classe do tainacan + $taxonomy->set_name('genero'); + + //insere a taxonomia + $taxonomy_id = $Tainacan_Taxonomies->insert($taxonomy); + + //retorna a taxonomia + $taxonomy_test = $Tainacan_Taxonomies->get_taxonomy_by_id($taxonomy_id); + + //insere um termo na taxonmia + $term_id = $Tainacan_Taxonomies->insert_term('Rock', $taxonomy_test->get_taxonomy_name()); + + //retorna o termo + $term = $Tainacan_Taxonomies->get_term_by('id', $term_id, $taxonomy_test->get_taxonomy_name()); + + $this->assertEquals( $term->name, 'Rock' ); + } +} \ No newline at end of file