Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
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);
 }