Permalink
Browse files

Fixing issue where whitelist would not be used for validation. Test c…

…ase added. Fixes #1037
  • Loading branch information...
1 parent 12d4b52 commit 5446a062ee444c6973c76a4562eb3afe2f46d967 @markstory markstory committed Aug 22, 2010
Showing with 25 additions and 2 deletions.
  1. +1 −1 cake/libs/model/model.php
  2. +24 −1 cake/tests/cases/libs/model/model_validation.test.php
@@ -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'];
}
@@ -164,12 +164,35 @@ 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
*
* @access public

0 comments on commit 5446a06

Please sign in to comment.