/** * Test for Form::getInput method. * * @return void */ public function testGetInput() { $form = new JFormInspector('form1'); $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $this->assertThat($form->getInput('title', null, 'The Title'), $this->equalTo('<input type="text" name="title" id="title_id" value="The Title" class="inputbox required"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field.'); $this->assertThat($form->getInput('show_title', 'params', '0'), $this->equalTo('<fieldset id="params_show_title" class="radio">' . '<input type="radio" id="params_show_title0" name="params[show_title]" value="1"/>' . '<label for="params_show_title0">' . Text::_('JYes') . '</label>' . '<input type="radio" id="params_show_title1" name="params[show_title]" value="0" checked="checked"/>' . '<label for="params_show_title1">' . Text::_('JNo') . '</label>' . '</fieldset>'), 'Line:' . __LINE__ . ' The method should return a radio list.'); $form = new JFormInspector('form1', array('control' => 'jform')); $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $this->assertThat($form->getInput('colours', 'params', 'blue'), $this->equalTo('<select id="jform_params_colours" name="jform[params][colours][]" multiple="multiple">' . "\n" . ' <option value="red">Red</option>' . "\n" . ' <option value="blue" selected="selected">Blue</option>' . "\n" . ' <option value="green">Green</option>' . "\n" . ' <option value="yellow">Yellow</option>' . "\n" . '</select>' . "\n"), 'Line:' . __LINE__ . ' XML string should load successfully.'); // Test translate default $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="DEFAULT_KEY"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is untranslated since the DEFAULT_KEY does not exist in the language.'); $lang = Language::getInstance(); $debug = $lang->setDebug(true); $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="??DEFAULT_KEY??"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is marked untranslated.'); $lang->load('form_test', __DIR__); $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="My Default"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is translated.'); $lang->setDebug($debug); }