mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46: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 ((!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);
|
||||
} elseif (isset($data[$fieldName])) {
|
||||
if(empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
|
||||
|
@ -2131,4 +2131,4 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|||
Overloadable::overload('Model');
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -28,10 +28,6 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||
$dispatcher = new ConsoleDispatcher($argv);
|
||||
}
|
||||
|
||||
class ConsoleDispatcher {
|
||||
/**
|
||||
* Standard input stream.
|
||||
|
@ -170,7 +166,7 @@ class ConsoleDispatcher {
|
|||
$this->shiftArgs();
|
||||
$this->scriptName = Inflector::camelize($this->script);
|
||||
$this->scriptClass = $this->scriptName . 'Script';
|
||||
|
||||
|
||||
if (method_exists($this, $this->script) && !in_array($this->script, $protectedCommands)) {
|
||||
$this->{$this->script}();
|
||||
} else {
|
||||
|
@ -198,7 +194,7 @@ class ConsoleDispatcher {
|
|||
$command = $this->args[0];
|
||||
}
|
||||
$classMethods = get_class_methods($script);
|
||||
|
||||
|
||||
$privateMethod = $missingCommand = false;
|
||||
if((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) {
|
||||
$privateMethod = true;
|
||||
|
@ -371,4 +367,7 @@ class ConsoleDispatcher {
|
|||
print_r($this->params);
|
||||
}
|
||||
}
|
||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||
$dispatcher = new ConsoleDispatcher($argv);
|
||||
}
|
||||
?>
|
|
@ -1236,6 +1236,26 @@ function testRecursiveFindAllWithLimit() {
|
|||
$this->assertTrue($result);
|
||||
$result = $this->model->validates();
|
||||
$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(
|
||||
'number' => array(
|
||||
|
@ -1835,4 +1855,4 @@ function testRecursiveFindAllWithLimit() {
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue