Skip to content

Commit

Permalink
Fixing issue where whitelist would not be used for validation. Test c…
Browse files Browse the repository at this point in the history
…ase added. Fixes #1037
  • Loading branch information
markstory committed Aug 22, 2010
1 parent 12d4b52 commit 5446a06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/model.php
Expand Up @@ -2511,7 +2511,7 @@ function invalidFields($options = array()) {
$_validate = $this->validate;
$whitelist = $this->whitelist;

if (array_key_exists('fieldList', $options)) {
if (!empty($options['fieldList'])) {
$whitelist = $options['fieldList'];
}

Expand Down
25 changes: 24 additions & 1 deletion cake/tests/cases/libs/model/model_validation.test.php
Expand Up @@ -164,11 +164,34 @@ function testInvalidFieldsWithFieldListParams() {
$TestModel->invalidFields();
$expected = array('name' => 'This field cannot be left blank');
$this->assertEqual($TestModel->validationErrors, $expected);
$TestModel->validationErrors = array();

$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
*
Expand Down

0 comments on commit 5446a06

Please sign in to comment.