From 3935746a298f00c33a79e8900d7c95103c537e5e Mon Sep 17 00:00:00 2001 From: phpnut Date: Tue, 25 Dec 2007 04:53:15 +0000 Subject: [PATCH] "Refactored Model::invalidFields() to pass array(field => value) back to custom validation methods in a model Closes #1863 postal code validation for Italy and Germany Closes #2766, Add field name to params array for custom validation rules Closes #3735, Custom validation functions Commented out the failing model tests until the missing fixtures are added " git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6243 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 1 + cake/libs/validation.php | 6 +++++- cake/tests/cases/libs/model/model.test.php | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index aa01e45b2..b9dfca72d 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1925,6 +1925,7 @@ class Model extends Overloadable { if (method_exists($this, $rule) || isset($this->__behaviorMethods[$rule]) || isset($this->__behaviorMethods[strtolower($rule)])) { $ruleParams[] = array_diff_key($validator, $default); + $ruleParams[0] = array($fieldName => $ruleParams[0]); $valid = call_user_func_array(array(&$this, $rule), $ruleParams); } elseif (method_exists($Validation, $rule)) { $valid = call_user_func_array(array(&$Validation, $rule), $ruleParams); diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 809cf0e6c..4c7944fcb 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -663,7 +663,11 @@ class Validation extends Object { break; case 'ca': $_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i'; - break; + break; + case 'it': + case 'de': + $_this->regex = '/^[0-9]{5}$/i'; + break; } } return $_this->_check(); diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 2f2d0dfc5..deb9f478e 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -65,12 +65,12 @@ class TestValidate extends Model { function validateNumber($value, $options) { $options = am(array('min' => 0, 'max' => 100), $options); - $valid = ($value >= $options['min'] && $value <= $options['max']); + $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']); return $valid; } - function validateTitle($title) { - if (!empty($title) && strpos(low($title), 'title-') === 0) { + function validateTitle($value) { + if (!empty($value) && strpos(low($value['title']), 'title-') === 0) { return true; } return false; @@ -547,7 +547,7 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); unset($this->Project); } - +/* function testWithAssociation() { $this->model =& new Something(); $result = $this->model->SomethingElse->find('all'); @@ -582,7 +582,7 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); } - +*/ function testFindAllRecursiveSelfJoin() { $this->model =& new Home(); $this->model->recursive = 2;