/**
  * Container rules should be called after element rules
  *
  * @link http://pear.php.net/bugs/17576
  */
 public function testRequest17576()
 {
     $container = new HTML_QuickForm2_ContainerImpl('last');
     $element = $container->appendChild(new HTML_QuickForm2_ElementImpl2('foo'));
     $ruleChange = $this->getMock('HTML_QuickForm2_Rule', array('validateOwner'), array($element, 'a message'));
     $ruleChange->expects($this->exactly(2))->method('validateOwner')->will($this->onConsecutiveCalls(true, false));
     $element->addRule($ruleChange);
     $container->addRule(new RuleRequest17576($container, 'a contained element is invalid'));
     // first call
     $this->assertTrue($container->validate());
     // second call
     $this->assertFalse($container->validate());
     $this->assertEquals('a contained element is invalid', $container->getError());
 }
 public function testValidate()
 {
     $cValidate = new HTML_QuickForm2_ContainerImpl('validate');
     $el1 = $cValidate->appendChild(new HTML_QuickForm2_ElementImpl2('foo'));
     $el2 = $cValidate->appendChild(new HTML_QuickForm2_ElementImpl2('bar'));
     $ruleTrue1 = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($cValidate, 'irrelevant message'));
     $ruleTrue1->expects($this->once())->method('checkValue')->will($this->returnValue(true));
     $ruleFalse = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($el1, 'some error'));
     $ruleFalse->expects($this->once())->method('checkValue')->will($this->returnValue(false));
     $ruleTrue2 = $this->getMock('HTML_QuickForm2_Rule', array('checkValue'), array($el2, 'irrelevant message'));
     $ruleTrue2->expects($this->once())->method('checkValue')->will($this->returnValue(true));
     $cValidate->addRule($ruleTrue1);
     $el1->addRule($ruleFalse);
     $el2->addRule($ruleTrue2);
     $this->assertFalse($cValidate->validate());
     $this->assertEquals('', $cValidate->getError());
 }