From 32d5b40cd0396cd8880d5d905a75333cf03ed794 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 30 Sep 2009 22:34:29 -0400 Subject: [PATCH] Adding error triggering while in debug mode for unhandled validation methods. --- cake/libs/model/model.php | 7 +++++ .../libs/model/model_validation.test.php | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 060e3bc01..854759adf 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -2547,6 +2547,13 @@ class Model extends Overloadable { $valid = $Validation->dispatchMethod($rule, $ruleParams); } elseif (!is_array($validator['rule'])) { $valid = preg_match($rule, $data[$fieldName]); + } elseif (Configure::read('debug') > 0) { + $error = sprintf( + __('Could not find validation handler %s for %s', true), + $rule, + $fieldName + ); + trigger_error($error, E_USER_WARNING); } if (!$valid || (is_string($valid) && strlen($valid) > 0)) { diff --git a/cake/tests/cases/libs/model/model_validation.test.php b/cake/tests/cases/libs/model/model_validation.test.php index 94a381502..0fbc2b63f 100644 --- a/cake/tests/cases/libs/model/model_validation.test.php +++ b/cake/tests/cases/libs/model/model_validation.test.php @@ -126,5 +126,32 @@ class ModelValidationTest extends BaseModelTest { $this->assertEqual($TestModel->validate, $validate); } +/** + * Test that missing validation methods trigger errors in development mode. + * Helps to make developement easier. + * + * @return void + **/ + function testMissingValidationErrorTriggering() { + $restore = Configure::read('debug'); + Configure::write('debug', 2); + + $TestModel =& new ValidationTest1(); + $TestModel->create(array('title' => 'foo')); + $TestModel->validate = array( + 'title' => array( + 'rule' => array('thisOneBringsThePain'), + 'required' => true + ) + ); + $this->expectError(new PatternExpectation('/thisOneBringsThePain for title/i')); + $TestModel->invalidFields(array('fieldList' => array('title'))); + + Configure::write('debug', 0); + $this->assertNoErrors(); + $TestModel->invalidFields(array('fieldList' => array('title'))); + Configure::write('debug', $restore); + } + } ?> \ No newline at end of file