Passing test for taxonomies

This commit is contained in:
Rodrigo de Oliveira 2021-03-12 01:18:12 -03:00
parent 461cff8a40
commit 246e5b92d3
3 changed files with 27 additions and 5 deletions

View File

@ -144,6 +144,11 @@ abstract class Repository {
}
$obj->WP_Post->post_type = $obj::get_post_type();
if ( $obj instanceof Entities\Taxonomy ) {
$sanitized = $this->sanitize_value($obj->get('name'));
$obj->WP_Post->post_title = $sanitized;
}
if ( $obj instanceof Entities\Log && ! ( isset( $obj->WP_Post->post_status ) && in_array( $obj->WP_Post->post_status, [
'publish',
'pending'

View File

@ -141,7 +141,6 @@ class Taxonomies extends Repository {
* @return Entities\Entity
*/
public function insert( $taxonomy ) {
$new_taxonomy = parent::insert( $taxonomy );
$new_taxonomy->tainacan_register_taxonomy();
@ -168,7 +167,6 @@ class Taxonomies extends Repository {
* @return \WP_Query|Array an instance of wp query OR array of entities;
*/
public function fetch( $args = [], $output = null ) {
// TODO: Pegar taxonomias registradas via código
if ( is_numeric( $args ) ) {

View File

@ -9,7 +9,7 @@ namespace Tainacan\Tests;
*/
/**
* Sample test case.
* HTML INJECTION test case.
*/
class HTML_Injection extends TAINACAN_UnitTestCase
{
@ -20,12 +20,14 @@ class HTML_Injection extends TAINACAN_UnitTestCase
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
// Evil attempts
$link = "<a href='www.tainacan.org'>link</a>";
$js = "<script>alert('XSS')</script>";
$css = "my text along with some style <style>a { display: none }</style>";
$iframe = "<iframe src='www.tainacan.org' title='Taiancan'></iframe>";
$text_and_link = "my very interesting name and $link as well";
// Accepted formatting
$strong = "I have some info to tell the world. And I can <strong> bold it </strong>";
@ -40,12 +42,14 @@ class HTML_Injection extends TAINACAN_UnitTestCase
true
);
$collection = $Tainacan_Collections->fetch($collection->get_id());
// Test Collection
$this->assertEquals($collection->get_name(), 'collection name link link2');
$metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadatum name <a href="www.tainacan.org">link</a>',
'name' => $text_and_link,
'description' => 'metadatum description',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text',
@ -53,7 +57,7 @@ class HTML_Injection extends TAINACAN_UnitTestCase
true
);
$metadatum = $Tainacan_Metadata->fetch($metadatum->get_id());
$this->assertEquals($metadatum->get_name(), 'metadatum name link');
$this->assertEquals($metadatum->get_name(), 'my very interesting name and link as well');
$item = $this->tainacan_entity_factory->create_entity(
'item',
@ -64,6 +68,17 @@ class HTML_Injection extends TAINACAN_UnitTestCase
),
true
);
$taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => $text_and_link,
'collections' => [$collection],
'status' => 'publish'
),
true
);
$item = $Tainacan_Items->fetch($item->get_id());
$this->assertEquals($item->get_title(), 'title item console.log("XSS")');
$this->assertEquals($item->get_description(), 'description item');
@ -102,5 +117,9 @@ class HTML_Injection extends TAINACAN_UnitTestCase
$this->assertEquals($item_metadata->get_value(), $html);
// Test terms
// Test taxonomies
$tx = $Tainacan_Taxonomies->fetch($taxonomy->get_id());
$this->assertEquals($tx->get_name(), 'my very interesting name and link as well');
}
}