Permalink
Browse files

Adding new test case for ModelValidator

  • Loading branch information...
1 parent 2a90baa commit 5ba5f906e6ff8f386fabac463a5913ee7c0ce561 @lorenzo lorenzo committed Jun 9, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 lib/Cake/Test/Case/Model/ModelValidationTest.php
@@ -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.