public function testAddElementWithUnderscoreInType() { HTML_QuickForm2_Factory::registerElement('super_box', 'HTML_QuickForm2_Element_InputCheckbox'); $this->assertTrue(HTML_QuickForm2_Factory::isElementRegistered('super_box')); $c = new HTML_QuickForm2_ContainerImpl('cCOT3'); $el1 = $c->addSuper_Box('sBox_1'); $el2 = $c->addsuper_box('sBox_2'); $el3 = $c->addSuper_box('sBox_3'); $this->assertSame($el1, $c->getElementById('sBox_1-0')); $this->assertSame($el2, $c->getElementById('sBox_2-0')); $this->assertSame($el3, $c->getElementById('sBox_3-0')); try { $c->addSuper_Select('sSel_1'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { $this->assertEquals("Element type 'super_select' is not known", $e->getMessage()); return; } $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown'); }
public function testGetValueBrackets() { $c = new HTML_QuickForm2_ContainerImpl('withBrackets'); $el1 = $c->appendChild(new HTML_QuickForm2_ElementImpl2('foo[]')); $el2 = $c->appendChild(new HTML_QuickForm2_ElementImpl2('foo[]')); $el1->setValue('first'); $el2->setValue('second'); $this->assertEquals(array('foo' => array('first', 'second')), $c->getValue()); }
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()); }