Merge pull request #519 from tainacan/396-test-render-html
Adds tests to metadata's HTML output
This commit is contained in:
commit
288b9bce52
|
@ -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/'
|
||||
|
||||
|
|
1
build.sh
1
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
|
||||
|
|
|
@ -6,7 +6,6 @@ command -v sass >/dev/null 2>&1 || {
|
|||
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
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -136,17 +135,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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +152,6 @@ class Item_Metadata_Entity extends Entity {
|
|||
$return = '';
|
||||
|
||||
if ( $this->is_multiple() ) {
|
||||
|
||||
$total = sizeof($value);
|
||||
$count = 0;
|
||||
$prefix = $this->get_multivalue_prefix();
|
||||
|
@ -163,13 +159,9 @@ class Item_Metadata_Entity extends Entity {
|
|||
$separator = $this->get_multivalue_separator();
|
||||
|
||||
foreach ($value as $v) {
|
||||
|
||||
$return .= $prefix;
|
||||
|
||||
$return .= (string) $v;
|
||||
|
||||
$return .= $suffix;
|
||||
|
||||
$count ++;
|
||||
if ($count < $total)
|
||||
$return .= $separator;
|
||||
|
@ -180,8 +172,6 @@ class Item_Metadata_Entity extends Entity {
|
|||
}
|
||||
|
||||
return $return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 = "<a data-linkto='item' data-id='$id' href='$link'>";
|
||||
$return.= $this->get_title();
|
||||
$return .= "</a>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 = "<a data-linkto='term' data-id='$id' href='$link'>";
|
||||
$return.= $this->get_name();
|
||||
$return .= "</a>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return apply_filters('tainacan-term-to-html', $return, $this);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -196,35 +196,45 @@ 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] = '<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 {
|
||||
$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" ;
|
||||
}
|
||||
}
|
||||
$return = '<div class="tainacan-compound-group">' . implode($separator, $elements) . '</div>';
|
||||
$return = implode($separator, $elements);
|
||||
} else {
|
||||
$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' ) );
|
||||
if ( $meta instanceof Item_Metadata_Entity && $meta->get_value_as_html() != '' ) {
|
||||
$html = $this->get_meta_html($meta);
|
||||
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 {
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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');
|
||||
|
@ -25,7 +25,6 @@ class Date extends Metadata_Type {
|
|||
</div>
|
||||
</div>
|
||||
');
|
||||
|
||||
$this->output_date_format = get_option('date_format');
|
||||
}
|
||||
|
||||
|
@ -37,31 +36,19 @@ 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,20 +69,30 @@ class Date extends Metadata_Type {
|
|||
if( empty( $el ) )
|
||||
continue;
|
||||
$return .= $prefix;
|
||||
$return .= mysql2date($this->output_date_format, ($el));
|
||||
$return .= $this->format_date_value($el);
|
||||
$return .= $suffix;
|
||||
$count ++;
|
||||
if ($count < $total)
|
||||
$return .= $separator;
|
||||
}
|
||||
} else {
|
||||
if( empty( $value ) )
|
||||
return "";
|
||||
$return = mysql2date($this->output_date_format, ($value));
|
||||
$return = $this->format_date_value($value);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -37,5 +37,4 @@ class Numeric extends Metadata_Type {
|
|||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -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,66 +169,47 @@ 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 ++;
|
||||
$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);
|
||||
}
|
||||
|
||||
} 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 +228,13 @@ class Relationship extends Metadata_Type {
|
|||
}
|
||||
|
||||
if (is_string($link)) {
|
||||
|
||||
$return = "<a data-linkto='item' data-id='$id' href='$link'>";
|
||||
$return.= $label;
|
||||
$return .= "</a>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,7 +242,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 +252,6 @@ class Relationship extends Metadata_Type {
|
|||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -323,7 +323,6 @@ class Taxonomy extends Metadata_Type {
|
|||
}
|
||||
|
||||
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
|
||||
*/
|
||||
public function get_value_as_html(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();
|
||||
|
@ -346,8 +342,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'));
|
||||
|
@ -355,35 +350,25 @@ 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 ) {
|
||||
|
||||
$terms = [];
|
||||
|
||||
$terms[] = $this->term_to_html($term);
|
||||
|
||||
while ($term->get_parent() > 0) {
|
||||
|
@ -392,11 +377,9 @@ class Taxonomy extends Metadata_Type {
|
|||
}
|
||||
|
||||
$terms = \array_reverse($terms);
|
||||
|
||||
$glue = apply_filters('tainacan-terms-hierarchy-html-separator', '<span class="hierarchy-separator"> > </span>');
|
||||
|
||||
return \implode($glue, $terms);
|
||||
|
||||
}
|
||||
|
||||
private function term_to_html($term) {
|
||||
|
|
|
@ -50,6 +50,6 @@ class Text extends Metadata_Type {
|
|||
} else {
|
||||
$return = $this->make_clickable_links($value);
|
||||
}
|
||||
return $return;
|
||||
return force_balance_tags($return);
|
||||
}
|
||||
}
|
|
@ -59,6 +59,6 @@ class Textarea extends Metadata_Type {
|
|||
} else {
|
||||
$return = nl2br($this->make_clickable_links($value));
|
||||
}
|
||||
return $return;
|
||||
return force_balance_tags($return);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -118,5 +118,3 @@ class Entity_Factory {
|
|||
return $this->entity;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
@ -794,9 +786,6 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
|
|||
$checkMeta = $Tainacan_Metadata->fetch( $metadatum->get_id() );
|
||||
|
||||
$this->assertEquals('no', $checkMeta->get_metadata_type_options()['allow_new_terms']);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,34 +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);
|
||||
//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 Item_Metadata_Entity($i, $metadatum);
|
||||
$compoundValue = $compoundItem->get_value();
|
||||
|
||||
$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[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' );
|
||||
|
@ -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' );
|
||||
|
||||
$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' );
|
||||
|
@ -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( '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(
|
||||
|
@ -308,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(
|
||||
|
@ -343,15 +325,11 @@ class CompoundMetadatumTypes extends TAINACAN_UnitTestCase {
|
|||
$newMetadatum->set_multiple('no');
|
||||
|
||||
$this->assertTrue($newMetadatum->validate());
|
||||
|
||||
|
||||
}
|
||||
|
||||
function teste_validations_metadada_order() {
|
||||
|
||||
function test_validations_metadada_order() {
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
|
||||
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -2,29 +2,52 @@
|
|||
|
||||
namespace Tainacan\Tests;
|
||||
|
||||
use Tainacan\Entities\Item_Metadata_Entity;
|
||||
|
||||
/**
|
||||
* Class TestCollections
|
||||
* Class Item_Metadata
|
||||
*
|
||||
* @package Test_Tainacan
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sample test case.
|
||||
* Item_Metadata test case.
|
||||
*/
|
||||
class Item_Metadata extends TAINACAN_UnitTestCase {
|
||||
|
||||
private $collection = null;
|
||||
private $item = null;
|
||||
private $separator = '<span class="multivalue-separator"> | </span>';
|
||||
|
||||
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
|
||||
*/
|
||||
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
|
||||
|
@ -46,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
|
||||
|
@ -57,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();
|
||||
|
@ -70,7 +93,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();
|
||||
|
||||
|
@ -111,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());
|
||||
|
@ -125,7 +148,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();
|
||||
|
||||
|
@ -176,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());
|
||||
|
@ -184,16 +207,16 @@ 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');
|
||||
}
|
||||
|
||||
function teste_fetch(){
|
||||
function test_fetch(){
|
||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
|
@ -247,8 +270,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(
|
||||
|
@ -291,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: <a href="http://www.google.com" target="_blank" title="www.google.com">www.google.com</a>';
|
||||
|
@ -303,12 +324,22 @@ 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
|
||||
$badFormatted_HTML = "<p> I started my content <div> and make something else here </div> without closing its HTML properly";
|
||||
|
||||
$item_metadata_text->set_value($badFormatted_HTML);
|
||||
$item_metadata_textarea->set_value($badFormatted_HTML);
|
||||
|
||||
$this->assertEquals($item_metadata_text->get_value_as_html(), $badFormatted_HTML ."</p>");
|
||||
$this->assertEquals($item_metadata_textarea->get_value_as_html(), $badFormatted_HTML ."</p>");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(
|
||||
|
@ -343,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();
|
||||
|
@ -351,7 +382,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);
|
||||
|
||||
|
@ -369,24 +400,366 @@ 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([
|
||||
''
|
||||
]);
|
||||
$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);
|
||||
|
||||
$this->assertTrue($item_metadata_text->has_value());
|
||||
}
|
||||
|
||||
function test_numeric_metadata_html() {
|
||||
// Simple numeric metadata
|
||||
$metadatum_numeric = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'Numeric important meta',
|
||||
'description' => 'and its description',
|
||||
'collection_id' => $this->collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
// Multiple numeric metadata
|
||||
$metadatum_numeric_multiple = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'Numeric important meta',
|
||||
'description' => 'and its description',
|
||||
'collection_id' => $this->collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
||||
'status' => 'publish',
|
||||
'multiple' => 'yes'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$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 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");
|
||||
}
|
||||
|
||||
function test_date_metadata_html() {
|
||||
// Simple date metadata
|
||||
$metadatum_date = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'Date important meta',
|
||||
'description' => 'and its description',
|
||||
'collection_id' => $this->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' => $this->collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Date',
|
||||
'status' => 'publish',
|
||||
'multiple' => 'yes'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$item_metadata_date = new Item_Metadata_Entity($this->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 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();
|
||||
$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' . $this->separator . '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 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 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' . $this->separator . '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 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 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');
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
$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());
|
||||
|
||||
$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
|
||||
);
|
||||
|
||||
$item_metadata_relationship = new Item_Metadata_Entity($this->item, $relationship_metadata);
|
||||
$item_metadata_relationship->validate();
|
||||
$this->assertEquals($item_metadata_relationship->get_value_as_html(), '');
|
||||
|
||||
$item_metadata_relationship->set_value($mystify->get_id());
|
||||
$item_metadata_relationship->validate();
|
||||
$this->assertEquals($item_metadata_relationship->get_value_as_html(), $expected_return);
|
||||
|
||||
$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}" . $this->separator . "${expected_return2}");
|
||||
}
|
||||
|
||||
function test_taxonomy_metadata_html() {
|
||||
$taxonomy = $this->tainacan_entity_factory->create_entity(
|
||||
'taxonomy',
|
||||
array(
|
||||
'name' => 'My Taxonomy test',
|
||||
'collections' => [$this->collection],
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$term = $this->tainacan_entity_factory->create_entity(
|
||||
'term',
|
||||
array(
|
||||
'taxonomy' => $taxonomy->get_db_identifier(),
|
||||
'name' => 'first term from my tax',
|
||||
),
|
||||
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(
|
||||
'name' => 'My tax meta',
|
||||
'status' => 'publish',
|
||||
'collection' => $this->collection,
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
|
||||
'metadata_type_options' => [
|
||||
'taxonomy_id' => $taxonomy->get_id(),
|
||||
]
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$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());
|
||||
|
||||
$item_taxonomy_metadata->set_value($term);
|
||||
$item_taxonomy_metadata->validate();
|
||||
$term_id = $term->get_id();
|
||||
$link = get_term_link( (int) $term_id );
|
||||
$this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "<a data-linkto='term' data-id='{$term_id}' href='{$link}'>first term from my tax</a>");
|
||||
|
||||
$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();
|
||||
$link = get_term_link( (int) $term_id );
|
||||
$link2 = get_term_link( (int) $term_id2 );
|
||||
$this->assertEquals($item_taxonomy_metadata->get_value_as_html(), "<a data-linkto='term' data-id='{$term_id}' href='{$link}'>first term from my tax</a><span class=\"multivalue-separator\"> | </span><a data-linkto='term' data-id='{$term_id2}' href='{$link2}'>Second term from my tax</a>");
|
||||
}
|
||||
|
||||
function test_compound_metadata_html() {
|
||||
$compound_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' => $compound_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' => $compound_meta->get_id()
|
||||
),
|
||||
true
|
||||
);
|
||||
$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(), "<div class='tainacan-compound-group'> </div>");
|
||||
}
|
||||
|
||||
private function relationship_expected_return($id, $title) {
|
||||
$URL = get_permalink($id);
|
||||
|
||||
return "<a data-linkto='item' data-id='${id}' href='${URL}'>${title}</a>";
|
||||
}
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
@ -467,10 +464,9 @@ class Metadata extends TAINACAN_UnitTestCase {
|
|||
|
||||
$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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue