Skip to content
Permalink
Browse files

added tests

  • Loading branch information...
JayPHP committed Apr 9, 2016
1 parent 9989334 commit 466ecf97310f1c828b17136fee6ca88e00672e36
Showing with 53 additions and 0 deletions.
  1. +53 −0 tests/TestCase/ORM/RulesCheckerIntegrationTest.php
@@ -369,6 +369,59 @@ public function testIsUniqueMultipleFields()
$this->assertSame($entity, $table->save($entity));
}
/**
* Tests isUnique with checkNull
*
* @group save
* @return void
*/
public function testIsUniqueCheckNull()
{
$entity = new Entity([
'name' => NULL
]);
$table = TableRegistry::get('Authors');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['name']),
['checkNull' => true]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('name'));
$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 and checkNull
*
* @group save
* @return void
*/
public function testIsUniqueMultipleFieldsCheckNull()
{
$entity = new Entity([
'author_id' => 1,
'title' => NULL
]);
$table = TableRegistry::get('Articles');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['title', 'author_id'], 'Nope'),
['checkNull' => true]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['title' => ['_isUnique' => 'Nope']], $entity->errors());
$entity->clean();
$entity->author_id = 2;
$this->assertSame($entity, $table->save($entity));
}
/**
* Tests the existsIn domain rule
*

0 comments on commit 466ecf9

Please sign in to comment.
You can’t perform that action at this time.