Fixing issue where whitelist would not be used for validation. Test case added. Fixes #1037

This commit is contained in:
mark_story 2010-08-21 22:48:59 -04:00
parent 12d4b52f10
commit 5446a062ee
2 changed files with 25 additions and 2 deletions

View file

@ -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'];
} }

View file

@ -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
* *