Example #1
0
 public function testValidateUntilErrorMessage()
 {
     $preError = new HTML_QuickForm2_NodeImpl();
     $preError->setError('some message');
     $ruleIrrelevant = $this->getMock('HTML_QuickForm2_Rule', array('validate', 'checkValue'), array($preError));
     $ruleIrrelevant->expects($this->never())->method('validate');
     $preError->addRule($ruleIrrelevant);
     $this->assertFalse($preError->validate());
     $manyRules = new HTML_QuickForm2_NodeImpl();
     $ruleTrue = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($manyRules, 'irrelevant message'));
     $ruleTrue->expects($this->once())->method('checkValue')->will($this->returnValue(true));
     $ruleFalseNoMessage = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($manyRules, ''));
     $ruleFalseNoMessage->expects($this->once())->method('checkValue')->will($this->returnValue(false));
     $ruleFalseWithMessage = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($manyRules, 'some error'));
     $ruleFalseWithMessage->expects($this->once())->method('checkValue')->will($this->returnValue(false));
     $ruleStillIrrelevant = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($manyRules, '...'));
     $ruleStillIrrelevant->expects($this->never())->method('checkValue');
     $manyRules->addRule($ruleTrue);
     $manyRules->addRule($ruleFalseNoMessage);
     $manyRules->addRule($ruleFalseWithMessage);
     $manyRules->addRule($ruleStillIrrelevant);
     $this->assertFalse($manyRules->validate());
     $this->assertEquals('some error', $manyRules->getError());
 }