tainacan/tests/test-collections.php

104 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2017-11-15 18:50:11 +00:00
namespace Tainacan\Tests;
/**
* Class TestCollections
*
* @package Test_Tainacan
*/
/**
* Sample test case.
*/
class Collections extends TAINACAN_UnitTestCase {
/**
* A single example test.
*/
function test_add() {
$x = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'default_order' => 'DESC'
),
true
);
global $Tainacan_Collections;
$this->assertEquals('Tainacan\Entities\Collection', get_class($x));
$test = $Tainacan_Collections->fetch($x->get_id());
2017-12-07 13:54:43 +00:00
$this->assertEquals('teste', $test->get_name());
$this->assertEquals('adasdasdsa', $test->get_description());
$this->assertEquals('DESC', $test->get_default_order());
$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() {
$x = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'default_order' => 'DESC'
),
true
);
global $Tainacan_Collections;
$collection = $Tainacan_Collections->fetch($x->get_id());
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'item test',
'description' => 'adasdasdsa',
'order' => 'DESC',
'collection' => $collection
),
true
);
global $Tainacan_Items;
$item = $Tainacan_Items->fetch( $i->get_id() );
2017-11-09 12:44:52 +00:00
$this->assertEquals($item->get_title(), 'item test');
2017-11-09 12:44:52 +00:00
$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 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'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-12-04 18:47:38 +00:00
}
function test_hooks() {
global $Tainacan_Collections;
$this->assertTrue(has_action('init', array($Tainacan_Collections, 'register_post_type')) !== false, 'Collections Init is not registred!');
2017-11-09 12:44:52 +00:00
}
}