mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Parse rules in getField()
This commit is contained in:
parent
03e2263b69
commit
60c611fa47
2 changed files with 19 additions and 0 deletions
|
@ -304,6 +304,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|||
* @return CakeValidationSet|array
|
||||
*/
|
||||
public function getField($name = null) {
|
||||
$this->_parseRules();
|
||||
if ($name !== null && !empty($this->_fields[$name])) {
|
||||
return $this->_fields[$name];
|
||||
} elseif ($name !== null) {
|
||||
|
|
|
@ -2087,6 +2087,24 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertSame($set, $Validator->getField('other'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that rules are parsed correctly when calling getField()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidator() {
|
||||
$TestModel = new Article();
|
||||
$Validator = $TestModel->validator();
|
||||
|
||||
$result = $Validator->getField();
|
||||
$expected = array('user_id', 'title', 'body');
|
||||
$this->assertEquals($expected, array_keys($result));
|
||||
$this->assertTrue($result['user_id'] instanceof CakeValidationSet);
|
||||
|
||||
$result = $TestModel->validator()->getField('title');
|
||||
$this->assertTrue($result instanceof CakeValidationSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that altering data in a beforeValidate callback will lead to saving those
|
||||
* values in database, this time with belongsTo associations
|
||||
|
|
Loading…
Add table
Reference in a new issue