mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing issue where whitelist would not be used for validation. Test case added. Fixes #1037
This commit is contained in:
parent
12d4b52f10
commit
5446a062ee
2 changed files with 25 additions and 2 deletions
|
@ -2511,7 +2511,7 @@ class Model extends Overloadable {
|
||||||
$_validate = $this->validate;
|
$_validate = $this->validate;
|
||||||
$whitelist = $this->whitelist;
|
$whitelist = $this->whitelist;
|
||||||
|
|
||||||
if (array_key_exists('fieldList', $options)) {
|
if (!empty($options['fieldList'])) {
|
||||||
$whitelist = $options['fieldList'];
|
$whitelist = $options['fieldList'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,11 +164,34 @@ class ModelValidationTest extends BaseModelTest {
|
||||||
$TestModel->invalidFields();
|
$TestModel->invalidFields();
|
||||||
$expected = array('name' => 'This field cannot be left blank');
|
$expected = array('name' => 'This field cannot be left blank');
|
||||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||||
$TestModel->validationErrors = array();
|
|
||||||
|
|
||||||
$this->assertEqual($TestModel->validate, $validate);
|
$this->assertEqual($TestModel->validate, $validate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that invalidFields() integrates well with save(). And that fieldList can be an empty type.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testInvalidFieldsWhitelist() {
|
||||||
|
$TestModel =& new ValidationTest1();
|
||||||
|
$TestModel->validate = $validate = array(
|
||||||
|
'title' => array(
|
||||||
|
'rule' => 'customValidator',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'name' => array(
|
||||||
|
'rule' => 'alphaNumeric',
|
||||||
|
'required' => true
|
||||||
|
));
|
||||||
|
|
||||||
|
$TestModel->whitelist = array('name');
|
||||||
|
$TestModel->save(array('name' => '#$$#'));
|
||||||
|
|
||||||
|
$expected = array('name' => 'This field cannot be left blank');
|
||||||
|
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testValidates method
|
* testValidates method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue