Merge pull request #519 from tainacan/396-test-render-html

Adds tests to metadata's HTML output
This commit is contained in:
Vinícius Nunes Medeiros 2021-04-09 12:34:26 -03:00 committed by GitHub
commit 288b9bce52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 746 additions and 497 deletions

View File

@ -1,6 +1,5 @@
#!/bin/bash #!/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/' echo 'Watching changes on src/'

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
# Loads user-defined variables at build-config file
source build-config.cfg source build-config.cfg
## Only run npm build if there was a change in a .js or .vue file ## Only run npm build if there was a change in a .js or .vue file

View File

@ -5,8 +5,7 @@ command -v sass >/dev/null 2>&1 || {
echo >&2 "Sass parece não estar disponivel."; echo >&2 "Sass parece não estar disponivel.";
exit 1; exit 1;
} }
# Define o caminho.
echo "Compilando Sass..." 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 sass -E 'UTF-8' --cache-location .tmp/sass-cache-1 src/views/admin/scss/tainacan-admin.scss:src/assets/css/tainacan-admin.css

View File

@ -231,7 +231,6 @@ class REST_Background_Processes_Controller extends REST_Controller {
$result = $this->prepare_item_for_response($result, $request); $result = $this->prepare_item_for_response($result, $request);
return new \WP_REST_Response( $result, 200 ); return new \WP_REST_Response( $result, 200 );
} }
public function prepare_item_for_response($item, $request) { 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); $result = $this->prepare_item_for_response($result, $request);
return new \WP_REST_Response( $result, 200 ); return new \WP_REST_Response( $result, 200 );
} }
public function delete_item( $request ) { public function delete_item( $request ) {
@ -334,7 +331,6 @@ class REST_Background_Processes_Controller extends REST_Controller {
// TODO: delete log files // TODO: delete log files
return new \WP_REST_Response( $result, 200 ); return new \WP_REST_Response( $result, 200 );
} }
public function get_log_url($id, $action, $type = '') { 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; $logs_url = $upload_url . 'tainacan/' . $filename;
return $logs_url; return $logs_url;
} }
} }

View File

@ -31,7 +31,6 @@ class Item_Metadata_Entity extends Entity {
* @param int $meta_id ID for a specific meta row * @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) { function __construct(Item $item = null, Metadatum $metadatum = null, $meta_id = null, $parent_meta_id = null) {
$this->set_item($item); $this->set_item($item);
$this->set_metadatum($metadatum); $this->set_metadatum($metadatum);
@ -136,17 +135,15 @@ class Item_Metadata_Entity extends Entity {
* Get the value as a HTML string, with markup and links * Get the value as a HTML string, with markup and links
* @return string * @return string
*/ */
public function get_value_as_html(){ public function get_value_as_html() {
$metadatum = $this->get_metadatum(); $metadatum = $this->get_metadatum();
if (is_object($metadatum)) { if (is_object($metadatum)) {
$fto = $metadatum->get_metadata_type_object(); $fto = $metadatum->get_metadata_type_object();
if (is_object($fto)) { if (is_object($fto)) {
if ( method_exists($fto, 'get_value_as_html') ) { if ( method_exists($fto, 'get_value_as_html') ) {
return $fto->get_value_as_html($this); return $fto->get_value_as_html($this);
} }
} }
} }
@ -155,7 +152,6 @@ class Item_Metadata_Entity extends Entity {
$return = ''; $return = '';
if ( $this->is_multiple() ) { if ( $this->is_multiple() ) {
$total = sizeof($value); $total = sizeof($value);
$count = 0; $count = 0;
$prefix = $this->get_multivalue_prefix(); $prefix = $this->get_multivalue_prefix();
@ -163,25 +159,19 @@ class Item_Metadata_Entity extends Entity {
$separator = $this->get_multivalue_separator(); $separator = $this->get_multivalue_separator();
foreach ($value as $v) { foreach ($value as $v) {
$return .= $prefix; $return .= $prefix;
$return .= (string) $v; $return .= (string) $v;
$return .= $suffix; $return .= $suffix;
$count ++; $count ++;
if ($count < $total) if ($count < $total)
$return .= $separator; $return .= $separator;
} }
} else { } else {
$return = (string) $value; $return = (string) $value;
} }
return $return; return $return;
} }
/** /**

View File

@ -500,26 +500,20 @@ class Item extends Entity {
public function _toHtml() { public function _toHtml() {
$return = ''; $return = '';
$id = $this->get_id(); $id = $this->get_id();
if ( $id ) { if ( $id ) {
$link = get_permalink( (int) $id ); $link = get_permalink( (int) $id );
if (is_string($link)) { if (is_string($link)) {
$return = "<a data-linkto='item' data-id='$id' href='$link'>"; $return = "<a data-linkto='item' data-id='$id' href='$link'>";
$return.= $this->get_title(); $return.= $this->get_title();
$return .= "</a>"; $return .= "</a>";
} }
} }
return $return; return $return;
} }
/** /**

View File

@ -245,25 +245,19 @@ class Term extends Entity {
} }
public function _toHtml() { public function _toHtml() {
$return = ''; $return = '';
$id = $this->get_id(); $id = $this->get_id();
if ( $id ) { if ( $id ) {
$link = get_term_link( (int) $id ); $link = get_term_link( (int) $id );
if (is_string($link)) { if (is_string($link)) {
$return = "<a data-linkto='term' data-id='$id' href='$link'>"; $return = "<a data-linkto='term' data-id='$id' href='$link'>";
$return.= $this->get_name(); $return.= $this->get_name();
$return .= "</a>"; $return .= "</a>";
} }
} }
return apply_filters('tainacan-term-to-html', $return, $this); return apply_filters('tainacan-term-to-html', $return, $this);
} }
} }

View File

@ -1,5 +1,5 @@
=== Tainacan === === 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 Tags: museums, libraries, archives, GLAM, collections, repository
Requires at least: 4.8 Requires at least: 4.8
Tested up to: 5.6 Tested up to: 5.6

View File

@ -196,35 +196,45 @@ class Compound extends Metadata_Type {
foreach ( $compound_element as $meta_id => $meta ) { foreach ( $compound_element as $meta_id => $meta ) {
$index = array_search( $meta_id, array_column( $order, 'id' ) ); $index = array_search( $meta_id, array_column( $order, 'id' ) );
if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) {
$html = $this->get_meta_html($meta);
if ( $index !== false ) { if ( $index !== false ) {
$metadata_value[$index] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>"; $metadata_value[$index] = $html;
} else { } else {
$metadata_value_not_ordinate[] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>"; $metadata_value_not_ordinate[] = $html;
} }
} }
} }
$elements[] = '<div class="tainacan-compound-metadatum">' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "</div> \n" ; $elements[] = '<div class="tainacan-compound-metadatum">' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "</div> \n" ;
} }
} }
$return = '<div class="tainacan-compound-group">' . implode($separator, $elements) . '</div>'; $return = implode($separator, $elements);
} else { } else {
$metadata_value = array_fill(0, count($value), null); $metadata_value = array_fill(0, count($value), null);
$metadata_value_not_ordinate = []; $metadata_value_not_ordinate = [];
foreach ( $value as $meta_id => $meta ) { foreach ( $value as $meta_id => $meta ) {
$index = array_search( $meta_id, array_column( $order, 'id' ) ); $index = array_search( $meta_id, array_column( $order, 'id' ) );
if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) { if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) {
$html = $this->get_meta_html($meta);
if ( $index !== false ) { if ( $index !== false ) {
$metadata_value[intval($index)] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>"; $metadata_value[intval($index)] = $html;
} else { } else {
$metadata_value_not_ordinate[] = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>"; $metadata_value_not_ordinate[] = $html;
} }
} }
} }
$return = '<div class="tainacan-compound-group">' . implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate)) . "</div> \n"; $return = implode("\n", array_merge($metadata_value, $metadata_value_not_ordinate));
} }
return $return; return "<div class='tainacan-compound-group'> {$return} </div>";
}
private function get_meta_html(Item_Metadata_Entity $meta) {
$html = '';
if ($meta instanceof Item_Metadata_Entity && !empty($meta->get_value_as_html())) {
$html = '<div class="tainacan-metadatum"><label class="label">' . $meta->get_metadatum()->get_name() . '</label> <p>' . $meta->get_value_as_html() . "</p></div>";
}
return $html;
} }
} }

View File

@ -11,7 +11,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
*/ */
class Date extends Metadata_Type { class Date extends Metadata_Type {
function __construct(){ function __construct() {
// call metadatum type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_primitive_type('date'); $this->set_primitive_type('date');
@ -25,7 +25,6 @@ class Date extends Metadata_Type {
</div> </div>
</div> </div>
'); ');
$this->output_date_format = get_option('date_format'); $this->output_date_format = get_option('date_format');
} }
@ -37,31 +36,19 @@ class Date extends Metadata_Type {
foreach ($value as $date_value) { foreach ($value as $date_value) {
$d = \DateTime::createFromFormat($format, $date_value); $d = \DateTime::createFromFormat($format, $date_value);
if (!$d || $d->format($format) !== $date_value) { if (!$d || $d->format($format) !== $date_value) {
$this->add_error( $this->add_error($this->format_error_msg($date_value));
sprintf(
__('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'),
$date_value
)
);
return false; return false;
} }
} }
return True; return true;
} }
$d = \DateTime::createFromFormat($format, $value); $d = \DateTime::createFromFormat($format, $value);
if (!$d || $d->format($format) !== $value) { if (!$d || $d->format($format) !== $value) {
$this->add_error( $this->add_error($this->format_error_msg($value));
sprintf(
__('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'),
$value
)
);
return false; return false;
} }
return true; return true;
} }
/** /**
@ -82,20 +69,30 @@ class Date extends Metadata_Type {
if( empty( $el ) ) if( empty( $el ) )
continue; continue;
$return .= $prefix; $return .= $prefix;
$return .= mysql2date($this->output_date_format, ($el)); $return .= $this->format_date_value($el);
$return .= $suffix; $return .= $suffix;
$count ++; $count ++;
if ($count < $total) if ($count < $total)
$return .= $separator; $return .= $separator;
} }
} else { } else {
if( empty( $value ) ) $return = $this->format_date_value($value);
return "";
$return = mysql2date($this->output_date_format, ($value));
} }
return $return; return $return;
} }
private function format_date_value($value) {
if (empty($value))
return "";
return mysql2date($this->output_date_format, ($value));
}
private function format_error_msg($value) {
return sprintf(
__('Invalid date format. Expected format is MM/DD/YYYY, got %s.', 'tainacan'),
$value
);
}
} }

View File

@ -37,5 +37,4 @@ class Numeric extends Metadata_Type {
] ]
]; ];
} }
} }

View File

@ -157,14 +157,11 @@ class Relationship extends Metadata_Type {
* @param Item_Metadata_Entity $item_metadata * @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 * @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(); $value = $item_metadata->get_value();
$return = ''; $return = '';
if ( $item_metadata->is_multiple() ) { if ( $item_metadata->is_multiple() ) {
$count = 1; $count = 1;
$total = sizeof($value); $total = sizeof($value);
$prefix = $item_metadata->get_multivalue_prefix(); $prefix = $item_metadata->get_multivalue_prefix();
@ -172,66 +169,47 @@ class Relationship extends Metadata_Type {
$separator = $item_metadata->get_multivalue_separator(); $separator = $item_metadata->get_multivalue_separator();
foreach ( $value as $item_id ) { foreach ( $value as $item_id ) {
try { try {
//$item = new \Tainacan\Entities\Item($item_id);
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$item = $Tainacan_Items->fetch( (int) $item_id); $item = $Tainacan_Items->fetch( (int) $item_id);
$count++;
$count ++;
if ( $item instanceof \Tainacan\Entities\Item ) { if ( $item instanceof \Tainacan\Entities\Item ) {
$return .= $prefix; $return .= $prefix;
$return .= $this->get_item_html($item); $return .= $this->get_item_html($item);
$return .= $suffix; $return .= $suffix;
if ( $count <= $total ) { if ( $count <= $total ) {
$return .= $separator; $return .= $separator;
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// item not found // item not found
} }
} }
} else { } else {
try { try {
$item = new \Tainacan\Entities\Item($value); $item = new \Tainacan\Entities\Item($value);
if ( $item instanceof \Tainacan\Entities\Item ) { if ( $item instanceof \Tainacan\Entities\Item ) {
$return .= $this->get_item_html($item); $return .= $this->get_item_html($item);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// item not found // item not found
} }
} }
return $return; return $return;
} }
private function get_item_html($item) { private function get_item_html($item) {
$return = ''; $return = '';
$id = $item->get_id(); $id = $item->get_id();
$search_meta_id = $this->get_option('search'); $search_meta_id = $this->get_option('search');
if ( $id && $search_meta_id ) { if ( $id && $search_meta_id ) {
$link = get_permalink( (int) $id ); $link = get_permalink( (int) $id );
$search_meta_id = $this->get_option('search'); $search_meta_id = $this->get_option('search');
@ -250,17 +228,13 @@ class Relationship extends Metadata_Type {
} }
if (is_string($link)) { if (is_string($link)) {
$return = "<a data-linkto='item' data-id='$id' href='$link'>"; $return = "<a data-linkto='item' data-id='$id' href='$link'>";
$return.= $label; $return.= $label;
$return .= "</a>"; $return .= "</a>";
} }
} }
return $return; return $return;
} }
/** /**
@ -268,7 +242,6 @@ class Relationship extends Metadata_Type {
* @return \Tainacan\Entities\Collection|false The Collection object or false * @return \Tainacan\Entities\Collection|false The Collection object or false
*/ */
public function get_collection() { public function get_collection() {
$collection_id = $this->get_option('collection_id'); $collection_id = $this->get_option('collection_id');
if ( is_numeric($collection_id) ) { if ( is_numeric($collection_id) ) {
@ -279,7 +252,6 @@ class Relationship extends Metadata_Type {
} }
return false; return false;
} }
/** /**

View File

@ -323,7 +323,6 @@ class Taxonomy extends Metadata_Type {
} }
return $valid; return $valid;
} }
/** /**
@ -332,13 +331,10 @@ 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 * @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) { public function get_value_as_html(Item_Metadata_Entity $item_metadata) {
$value = $item_metadata->get_value();
$value = $item_metadata->get_value();
$return = ''; $return = '';
if ( $item_metadata->is_multiple() ) { if ( $item_metadata->is_multiple() ) {
$count = 1; $count = 1;
$total = sizeof($value); $total = sizeof($value);
$prefix = $item_metadata->get_multivalue_prefix(); $prefix = $item_metadata->get_multivalue_prefix();
@ -346,8 +342,7 @@ class Taxonomy extends Metadata_Type {
$separator = $item_metadata->get_multivalue_separator(); $separator = $item_metadata->get_multivalue_separator();
foreach ( $value as $term ) { foreach ( $value as $term ) {
$count++;
$count ++;
if ( is_integer($term) ) { if ( is_integer($term) ) {
$term = \Tainacan\Repositories\Terms::get_instance()->fetch($term, $this->get_option('taxonomy_id')); $term = \Tainacan\Repositories\Terms::get_instance()->fetch($term, $this->get_option('taxonomy_id'));
@ -355,35 +350,25 @@ class Taxonomy extends Metadata_Type {
if ( $term instanceof \Tainacan\Entities\Term ) { if ( $term instanceof \Tainacan\Entities\Term ) {
$return .= $prefix; $return .= $prefix;
$return .= $this->get_term_hierarchy_html($term); $return .= $this->get_term_hierarchy_html($term);
$return .= $suffix; $return .= $suffix;
if ( $count <= $total ) { if ( $count <= $total ) {
$return .= $separator; $return .= $separator;
} }
} }
} }
} else { } else {
if ( $value instanceof \Tainacan\Entities\Term ) { if ( $value instanceof \Tainacan\Entities\Term ) {
$return .= $this->get_term_hierarchy_html($value); $return .= $this->get_term_hierarchy_html($value);
} }
} }
return $return; return $return;
} }
private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) {
$terms = []; $terms = [];
$terms[] = $this->term_to_html($term); $terms[] = $this->term_to_html($term);
while ($term->get_parent() > 0) { while ($term->get_parent() > 0) {
@ -392,11 +377,9 @@ class Taxonomy extends Metadata_Type {
} }
$terms = \array_reverse($terms); $terms = \array_reverse($terms);
$glue = apply_filters('tainacan-terms-hierarchy-html-separator', '<span class="hierarchy-separator"> > </span>'); $glue = apply_filters('tainacan-terms-hierarchy-html-separator', '<span class="hierarchy-separator"> > </span>');
return \implode($glue, $terms); return \implode($glue, $terms);
} }
private function term_to_html($term) { private function term_to_html($term) {

View File

@ -50,6 +50,6 @@ class Text extends Metadata_Type {
} else { } else {
$return = $this->make_clickable_links($value); $return = $this->make_clickable_links($value);
} }
return $return; return force_balance_tags($return);
} }
} }

View File

@ -59,6 +59,6 @@ class Textarea extends Metadata_Type {
} else { } else {
$return = nl2br($this->make_clickable_links($value)); $return = nl2br($this->make_clickable_links($value));
} }
return $return; return force_balance_tags($return);
} }
} }

View File

@ -1154,8 +1154,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
]); ]);
$this->assertEquals(7, $bulk->count_posts()); $this->assertEquals(7, $bulk->count_posts());
} }
/** /**
@ -1206,8 +1204,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
$item_id = $bulk->get_item_id_by_index(30); $item_id = $bulk->get_item_id_by_index(30);
$this->assertFalse($item_id); $this->assertFalse($item_id);
} }
function test_set_multiple_tax_meta() { function test_set_multiple_tax_meta() {
@ -1228,14 +1224,8 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
'collection_id' => $this->collection->get_id() 'collection_id' => $this->collection->get_id()
]); ]);
$bulk->set_value($this->category, ['super', 'dooper']); $bulk->set_value($this->category, ['super', 'dooper']);
$items = $Tainacan_Items->fetch([ $items = $Tainacan_Items->fetch([
'tax_query' => [ 'tax_query' => [
[ [
@ -1342,6 +1332,4 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
$this->assertEquals(5, $items->found_posts); $this->assertEquals(5, $items->found_posts);
} }
} }

View File

@ -10,7 +10,7 @@ class Entity_Factory {
* *
* @var \Tainacan\Entities\Entity * @var \Tainacan\Entities\Entity
*/ */
private $entity; private $entity;
/** /**
* *
@ -118,5 +118,3 @@ class Entity_Factory {
return $this->entity; return $this->entity;
} }
} }
?>

View File

@ -16,12 +16,10 @@ use Tainacan\Entities;
class BGProcess extends TAINACAN_UnitApiTestCase { class BGProcess extends TAINACAN_UnitApiTestCase {
function test_table() { function test_table() {
global $wpdb; global $wpdb;
$table_name = $wpdb->prefix . 'tnc_bg_process'; $table_name = $wpdb->prefix . 'tnc_bg_process';
$table_exists = $wpdb->get_var( "SHOW TABLES LIKE '".$table_name."'" ); $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '".$table_name."'" );
$this->assertNotEquals(null, $table_exists); $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'" ); $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'); $this->assertEquals('output', $column_exists, 'BG processes table misconfigured');
} }
} }

View File

@ -79,10 +79,6 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
true true
); );
$term = $this->tainacan_entity_factory->create_entity( $term = $this->tainacan_entity_factory->create_entity(
'term', 'term',
array( 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'); $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() { function test_relate_taxonomy_match() {
@ -794,9 +786,6 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
$checkMeta = $Tainacan_Metadata->fetch( $metadatum->get_id() ); $checkMeta = $Tainacan_Metadata->fetch( $metadatum->get_id() );
$this->assertEquals('no', $checkMeta->get_metadata_type_options()['allow_new_terms']); $this->assertEquals('no', $checkMeta->get_metadata_type_options()['allow_new_terms']);
} }
} }

View File

@ -8,7 +8,7 @@ namespace Tainacan\Tests;
* @package Test_Tainacan * @package Test_Tainacan
*/ */
use Tainacan\Entities; use Tainacan\Entities\Item_Metadata_Entity;
/** /**
* Compound Metadatum Types test case. * Compound Metadatum Types test case.
@ -17,10 +17,7 @@ use Tainacan\Entities;
class CompoundMetadatumTypes extends TAINACAN_UnitTestCase { class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
function test_compound_metadata_types() { function test_compound_metadata_types() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_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 = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -79,23 +76,21 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
true 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->set_value('Red');
$item_metadata1->validate(); $item_metadata1->validate();
$item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1); $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->set_value('Blue');
$item_metadata->validate(); $item_metadata->validate();
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
$compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); $compoundItem = new Item_Metadata_Entity($i, $metadatum);
global $wpdb;
$compoundValue = $compoundItem->get_value(); $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_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( 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_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 \Tainacan\Entities\Item_Metadata_Entity , 'Second 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( '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' ); $this->assertEquals( 'Blue', $compoundValue[$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
} }
function test_multiple_compound_metadata_types() { function test_multiple_compound_metadata_types() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_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 = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -124,7 +117,7 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
), ),
true true
); );
$metadatum = $this->tainacan_entity_factory->create_entity( $metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
@ -175,34 +168,30 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
true true
); );
global $wpdb;
// First Instance // 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->set_value('Red');
$item_metadata1->validate(); $item_metadata1->validate();
$item_metadata1 = $Tainacan_Item_Metadata->insert($item_metadata1); $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->set_value('Blue');
$item_metadata->validate(); $item_metadata->validate();
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
// Second Instance // 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->set_value('Green');
$item_metadata3->validate(); $item_metadata3->validate();
$item_metadata3 = $Tainacan_Item_Metadata->insert($item_metadata3); $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->set_value('Yellow');
$item_metadata->validate(); $item_metadata->validate();
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
$compoundItem = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum); $compoundItem = new 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()}"));
$compoundValue = $compoundItem->get_value(); $compoundValue = $compoundItem->get_value();
$this->assertTrue( is_array($compoundValue), 'value of a compound should return array' ); $this->assertTrue( is_array($compoundValue), 'value of a compound should return array' );
@ -214,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[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( 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[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 \Tainacan\Entities\Item_Metadata_Entity , 'Second 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( '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' ); $this->assertEquals( 'Blue', $compoundValue[0][$metadatum_child2->get_id()]->get_value() , 'Second element of value should have "Blue" value' );
@ -224,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' ); $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()); $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(); $compoundValue = $compoundItem->get_value();
$this->assertTrue( is_array($compoundValue), 'value of a compound should return array' ); $this->assertTrue( is_array($compoundValue), 'value of a compound should return array' );
@ -232,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( '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' ); $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() { function test_validations_taxonomy_in_multiple() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
@ -308,9 +293,6 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
} }
function test_validations_multiple_metadata() { function test_validations_multiple_metadata() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
@ -343,14 +325,10 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
$newMetadatum->set_multiple('no'); $newMetadatum->set_multiple('no');
$this->assertTrue($newMetadatum->validate()); $this->assertTrue($newMetadatum->validate());
} }
function teste_validations_metadada_order() { function test_validations_metadada_order() {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -14,7 +14,7 @@ namespace Tainacan\Tests;
class Filters extends TAINACAN_UnitTestCase { class Filters extends TAINACAN_UnitTestCase {
function teste_add(){ function test_add(){
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(

File diff suppressed because it is too large Load Diff

View File

@ -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!'); $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 = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( 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 = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(

View File

@ -200,7 +200,6 @@ class Metadata extends TAINACAN_UnitTestCase {
$this->assertEquals( 9, sizeof( $Tainacan_Metadata->fetch_metadata_types() ) ); $this->assertEquals( 9, sizeof( $Tainacan_Metadata->fetch_metadata_types() ) );
} }
/** /**
* *
*/ */
@ -426,9 +425,7 @@ class Metadata extends TAINACAN_UnitTestCase {
} }
function test_relatioship_get_collection_method() { function test_relationship_get_collection_method() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
@ -460,17 +457,16 @@ class Metadata extends TAINACAN_UnitTestCase {
), ),
true true
); );
$object = $metadatum->get_metadata_type_object(); $object = $metadatum->get_metadata_type_object();
$colCheck = $object->get_collection(); $colCheck = $object->get_collection();
$this->assertTrue( $colCheck instanceof \Tainacan\Entities\Collection ); $this->assertTrue( $colCheck instanceof \Tainacan\Entities\Collection );
$this->assertEquals($collection2->get_id(), $colCheck->get_id()); $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_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();