Adding additional tests for validation.

Added fix to model to pass the new tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4970 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-05-01 10:30:36 +00:00
parent d1701327f8
commit 5cd13cff26
2 changed files with 13 additions and 1 deletions

View file

@ -1719,7 +1719,7 @@ class Model extends Overloadable {
if ((!isset($data[$fieldName]) && $validator['required'] === true) || (isset($data[$fieldName]) && (empty($data[$fieldName]) && $data[$fieldName] != 0) && $validator['allowEmpty'] === false)) {
$this->invalidate($fieldName, $message);
} elseif (isset($data[$fieldName])) {
if(empty($data[$fieldName]) && $validator['allowEmpty'] === true) {
if(empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
break;
}
if (is_array($validator['rule'])) {

View file

@ -1140,6 +1140,18 @@ function testRecursiveFindAllWithLimit() {
$this->assertTrue($result);
$result = $this->model->validates();
$this->assertFalse($result);
$data = array('Article' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => 0));
$result = $this->model->create($data);
$this->assertTrue($result);
$result = $this->model->validates();
$this->assertFalse($result);
$data = array('Article' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '0'));
$result = $this->model->create($data);
$this->assertTrue($result);
$result = $this->model->validates();
$this->assertFalse($result);
}
function testSave() {