Skip to content
Permalink
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...
markstory committed Jan 2, 2010
1 parent 425dcf2 commit 3c88d817352d2217c6725cf09f48fa5eefe89379
Showing with 60 additions and 0 deletions.
  1. +50 −0 cake/tests/cases/libs/model/model_validation.test.php
  2. +10 −0 cake/tests/cases/libs/model/models.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
@@ -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

0 comments on commit 3c88d81

Please sign in to comment.
You can’t perform that action at this time.