mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding error triggering while in debug mode for unhandled validation methods.
This commit is contained in:
parent
58ec259714
commit
32d5b40cd0
2 changed files with 34 additions and 0 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue