link"; private $js = ""; private $css = "my text along with some style "; private $iframe = ""; private $text_and_link = ""; private $text_and_iframe = ""; // Accepted formatting private $strong = "I have some info to tell the world. And I can bold it "; private $html = "

Main Info

sub title

My structure description

and another paragraph

"; // Expected returns private $expected_title = 'my very interesting name and link as well'; private $expected_desc = 'description item'; private $collection = null; private $item = null; private $metadatum = null; private $taxonomy = null; private $taxonomy_db = null; public function setUp(): void { parent::setUp(); $link = $this->link; $iframe = $this->iframe; $this->text_and_link = "my very interesting name and $link as well"; $this->text_and_iframe = "description item $iframe"; $this->test_collections(); } function test_collections() { $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( 'name' => 'collection name link link2 ', 'description' => $this->text_and_iframe, ), true ); $collection = $Tainacan_Collections->fetch($collection->get_id()); $this->assertEquals($collection->get_name(), 'collection name link link2'); $this->assertEquals($collection->get_description(), $this->expected_desc); $this->collection = $collection; $this->test_items(); } function test_items() { $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $item = $this->tainacan_entity_factory->create_entity( 'item', array( 'title' => 'title item ', 'description' => $this->text_and_iframe, 'collection' => $this->collection ), true ); $item = $Tainacan_Items->fetch($item->get_id()); $this->assertEquals($item->get_title(), 'title item console.log("XSS")'); $this->assertEquals($item->get_description(), $this->expected_desc); $this->item = $item; $this->test_metadata(); } function test_metadata() { $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $metadatum = $this->tainacan_entity_factory->create_entity( 'metadatum', array( 'name' => $this->text_and_link, 'description' => 'metadatum description', 'collection' => $this->collection, 'metadata_type' => 'Tainacan\Metadata_Types\Text', ), true ); $metadatum = $Tainacan_Metadata->fetch($metadatum->get_id()); $this->assertEquals($metadatum->get_name(), $this->expected_title); $this->metadatum = $metadatum; $this->test_taxonomies(); } function test_taxonomies() { $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', array( 'name' => $this->text_and_link, 'collections' => [$this->collection], 'description' => $this->text_and_iframe, 'status' => 'publish' ), true ); $tx = $Tainacan_Taxonomies->fetch($taxonomy->get_id()); $this->assertEquals($tx->get_name(), $this->expected_title); $this->assertEquals($tx->get_description(), $this->expected_desc); $this->taxonomy = $taxonomy; $this->taxonomy_db = $taxonomy->get_db_identifier(); } function test_terms() { $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); $term = $this->tainacan_entity_factory->create_entity( 'term', array( 'taxonomy' => $this->taxonomy_db, 'name' => $this->css, ), true ); $t = $Tainacan_Terms->fetch($term->get_term_id(), $this->taxonomy); $this->assertEquals($t->get_name(), 'my text along with some style'); } function test_item_metadata() { $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this->item, $this->metadatum); $item_metadata->set_value($this->js); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); $this->assertEquals($item_metadata->get_value(), "alert('XSS')"); $item_metadata->set_value($this->link); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->update($item_metadata); $this->assertEquals($item_metadata->get_value(), 'link'); $item_metadata->set_value($this->css); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->update($item_metadata); $this->assertEquals($item_metadata->get_value(), 'my text along with some style a { display: none }'); $item_metadata->set_value($this->iframe); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->update($item_metadata); $this->assertEquals($item_metadata->get_value(), ''); $item_metadata->set_value($this->strong); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->update($item_metadata); $this->assertEquals($item_metadata->get_value(), $this->strong); $item_metadata->set_value($this->html); $item_metadata->validate(); $item_metadata = $Tainacan_Item_Metadata->update($item_metadata); $this->assertEquals($item_metadata->get_value(), $this->html); } }