From 657ddc6f9a3cb9ad7684caf62a843d4f341fb938 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 29 Mar 2021 01:44:06 -0300 Subject: [PATCH 01/30] renames test functions --- tests/test-item-metadata.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 9badf85e3..6ac548662 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -70,7 +70,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { /** * Teste da insercao de um metadado simples com o tipo */ - function teste_required(){ + function test_required(){ $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); @@ -125,7 +125,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals('teste_value', $item_metadata->get_value()); } - function teste_collection_key(){ + function test_collection_key(){ $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); @@ -193,7 +193,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertFalse($n_item_metadata2->validate(), 'Collection key should not validate another item metadatada with the same value'); } - function teste_fetch(){ + function test_fetch(){ $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( From cf046af8c7b224aabd21f8f9d089f52469ab4488 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 29 Mar 2021 01:45:27 -0300 Subject: [PATCH 02/30] Renames more test functions to a common pattern --- tests/test-compound-metadatum-types.php | 2 +- tests/test-filters.php | 2 +- tests/test-items.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-compound-metadatum-types.php b/tests/test-compound-metadatum-types.php index 14d758374..539fb74c3 100644 --- a/tests/test-compound-metadatum-types.php +++ b/tests/test-compound-metadatum-types.php @@ -347,7 +347,7 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { } - function teste_validations_metadada_order() { + function test_validations_metadada_order() { $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); diff --git a/tests/test-filters.php b/tests/test-filters.php index d21d4ed36..27517e746 100644 --- a/tests/test-filters.php +++ b/tests/test-filters.php @@ -14,7 +14,7 @@ namespace Tainacan\Tests; class Filters extends TAINACAN_UnitTestCase { - function teste_add(){ + function test_add(){ $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( diff --git a/tests/test-items.php b/tests/test-items.php index 8cae8b3df..fe8def1c4 100644 --- a/tests/test-items.php +++ b/tests/test-items.php @@ -48,7 +48,7 @@ class Items extends TAINACAN_UnitTestCase { $this->assertTrue(current_user_can($collection->get_items_capabilities()->edit_post, $item->get_id()), 'Administrator cannot edit an item!'); } - function teste_query(){ + function test_query(){ $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -246,7 +246,7 @@ class Items extends TAINACAN_UnitTestCase { } - function teste_meta_query_in(){ + function test_meta_query_in(){ $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( From 37b21ae9477982bc3556c9929599ad8bb21213a0 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 29 Mar 2021 02:41:31 -0300 Subject: [PATCH 03/30] adds myself to contributors (: --- src/readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/readme.txt b/src/readme.txt index b8cccfaef..e465e24c2 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -1,5 +1,5 @@ === Tainacan === -Contributors: andrebenedito, daltonmartins, fabianobn, jacsonp, leogermani, weryques, wetah, eduardohumberto, ravipassos, jessicafpx, marinagiolo, omarceloavila, vnmedeiros, tainacan +Contributors: andrebenedito, daltonmartins, fabianobn, jacsonp, leogermani, weryques, wetah, eduardohumberto, ravipassos, jessicafpx, marinagiolo, omarceloavila, vnmedeiros, tainacan, r-guimaraes Tags: museums, libraries, archives, GLAM, collections, repository Requires at least: 4.8 Tested up to: 5.6 From 56246053ca34e44df699efed6e26d574393b44b6 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 29 Mar 2021 02:50:31 -0300 Subject: [PATCH 04/30] script files tiny doc tweaks --- build-watch.sh | 3 +-- build.sh | 1 + compile-sass.sh | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build-watch.sh b/build-watch.sh index 6df90f65b..c1e355644 100755 --- a/build-watch.sh +++ b/build-watch.sh @@ -1,6 +1,5 @@ #!/bin/bash -## Run the build script whenever there is a change in src folder - +## Runs build script whenever there is a change in src folder echo 'Watching changes on src/' diff --git a/build.sh b/build.sh index 0217b9435..3408e8c45 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ #!/bin/bash +# Loads user-defined variables at build-config file source build-config.cfg ## Only run npm build if there was a change in a .js or .vue file diff --git a/compile-sass.sh b/compile-sass.sh index 36a3e9dcb..11d00a92e 100644 --- a/compile-sass.sh +++ b/compile-sass.sh @@ -5,8 +5,7 @@ command -v sass >/dev/null 2>&1 || { echo >&2 "Sass parece não estar disponivel."; exit 1; } - -# Define o caminho. + echo "Compilando Sass..." sass -E 'UTF-8' --cache-location .tmp/sass-cache-1 src/views/admin/scss/tainacan-admin.scss:src/assets/css/tainacan-admin.css From 0686795afcaa3a95a09adb05b12cbc9bb82ff504 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 29 Mar 2021 03:20:52 -0300 Subject: [PATCH 05/30] adds first render_as_html new passing tests --- .../textarea/class-tainacan-textarea.php | 2 +- tests/test-item-metadata.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/views/admin/components/metadata-types/textarea/class-tainacan-textarea.php b/src/views/admin/components/metadata-types/textarea/class-tainacan-textarea.php index 40b3590fb..f8bfee1c2 100644 --- a/src/views/admin/components/metadata-types/textarea/class-tainacan-textarea.php +++ b/src/views/admin/components/metadata-types/textarea/class-tainacan-textarea.php @@ -59,6 +59,6 @@ class Textarea extends Metadata_Type { } else { $return = nl2br($this->make_clickable_links($value)); } - return $return; + return force_balance_tags($return); } } \ No newline at end of file diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 6ac548662..92cf4af17 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -303,12 +303,19 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_metadata_text->get_value_as_html(), $response_text); $this->assertEquals($item_metadata_textarea->get_value_as_html(), $response_textarea); + + // Poor HTML entry tests + $malformatted_HTML = "

I started my content

and make something else here
withou closing it properly"; + + $item_metadata_textarea->set_value($malformatted_HTML); + $this->assertEquals($item_metadata_textarea->get_value_as_html(), $malformatted_HTML ."

"); } /** * @group test_item_metadata_has_value */ function test_item_metadata_has_value() { + $test_value = 'has_value'; $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( @@ -351,7 +358,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertFalse($item_metadata_textarea->has_value()); - $item_metadata_textarea->set_value('has_value'); + $item_metadata_textarea->set_value($test_value); $item_metadata_textarea->validate(); $item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea); @@ -371,18 +378,14 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata_text = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_text); - $item_metadata_text->set_value([ - '' - ]); + $item_metadata_text->set_value([ $value_textarea ]); $item_metadata_text->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata_text); $this->assertFalse($item_metadata->has_value()); - $item_metadata_text->set_value([ - 'has_value' - ]); + $item_metadata_text->set_value([ $test_value ]); $item_metadata_text->validate(); $item_metadata_text = $Tainacan_Item_Metadata->insert($item_metadata_text); From a50f8787252ab3e85a1d5ac121956b8750ee481f Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 29 Mar 2021 17:09:17 -0300 Subject: [PATCH 06/30] Adds test for text metadata --- .../components/metadata-types/text/class-tainacan-text.php | 2 +- tests/test-item-metadata.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/views/admin/components/metadata-types/text/class-tainacan-text.php b/src/views/admin/components/metadata-types/text/class-tainacan-text.php index 9f577c15d..ea723069f 100644 --- a/src/views/admin/components/metadata-types/text/class-tainacan-text.php +++ b/src/views/admin/components/metadata-types/text/class-tainacan-text.php @@ -50,6 +50,6 @@ class Text extends Metadata_Type { } else { $return = $this->make_clickable_links($value); } - return $return; + return force_balance_tags($return); } } \ No newline at end of file diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 92cf4af17..bd6c95a65 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -305,9 +305,12 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_metadata_textarea->get_value_as_html(), $response_textarea); // Poor HTML entry tests - $malformatted_HTML = "

I started my content

and make something else here
withou closing it properly"; + $malformatted_HTML = "

I started my content

and make something else here
without closing its HTML properly"; + $item_metadata_text->set_value($malformatted_HTML); $item_metadata_textarea->set_value($malformatted_HTML); + + $this->assertEquals($item_metadata_text->get_value_as_html(), $malformatted_HTML ."

"); $this->assertEquals($item_metadata_textarea->get_value_as_html(), $malformatted_HTML ."

"); } From 55afa4567c0431945b4d8a898d1aecd6de4949a8 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sun, 4 Apr 2021 23:31:32 -0300 Subject: [PATCH 07/30] Refactors HTML return for date meta --- .../class-tainacan-item-metadata-entity.php | 9 ++------- .../metadata-types/date/class-tainacan-date.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 4fb83faa4..8b215f01d 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -136,17 +136,15 @@ class Item_Metadata_Entity extends Entity { * Get the value as a HTML string, with markup and links * @return string */ - public function get_value_as_html(){ + public function get_value_as_html(){ $metadatum = $this->get_metadatum(); if (is_object($metadatum)) { $fto = $metadatum->get_metadata_type_object(); if (is_object($fto)) { - if ( method_exists($fto, 'get_value_as_html') ) { return $fto->get_value_as_html($this); } - } } @@ -163,7 +161,6 @@ class Item_Metadata_Entity extends Entity { $separator = $this->get_multivalue_separator(); foreach ($value as $v) { - $return .= $prefix; $return .= (string) $v; @@ -174,14 +171,12 @@ class Item_Metadata_Entity extends Entity { if ($count < $total) $return .= $separator; } - + } else { $return = (string) $value; } return $return; - - } /** diff --git a/src/views/admin/components/metadata-types/date/class-tainacan-date.php b/src/views/admin/components/metadata-types/date/class-tainacan-date.php index a17d883de..767a34ee3 100644 --- a/src/views/admin/components/metadata-types/date/class-tainacan-date.php +++ b/src/views/admin/components/metadata-types/date/class-tainacan-date.php @@ -80,20 +80,23 @@ class Date extends Metadata_Type { if( empty( $el ) ) continue; $return .= $prefix; - $return .= mysql2date(get_option('date_format'), ($el)); + $return .= $this->format_date_value($el); $return .= $suffix; $count ++; if ($count < $total) $return .= $separator; } } else { - if( empty( $value ) ) - return ""; - $return = mysql2date(get_option('date_format'), ($value)); + + $return = $this->format_date_value($value); } return $return; - } + private function format_date_value($value) { + if (empty($value)) + return ""; + return mysql2date(get_option('date_format'), ($value)); + } } \ No newline at end of file From 3ea5c2134b699a1ebc671507360de50361d572ed Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sun, 4 Apr 2021 23:38:59 -0300 Subject: [PATCH 08/30] Extracts validation error msg --- .../date/class-tainacan-date.php | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/views/admin/components/metadata-types/date/class-tainacan-date.php b/src/views/admin/components/metadata-types/date/class-tainacan-date.php index 767a34ee3..29eacea34 100644 --- a/src/views/admin/components/metadata-types/date/class-tainacan-date.php +++ b/src/views/admin/components/metadata-types/date/class-tainacan-date.php @@ -35,31 +35,21 @@ class Date extends Metadata_Type { foreach ($value as $date_value) { $d = \DateTime::createFromFormat($format, $date_value); if (!$d || $d->format($format) !== $date_value) { - $this->add_error( - sprintf( - __('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'), - $date_value - ) - ); + $this->add_error($this->format_error_msg($date_value)); return false; } } - return True; + return true; } $d = \DateTime::createFromFormat($format, $value); if (!$d || $d->format($format) !== $value) { - $this->add_error( - sprintf( - __('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'), - $value - ) - ); + $this->add_error($this->format_error_msg($value)); + return false; } return true; - } /** @@ -99,4 +89,11 @@ class Date extends Metadata_Type { return mysql2date(get_option('date_format'), ($value)); } + private function format_error_msg($value) { + return sprintf( + __('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'), + $value + ); + } + } \ No newline at end of file From e92a73101e442f8c1c76a274803c001dd07461af Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sun, 4 Apr 2021 23:42:03 -0300 Subject: [PATCH 09/30] changes date format to actually expected format --- .../components/metadata-types/date/class-tainacan-date.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/admin/components/metadata-types/date/class-tainacan-date.php b/src/views/admin/components/metadata-types/date/class-tainacan-date.php index 29eacea34..45abfa299 100644 --- a/src/views/admin/components/metadata-types/date/class-tainacan-date.php +++ b/src/views/admin/components/metadata-types/date/class-tainacan-date.php @@ -91,7 +91,7 @@ class Date extends Metadata_Type { private function format_error_msg($value) { return sprintf( - __('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'), + __('Invalid date format. Expected format is MM/DD/YYYY, got %s.', 'tainacan'), $value ); } From f1d83ed0a4c143198ec6e67c3754d7e0eaa85fc9 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 01:11:45 -0300 Subject: [PATCH 10/30] Removes old dumps --- tests/test-compound-metadatum-types.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test-compound-metadatum-types.php b/tests/test-compound-metadatum-types.php index 539fb74c3..cf0811154 100644 --- a/tests/test-compound-metadatum-types.php +++ b/tests/test-compound-metadatum-types.php @@ -124,7 +124,7 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { ), true ); - + $metadatum = $this->tainacan_entity_factory->create_entity( 'metadatum', array( @@ -200,9 +200,7 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); - //var_dump($wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = {$i->get_id()}")); - //var_dump($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE parent = {$metadatum->get_id()}")); + $compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); $compoundValue = $compoundItem->get_value(); $this->assertTrue( is_array($compoundValue), 'value of a compound should return array' ); From 3392ddfa2dfc9f08f5c44a9cef5da0b7f757e66c Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 02:36:27 -0300 Subject: [PATCH 11/30] Extracts compound meta return markup --- .../compound/class-tainacan-compound.php | 24 +++++++++++++------ .../date/class-tainacan-date.php | 2 +- .../taxonomy/class-tainacan-taxonomy.php | 9 ------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php b/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php index 1669efce5..a6962428c 100644 --- a/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php +++ b/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php @@ -196,10 +196,11 @@ class Compound extends Metadata_Type { foreach ( $compound_element as $meta_id => $meta ) { $index = array_search( $meta_id, array_column( $order, 'id' ) ); if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { + $html = $this->get_meta_html($meta); if ( $index !== false ) { - $metadata_value[$index] = '

' . $meta->get_value_as_html() . "

"; + $metadata_value[$index] = $html; } else { - $metadata_value_not_ordinate[] = '

' . $meta->get_value_as_html() . "

"; + $metadata_value_not_ordinate[] = $html; } } } @@ -213,18 +214,27 @@ class Compound extends Metadata_Type { foreach ( $value as $meta_id => $meta ) { $index = array_search( $meta_id, array_column( $order, 'id' ) ); if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { + $html = $this->get_meta_html($meta); if ( $index !== false ) { - $metadata_value[intval($index)] = '

' . $meta->get_value_as_html() . "

"; + $metadata_value[intval($index)] = $html; } else { - $metadata_value_not_ordinate[] = '

' . $meta->get_value_as_html() . "

"; + $metadata_value_not_ordinate[] = $html; } } - } - $return = '
' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "
\n"; + } + $return = '
' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "
\n"; } return $return; - + } + + private function get_meta_html(Item_Metadata_Entity $meta) { + $html = ''; + if ($meta instanceof Item_Metadata_Entity && !empty($meta->get_value_as_html())) { + $html = '

' . $meta->get_value_as_html() . "

"; + } + + return $html; } } \ No newline at end of file diff --git a/src/views/admin/components/metadata-types/date/class-tainacan-date.php b/src/views/admin/components/metadata-types/date/class-tainacan-date.php index 45abfa299..a842c27f8 100644 --- a/src/views/admin/components/metadata-types/date/class-tainacan-date.php +++ b/src/views/admin/components/metadata-types/date/class-tainacan-date.php @@ -77,9 +77,9 @@ class Date extends Metadata_Type { $return .= $separator; } } else { - $return = $this->format_date_value($value); } + return $return; } diff --git a/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php index e46988e1d..27ad6fd1c 100644 --- a/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -338,7 +338,6 @@ class Taxonomy extends Metadata_Type { $return = ''; if ( $item_metadata->is_multiple() ) { - $count = 1; $total = sizeof($value); $prefix = $item_metadata->get_multivalue_prefix(); @@ -346,7 +345,6 @@ class Taxonomy extends Metadata_Type { $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $term ) { - $count ++; if ( is_integer($term) ) { @@ -355,29 +353,22 @@ class Taxonomy extends Metadata_Type { if ( $term instanceof \Tainacan\Entities\Term ) { $return .= $prefix; - $return .= $this->get_term_hierarchy_html($term); - $return .= $suffix; if ( $count <= $total ) { $return .= $separator; } - } - } } else { - if ( $value instanceof \Tainacan\Entities\Term ) { $return .= $this->get_term_hierarchy_html($value); } - } return $return; - } private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { From c0df4dde06d50ee45b22d97e3db476b1c93608a8 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 02:50:11 -0300 Subject: [PATCH 12/30] Refactors returned default markup --- .../compound/class-tainacan-compound.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php b/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php index a6962428c..a21b8467f 100644 --- a/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php +++ b/src/views/admin/components/metadata-types/compound/class-tainacan-compound.php @@ -207,9 +207,9 @@ class Compound extends Metadata_Type { $elements[] = '
' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "
\n" ; } } - $return = '
' . implode($separator, $elements) . '
'; + $return = implode($separator, $elements); } else { - $metadata_value = array_fill(0, count($value), null); + $metadata_value = array_fill(0, count($value), null); $metadata_value_not_ordinate = []; foreach ( $value as $meta_id => $meta ) { $index = array_search( $meta_id, array_column( $order, 'id' ) ); @@ -220,12 +220,12 @@ class Compound extends Metadata_Type { } else { $metadata_value_not_ordinate[] = $html; } - } - } - $return = '
' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "
\n"; + } + } + $return = implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)); } - return $return; + return "
{$return}
"; } private function get_meta_html(Item_Metadata_Entity $meta) { From 4ce2c9491b34207c8a22915d972a8c2da048edc0 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 11:57:23 -0300 Subject: [PATCH 13/30] ads html tests for numeric meta type --- .../numeric/class-tainacan-numeric.php | 1 - tests/test-item-metadata.php | 52 +++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/views/admin/components/metadata-types/numeric/class-tainacan-numeric.php b/src/views/admin/components/metadata-types/numeric/class-tainacan-numeric.php index cc496cab0..4ad0584e7 100644 --- a/src/views/admin/components/metadata-types/numeric/class-tainacan-numeric.php +++ b/src/views/admin/components/metadata-types/numeric/class-tainacan-numeric.php @@ -37,5 +37,4 @@ class Numeric extends Metadata_Type { ] ]; } - } \ No newline at end of file diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index bd6c95a65..fa5c98e3f 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -9,7 +9,7 @@ namespace Tainacan\Tests; */ /** - * Sample test case. + * Item_Metadata test case. */ class Item_Metadata extends TAINACAN_UnitTestCase { @@ -247,8 +247,6 @@ class Item_Metadata extends TAINACAN_UnitTestCase { } function test_metadata_text_textarea() { - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -395,4 +393,52 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertTrue($item_metadata_text->has_value()); } + + function test_metadata_numeric_html() { + $collection = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); + $item = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'My test item', + 'description' => 'item description', + 'collection' => $collection, + 'status' => 'publish' + ), + true + ); + $metadatum_numeric = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'Numeric important meta', + 'description' => 'and its description', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Numeric', + 'status' => 'publish' + ), + true + ); + + $metadatum_numeric_multiple = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'Numeric important meta', + 'description' => 'and its description', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Numeric', + 'status' => 'publish', + 'multiple' => 'yes' + ), + true + ); + + $item_metadata_numeric = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_numeric); + $item_metadata_numeric->set_value(10); + $item_metadata_numeric->validate(); + $this->assertEquals($item_metadata_numeric->get_value_as_html(), 10); + + $item_metadata_numeric_mult = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_numeric_multiple); + $item_metadata_numeric_mult->set_value([10,22,4]); + $item_metadata_numeric_mult->validate(); + $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10 | 22 | 4'); + } } \ No newline at end of file From 62abad4839540213082e05bc616b3f7af90083b3 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 13:37:15 -0300 Subject: [PATCH 14/30] adds html tests for date meta --- .../class-tainacan-item-metadata-entity.php | 6 +- .../date/class-tainacan-date.php | 2 +- tests/test-bgprocess.php | 6 -- tests/test-category-metadatum-types.php | 3 - tests/test-item-metadata.php | 66 ++++++++++++++++++- 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 8b215f01d..264eb3cf0 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -136,7 +136,7 @@ class Item_Metadata_Entity extends Entity { * Get the value as a HTML string, with markup and links * @return string */ - public function get_value_as_html(){ + public function get_value_as_html() { $metadatum = $this->get_metadatum(); if (is_object($metadatum)) { @@ -153,7 +153,6 @@ class Item_Metadata_Entity extends Entity { $return = ''; if ( $this->is_multiple() ) { - $total = sizeof($value); $count = 0; $prefix = $this->get_multivalue_prefix(); @@ -162,11 +161,8 @@ class Item_Metadata_Entity extends Entity { foreach ($value as $v) { $return .= $prefix; - $return .= (string) $v; - $return .= $suffix; - $count ++; if ($count < $total) $return .= $separator; diff --git a/src/views/admin/components/metadata-types/date/class-tainacan-date.php b/src/views/admin/components/metadata-types/date/class-tainacan-date.php index a842c27f8..6e0247fb5 100644 --- a/src/views/admin/components/metadata-types/date/class-tainacan-date.php +++ b/src/views/admin/components/metadata-types/date/class-tainacan-date.php @@ -11,7 +11,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); */ class Date extends Metadata_Type { - function __construct(){ + function __construct() { // call metadatum type constructor parent::__construct(); $this->set_primitive_type('date'); diff --git a/tests/test-bgprocess.php b/tests/test-bgprocess.php index 91f8ac3d7..a70298a99 100644 --- a/tests/test-bgprocess.php +++ b/tests/test-bgprocess.php @@ -16,12 +16,10 @@ use Tainacan\Entities; class BGProcess extends TAINACAN_UnitApiTestCase { function test_table() { - global $wpdb; $table_name = $wpdb->prefix . 'tnc_bg_process'; - $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '".$table_name."'" ); $this->assertNotEquals(null, $table_exists); @@ -29,10 +27,6 @@ class BGProcess extends TAINACAN_UnitApiTestCase { $column_exists = $wpdb->get_var( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'output'" ); $this->assertEquals('output', $column_exists, 'BG processes table misconfigured'); - } - - - } \ No newline at end of file diff --git a/tests/test-category-metadatum-types.php b/tests/test-category-metadatum-types.php index 8ace43b58..b0de80955 100644 --- a/tests/test-category-metadatum-types.php +++ b/tests/test-category-metadatum-types.php @@ -794,9 +794,6 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $checkMeta = $Tainacan_Metadata->fetch( $metadatum->get_id() ); $this->assertEquals('no', $checkMeta->get_metadata_type_options()['allow_new_terms']); - - - } } diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index fa5c98e3f..7c50ff4e2 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -3,7 +3,7 @@ namespace Tainacan\Tests; /** - * Class TestCollections + * Class Item_Metadata * * @package Test_Tainacan */ @@ -406,6 +406,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ), true ); + + // Simple numeric metadata $metadatum_numeric = $this->tainacan_entity_factory->create_entity( 'metadatum', array( @@ -418,6 +420,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); + // Multiple numeric metadata $metadatum_numeric_multiple = $this->tainacan_entity_factory->create_entity( 'metadatum', array( @@ -441,4 +444,65 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata_numeric_mult->validate(); $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10 | 22 | 4'); } + + function test_metadata_date_html() { + $collection = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); + $item = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'My test item', + 'description' => 'item description', + 'collection' => $collection, + 'status' => 'publish' + ), + true + ); + + // Simple date metadata + $metadatum_date = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'Date important meta', + 'description' => 'and its description', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Date', + 'status' => 'publish' + ), + true + ); + + // Multiple date metadata + $metadatum_date_multiple = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'Date meta', + 'description' => 'and its description', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Date', + 'status' => 'publish', + 'multiple' => 'yes' + ), + true + ); + + $item_metadata_date = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_date); + // Invalid date value + $item_metadata_date->set_value(10); + $item_metadata_date->validate(); + $this->assertFalse($item_metadata_date->get_value_as_html()); + + $item_metadata_date->set_value("2021-04-05"); + $item_metadata_date->validate(); + $this->assertEquals($item_metadata_date->get_value_as_html(), "April 5, 2021"); + + $item_metadata_date_mult = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_date_multiple); + // Invalid date values + $item_metadata_date_mult->set_value([10,22,4]); + $item_metadata_date_mult->validate(); + $this->assertEquals($item_metadata_date_mult->get_value_as_html(), ' | | '); + + $item_metadata_date_mult->set_value(["2021-04-05", "2021-12-30"]); + $item_metadata_date_mult->validate(); + $this->assertEquals($item_metadata_date_mult->get_value_as_html(), 'April 5, 2021 | December 30, 2021'); + } } \ No newline at end of file From 5503abc6b6debe7df31f24cdf3cb1c43c754bbee Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 14:07:57 -0300 Subject: [PATCH 15/30] Refactors base test setup boilerplate --- tests/test-item-metadata.php | 63 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 7c50ff4e2..882449395 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -13,6 +13,27 @@ namespace Tainacan\Tests; */ class Item_Metadata extends TAINACAN_UnitTestCase { + private $collection = null; + private $item = null; + + public function setUp() { + parent::setUp(); + $c = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'My test item', + 'description' => 'item description', + 'collection' => $c, + 'status' => 'publish' + ), + true + ); + + $this->collection = $c; + $this->item = $i; + } + /** * Teste da insercao de um metadado simples sem o tipo */ @@ -394,26 +415,14 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertTrue($item_metadata_text->has_value()); } - function test_metadata_numeric_html() { - $collection = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); - $item = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'My test item', - 'description' => 'item description', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); - + function test_metadata_numeric_html() { // Simple numeric metadata $metadatum_numeric = $this->tainacan_entity_factory->create_entity( 'metadatum', array( 'name' => 'Numeric important meta', 'description' => 'and its description', - 'collection_id' => $collection->get_id(), + 'collection_id' => $this->collection->get_id(), 'metadata_type' => 'Tainacan\Metadata_Types\Numeric', 'status' => 'publish' ), @@ -426,7 +435,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { array( 'name' => 'Numeric important meta', 'description' => 'and its description', - 'collection_id' => $collection->get_id(), + 'collection_id' => $this->collection->get_id(), 'metadata_type' => 'Tainacan\Metadata_Types\Numeric', 'status' => 'publish', 'multiple' => 'yes' @@ -434,37 +443,25 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_metadata_numeric = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_numeric); + $item_metadata_numeric = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_numeric); $item_metadata_numeric->set_value(10); $item_metadata_numeric->validate(); $this->assertEquals($item_metadata_numeric->get_value_as_html(), 10); - $item_metadata_numeric_mult = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_numeric_multiple); + $item_metadata_numeric_mult = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_numeric_multiple); $item_metadata_numeric_mult->set_value([10,22,4]); $item_metadata_numeric_mult->validate(); $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10 | 22 | 4'); } function test_metadata_date_html() { - $collection = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); - $item = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'My test item', - 'description' => 'item description', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); - // Simple date metadata $metadatum_date = $this->tainacan_entity_factory->create_entity( 'metadatum', array( 'name' => 'Date important meta', 'description' => 'and its description', - 'collection_id' => $collection->get_id(), + 'collection_id' => $this->collection->get_id(), 'metadata_type' => 'Tainacan\Metadata_Types\Date', 'status' => 'publish' ), @@ -477,7 +474,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { array( 'name' => 'Date meta', 'description' => 'and its description', - 'collection_id' => $collection->get_id(), + 'collection_id' => $this->collection->get_id(), 'metadata_type' => 'Tainacan\Metadata_Types\Date', 'status' => 'publish', 'multiple' => 'yes' @@ -485,7 +482,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_metadata_date = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_date); + $item_metadata_date = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_date); // Invalid date value $item_metadata_date->set_value(10); $item_metadata_date->validate(); @@ -495,7 +492,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata_date->validate(); $this->assertEquals($item_metadata_date->get_value_as_html(), "April 5, 2021"); - $item_metadata_date_mult = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum_date_multiple); + $item_metadata_date_mult = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_date_multiple); // Invalid date values $item_metadata_date_mult->set_value([10,22,4]); $item_metadata_date_mult->validate(); From 6dc8510bb0dbafcf88f66d18b6966a86957471b1 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 14:38:09 -0300 Subject: [PATCH 16/30] Adds tests for user metadata html --- tests/test-item-metadata.php | 48 ++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 882449395..53ffa83c3 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -415,7 +415,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertTrue($item_metadata_text->has_value()); } - function test_metadata_numeric_html() { + function test_numeric_metadata_html() { // Simple numeric metadata $metadatum_numeric = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -454,7 +454,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10 | 22 | 4'); } - function test_metadata_date_html() { + function test_date_metadata_html() { // Simple date metadata $metadatum_date = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -502,4 +502,48 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata_date_mult->validate(); $this->assertEquals($item_metadata_date_mult->get_value_as_html(), 'April 5, 2021 | December 30, 2021'); } + + function test_user_metadata_html() { + $user_metadata = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'User metadata', + 'description' => 'and its description', + 'collection_id' => $this->collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\User', + 'status' => 'publish' + ), + true + ); + + $user_meta = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $user_metadata); + // Empty val + $this->assertEmpty($user_meta->get_value_as_html()); + + $new_user = $this->factory()->user->create(array( 'role' => 'subscriber', 'display_name' => 'User Name' )); + + $user_meta->set_value($new_user); + $user_meta->validate(); + $this->assertEquals($user_meta->get_value_as_html(), "User Name"); + + $user_metadata_multiple = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'User metadata', + 'description' => 'and its description', + 'collection_id' => $this->collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\User', + 'status' => 'publish', + 'multiple' => 'yes' + ), + true + ); + $user_meta_multi = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $user_metadata_multiple); + $this->assertEmpty($user_meta_multi->get_value_as_html()); + + $sec_user = $this->factory()->user->create(array( 'role' => 'subscriber', 'display_name' => 'User Name 2' )); + $user_meta_multi->set_value([$new_user, $sec_user]); + $user_meta_multi->validate(); + $this->assertEquals($user_meta_multi->get_value_as_html(), 'User Name | User Name 2'); + } } \ No newline at end of file From b9017f85e0de2d78705046a17055431c4177f7d6 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Mon, 5 Apr 2021 15:46:51 -0300 Subject: [PATCH 17/30] adds tests to html returned selectbox metadata --- tests/test-item-metadata.php | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 53ffa83c3..64d8c22ed 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -546,4 +546,48 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $user_meta_multi->validate(); $this->assertEquals($user_meta_multi->get_value_as_html(), 'User Name | User Name 2'); } + + function test_selectbox_metadata_html() { + $selectbox_metadata = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'My selectbox meta', + 'status' => 'publish', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Selectbox', + 'metadata_type_options' => [ + 'options' => ['tainacan', 'wordpress', 'php'] + ] + ), + true + ); + + $selectbox_metadata_multiple = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'My selectbox meta', + 'status' => 'publish', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Selectbox', + 'multiple' => 'yes', + 'metadata_type_options' => [ + 'options' => ['tainacan', 'wordpress', 'php'] + ] + ), + true + ); + + $sb_meta = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $selectbox_metadata); + $sb_meta->set_value('tainacan'); + $sb_meta->validate(); + $this->assertEquals($sb_meta->get_value_as_html(), 'tainacan'); + + $sb_meta->set_value('php'); + $this->assertEquals($sb_meta->get_value_as_html(), 'php'); + + $sb_meta_multi = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $selectbox_metadata_multiple); + $sb_meta_multi->set_value(['tainacan', 'wordpress']); + $sb_meta_multi->validate(); + $this->assertEquals($sb_meta_multi->get_value_as_html(), 'tainacan | wordpress'); + } } \ No newline at end of file From 5e4dd01e08afe0448f6a383d77803e3a6fa513a9 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 01:21:22 -0300 Subject: [PATCH 18/30] tiny lints --- .../class-tainacan-relationship.php | 30 ++----------------- .../class-tainacan-entity-factory.php | 4 +-- tests/test-metadata.php | 10 ++----- 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php index 9c4680e77..08901a526 100644 --- a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php +++ b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php @@ -158,13 +158,10 @@ class Relationship extends Metadata_Type { * @return string The HTML representation of the value, containing one or multiple items names, linked to the item page */ public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { - $value = $item_metadata->get_value(); $return = ''; - if ( $item_metadata->is_multiple() ) { - $count = 1; $total = sizeof($value); $prefix = $item_metadata->get_multivalue_prefix(); @@ -172,43 +169,30 @@ class Relationship extends Metadata_Type { $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $item_id ) { - try { - //$item = new \Tainacan\Entities\Item($item_id); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $item = $Tainacan_Items->fetch( (int) $item_id); - $count ++; if ( $item instanceof \Tainacan\Entities\Item ) { - $return .= $prefix; - $return .= $this->get_item_html($item); - $return .= $suffix; - + if ( $count <= $total ) { $return .= $separator; } - } - - + } catch (\Exception $e) { // item not found } - } - } else { - try { - $item = new \Tainacan\Entities\Item($value); - if ( $item instanceof \Tainacan\Entities\Item ) { $return .= $this->get_item_html($item); } @@ -216,22 +200,18 @@ class Relationship extends Metadata_Type { } catch (\Exception $e) { // item not found } - } return $return; - } private function get_item_html($item) { - $return = ''; $id = $item->get_id(); $search_meta_id = $this->get_option('search'); if ( $id && $search_meta_id ) { - $link = get_permalink( (int) $id ); $search_meta_id = $this->get_option('search'); @@ -250,17 +230,13 @@ class Relationship extends Metadata_Type { } if (is_string($link)) { - $return = ""; $return.= $label; $return .= ""; - } - } return $return; - } /** @@ -268,7 +244,6 @@ class Relationship extends Metadata_Type { * @return \Tainacan\Entities\Collection|false The Collection object or false */ public function get_collection() { - $collection_id = $this->get_option('collection_id'); if ( is_numeric($collection_id) ) { @@ -279,7 +254,6 @@ class Relationship extends Metadata_Type { } return false; - } /** diff --git a/tests/factories/class-tainacan-entity-factory.php b/tests/factories/class-tainacan-entity-factory.php index 47dab8fd3..fb14717d2 100644 --- a/tests/factories/class-tainacan-entity-factory.php +++ b/tests/factories/class-tainacan-entity-factory.php @@ -10,7 +10,7 @@ class Entity_Factory { * * @var \Tainacan\Entities\Entity */ - private $entity; + private $entity; /** * @@ -118,5 +118,3 @@ class Entity_Factory { return $this->entity; } } - -?> diff --git a/tests/test-metadata.php b/tests/test-metadata.php index 43a47d73b..3e0a7ab6f 100644 --- a/tests/test-metadata.php +++ b/tests/test-metadata.php @@ -200,7 +200,6 @@ class Metadata extends TAINACAN_UnitTestCase { $this->assertEquals( 9, sizeof( $Tainacan_Metadata->fetch_metadata_types() ) ); } - /** * */ @@ -426,9 +425,7 @@ class Metadata extends TAINACAN_UnitTestCase { } - function test_relatioship_get_collection_method() { - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - + function test_relationship_get_collection_method() { $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -460,17 +457,16 @@ class Metadata extends TAINACAN_UnitTestCase { ), true ); - + $object = $metadatum->get_metadata_type_object(); $colCheck = $object->get_collection(); $this->assertTrue( $colCheck instanceof \Tainacan\Entities\Collection ); $this->assertEquals($collection2->get_id(), $colCheck->get_id()); - } - public function test_update_taxonomy_cascate_status() { + function test_update_taxonomy_cascate_status() { $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); From 2132505095d22c99c2d2e5d3729cef52d42267f9 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 02:04:43 -0300 Subject: [PATCH 19/30] adds html tests to relationship meta --- .../class-tainacan-item-metadata-entity.php | 1 - .../class-tainacan-relationship.php | 8 ++- tests/test-item-metadata.php | 53 +++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 264eb3cf0..e4b2f9eca 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -31,7 +31,6 @@ class Item_Metadata_Entity extends Entity { * @param int $meta_id ID for a specific meta row */ function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) { - $this->set_item($item); $this->set_metadatum($metadatum); diff --git a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php index 08901a526..13dcc0622 100644 --- a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php +++ b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php @@ -157,7 +157,7 @@ class Relationship extends Metadata_Type { * @param Item_Metadata_Entity $item_metadata * @return string The HTML representation of the value, containing one or multiple items names, linked to the item page */ - public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { + public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { $value = $item_metadata->get_value(); $return = ''; @@ -170,11 +170,10 @@ class Relationship extends Metadata_Type { foreach ( $value as $item_id ) { try { - //$item = new \Tainacan\Entities\Item($item_id); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $item = $Tainacan_Items->fetch( (int) $item_id); - $count ++; + $count++; if ( $item instanceof \Tainacan\Entities\Item ) { $return .= $prefix; @@ -196,12 +195,11 @@ class Relationship extends Metadata_Type { if ( $item instanceof \Tainacan\Entities\Item ) { $return .= $this->get_item_html($item); } - } catch (\Exception $e) { // item not found } } - + return $return; } diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 64d8c22ed..ed020da69 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -590,4 +590,57 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $sb_meta_multi->validate(); $this->assertEquals($sb_meta_multi->get_value_as_html(), 'tainacan | wordpress'); } + + function test_relationship_metadata_html() { + $referenced_collection = $this->tainacan_entity_factory->create_entity( + 'collection', + ['name' => 'INXS Songs'], + true + ); + $mystify = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'Mystify', + 'description' => '"Mystify" is the 9th track of INXS 6th album "Kick".', + 'collection' => $referenced_collection, + 'status' => 'publish' + ), + true + ); + $expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title()); + + $relationship_metadata = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'Relationship meta', + 'description' => 'My desc', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Relationship', + 'status' => 'publish', + 'metadata_type_options' => [ + 'collection_id' => $referenced_collection->get_id(), + 'search' => $referenced_collection->get_core_title_metadatum()->get_id() + ] + ), + true + ); + + $rel_meta = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $relationship_metadata); + $rel_meta->validate(); + $this->assertEquals($rel_meta->get_value_as_html(), ''); + + $rel_meta->set_value($mystify->get_id()); + $rel_meta->validate(); + $this->assertEquals($rel_meta->get_value_as_html(), $expected_return); + + $rel_meta->set_value([$this->collection->get_id()]); + $rel_meta->validate(); + $this->assertEquals($rel_meta->get_value_as_html(), ''); + } + + private function relationship_expected_return($id, $title) { + $URL = get_permalink($id); + + return "${title}"; + } } \ No newline at end of file From d4b67beb30bf3487bdf9697bede65096185d1449 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 06:32:15 -0300 Subject: [PATCH 20/30] Covers yet more test cases for relationship metadata --- tests/test-item-metadata.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index ed020da69..b2ffacc21 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -607,7 +607,19 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ), true ); - $expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title()); + $disappear = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'Disappear', + 'description' => '"Disappear" is the second single from INXS 7th album "X".It was released in December 1990.', + 'collection' => $referenced_collection, + 'status' => 'publish' + ), + true + ); + $expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title()); + $expected_return2 = $this->relationship_expected_return($disappear->get_id(), $disappear->get_title()); + $separator = ' | '; $relationship_metadata = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -625,17 +637,21 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $rel_meta = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $relationship_metadata); - $rel_meta->validate(); - $this->assertEquals($rel_meta->get_value_as_html(), ''); + $item_metadata_relationship = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $relationship_metadata); + $item_metadata_relationship->validate(); + $this->assertEquals($item_metadata_relationship->get_value_as_html(), ''); - $rel_meta->set_value($mystify->get_id()); - $rel_meta->validate(); - $this->assertEquals($rel_meta->get_value_as_html(), $expected_return); + $item_metadata_relationship->set_value($mystify->get_id()); + $item_metadata_relationship->validate(); + $this->assertEquals($item_metadata_relationship->get_value_as_html(), $expected_return); - $rel_meta->set_value([$this->collection->get_id()]); - $rel_meta->validate(); - $this->assertEquals($rel_meta->get_value_as_html(), ''); + $item_metadata_relationship->set_value([$this->collection->get_id()]); + $item_metadata_relationship->validate(); + $this->assertEquals($item_metadata_relationship->get_value_as_html(), ''); + + $relationship_metadata->set_multiple('yes'); + $item_metadata_relationship->set_value([ $mystify->get_id(), $disappear->get_id() ]); + $this->assertEquals($item_metadata_relationship->get_value_as_html(), "${expected_return}${separator}${expected_return2}"); } private function relationship_expected_return($id, $title) { From 7e7c36d60b7644d2d8ac239176498a3817765797 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 08:40:05 -0300 Subject: [PATCH 21/30] bootstraps for taxonomy html test --- src/classes/entities/class-tainacan-item.php | 6 ----- src/classes/entities/class-tainacan-term.php | 8 +----- .../taxonomy/class-tainacan-taxonomy.php | 9 +------ tests/test-item-metadata.php | 26 +++++++++++++++++++ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index e69a03faf..4fa716783 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -500,26 +500,20 @@ class Item extends Entity { public function _toHtml() { - $return = ''; $id = $this->get_id(); if ( $id ) { - $link = get_permalink( (int) $id ); if (is_string($link)) { - $return = ""; $return.= $this->get_title(); $return .= ""; - } - } return $return; - } /** diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 0241c4fb2..7d4b55f2e 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -245,25 +245,19 @@ class Term extends Entity { } public function _toHtml() { - $return = ''; $id = $this->get_id(); if ( $id ) { - $link = get_term_link( (int) $id ); if (is_string($link)) { - $return = ""; $return.= $this->get_name(); $return .= ""; - } - } - return apply_filters('tainacan-term-to-html', $return, $this); - + return apply_filters('tainacan-term-to-html', $return, $this); } } diff --git a/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php index 27ad6fd1c..031ca13c2 100644 --- a/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -332,9 +332,7 @@ class Taxonomy extends Metadata_Type { * @return string The HTML representation of the value, containing one or multiple terms, separated by comma, linked to term page */ public function get_value_as_html(Item_Metadata_Entity $item_metadata) { - $value = $item_metadata->get_value(); - $return = ''; if ( $item_metadata->is_multiple() ) { @@ -345,7 +343,7 @@ class Taxonomy extends Metadata_Type { $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $term ) { - $count ++; + $count++; if ( is_integer($term) ) { $term = \Tainacan\Repositories\Terms::get_instance()->fetch($term, $this->get_option('taxonomy_id')); @@ -361,7 +359,6 @@ class Taxonomy extends Metadata_Type { } } } - } else { if ( $value instanceof \Tainacan\Entities\Term ) { $return .= $this->get_term_hierarchy_html($value); @@ -372,9 +369,7 @@ class Taxonomy extends Metadata_Type { } private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { - $terms = []; - $terms[] = $this->term_to_html($term); while ($term->get_parent() > 0) { @@ -383,11 +378,9 @@ class Taxonomy extends Metadata_Type { } $terms = \array_reverse($terms); - $glue = apply_filters('tainacan-terms-hierarchy-html-separator', ' > '); return \implode($glue, $terms); - } private function term_to_html($term) { diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index b2ffacc21..75c1a1356 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -659,4 +659,30 @@ class Item_Metadata extends TAINACAN_UnitTestCase { return "${title}"; } + + function test_taxonomy_metadata_html() { + $taxonomy = $this->tainacan_entity_factory->create_entity( + 'taxonomy', + array( + 'name' => 'My Taxonomy test', + 'collections' => [$this->collection], + 'status' => 'publish' + ), + true + ); + + $meta = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'My tax meta', + 'status' => 'publish', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', + 'metadata_type_options' => [ + 'taxonomy_id' => $taxonomy->get_id(), + ] + ), + true + ); + } } \ No newline at end of file From d7637bde12b9181f83ecd551790984239dd5e4eb Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 09:41:32 -0300 Subject: [PATCH 22/30] finishes first tests for taxonomy meta html --- .../taxonomy/class-tainacan-taxonomy.php | 3 +-- tests/__test-bulkedit.php | 12 ------------ tests/test-category-metadatum-types.php | 8 -------- tests/test-item-metadata.php | 16 +++++++++++++++- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php index 031ca13c2..d777d08e0 100644 --- a/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/views/admin/components/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -323,7 +323,6 @@ class Taxonomy extends Metadata_Type { } return $valid; - } /** @@ -332,7 +331,7 @@ class Taxonomy extends Metadata_Type { * @return string The HTML representation of the value, containing one or multiple terms, separated by comma, linked to term page */ public function get_value_as_html(Item_Metadata_Entity $item_metadata) { - $value = $item_metadata->get_value(); + $value = $item_metadata->get_value(); $return = ''; if ( $item_metadata->is_multiple() ) { diff --git a/tests/__test-bulkedit.php b/tests/__test-bulkedit.php index 3db4df885..c30e15080 100644 --- a/tests/__test-bulkedit.php +++ b/tests/__test-bulkedit.php @@ -1154,8 +1154,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { ]); $this->assertEquals(7, $bulk->count_posts()); - - } /** @@ -1206,8 +1204,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { $item_id = $bulk->get_item_id_by_index(30); $this->assertFalse($item_id); - - } function test_set_multiple_tax_meta() { @@ -1228,14 +1224,8 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { 'collection_id' => $this->collection->get_id() ]); - - - $bulk->set_value($this->category, ['super', 'dooper']); - - - $items = $Tainacan_Items->fetch([ 'tax_query' => [ [ @@ -1342,6 +1332,4 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { $this->assertEquals(5, $items->found_posts); } - - } diff --git a/tests/test-category-metadatum-types.php b/tests/test-category-metadatum-types.php index b0de80955..37c7d7bef 100644 --- a/tests/test-category-metadatum-types.php +++ b/tests/test-category-metadatum-types.php @@ -79,10 +79,6 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { true ); - - - - $term = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -237,10 +233,6 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { ); $this->assertContains($tax3->get_db_identifier(), get_object_taxonomies($collection->get_db_identifier()), 'Taxonommy used by repository level metadatum must be assigned to all collections post types'); - - - - } function test_relate_taxonomy_match() { diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 75c1a1356..5bafc6353 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -671,7 +671,16 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $meta = $this->tainacan_entity_factory->create_entity( + $term = $this->tainacan_entity_factory->create_entity( + 'term', + array( + 'taxonomy' => $taxonomy->get_db_identifier(), + 'name' => 'first term from my tax', + ), + true + ); + + $taxonomy_meta = $this->tainacan_entity_factory->create_entity( 'metadatum', array( 'name' => 'My tax meta', @@ -684,5 +693,10 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ), true ); + + $item_taxonomy_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $taxonomy_meta); + $item_taxonomy_metadata->set_value($term); + $item_taxonomy_metadata->validate(); + $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax"); } } \ No newline at end of file From 9b4a45b8af3a6f05af605f36029b58cb29a9ed30 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 09:51:26 -0300 Subject: [PATCH 23/30] adds more test cases for taxonomy meta html --- tests/test-item-metadata.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 5bafc6353..3a97878a5 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -654,12 +654,6 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_metadata_relationship->get_value_as_html(), "${expected_return}${separator}${expected_return2}"); } - private function relationship_expected_return($id, $title) { - $URL = get_permalink($id); - - return "${title}"; - } - function test_taxonomy_metadata_html() { $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', @@ -680,6 +674,15 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); + $term2 = $this->tainacan_entity_factory->create_entity( + 'term', + array( + 'taxonomy' => $taxonomy->get_db_identifier(), + 'name' => 'Second term from my tax', + ), + true + ); + $taxonomy_meta = $this->tainacan_entity_factory->create_entity( 'metadatum', array( @@ -695,8 +698,23 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ); $item_taxonomy_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $taxonomy_meta); + $item_taxonomy_metadata->set_value(''); + $item_taxonomy_metadata->validate(); + $this->assertEmpty($item_taxonomy_metadata->get_value_as_html()); + $item_taxonomy_metadata->set_value($term); $item_taxonomy_metadata->validate(); $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax"); + + $taxonomy_meta->set_multiple('yes'); + $item_taxonomy_metadata->set_value([ $term, $term2 ]); + $item_taxonomy_metadata->validate(); + $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); + } + + private function relationship_expected_return($id, $title) { + $URL = get_permalink($id); + + return "${title}"; } } \ No newline at end of file From e394dadde0d6707b5ef03518ea76f507f0acfbb9 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Tue, 6 Apr 2021 10:01:14 -0300 Subject: [PATCH 24/30] Refactors common markup pattern --- tests/test-item-metadata.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 3a97878a5..f023b8499 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -15,6 +15,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { private $collection = null; private $item = null; + private $separator = ' | '; public function setUp() { parent::setUp(); @@ -451,7 +452,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata_numeric_mult = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_numeric_multiple); $item_metadata_numeric_mult->set_value([10,22,4]); $item_metadata_numeric_mult->validate(); - $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10 | 22 | 4'); + $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), "10" . $this->separator . "22" . $this->separator . "4"); } function test_date_metadata_html() { @@ -496,11 +497,11 @@ class Item_Metadata extends TAINACAN_UnitTestCase { // Invalid date values $item_metadata_date_mult->set_value([10,22,4]); $item_metadata_date_mult->validate(); - $this->assertEquals($item_metadata_date_mult->get_value_as_html(), ' | | '); + $this->assertEquals($item_metadata_date_mult->get_value_as_html(), $this->separator . $this->separator ); $item_metadata_date_mult->set_value(["2021-04-05", "2021-12-30"]); $item_metadata_date_mult->validate(); - $this->assertEquals($item_metadata_date_mult->get_value_as_html(), 'April 5, 2021 | December 30, 2021'); + $this->assertEquals($item_metadata_date_mult->get_value_as_html(), 'April 5, 2021' . $this->separator . 'December 30, 2021'); } function test_user_metadata_html() { @@ -544,7 +545,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $sec_user = $this->factory()->user->create(array( 'role' => 'subscriber', 'display_name' => 'User Name 2' )); $user_meta_multi->set_value([$new_user, $sec_user]); $user_meta_multi->validate(); - $this->assertEquals($user_meta_multi->get_value_as_html(), 'User Name | User Name 2'); + $this->assertEquals($user_meta_multi->get_value_as_html(), 'User Name' . $this->separator . 'User Name 2'); } function test_selectbox_metadata_html() { @@ -588,7 +589,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $sb_meta_multi = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $selectbox_metadata_multiple); $sb_meta_multi->set_value(['tainacan', 'wordpress']); $sb_meta_multi->validate(); - $this->assertEquals($sb_meta_multi->get_value_as_html(), 'tainacan | wordpress'); + $this->assertEquals($sb_meta_multi->get_value_as_html(), 'tainacan' . $this->separator . 'wordpress'); } function test_relationship_metadata_html() { @@ -619,7 +620,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ); $expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title()); $expected_return2 = $this->relationship_expected_return($disappear->get_id(), $disappear->get_title()); - $separator = ' | '; + #$separator = ' | '; $relationship_metadata = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -651,7 +652,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $relationship_metadata->set_multiple('yes'); $item_metadata_relationship->set_value([ $mystify->get_id(), $disappear->get_id() ]); - $this->assertEquals($item_metadata_relationship->get_value_as_html(), "${expected_return}${separator}${expected_return2}"); + $this->assertEquals($item_metadata_relationship->get_value_as_html(), "${expected_return}" . $this->separator . "${expected_return2}"); } function test_taxonomy_metadata_html() { From 1cd3a3052b9d9f6a5dd8605d323870d31795cb52 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Wed, 7 Apr 2021 22:32:17 -0300 Subject: [PATCH 25/30] Introduces compound meta render tests --- tests/test-compound-metadatum-types.php | 48 ++++++++----------------- tests/test-item-metadata.php | 41 +++++++++++++++++++-- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/tests/test-compound-metadatum-types.php b/tests/test-compound-metadatum-types.php index cf0811154..4cd03302f 100644 --- a/tests/test-compound-metadatum-types.php +++ b/tests/test-compound-metadatum-types.php @@ -8,7 +8,7 @@ namespace Tainacan\Tests; * @package Test_Tainacan */ -use Tainacan\Entities; +use Tainacan\Entities\Item_Metadata_Entity; /** * Compound Metadatum Types test case. @@ -17,10 +17,7 @@ use Tainacan\Entities; class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { function test_compound_metadata_types() { - - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', @@ -79,23 +76,21 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { true ); - $item_metadata1 = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child1); + $item_metadata1 = new Item_Metadata_Entity($i, $metadatum_child1); $item_metadata1->set_value('Red'); $item_metadata1->validate(); $item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1); - $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id()); + $item_metadata = new Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id()); $item_metadata->set_value('Blue'); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); - - global $wpdb; + $compoundItem = new Item_Metadata_Entity($i, $metadatum); $compoundValue = $compoundItem->get_value(); @@ -105,17 +100,15 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertTrue( isset($compoundValue[$metadatum_child1->get_id()]), 'First element of value must be set' ); $this->assertTrue( isset($compoundValue[$metadatum_child2->get_id()]), 'Second element of value must be set' ); - $this->assertTrue( $compoundValue[$metadatum_child1->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'First element of value should be an item metadata entity' ); - $this->assertTrue( $compoundValue[$metadatum_child2->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'Second element of value should be an item metadata entity' ); + $this->assertTrue( $compoundValue[$metadatum_child1->get_id()] instanceof Item_Metadata_Entity , 'First element of value should be an item metadata entity' ); + $this->assertTrue( $compoundValue[$metadatum_child2->get_id()] instanceof Item_Metadata_Entity , 'Second element of value should be an item metadata entity' ); $this->assertEquals( 'Red', $compoundValue[$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' ); $this->assertEquals( 'Blue', $compoundValue[$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' ); } function test_multiple_compound_metadata_types() { - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', @@ -175,32 +168,30 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { true ); - global $wpdb; - // First Instance - $item_metadata1 = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child1); + $item_metadata1 = new Item_Metadata_Entity($i, $metadatum_child1); $item_metadata1->set_value('Red'); $item_metadata1->validate(); $item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1); - $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id()); + $item_metadata = new Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata1->get_parent_meta_id()); $item_metadata->set_value('Blue'); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); // Second Instance - $item_metadata3 = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child1); + $item_metadata3 = new Item_Metadata_Entity($i, $metadatum_child1); $item_metadata3->set_value('Green'); $item_metadata3->validate(); $item_metadata3 = $Tainacan_Item_Metadata->insert($item_metadata3); - $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata3->get_parent_meta_id()); + $item_metadata = new Item_Metadata_Entity($i, $metadatum_child2, null, $item_metadata3->get_parent_meta_id()); $item_metadata->set_value('Yellow'); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); + $compoundItem = new Item_Metadata_Entity($i, $metadatum); $compoundValue = $compoundItem->get_value(); $this->assertTrue( is_array($compoundValue), 'value of a compound should return array' ); @@ -212,8 +203,8 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertTrue( isset($compoundValue[0][$metadatum_child1->get_id()]), 'First element of value must be set' ); $this->assertTrue( isset($compoundValue[1][$metadatum_child2->get_id()]), 'Second element of value must be set' ); - $this->assertTrue( $compoundValue[0][$metadatum_child1->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'First element of value should be an item metadata entity' ); - $this->assertTrue( $compoundValue[1][$metadatum_child2->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity , 'Second element of value should be an item metadata entity' ); + $this->assertTrue( $compoundValue[0][$metadatum_child1->get_id()] instanceof Item_Metadata_Entity , 'First element of value should be an item metadata entity' ); + $this->assertTrue( $compoundValue[1][$metadatum_child2->get_id()] instanceof Item_Metadata_Entity , 'Second element of value should be an item metadata entity' ); $this->assertEquals( 'Red', $compoundValue[0][$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' ); $this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' ); @@ -222,7 +213,7 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertEquals( 'Yellow', $compoundValue[1][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' ); $item_metadata_removed = $Tainacan_Item_Metadata->remove_compound_value($i, $metadatum, $item_metadata3->get_parent_meta_id()); - $compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); + $compoundItem = new Item_Metadata_Entity($i, $metadatum); $compoundValue = $compoundItem->get_value(); $this->assertTrue( is_array($compoundValue), 'value of a compound should return array' ); @@ -230,13 +221,9 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertEquals( 'Red', $compoundValue[0][$metadatum_child1->get_id()]->get_value() , 'First element of value should have "Red" value' ); $this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' ); - } function test_validations_taxonomy_in_multiple() { - - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -306,9 +293,6 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { } function test_validations_multiple_metadata() { - - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -341,14 +325,10 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { $newMetadatum->set_multiple('no'); $this->assertTrue($newMetadatum->validate()); - - } function test_validations_metadada_order() { - $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index f023b8499..06c6e739c 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -416,7 +416,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertTrue($item_metadata_text->has_value()); } - function test_numeric_metadata_html() { + function test_numeric_metadata_html() { // Simple numeric metadata $metadatum_numeric = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -620,7 +620,6 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ); $expected_return = $this->relationship_expected_return($mystify->get_id(), $mystify->get_title()); $expected_return2 = $this->relationship_expected_return($disappear->get_id(), $disappear->get_title()); - #$separator = ' | '; $relationship_metadata = $this->tainacan_entity_factory->create_entity( 'metadatum', @@ -713,6 +712,44 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); } + function test_compound_metadata_html() { + $coumpound_meta = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'My compound Meta', + 'status' => 'publish', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Compound', + ), + true + ); + $text_meta = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'My Text meta', + 'status' => 'publish', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + 'parent' => $coumpound_meta->get_id() + ), + true + ); + $textarea_meta = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'My Textarea meta!', + 'status' => 'publish', + 'collection' => $this->collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Textarea', + 'parent' => $coumpound_meta->get_id() + ), + true + ); + $item_compound_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $coumpound_meta); + $item_compound_metadata->set_value(['invalid meta value!']); + $this->assertEquals($item_compound_metadata->get_value_as_html(), "
"); + } + private function relationship_expected_return($id, $title) { $URL = get_permalink($id); From 38458d23781d3b66c20c9ee153330094b9dd404c Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Wed, 7 Apr 2021 23:16:56 -0300 Subject: [PATCH 26/30] General lints and tests refactors --- ...n-rest-background-processes-controller.php | 5 -- tests/test-item-metadata.php | 73 ++++++++++--------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php b/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php index c3131186c..30405f303 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php @@ -231,7 +231,6 @@ class REST_Background_Processes_Controller extends REST_Controller { $result = $this->prepare_item_for_response($result, $request); return new \WP_REST_Response( $result, 200 ); - } public function prepare_item_for_response($item, $request) { @@ -309,8 +308,6 @@ class REST_Background_Processes_Controller extends REST_Controller { $result = $this->prepare_item_for_response($result, $request); return new \WP_REST_Response( $result, 200 ); - - } public function delete_item( $request ) { @@ -334,7 +331,6 @@ class REST_Background_Processes_Controller extends REST_Controller { // TODO: delete log files return new \WP_REST_Response( $result, 200 ); - } public function get_log_url($id, $action, $type = '') { @@ -352,7 +348,6 @@ class REST_Background_Processes_Controller extends REST_Controller { $logs_url = $upload_url . 'tainacan/' . $filename; return $logs_url; - } } diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 06c6e739c..789186392 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -2,6 +2,8 @@ namespace Tainacan\Tests; +use Tainacan\Entities\Item_Metadata_Entity; + /** * Class Item_Metadata * @@ -39,14 +41,13 @@ class Item_Metadata extends TAINACAN_UnitTestCase { * Teste da insercao de um metadado simples sem o tipo */ function test_add() { - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( - 'name' => 'teste', + 'name' => 'test', 'description' => 'No description', ), true @@ -55,10 +56,10 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $metadatum = $this->tainacan_entity_factory->create_entity( 'metadatum', array( - 'name' => 'metadado', - 'description' => 'descricao', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Text', + 'name' => 'metadado', + 'description' => 'descricao', + 'collection' => $collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', ), true ); @@ -68,8 +69,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $i = $this->tainacan_entity_factory->create_entity( 'item', array( - 'title' => 'item teste', - 'description' => 'adasdasdsa', + 'title' => 'item teste title', + 'description' => 'item description', 'collection' => $collection ), true @@ -79,7 +80,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item = $Tainacan_Items->fetch($i->get_id()); - $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $test); + $item_metadata = new Item_Metadata_Entity($item, $test); $item_metadata->set_value('teste_value'); $item_metadata->validate(); @@ -133,7 +134,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $item = $Tainacan_Items->fetch($i->get_id()); - $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $test); + $item_metadata = new Item_Metadata_Entity($item, $test); // false because its required $this->assertFalse($item_metadata->validate()); @@ -198,7 +199,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $value = 'teste_val'; - $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); + $item_metadata = new Item_Metadata_Entity($i, $metadatum); $item_metadata->set_value($value); $this->assertTrue($item_metadata->validate()); @@ -206,11 +207,11 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $n_item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); + $n_item_metadata = new Item_Metadata_Entity($i, $metadatum); $n_item_metadata->set_value($value); $this->assertTrue($n_item_metadata->validate(), 'trying to validate the same item with same value should be ok'); - $n_item_metadata2 = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum); + $n_item_metadata2 = new Item_Metadata_Entity($i2, $metadatum); $n_item_metadata2->set_value($value); $this->assertFalse($n_item_metadata2->validate(), 'Collection key should not validate another item metadatada with the same value'); } @@ -311,11 +312,11 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ); $value_text = 'GOOGLE: www.google.com'; - $item_metadata_text = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_text); + $item_metadata_text = new Item_Metadata_Entity($i, $metadatum_text); $item_metadata_text->set_value($value_text); $value_textarea = 'GOOGLE: www.google.com \n GOOGLE: https://www.google.com'; - $item_metadata_textarea = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_textarea); + $item_metadata_textarea = new Item_Metadata_Entity($i, $metadatum_textarea); $item_metadata_textarea->set_value($value_textarea); $response_text = 'GOOGLE: www.google.com'; @@ -325,13 +326,13 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_metadata_textarea->get_value_as_html(), $response_textarea); // Poor HTML entry tests - $malformatted_HTML = "

I started my content

and make something else here
without closing its HTML properly"; + $badFormatted_HTML = "

I started my content

and make something else here
without closing its HTML properly"; - $item_metadata_text->set_value($malformatted_HTML); - $item_metadata_textarea->set_value($malformatted_HTML); + $item_metadata_text->set_value($badFormatted_HTML); + $item_metadata_textarea->set_value($badFormatted_HTML); - $this->assertEquals($item_metadata_text->get_value_as_html(), $malformatted_HTML ."

"); - $this->assertEquals($item_metadata_textarea->get_value_as_html(), $malformatted_HTML ."

"); + $this->assertEquals($item_metadata_text->get_value_as_html(), $badFormatted_HTML ."

"); + $this->assertEquals($item_metadata_textarea->get_value_as_html(), $badFormatted_HTML ."

"); } /** @@ -373,7 +374,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ); $value_textarea = ''; - $item_metadata_textarea = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_textarea); + $item_metadata_textarea = new Item_Metadata_Entity($i, $metadatum_textarea); $item_metadata_textarea->set_value($value_textarea); $item_metadata_textarea->validate(); @@ -399,7 +400,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_metadata_text = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_text); + $item_metadata_text = new Item_Metadata_Entity($i, $metadatum_text); $item_metadata_text->set_value([ $value_textarea ]); @@ -444,12 +445,12 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_metadata_numeric = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_numeric); + $item_metadata_numeric = new Item_Metadata_Entity($this->item, $metadatum_numeric); $item_metadata_numeric->set_value(10); $item_metadata_numeric->validate(); $this->assertEquals($item_metadata_numeric->get_value_as_html(), 10); - $item_metadata_numeric_mult = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_numeric_multiple); + $item_metadata_numeric_mult = new Item_Metadata_Entity($this->item, $metadatum_numeric_multiple); $item_metadata_numeric_mult->set_value([10,22,4]); $item_metadata_numeric_mult->validate(); $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), "10" . $this->separator . "22" . $this->separator . "4"); @@ -483,7 +484,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_metadata_date = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_date); + $item_metadata_date = new Item_Metadata_Entity($this->item, $metadatum_date); // Invalid date value $item_metadata_date->set_value(10); $item_metadata_date->validate(); @@ -493,7 +494,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_metadata_date->validate(); $this->assertEquals($item_metadata_date->get_value_as_html(), "April 5, 2021"); - $item_metadata_date_mult = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $metadatum_date_multiple); + $item_metadata_date_mult = new Item_Metadata_Entity($this->item, $metadatum_date_multiple); // Invalid date values $item_metadata_date_mult->set_value([10,22,4]); $item_metadata_date_mult->validate(); @@ -517,7 +518,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $user_meta = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $user_metadata); + $user_meta = new Item_Metadata_Entity($this->item, $user_metadata); // Empty val $this->assertEmpty($user_meta->get_value_as_html()); @@ -539,7 +540,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ), true ); - $user_meta_multi = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $user_metadata_multiple); + $user_meta_multi = new Item_Metadata_Entity($this->item, $user_metadata_multiple); $this->assertEmpty($user_meta_multi->get_value_as_html()); $sec_user = $this->factory()->user->create(array( 'role' => 'subscriber', 'display_name' => 'User Name 2' )); @@ -578,7 +579,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $sb_meta = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $selectbox_metadata); + $sb_meta = new Item_Metadata_Entity($this->item, $selectbox_metadata); $sb_meta->set_value('tainacan'); $sb_meta->validate(); $this->assertEquals($sb_meta->get_value_as_html(), 'tainacan'); @@ -586,7 +587,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $sb_meta->set_value('php'); $this->assertEquals($sb_meta->get_value_as_html(), 'php'); - $sb_meta_multi = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $selectbox_metadata_multiple); + $sb_meta_multi = new Item_Metadata_Entity($this->item, $selectbox_metadata_multiple); $sb_meta_multi->set_value(['tainacan', 'wordpress']); $sb_meta_multi->validate(); $this->assertEquals($sb_meta_multi->get_value_as_html(), 'tainacan' . $this->separator . 'wordpress'); @@ -637,7 +638,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_metadata_relationship = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $relationship_metadata); + $item_metadata_relationship = new Item_Metadata_Entity($this->item, $relationship_metadata); $item_metadata_relationship->validate(); $this->assertEquals($item_metadata_relationship->get_value_as_html(), ''); @@ -697,7 +698,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { true ); - $item_taxonomy_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $taxonomy_meta); + $item_taxonomy_metadata = new Item_Metadata_Entity($this->item, $taxonomy_meta); $item_taxonomy_metadata->set_value(''); $item_taxonomy_metadata->validate(); $this->assertEmpty($item_taxonomy_metadata->get_value_as_html()); @@ -713,7 +714,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { } function test_compound_metadata_html() { - $coumpound_meta = $this->tainacan_entity_factory->create_entity( + $compound_meta = $this->tainacan_entity_factory->create_entity( 'metadatum', array( 'name' => 'My compound Meta', @@ -730,7 +731,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { 'status' => 'publish', 'collection' => $this->collection, 'metadata_type' => 'Tainacan\Metadata_Types\Text', - 'parent' => $coumpound_meta->get_id() + 'parent' => $compound_meta->get_id() ), true ); @@ -741,11 +742,11 @@ class Item_Metadata extends TAINACAN_UnitTestCase { 'status' => 'publish', 'collection' => $this->collection, 'metadata_type' => 'Tainacan\Metadata_Types\Textarea', - 'parent' => $coumpound_meta->get_id() + 'parent' => $compound_meta->get_id() ), true ); - $item_compound_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $coumpound_meta); + $item_compound_metadata = new Item_Metadata_Entity($this->item, $compound_meta); $item_compound_metadata->set_value(['invalid meta value!']); $this->assertEquals($item_compound_metadata->get_value_as_html(), "
"); } From 8bea440564be98ef96cea9fb17b83334fa879591 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Wed, 7 Apr 2021 23:26:33 -0300 Subject: [PATCH 27/30] Fix indentation --- tests/test-item-metadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 789186392..9d5a57659 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -24,7 +24,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $c = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); $i = $this->tainacan_entity_factory->create_entity( 'item', - array( + array( 'title' => 'My test item', 'description' => 'item description', 'collection' => $c, From a7ff08dbf6cef60d8bb9a8b12dfb602acb378ef3 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 9 Apr 2021 11:20:17 -0300 Subject: [PATCH 28/30] fix: indentations --- tests/test-item-metadata.php | 564 +++++++++++++++++------------------ 1 file changed, 282 insertions(+), 282 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 9d5a57659..50df7b7c8 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -37,152 +37,152 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->item = $i; } - /** - * Teste da insercao de um metadado simples sem o tipo - */ - function test_add() { - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + /** + * Teste da insercao de um metadado simples sem o tipo + */ + function test_add() { + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'test', - 'description' => 'No description', - ), - true - ); + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'test', + 'description' => 'No description', + ), + true + ); - $metadatum = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'description' => 'descricao', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado', + 'description' => 'descricao', + 'collection' => $collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - $test = $Tainacan_Metadata->fetch($metadatum->get_id()); - - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'item teste title', - 'description' => 'item description', - 'collection' => $collection - ), - true - ); - - $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); - - $item = $Tainacan_Items->fetch($i->get_id()); + $test = $Tainacan_Metadata->fetch($metadatum->get_id()); + + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste title', + 'description' => 'item description', + 'collection' => $collection + ), + true + ); + + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + + $item = $Tainacan_Items->fetch($i->get_id()); - $item_metadata = new Item_Metadata_Entity($item, $test); - $item_metadata->set_value('teste_value'); + $item_metadata = new Item_Metadata_Entity($item, $test); + $item_metadata->set_value('teste_value'); $item_metadata->validate(); - $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - - $this->assertEquals('teste_value', $item_metadata->get_value()); - } + $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); + + $this->assertEquals('teste_value', $item_metadata->get_value()); + } - /** - * Teste da insercao de um metadado simples com o tipo - */ - function test_required(){ - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + /** + * Teste da insercao de um metadado simples com o tipo + */ + function test_required(){ + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste', - 'description' => 'No description', - ), - true - ); + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste', + 'description' => 'No description', + ), + true + ); - $metadatum = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'description' => 'descricao', - 'collection' => $collection, - 'required' => 'yes', - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado', + 'description' => 'descricao', + 'collection' => $collection, + 'required' => 'yes', + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - $test = $Tainacan_Metadata->fetch($metadatum->get_id()); - - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'item teste', - 'status' => 'publish', - 'description' => 'adasdasdsa', - 'collection' => $collection - ), - true - ); - - $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); - - $item = $Tainacan_Items->fetch($i->get_id()); - $item_metadata = new Item_Metadata_Entity($item, $test); - - // false because its required - $this->assertFalse($item_metadata->validate()); - - $item_metadata->set_value('teste_value'); - - $this->assertTrue($item_metadata->validate()); - - $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - - $this->assertEquals('teste_value', $item_metadata->get_value()); - } - - function test_collection_key(){ - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + $test = $Tainacan_Metadata->fetch($metadatum->get_id()); + + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste', + 'status' => 'publish', + 'description' => 'adasdasdsa', + 'collection' => $collection + ), + true + ); + + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + + $item = $Tainacan_Items->fetch($i->get_id()); + $item_metadata = new Item_Metadata_Entity($item, $test); + + // false because its required + $this->assertFalse($item_metadata->validate()); + + $item_metadata->set_value('teste_value'); + + $this->assertTrue($item_metadata->validate()); + + $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); + + $this->assertEquals('teste_value', $item_metadata->get_value()); + } + + function test_collection_key(){ + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste', - 'description' => 'No description', - ), - true - ); + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste', + 'description' => 'No description', + ), + true + ); - $metadatum = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'description' => 'descricao', - 'collection' => $collection, - 'collection_key' => 'yes', - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado', + 'description' => 'descricao', + 'collection' => $collection, + 'collection_key' => 'yes', + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'item teste', - 'description' => 'adasdasdsa', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste', + 'description' => 'adasdasdsa', + 'collection' => $collection, + 'status' => 'publish' + ), + true + ); $i2 = $this->tainacan_entity_factory->create_entity( 'item', @@ -194,121 +194,121 @@ class Item_Metadata extends TAINACAN_UnitTestCase { ), true ); - - $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); - $value = 'teste_val'; - - $item_metadata = new Item_Metadata_Entity($i, $metadatum); - $item_metadata->set_value($value); + $value = 'teste_val'; + + $item_metadata = new Item_Metadata_Entity($i, $metadatum); + $item_metadata->set_value($value); - $this->assertTrue($item_metadata->validate()); + $this->assertTrue($item_metadata->validate()); - $item_metadata->validate(); - $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); + $item_metadata->validate(); + $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $n_item_metadata = new Item_Metadata_Entity($i, $metadatum); - $n_item_metadata->set_value($value); + $n_item_metadata = new Item_Metadata_Entity($i, $metadatum); + $n_item_metadata->set_value($value); $this->assertTrue($n_item_metadata->validate(), 'trying to validate the same item with same value should be ok'); $n_item_metadata2 = new Item_Metadata_Entity($i2, $metadatum); $n_item_metadata2->set_value($value); $this->assertFalse($n_item_metadata2->validate(), 'Collection key should not validate another item metadatada with the same value'); - } - - function test_fetch(){ - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + } + + function test_fetch(){ + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste', - 'description' => 'No description', - ), - true - ); + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste', + 'description' => 'No description', + ), + true + ); - $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'description' => 'descricao', - 'collection' => $collection, - 'status' => 'publish', - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado', + 'description' => 'descricao', + 'collection' => $collection, + 'status' => 'publish', + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - //$test = $Tainacan_Metadata->fetch($metadatum->get_id()); - - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'item teste', - 'description' => 'adasdasdsa', - 'collection' => $collection - ), - true - ); + //$test = $Tainacan_Metadata->fetch($metadatum->get_id()); + + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste', + 'description' => 'adasdasdsa', + 'collection' => $collection + ), + true + ); - $item_metadatas = $Tainacan_Item_Metadata->fetch($i, 'OBJECT'); + $item_metadatas = $Tainacan_Item_Metadata->fetch($i, 'OBJECT'); - $names = []; - foreach ($item_metadatas as $item_metadata) { - $names[] = $item_metadata->get_metadatum()->get_name(); - } - - $this->assertTrue(is_array($item_metadatas)); + $names = []; + foreach ($item_metadatas as $item_metadata) { + $names[] = $item_metadata->get_metadatum()->get_name(); + } + + $this->assertTrue(is_array($item_metadatas)); - // notice for repository metadata - $this->assertEquals(3, sizeof($item_metadatas)); - //first 2 metadata are repository metadata - $this->assertTrue( in_array('metadado', $names) ); - + // notice for repository metadata + $this->assertEquals(3, sizeof($item_metadatas)); + //first 2 metadata are repository metadata + $this->assertTrue( in_array('metadado', $names) ); + } function test_metadata_text_textarea() { - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste' - ), - true + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste' + ), + true ); $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'item teste', - 'description' => 'description', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); + 'item', + array( + 'title' => 'item teste', + 'description' => 'description', + 'collection' => $collection, + 'status' => 'publish' + ), + true + ); - $metadatum_text = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadadoText', - 'description' => 'descricao', - 'collection_id' => $collection->get_id(), - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true + $metadatum_text = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadadoText', + 'description' => 'descricao', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true ); $metadatum_textarea = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadadoTextarea', - 'description' => 'descricao', - 'collection_id' => $collection->get_id(), - 'metadata_type' => 'Tainacan\Metadata_Types\Textarea', - ), - true + 'metadatum', + array( + 'name' => 'metadadoTextarea', + 'description' => 'descricao', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Textarea', + ), + true ); $value_text = 'GOOGLE: www.google.com'; @@ -335,87 +335,87 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $this->assertEquals($item_metadata_textarea->get_value_as_html(), $badFormatted_HTML ."

"); } - /** - * @group test_item_metadata_has_value - */ + /** + * @group test_item_metadata_has_value + */ function test_item_metadata_has_value() { $test_value = 'has_value'; - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste' - ), - true - ); + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste' + ), + true + ); - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'item teste', - 'description' => 'description', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste', + 'description' => 'description', + 'collection' => $collection, + 'status' => 'publish' + ), + true + ); - $metadatum_textarea = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadadoTextarea', - 'description' => 'descricao', - 'collection_id' => $collection->get_id(), - 'metadata_type' => 'Tainacan\Metadata_Types\Textarea', - ), - true - ); + $metadatum_textarea = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadadoTextarea', + 'description' => 'descricao', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Textarea', + ), + true + ); - $value_textarea = ''; - $item_metadata_textarea = new Item_Metadata_Entity($i, $metadatum_textarea); - $item_metadata_textarea->set_value($value_textarea); + $value_textarea = ''; + $item_metadata_textarea = new Item_Metadata_Entity($i, $metadatum_textarea); + $item_metadata_textarea->set_value($value_textarea); - $item_metadata_textarea->validate(); - $item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea); + $item_metadata_textarea->validate(); + $item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea); - $this->assertFalse($item_metadata_textarea->has_value()); + $this->assertFalse($item_metadata_textarea->has_value()); - $item_metadata_textarea->set_value($test_value); - $item_metadata_textarea->validate(); - $item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea); + $item_metadata_textarea->set_value($test_value); + $item_metadata_textarea->validate(); + $item_metadata_textarea = $Tainacan_Item_Metadata->insert($item_metadata_textarea); - $this->assertTrue($item_metadata_textarea->has_value()); + $this->assertTrue($item_metadata_textarea->has_value()); - $metadatum_text = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadadoText', - 'description' => 'descricao', - 'collection_id' => $collection->get_id(), - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - 'multiple' => 'yes' - ), - true - ); + $metadatum_text = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadadoText', + 'description' => 'descricao', + 'collection_id' => $collection->get_id(), + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + 'multiple' => 'yes' + ), + true + ); - $item_metadata_text = new Item_Metadata_Entity($i, $metadatum_text); + $item_metadata_text = new Item_Metadata_Entity($i, $metadatum_text); - $item_metadata_text->set_value([ $value_textarea ]); + $item_metadata_text->set_value([ $value_textarea ]); - $item_metadata_text->validate(); - $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata_text); + $item_metadata_text->validate(); + $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata_text); - $this->assertFalse($item_metadata->has_value()); + $this->assertFalse($item_metadata->has_value()); $item_metadata_text->set_value([ $test_value ]); - $item_metadata_text->validate(); - $item_metadata_text = $Tainacan_Item_Metadata->insert($item_metadata_text); + $item_metadata_text->validate(); + $item_metadata_text = $Tainacan_Item_Metadata->insert($item_metadata_text); - $this->assertTrue($item_metadata_text->has_value()); - } + $this->assertTrue($item_metadata_text->has_value()); + } function test_numeric_metadata_html() { // Simple numeric metadata From c1fab38a0dc91bd4b093eb2bbfa02a1caeaf7642 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 9 Apr 2021 11:27:22 -0300 Subject: [PATCH 29/30] test: create attribute html data-id with term id #396 --- tests/test-item-metadata.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 50df7b7c8..8de75cfd9 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -705,12 +705,15 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_taxonomy_metadata->set_value($term); $item_taxonomy_metadata->validate(); - $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax"); + $term_id = $term->get_id(); + $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax"); $taxonomy_meta->set_multiple('yes'); $item_taxonomy_metadata->set_value([ $term, $term2 ]); $item_taxonomy_metadata->validate(); - $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); + $term_id = $term->get_id(); + $term_id2 = $term2->get_id(); + $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); } function test_compound_metadata_html() { From 9fe6446a236ced399c7f66d8fa1fb5d408e92817 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 9 Apr 2021 12:00:44 -0300 Subject: [PATCH 30/30] test: create attribute html href with term link #396 --- tests/test-item-metadata.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 8de75cfd9..47db77b1a 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -706,14 +706,17 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $item_taxonomy_metadata->set_value($term); $item_taxonomy_metadata->validate(); $term_id = $term->get_id(); - $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax"); + $link = get_term_link( (int) $term_id ); + $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax"); $taxonomy_meta->set_multiple('yes'); $item_taxonomy_metadata->set_value([ $term, $term2 ]); $item_taxonomy_metadata->validate(); $term_id = $term->get_id(); $term_id2 = $term2->get_id(); - $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); + $link = get_term_link( (int) $term_id ); + $link2 = get_term_link( (int) $term_id2 ); + $this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "first term from my tax | Second term from my tax"); } function test_compound_metadata_html() {