/** * Test the getInput method. * * @return void * * @since 12.1 */ public function testGetInput() { $form = new JFormInspector('form1'); $this->assertThat( $form->load('<form><field name="sql" type="sql" key_field="id" query="SELECT * FROM `jos_categories`"><option value="*">None</option></field></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.' ); $field = new JFormFieldSQL($form); $this->assertThat( $field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.' ); if (!is_null(self::$driver)) { $this->assertThat( strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.' ); } else { $this->markTestSkipped(); } }
/** * Tests folder attribute setup by JFormFieldPlugins::setup method * * @covers JFormField::setup * @covers JFormField::__get * * @return void */ public function testSetup() { $field = new JFormFieldSQL(); $element = simplexml_load_string('<field name="sql" type="sql" value_field="title" key_field="id" query="SELECT * FROM `jos_categories`">' . '<option value="*">None</option></field>'); $this->assertThat($field->setup($element, ''), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.'); $this->assertThat($field->keyField, $this->equalTo("id"), 'Line:' . __LINE__ . ' The property should be computed from the XML.'); $this->assertThat($field->valueField, $this->equalTo("title"), 'Line:' . __LINE__ . ' The property should be computed from the XML.'); $this->assertThat($field->translate, $this->isFalse(), 'Line:' . __LINE__ . ' The property should be computed from the XML.'); $this->assertThat($field->query, $this->equalTo("SELECT * FROM `jos_categories`"), 'Line:' . __LINE__ . ' The property should be computed from the XML.'); }
/** * Method to get the custom field options. * Use the query attribute to supply a query to generate the list. * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { // Initialize variables. $options = array(); // Initialize some field attributes. $this->element['key_field'] = 'value'; $this->element['value_field'] = 'name'; $this->element['translate'] = false; $query = 'SELECT "Default" as name,"default" as value UNION SELECT concat( upper(substring(name,1,1)),lower(substring(name,2)) ) as name, name AS value FROM #__jckplugins WHERE type = "filebrowser" AND published = 1 UNION SELECT concat( upper(substring(name,1,1)),lower(substring(name,2)) ) as name, name AS value FROM #__jckplugins WHERE name = "jckexplorer" AND type = "plugin" AND published = 1'; $this->element['query'] = $query; return parent::getOptions(); }