From e4a5af8e90d20d8e956f4946deef1bd2e085c947 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 30 Nov 2014 18:18:57 +0100 Subject: [PATCH] Adding another test for the IsUnique rule --- .../ORM/DomainRulesIntegrationTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/TestCase/ORM/DomainRulesIntegrationTest.php b/tests/TestCase/ORM/DomainRulesIntegrationTest.php index a0ab9a965a5..b8ecfe9f2eb 100644 --- a/tests/TestCase/ORM/DomainRulesIntegrationTest.php +++ b/tests/TestCase/ORM/DomainRulesIntegrationTest.php @@ -297,6 +297,32 @@ public function testIsUniqueDomainRule() { $entity->name = 'jose'; $this->assertSame($entity, $table->save($entity)); + + $entity = $table->get(1); + $entity->dirty('name', true); + $this->assertSame($entity, $table->save($entity)); + } + +/** + * Tests isUnique with multiple fields + * + * @group save + * @return void + */ + public function testIsUniqueMultipleFields() { + $entity = new Entity([ + 'author_id' => 1, + 'title' => 'First Article' + ]); + + $table = TableRegistry::get('Articles'); + $rules = $table->domainRules(); + $rules->add($rules->isUnique(['author_id', 'title'])); + + $this->assertFalse($table->save($entity)); + + $entity->author_id = 2; + $this->assertSame($entity, $table->save($entity)); } }