2017-10-20 14:30:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
2017-11-13 16:03:04 +00:00
|
|
|
class Test_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-13 16:03:04 +00:00
|
|
|
$x = new Tainacan_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');
|
|
|
|
$x->set_itens_per_page(23);
|
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
global $Tainacan_Collections;
|
|
|
|
$col = $Tainacan_Collections->insert($x);
|
2017-11-03 20:23:41 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
$test = $Tainacan_Collections->get_collection_by_id($col->get_id());
|
2017-11-03 20:23:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($test->get_name(), 'teste');
|
|
|
|
$this->assertEquals($test->get_description(), 'adasdasdsa');
|
|
|
|
$this->assertEquals($test->get_itens_per_page(), 23);
|
2017-10-20 14:30:04 +00:00
|
|
|
|
|
|
|
|
2017-11-10 16:45:40 +00:00
|
|
|
}
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
function test_item() {
|
|
|
|
|
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
$x = new Tainacan_Collection();
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
$x->set_name('teste');
|
|
|
|
$x->set_description('adasdasdsa');
|
|
|
|
$x->set_itens_per_page(23);
|
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
global $Tainacan_Collections;
|
|
|
|
$col = $Tainacan_Collections->insert($x);
|
2017-11-09 12:44:52 +00:00
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
$collection = $Tainacan_Collections->get_collection_by_id($col->get_id());
|
2017-11-09 12:44:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
$i = new Tainacan_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;
|
|
|
|
$item = $Tainacan_Items->insert($i);
|
2017-11-09 12:44:52 +00:00
|
|
|
|
2017-11-13 16:03:04 +00:00
|
|
|
$item = $Tainacan_Items->get_item_by_id($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() {
|
|
|
|
|
|
|
|
$x = new Tainacan_Collection();
|
|
|
|
|
|
|
|
$x->set_name('teste');
|
|
|
|
$x->set_description('adasdasdsa');
|
|
|
|
$x->set_itens_per_page('blah');
|
|
|
|
|
|
|
|
$this->assertFalse($x->validate());
|
|
|
|
$this->assertTrue(sizeof($x->get_errors()) > 0);
|
|
|
|
|
|
|
|
$x->set_itens_per_page(15);
|
|
|
|
$this->assertTrue($x->validate());
|
|
|
|
$this->assertTrue(empty($x->get_errors()));
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-09 12:44:52 +00:00
|
|
|
}
|
2017-10-20 14:30:04 +00:00
|
|
|
}
|