Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JayPHP committed Apr 9, 2016
1 parent 9989334 commit 466ecf9
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/TestCase/ORM/RulesCheckerIntegrationTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 466ecf9

Please sign in to comment.