From b42e908656b4a6e3b45da236358c13c487c8bd98 Mon Sep 17 00:00:00 2001 From: phpnut Date: Fri, 4 May 2007 07:13:15 +0000 Subject: [PATCH] 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 --- cake/libs/model/model.php | 4 ++-- cake/scripts/dispatch.php | 11 +++++------ cake/tests/cases/libs/model/model.test.php | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index fcdaf32de..199c6a17c 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -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'); } -?> \ No newline at end of file +?> diff --git a/cake/scripts/dispatch.php b/cake/scripts/dispatch.php index cdaff5397..beb459652 100644 --- a/cake/scripts/dispatch.php +++ b/cake/scripts/dispatch.php @@ -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); +} ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index c74c29706..bd893cc25 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -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() { } } -?> \ No newline at end of file +?>