From 4825cc3469d3bb5e8995385f2774f0e4a4d88f03 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Wed, 21 Feb 2018 13:52:36 -0300 Subject: [PATCH] fix collections api test and new test for unique slugs --- tests/test-api-collections.php | 8 ++--- tests/test-collections.php | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/tests/test-api-collections.php b/tests/test-api-collections.php index 4d02b8a41..4be254bb1 100644 --- a/tests/test-api-collections.php +++ b/tests/test-api-collections.php @@ -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(){ diff --git a/tests/test-collections.php b/tests/test-collections.php index 8276a82fd..d8f7b8647 100644 --- a/tests/test-collections.php +++ b/tests/test-collections.php @@ -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',