mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding tests for model method validation with multiple parameters and addition of original validation rule to method params. Closes #149
This commit is contained in:
parent
425dcf2df5
commit
3c88d81735
2 changed files with 60 additions and 0 deletions
|
@ -73,6 +73,56 @@ class ModelValidationTest extends BaseModelTest {
|
|||
);
|
||||
|
||||
$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 @@ class ValidationTest1 extends CakeTestModel {
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue