Skip to content
Permalink
Browse files

Using pre-existing fixture + CS Fix

  • Loading branch information...
james.byrne
james.byrne committed Apr 11, 2016
1 parent 7a59f20 commit c45341845ece1573972426399ed8acee886fe3a3
@@ -54,7 +54,7 @@ public function __invoke(EntityInterface $entity, array $options)
}
$permitMultipleNulls = true;
if(isset($options['permitMultipleNulls'])) {
if (isset($options['permitMultipleNulls'])) {
$permitMultipleNulls = $options['permitMultipleNulls'] === true ? true : false;
}
@@ -68,7 +68,7 @@ public function __invoke(EntityInterface $entity, array $options)
}
}
if ($permitMultipleNulls) {
if (!$permitMultipleNulls) {
foreach ($conditions as $key => $value) {
if ($value === null) {
$conditions[$key . ' IS'] = $value;

This file was deleted.

Oops, something went wrong.
@@ -48,6 +48,7 @@ class SpecialTagsFixture extends TestFixture
*/
public $records = [
['article_id' => 1, 'tag_id' => 3, 'highlighted' => false, 'highlighted_time' => null, 'author_id' => 1],
['article_id' => 2, 'tag_id' => 1, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => 2]
['article_id' => 2, 'tag_id' => 1, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => 2],
['article_id' => 10, 'tag_id' => 10, 'highlighted' => true, 'highlighted_time' => '2014-06-01 10:10:00', 'author_id' => null]
];
}
@@ -29,7 +29,7 @@ class RulesCheckerIntegrationTest extends TestCase
*
* @var array
*/
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.tags', 'core.logs'];
public $fixtures = ['core.articles', 'core.articles_tags', 'core.authors', 'core.special_tags'];
/**
* Tear down
@@ -378,21 +378,23 @@ public function testIsUniqueMultipleFields()
public function testIsUniquePermitMultipleNulls()
{
$entity = new Entity([
'log_id' => null
'article_id' => 11,
'tag_id' => 11,
'author_id' => null
]);
$table = TableRegistry::get('Logs');
$table = TableRegistry::get('SpecialTags');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['log_id']), ['permitMultipleNulls' => true]);
$rules->add($rules->isUnique(['author_id']), ['permitMultipleNulls' => false]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('log_id'));
$this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('author_id'));
$entity->log_id = 4;
$entity->author_id = 11;
$this->assertSame($entity, $table->save($entity));
$entity = $table->get(1);
$entity->dirty('log_id', true);
$entity->dirty('author_id', true);
$this->assertSame($entity, $table->save($entity));
}
@@ -405,19 +407,22 @@ public function testIsUniquePermitMultipleNulls()
public function testIsUniqueMultipleFieldsPermitMultipleNulls()
{
$entity = new Entity([
'log_id' => 3,
'type' => null
'article_id' => 10,
'tag_id' => 12,
'author_id' => null
]);
$table = TableRegistry::get('Logs');
$table = TableRegistry::get('SpecialTags');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['log_id', 'type'], 'Nope'), ['permitMultipleNulls' => true]);
$rules->add($rules->isUnique(['author_id', 'article_id'], 'Nope'), ['permitMultipleNulls' => false]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['log_id' => ['_isUnique' => 'Nope']], $entity->errors());
$this->assertEquals(['author_id' => ['_isUnique' => 'Nope']], $entity->errors());
$entity->clean();
$entity->type = 'Access';
$entity->article_id = 10;
$entity->tag_id = 12;
$entity->author_id = 12;
$this->assertSame($entity, $table->save($entity));
}

0 comments on commit c453418

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