Skip to content

Commit

Permalink
Adding new test case for ModelValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 9, 2012
1 parent 2a90baa commit 5ba5f90
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/Cake/Test/Case/Model/ModelValidationTest.php
Expand Up @@ -2086,5 +2086,24 @@ public function testValidateFirstAssociatedWithBeforeValidate2() {

$this->assertEquals('foo', $model->field('title', array('body' => 'a test')));
}


/**
* Testing you can dynamically add rules to a field, added this to dispel doubts
* after a presentation made to show off this new feature
*
* @return void
**/
public function testDynamicValidationRuleBuilding() {
$model = new Article;
$validator = $model->validator();
$validator->add('body', 'isSpecial', array('rule' => 'special'));
$rules = $validator['body']->getRules();
$this->assertCount(2, $rules);
$this->assertEquals('special', $rules['isSpecial']->rule);
$validator['body']->setRule('isAwesome', array('rule' => 'awesome'));
$rules = $validator['body']->getRules();
$this->assertCount(3, $rules);
$this->assertEquals('awesome', $rules['isAwesome']->rule);
}

}

0 comments on commit 5ba5f90

Please sign in to comment.