Skip to content
Permalink
Browse files

Correctly setting the error message for existsIn() when an array is used

  • Loading branch information...
lorenzo committed Mar 27, 2015
1 parent 099b39f commit e7580d31ea807a539a6f88b8f3883843b5fe227b
Showing with 22 additions and 1 deletion.
  1. +1 −1 src/ORM/RulesChecker.php
  2. +21 −0 tests/TestCase/ORM/RulesCheckerIntegrationTest.php
@@ -354,7 +354,7 @@ public function existsIn($field, $table, $message = null)
}
}
$errorField = $field;
$errorField = is_string($field) ? $field : current($field);
return $this->_addError(new ExistsIn($field, $table), '_existsIn', compact('errorField', 'message'));
}
@@ -633,6 +633,27 @@ public function testExistsInAliasPrefix()
$this->assertEquals(['_existsIn' => 'This value does not exist'], $entity->errors('author_id'));
}
/**
* Tests that using an array in existsIn() sets the error message correctly
*
* @return
*/
public function testExistsInErrorWithArrayField()
{
$entity = new Entity([
'title' => 'An Article',
'author_id' => 500
]);
$table = TableRegistry::get('Articles');
$table->belongsTo('Authors');
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id'], 'Authors'));
$this->assertFalse($table->save($entity));
$this->assertEquals(['_existsIn' => 'This value does not exist'], $entity->errors('author_id'));
}
/**
* Tests using rules to prevent delete operations
*

0 comments on commit e7580d3

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