adds html tests for date meta

This commit is contained in:
Rodrigo de Oliveira 2021-04-05 13:37:15 -03:00
parent 4ce2c9491b
commit 62abad4839
5 changed files with 67 additions and 16 deletions

View File

@ -136,7 +136,7 @@ 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)) {
@ -153,7 +153,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();
@ -162,11 +161,8 @@ class Item_Metadata_Entity extends Entity {
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;

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');

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

@ -794,9 +794,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

@ -3,7 +3,7 @@
namespace Tainacan\Tests; namespace Tainacan\Tests;
/** /**
* Class TestCollections * Class Item_Metadata
* *
* @package Test_Tainacan * @package Test_Tainacan
*/ */
@ -406,6 +406,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
), ),
true true
); );
// Simple numeric metadata
$metadatum_numeric = $this->tainacan_entity_factory->create_entity( $metadatum_numeric = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
@ -418,6 +420,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true true
); );
// Multiple numeric metadata
$metadatum_numeric_multiple = $this->tainacan_entity_factory->create_entity( $metadatum_numeric_multiple = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
@ -441,4 +444,65 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$item_metadata_numeric_mult->validate(); $item_metadata_numeric_mult->validate();
$this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10<span class="multivalue-separator"> | </span>22<span class="multivalue-separator"> | </span>4'); $this->assertEquals($item_metadata_numeric_mult->get_value_as_html(), '10<span class="multivalue-separator"> | </span>22<span class="multivalue-separator"> | </span>4');
} }
function test_metadata_date_html() {
$collection = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true);
$item = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'My test item',
'description' => 'item description',
'collection' => $collection,
'status' => 'publish'
),
true
);
// Simple date metadata
$metadatum_date = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'Date important meta',
'description' => 'and its description',
'collection_id' => $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' => $collection->get_id(),
'metadata_type' => 'Tainacan\Metadata_Types\Date',
'status' => 'publish',
'multiple' => 'yes'
),
true
);
$item_metadata_date = new \Tainacan\Entities\Item_Metadata_Entity($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 \Tainacan\Entities\Item_Metadata_Entity($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(), '<span class="multivalue-separator"> | </span><span class="multivalue-separator"> | </span>');
$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<span class="multivalue-separator"> | </span>December 30, 2021');
}
} }