fix collections api test and new test for unique slugs

This commit is contained in:
Leo Germani 2018-02-21 13:52:36 -03:00
parent b201c4ba17
commit 4825cc3469
2 changed files with 68 additions and 4 deletions

View File

@ -87,11 +87,11 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_UnitApiTestCase {
//$data is a valid json?
//$this->assertTrue(json_last_error() === JSON_ERROR_NONE);
$other_collection = $data[0];
$one_collection = $data[1];
$collectionsNames = array_map(function($data) {return $data['name'];}, $data);
$this->assertContains('testeApi', $collectionsNames);
$this->assertContains('Other', $collectionsNames);
$this->assertEquals('testeApi', $one_collection['name']);
$this->assertEquals('Other', $other_collection['name']);
}
public function test_delete_or_trash_a_collection(){

View File

@ -158,6 +158,70 @@ class Collections extends TAINACAN_UnitTestCase {
$this->assertEquals('draft', $test->get_status());
}
function test_unique_slugs() {
$x = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'default_order' => 'DESC',
'slug' => 'duplicated_slug',
'status' => 'publish'
),
true
);
$y = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'default_order' => 'DESC',
'slug' => 'duplicated_slug',
'status' => 'publish'
),
true
);
$this->assertNotEquals($x->get_slug(), $y->get_slug());
// Create as draft and publish later
$x = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'default_order' => 'DESC',
'slug' => 'duplicated_slug',
),
true
);
$y = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'description' => 'adasdasdsa',
'default_order' => 'DESC',
'slug' => 'duplicated_slug',
),
true
);
$this->assertEquals($x->get_slug(), $y->get_slug());
global $Tainacan_Collections;
$x->set_status('publish');
$x->validate();
$x = $Tainacan_Collections->insert($x);
$y->set_status('private'); // or publish shoud behave the same
$y->validate();
$y = $Tainacan_Collections->insert($y);
$this->assertNotEquals($x->get_slug(), $y->get_slug());
}
function test_item() {
$x = $this->tainacan_entity_factory->create_entity(
'collection',