From 14228876968657d34d49318d9cec89241a410d7a Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Fri, 12 Mar 2021 03:53:13 -0300 Subject: [PATCH] adds tests for terms --- src/classes/entities/class-tainacan-term.php | 6 +++--- tests/test-html-injection.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 972885ff6..0241c4fb2 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -51,11 +51,11 @@ class Term extends Entity { } } - public function __toString(){ - return apply_filters("tainacan-term-to-string", $this->get_name(), $this); + public function __toString() { + return (string) apply_filters("tainacan-term-to-string", $this->get_name(), $this); } - public function _toArray(){ + public function _toArray() { $term_array = parent::_toArray(); $term_id = $term_array['term_id']; diff --git a/tests/test-html-injection.php b/tests/test-html-injection.php index 3bc45eb2e..f8275e68d 100644 --- a/tests/test-html-injection.php +++ b/tests/test-html-injection.php @@ -21,6 +21,7 @@ class HTML_Injection extends TAINACAN_UnitTestCase $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); + $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); // Evil attempts $link = "link"; @@ -128,6 +129,17 @@ class HTML_Injection extends TAINACAN_UnitTestCase /* * Test terms */ + $term = $this->tainacan_entity_factory->create_entity( + 'term', + array( + 'taxonomy' => $taxonomy->get_db_identifier(), + 'name' => $css, + ), + true + ); + + $t = $Tainacan_Terms->fetch($term->get_term_id(), $taxonomy); + $this->assertEquals($t->get_name(), 'my text along with some style'); /* * Test taxonomies