示例#1
0
 public function testSetGetValidator()
 {
     $ruleSet = new RuleSet();
     $ruleSet->setRule('required', $this->createRequiredRule());
     $validator = new Validator($ruleSet, 'required', 'required field');
     $this->field->setValidator($validator);
     $this->assertSame($validator, $this->field->getValidator());
 }
示例#2
0
 public function setUp()
 {
     $ruleset = new RuleSet();
     $ruleset->setRule('required', $this->createRequiredRule());
     $ruleset->setRule('trim', $this->createTrimRule());
     $ruleset->setRule('regex', $this->createRegexRule());
     $this->ruleset = $ruleset;
 }
示例#3
0
 public function testOverrideRule()
 {
     $rule1 = $this->createMockRule();
     $rule2 = $this->createMockRule();
     $this->ruleSet->setRule('test', $rule1);
     $this->ruleSet->setRule('test', $rule2);
     $this->assertNotSame($this->ruleSet->getRule('test'), $rule1);
     $this->assertSame($this->ruleSet->getRule('test'), $rule2);
 }
示例#4
0
 public function validate(&$value)
 {
     $parsedRules = $this->parseRules();
     foreach ($parsedRules as $rule) {
         $validationRule = $this->ruleSet->getRule($rule['name']);
         if ($validationRule) {
             $validationRule->validate($value, $this->fieldName, $rule['arguments']);
         } else {
             throw new InvalidRuleException($rule['name'] . ' is not a recognized validation rule.');
         }
     }
 }
示例#5
0
 /**
  * @expectedException \LiftKit\Form\Validator\Rule\Exception\Validation
  */
 public function testExecuteValidates()
 {
     $input = new Request([]);
     $ruleSet = new RuleSet();
     $ruleSet->setRule('required', new Rule(function ($value) {
         return (bool) $value;
     }, 'The field is required'));
     $element = new Field();
     $element->setValidator(new Validator($ruleSet, 'required'));
     $this->fieldSet->attachElement($element);
     $this->fieldSet->execute($input);
 }