Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests for model method validation with multiple parameters and…

… addition of original validation rule to method params. Closes #149
  • Loading branch information...
commit 3c88d817352d2217c6725cf09f48fa5eefe89379 1 parent 425dcf2
@markstory markstory authored
View
50 cake/tests/cases/libs/model/model_validation.test.php
@@ -73,6 +73,56 @@ function testValidationParams() {
);
$this->assertEqual($TestModel->invalidFields(), $expected);
+
+ $TestModel->validate['title'] = array(
+ 'rule' => array('customValidatorWithSixParams', 'one', 'two', null, 'four'),
+ 'required' => true
+ );
+ $TestModel->create(array('title' => 'foo'));
+ $TestModel->invalidFields();
+ $expected = array(
+ 'data' => array(
+ 'title' => 'foo'
+ ),
+ 'one' => 'one',
+ 'two' => 'two',
+ 'three' => null,
+ 'four' => 'four',
+ 'five' => array(
+ 'rule' => array(1 => 'one', 2 => 'two', 3 => null, 4 => 'four'),
+ 'on' => null,
+ 'last' => false,
+ 'allowEmpty' => false,
+ 'required' => true
+ ),
+ 'six' => 6
+ );
+ $this->assertEqual($TestModel->validatorParams, $expected);
+
+ $TestModel->validate['title'] = array(
+ 'rule' => array('customValidatorWithSixParams', 'one', array('two'), null, 'four', array('five' => 5)),
+ 'required' => true
+ );
+ $TestModel->create(array('title' => 'foo'));
+ $TestModel->invalidFields();
+ $expected = array(
+ 'data' => array(
+ 'title' => 'foo'
+ ),
+ 'one' => 'one',
+ 'two' => array('two'),
+ 'three' => null,
+ 'four' => 'four',
+ 'five' => array('five' => 5),
+ 'six' => array(
+ 'rule' => array(1 => 'one', 2 => array('two'), 3 => null, 4 => 'four', 5 => array('five' => 5)),
+ 'on' => null,
+ 'last' => false,
+ 'allowEmpty' => false,
+ 'required' => true
+ )
+ );
+ $this->assertEqual($TestModel->validatorParams, $expected);
}
/**
* Tests validation parameter fieldList in invalidFields
View
10 cake/tests/cases/libs/model/models.php
@@ -1939,6 +1939,16 @@ function customValidatorWithParams($data, $validator, $or = true, $ignore_on_sam
function customValidatorWithMessage($data) {
return 'This field will *never* validate! Muhahaha!';
}
+/**
+ * Test validation with many parameters
+ *
+ * @return void
+ */
+ function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) {
+ $this->validatorParams = get_defined_vars();
+ unset($this->validatorParams['this']);
+ return true;
+ }
}
/**
* ValidationTest2 class
Please sign in to comment.
Something went wrong with that request. Please try again.