tainacan/tests/test-date-metadatum-types.php

149 lines
4.7 KiB
PHP
Raw Permalink Normal View History

2018-09-18 13:20:15 +00:00
<?php
namespace Tainacan\Tests;
/**
* Class TestCollections
*
* @package Test_Tainacan
*/
use Tainacan\Entities;
/**
* Sample test case.
*/
class DateMetadatumTypes extends TAINACAN_UnitTestCase {
function test_date_metadata_types() {
2018-09-18 13:20:15 +00:00
$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',
array(
'name' => 'test',
),
true
);
$metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'meta',
'description' => 'description',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Date',
'status' => 'publish',
),
true
);
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'item test',
'description' => 'adasdasdsa',
'collection' => $collection,
'status' => 'publish',
),
true
);
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum);
$item_metadata->set_value('2010-01-01');
$this->assertTrue($item_metadata->validate());
$item_metadata->set_value('2010-12-01');
$this->assertTrue($item_metadata->validate());
$item_metadata->set_value('2010-12-31');
$this->assertTrue($item_metadata->validate());
$item_metadata->set_value('2010-22-01');
$this->assertFalse($item_metadata->validate());
$item_metadata->set_value('3/3/1202');
$this->assertFalse($item_metadata->validate());
$item_metadata->set_value('2010-02-30');
$this->assertFalse($item_metadata->validate());
}
function test_date_metadata_multiple_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',
array(
'name' => 'test',
),
true
);
$metadatum_multiple = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'meta',
'description' => 'description',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Date',
'status' => 'publish',
'multiple' => 'yes'
),
true
);
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'item test',
'description' => 'adasdasdsa',
'collection' => $collection,
'status' => 'publish',
),
true
);
$item_metadata_multiple = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_multiple);
$item_metadata_multiple->set_value(['2010-01-01', '2010-12-01']);
$this->assertTrue($item_metadata_multiple->validate());
$item_metadata_multiple->set_value(['2010-12-01']);
$this->assertTrue($item_metadata_multiple->validate());
$item_metadata_multiple->set_value(['2010-12-31', '2010-05-05']);
$this->assertTrue($item_metadata_multiple->validate());
2021-06-07 15:33:11 +00:00
$item_metadata_multiple->set_value(['2010-01-01', '2010-12-01', null]);
$this->assertTrue($item_metadata_multiple->validate());
$item_metadata_multiple->set_value(['2010-01-01', '2010-12-01', '']);
$this->assertTrue($item_metadata_multiple->validate());
$item_metadata_multiple->set_value('2010-22-01');
$this->assertFalse($item_metadata_multiple->validate());
$item_metadata_multiple->set_value(['3/3/1202','2010-02-30']);
$this->assertFalse($item_metadata_multiple->validate());
$item_metadata_multiple->set_value(['3/3/1202','2010-02-30', '2010-12-31', '2010-22-01', '2010-01-01', '2010-12-01']);
$this->assertFalse($item_metadata_multiple->validate());
2021-06-07 15:33:11 +00:00
$item_metadata_multiple->set_value(['3/3/1202','2010-02-']);
$this->assertFalse($item_metadata_multiple->validate());
2021-06-07 15:33:11 +00:00
$item_metadata_multiple->set_value(['3/3/1202','201002']);
$this->assertFalse($item_metadata_multiple->validate());
2021-06-07 15:33:11 +00:00
}
2018-09-18 13:20:15 +00:00
}