fixes #6203, Model::invalidFields respecting Model::whitelist

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8113 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2009-03-17 18:19:12 +00:00
parent 7f853532d9
commit de5907326e
2 changed files with 28 additions and 15 deletions

View file

@ -2343,9 +2343,15 @@ class Model extends Overloadable {
$this->exists();
$_validate = $this->validate;
if (array_key_exists('fieldList', $options) && is_array($options['fieldList']) && !empty($options['fieldList'])) {
$whitelist = $this->whitelist;
if (array_key_exists('fieldList', $options)) {
$whitelist = $options['fieldList'];
}
if (!empty($whitelist)) {
$validate = array();
foreach ($options['fieldList'] as $f) {
foreach ((array)$whitelist as $f) {
if (!empty($this->validate[$f])) {
$validate[$f] = $this->validate[$f];
}

View file

@ -4983,6 +4983,13 @@ class ModelTest extends CakeTestCase {
$TestModel->invalidFields(array('fieldList' => array('name', 'title')));
$expected = array('name' => 'This field cannot be left blank', 'title' => 'This field cannot be left blank');
$this->assertEqual($TestModel->validationErrors, $expected);
$TestModel->validationErrors = array();
$TestModel->whitelist = array('name');
$TestModel->invalidFields();
$expected = array('name' => 'This field cannot be left blank');
$this->assertEqual($TestModel->validationErrors, $expected);
$TestModel->validationErrors = array();
$this->assertEqual($TestModel->validate, $validate);
}