public function testRenderGroupedElementsWithSeparators() { $group = HTML_QuickForm2_Factory::createElement('group', 'foo', array('id' => 'testSeparators')); $element1 = $group->addElement('text', 'bar'); $element2 = $group->addElement('text', 'baz'); $element3 = $group->addElement('text', 'quux'); $renderer = HTML_Quickform2_Renderer::factory('callback')->setCallbackForId('testSeparators', array(get_class($this), '_renderTestSeparators'))->setElementCallbackForGroupId('testSeparators', 'HTML_QuickForm2_Element_InputText', array(get_class($this), '_renderTestSeparators2')); $this->assertEquals('<foo>' . $element1 . '</foo><foo>' . $element2 . '</foo><foo>' . $element3 . '</foo>', $group->render($renderer->reset())->__toString()); $group->setSeparator(' '); $this->assertEquals('<foo>' . $element1 . '</foo> <foo>' . $element2 . '</foo> <foo>' . $element3 . '</foo>', $group->render($renderer->reset())->__toString()); $group->setSeparator(array('<br />', ' ')); $this->assertEquals('<foo>' . $element1 . '</foo><br /><foo>' . $element2 . '</foo> <foo>' . $element3 . '</foo>', $group->render($renderer->reset())->__toString()); }
public function testRenderWithStyle() { $form = new HTML_QuickForm2('arrayStyle'); $text1 = $form->addText('foo', array('id' => 'testArrayWithStyle')); $text2 = $form->addText('bar', array('id' => 'testArrayWithoutStyle')); $renderer = HTML_Quickform2_Renderer::factory('array')->setStyleForId('testArrayWithStyle', 'weird'); $array = $form->render($renderer)->toArray(); $this->assertEquals('weird', $array['elements'][0]['style']); $this->assertArrayNotHasKey('style', $array['elements'][1]); }
public function testDuplicateMethodNamesDisallowed() { $type = 'fake' . mt_rand(); HTML_QuickForm2_Renderer::register($type, 'HTML_QuickForm2_FakeRenderer'); HTML_QuickForm2_Renderer::registerPlugin($type, 'HTML_QuickForm2_FakeRenderer_HelloPlugin'); HTML_QuickForm2_Renderer::registerPlugin($type, 'HTML_QuickForm2_FakeRenderer_AnotherHelloPlugin'); try { $renderer = HTML_Quickform2_Renderer::factory($type); $renderer->sayHello(); } catch (HTML_QuickForm2_InvalidArgumentException $e) { $this->assertRegexp('/^Duplicate method name/', $e->getMessage()); return; } $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown'); }