2017-10-20 14:30:04 +00:00
|
|
|
<?php
|
2017-11-15 18:50:11 +00:00
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
2017-10-20 14:30:04 +00:00
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
2017-11-15 18:50:11 +00:00
|
|
|
class Collections extends \WP_UnitTestCase {
|
2017-10-20 14:30:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A single example test.
|
|
|
|
*/
|
|
|
|
function test_add() {
|
2017-11-03 20:23:41 +00:00
|
|
|
|
2017-11-15 18:50:11 +00:00
|
|
|
$x = new \Tainacan\Entities\Collection();
|
2017-10-20 14:30:04 +00:00
|
|
|
|
2017-11-03 20:23:41 +00:00
|
|
|
$x->set_name('teste');
|
|
|
|
$x->set_description('adasdasdsa');
|
2017-11-28 20:49:20 +00:00
|
|
|
$x->set_default_order('DESC');
|
2017-11-03 20:23:41 +00:00
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
global $Tainacan_Collections;
|
2017-11-30 18:00:25 +00:00
|
|
|
$x->validate();
|
2017-11-13 16:03:04 +00:00
|
|
|
$col = $Tainacan_Collections->insert($x);
|
2017-11-03 20:23:41 +00:00
|
|
|
|
2017-11-23 00:30:48 +00:00
|
|
|
$this->assertEquals('Tainacan\Entities\Collection', get_class($col));
|
|
|
|
|
2017-11-20 14:41:54 +00:00
|
|
|
$test = $Tainacan_Collections->fetch($col->get_id());
|
2017-11-24 17:32:27 +00:00
|
|
|
|
2017-11-03 20:23:41 +00:00
|
|
|
$this->assertEquals($test->get_name(), 'teste');
|
|
|
|
$this->assertEquals($test->get_description(), 'adasdasdsa');
|
2017-11-28 20:49:20 +00:00
|
|
|
$this->assertEquals($test->get_default_order(), 'DESC');
|
2017-12-01 02:53:20 +00:00
|
|
|
$this->assertEquals('draft', $test->get_status());
|
2017-11-10 16:45:40 +00:00
|
|
|
}
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
function test_item() {
|
|
|
|
|
|
|
|
|
2017-11-15 18:50:11 +00:00
|
|
|
$x = new \Tainacan\Entities\Collection();
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
$x->set_name('teste');
|
|
|
|
$x->set_description('adasdasdsa');
|
2017-11-28 20:49:20 +00:00
|
|
|
$x->set_default_order('DESC');
|
2017-11-09 12:44:52 +00:00
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
global $Tainacan_Collections;
|
2017-11-30 18:00:25 +00:00
|
|
|
$x->validate();
|
2017-11-13 16:03:04 +00:00
|
|
|
$col = $Tainacan_Collections->insert($x);
|
2017-11-09 12:44:52 +00:00
|
|
|
|
2017-11-20 14:41:54 +00:00
|
|
|
$collection = $Tainacan_Collections->fetch($col->get_id());
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-15 18:50:11 +00:00
|
|
|
$i = new \Tainacan\Entities\Item();
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
$i->set_title('item teste');
|
|
|
|
$i->set_description('adasdasdsa');
|
|
|
|
$i->set_collection($collection);
|
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
global $Tainacan_Items;
|
2017-11-30 18:00:25 +00:00
|
|
|
$i->validate();
|
2017-11-29 18:06:22 +00:00
|
|
|
$item = $Tainacan_Items->insert( $i );
|
2017-11-09 12:44:52 +00:00
|
|
|
|
2017-11-29 18:06:22 +00:00
|
|
|
$item = $Tainacan_Items->fetch( $item->get_id() );
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
$this->assertEquals($item->get_title(), 'item teste');
|
|
|
|
$this->assertEquals($item->get_description(), 'adasdasdsa');
|
2017-11-12 23:14:47 +00:00
|
|
|
$this->assertEquals($item->get_collection_id(), $collection->get_id());
|
2017-11-09 12:44:52 +00:00
|
|
|
|
2017-11-15 02:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_validation() {
|
|
|
|
|
2017-11-15 18:50:11 +00:00
|
|
|
$x = new \Tainacan\Entities\Collection();
|
2017-11-15 02:04:40 +00:00
|
|
|
|
|
|
|
$x->set_name('teste');
|
|
|
|
$x->set_description('adasdasdsa');
|
2017-11-28 20:49:20 +00:00
|
|
|
$x->set_default_order(13);
|
2017-11-15 02:04:40 +00:00
|
|
|
|
|
|
|
$this->assertFalse($x->validate());
|
|
|
|
$this->assertTrue(sizeof($x->get_errors()) > 0);
|
|
|
|
|
2017-11-28 20:49:20 +00:00
|
|
|
$x->set_default_order('ASDASD');
|
|
|
|
|
|
|
|
$this->assertFalse($x->validate());
|
|
|
|
$this->assertTrue(sizeof($x->get_errors()) > 0);
|
|
|
|
|
|
|
|
$x->set_default_order('DESC');
|
2017-11-15 02:04:40 +00:00
|
|
|
$this->assertTrue($x->validate());
|
|
|
|
$this->assertTrue(empty($x->get_errors()));
|
|
|
|
|
2017-11-23 19:06:57 +00:00
|
|
|
global $Tainacan_Collections;
|
2017-11-15 02:04:40 +00:00
|
|
|
|
2017-11-23 19:06:57 +00:00
|
|
|
$this->assertTrue(has_action('init', array($Tainacan_Collections, 'register_post_type')) !== false, 'Collections Init is not registred!');
|
2017-11-15 02:04:40 +00:00
|
|
|
|
2017-11-09 12:44:52 +00:00
|
|
|
}
|
2017-10-20 14:30:04 +00:00
|
|
|
}
|