mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-05-31 11:53:32 +00:00
Merge remote-tracking branch 'origin/2.5' into k-halaburda-master
This commit is contained in:
commit
df549898ad
45 changed files with 2654 additions and 225 deletions
lib/Cake/Test/Case/Model
|
@ -612,6 +612,34 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertEquals(0, $joinRecords, 'Records were saved on the join table. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that if a behavior modifies the model's whitelist validation gets triggered
|
||||
* properly for those fields.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateWithFieldListAndBehavior() {
|
||||
$TestModel = new ValidationTest1();
|
||||
$TestModel->validate = array(
|
||||
'title' => array(
|
||||
'rule' => 'notEmpty',
|
||||
),
|
||||
'name' => array(
|
||||
'rule' => 'notEmpty',
|
||||
));
|
||||
$TestModel->Behaviors->attach('ValidationRule', array('fields' => array('name')));
|
||||
|
||||
$data = array(
|
||||
'title' => '',
|
||||
'name' => '',
|
||||
);
|
||||
$result = $TestModel->save($data, array('fieldList' => array('title')));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$expected = array('title' => array('This field cannot be left blank'), 'name' => array('This field cannot be left blank'));
|
||||
$this->assertEquals($expected, $TestModel->validationErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that saveAll and with models with validation interact well
|
||||
*
|
||||
|
@ -2380,3 +2408,21 @@ class ModelValidationTest extends BaseModelTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Behavior for testing validation rules.
|
||||
*/
|
||||
class ValidationRuleBehavior extends ModelBehavior {
|
||||
|
||||
public function setup(Model $Model, $config = array()) {
|
||||
$this->settings[$Model->alias] = $config;
|
||||
}
|
||||
|
||||
public function beforeValidate(Model $Model, $options = array()) {
|
||||
$fields = $this->settings[$Model->alias]['fields'];
|
||||
foreach ($fields as $field) {
|
||||
$Model->whitelist[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue