Adding new test case for ModelValidator

This commit is contained in:
Jose Lorenzo Rodriguez 2012-06-09 15:27:22 -04:30
parent 2a90baae0c
commit 5ba5f906e6

View file

@ -2087,4 +2087,23 @@ class ModelValidationTest extends BaseModelTest {
$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);
}
}