mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding patch from #2528, fixes validation passing when even when allowEmpty === false
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5010 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
9e6677030b
commit
b42e908656
3 changed files with 28 additions and 9 deletions
|
@ -1711,7 +1711,7 @@ class Model extends Overloadable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($validator['on']) || ($validator['on'] == 'create' && !$this->exists()) || ($validator['on'] == 'update' && $this->exists())) {
|
if (empty($validator['on']) || ($validator['on'] == 'create' && !$this->exists()) || ($validator['on'] == 'update' && $this->exists())) {
|
||||||
if ((!isset($data[$fieldName]) && $validator['required'] === true) || (isset($data[$fieldName]) && (empty($data[$fieldName]) && $data[$fieldName] != 0) && $validator['allowEmpty'] === false)) {
|
if ((!isset($data[$fieldName]) && $validator['required'] === true) || (isset($data[$fieldName]) && (empty($data[$fieldName]) && !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false)) {
|
||||||
$this->invalidate($fieldName, $message);
|
$this->invalidate($fieldName, $message);
|
||||||
} elseif (isset($data[$fieldName])) {
|
} elseif (isset($data[$fieldName])) {
|
||||||
if(empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
|
if(empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
|
||||||
|
|
|
@ -28,10 +28,6 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
|
||||||
$dispatcher = new ConsoleDispatcher($argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConsoleDispatcher {
|
class ConsoleDispatcher {
|
||||||
/**
|
/**
|
||||||
* Standard input stream.
|
* Standard input stream.
|
||||||
|
@ -371,4 +367,7 @@ class ConsoleDispatcher {
|
||||||
print_r($this->params);
|
print_r($this->params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||||
|
$dispatcher = new ConsoleDispatcher($argv);
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -1237,6 +1237,26 @@ function testRecursiveFindAllWithLimit() {
|
||||||
$result = $this->model->validates();
|
$result = $this->model->validates();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
|
$this->model->validate['slug'] = array('allowEmpty' => false, 'rule' => array('maxLength', 45));
|
||||||
|
|
||||||
|
$data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => ''));
|
||||||
|
$result = $this->model->create($data);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$result = $this->model->validates();
|
||||||
|
$this->assertFalse($result);
|
||||||
|
|
||||||
|
$data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => 'slug-right-here'));
|
||||||
|
$result = $this->model->create($data);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$result = $this->model->validates();
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'));
|
||||||
|
$result = $this->model->create($data);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$result = $this->model->validates();
|
||||||
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$this->model->validate = array(
|
$this->model->validate = array(
|
||||||
'number' => array(
|
'number' => array(
|
||||||
'rule' => 'validateNumber',
|
'rule' => 'validateNumber',
|
||||||
|
|
Loading…
Add table
Reference in a new issue