/** * Test the getInput method. * * @return void * * @since 1.0 */ public function testGetInput() { $form = new JFormInspector('form1'); $this->assertThat($form->load('<form><field name="groupedlist" type="groupedlist" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new Field_GroupedList($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); // TODO: Should check all the attributes have come in properly. }
/** * Method to get the time zone field option groups. * * @return array The field option objects as a nested array in groups. * * @since 1.0 */ protected function getGroups() { $groups = array(); // Get the list of time zones from the server. $zones = \DateTimeZone::listIdentifiers(); // Build the group lists. foreach ($zones as $zone) { // Time zones not in a group we will ignore. if (strpos($zone, '/') === false) { continue; } // Get the group/locale from the timezone. list($group, $locale) = explode('/', $zone, 2); // Only use known groups. if (in_array($group, self::$zones)) { // Initialize the group if necessary. if (!isset($groups[$group])) { $groups[$group] = array(); } // Only add options where a locale exists. if (!empty($locale)) { $groups[$group][$zone] = Select::option($zone, str_replace('_', ' ', $locale), 'value', 'text', false); } } } // Sort the group lists. ksort($groups); foreach ($groups as &$location) { sort($location); } // Merge any additional groups in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }
/** * Method to get the time zone field option groups. * * @return array The field option objects as a nested array in groups. * * @since 11.1 */ protected function getGroups() { $groups = array(); $keyField = $this->element['key_field'] ? (string) $this->element['key_field'] : 'id'; $keyValue = $this->form->getValue($keyField); // If the timezone is not set use the server setting. if (strlen($this->value) == 0 && empty($keyValue)) { $this->value = Factory::getConfig()->get('offset'); } // Get the list of time zones from the server. $zones = DateTimeZone::listIdentifiers(); // Build the group lists. foreach ($zones as $zone) { // Time zones not in a group we will ignore. if (strpos($zone, '/') === false) { continue; } // Get the group/locale from the timezone. list($group, $locale) = explode('/', $zone, 2); // Only use known groups. if (in_array($group, self::$zones)) { // Initialize the group if necessary. if (!isset($groups[$group])) { $groups[$group] = array(); } // Only add options where a locale exists. if (!empty($locale)) { $groups[$group][$zone] = Html::_('select.option', $zone, str_replace('_', ' ', $locale), 'value', 'text', false); } } } // Sort the group lists. ksort($groups); foreach ($groups as $zone => &$location) { sort($location); } // Merge any additional groups in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }