Skip to content
Permalink
Browse files

Parse rules in getField()

  • Loading branch information...
ceeram committed Jun 20, 2012
1 parent 03e2263 commit 60c611fa47321e2a359ea8e66b8351cb8d07e09d
Showing with 19 additions and 0 deletions.
  1. +1 −0 lib/Cake/Model/ModelValidator.php
  2. +18 −0 lib/Cake/Test/Case/Model/ModelValidationTest.php
@@ -304,6 +304,7 @@ public function getMethods() {
* @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 @@ public function testAddMultipleRules() {
$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

0 comments on commit 60c611f

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