/** * Test for PMA_displayGroupHeader() * * @return void */ public function testDisplayGroupHeader() { if (!PMA_HAS_RUNKIT) { $this->markTestSkipped('Cannot modify constant'); } $this->assertNull(PMA_displayGroupHeader('')); $GLOBALS['_FormDisplayGroup'] = 3; if (!defined('PMA_SETUP')) { define('PMA_SETUP', true); } $result = PMA_displayGroupHeader('headerText'); $this->assertContains('<tr class="group-header group-header-4">', $result); // without PMA_SETUP runkit_constant_remove('PMA_SETUP'); $GLOBALS['_FormDisplayGroup'] = 3; $result = PMA_displayGroupHeader('headerText'); $this->assertContains('<tr class="group-header group-header-4">', $result); }
/** * Prepares data for input field display and outputs HTML code * * @param Form $form Form object * @param string $field field name as it appears in $form * @param string $system_path field path, eg. Servers/1/verbose * @param string $work_path work path, eg. Servers/4/verbose * @param string $translated_path work path changed so that it can be * used as XHTML id * @param bool $show_restore_default whether show "restore default" button * besides the input field * @param bool|null $userprefs_allow whether user preferences are enabled * for this field (null - no support, * true/false - enabled/disabled) * @param array &$js_default array which stores JavaScript code * to be displayed * * @return string HTML for input field */ private function _displayFieldInput(Form $form, $field, $system_path, $work_path, $translated_path, $show_restore_default, $userprefs_allow, array &$js_default) { $name = PMA_langName($system_path); $description = PMA_langName($system_path, 'desc', ''); $value = $this->_configFile->get($work_path); $value_default = $this->_configFile->getDefault($system_path); $value_is_default = false; if ($value === null || $value === $value_default) { $value = $value_default; $value_is_default = true; } $opts = array('doc' => $this->getDocLink($system_path), 'show_restore_default' => $show_restore_default, 'userprefs_allow' => $userprefs_allow, 'userprefs_comment' => PMA_langName($system_path, 'cmt', '')); if (isset($form->default[$system_path])) { $opts['setvalue'] = $form->default[$system_path]; } if (isset($this->_errors[$work_path])) { $opts['errors'] = $this->_errors[$work_path]; } $type = ''; switch ($form->getOptionType($field)) { case 'string': $type = 'text'; break; case 'short_string': $type = 'short_text'; break; case 'double': case 'integer': $type = 'number_text'; break; case 'boolean': $type = 'checkbox'; break; case 'select': $type = 'select'; $opts['values'] = $form->getOptionValueList($form->fields[$field]); break; case 'array': $type = 'list'; $value = (array) $value; $value_default = (array) $value_default; break; case 'group': // :group:end is changed to :group:end:{unique id} in Form class $htmlOutput = ''; if (mb_substr($field, 7, 4) != 'end:') { $htmlOutput .= PMA_displayGroupHeader(mb_substr($field, 7)); } else { PMA_displayGroupFooter(); } return $htmlOutput; case 'NULL': trigger_error("Field {$system_path} has no type", E_USER_WARNING); return null; } // detect password fields if ($type === 'text' && mb_substr($translated_path, -9) === '-password') { $type = 'password'; } // TrustedProxies requires changes before displaying if ($system_path == 'TrustedProxies') { foreach ($value as $ip => &$v) { if (!preg_match('/^-\\d+$/', $ip)) { $v = $ip . ': ' . $v; } } } $this->_setComments($system_path, $opts); // send default value to form's JS $js_line = '\'' . $translated_path . '\': '; switch ($type) { case 'text': case 'short_text': case 'number_text': case 'password': $js_line .= '\'' . Sanitize::escapeJsString($value_default) . '\''; break; case 'checkbox': $js_line .= $value_default ? 'true' : 'false'; break; case 'select': $value_default_js = is_bool($value_default) ? (int) $value_default : $value_default; $js_line .= '[\'' . Sanitize::escapeJsString($value_default_js) . '\']'; break; case 'list': $js_line .= '\'' . Sanitize::escapeJsString(implode("\n", $value_default)) . '\''; break; } $js_default[] = $js_line; return PMA_displayInput($translated_path, $name, $type, $value, $description, $value_is_default, $opts); }
/** * Test for PMA_displayGroupHeader() * * @return void */ public function testDisplayGroupHeader() { if (! PMA_HAS_RUNKIT) { $this->markTestSkipped('Cannot modify constant'); } $this->assertNull( PMA_displayGroupHeader('') ); $GLOBALS['_FormDisplayGroup'] = 3; if (!defined('PMA_SETUP')) { define('PMA_SETUP', true); } ob_start(); PMA_displayGroupHeader('headerText'); $result = ob_get_clean(); $this->assertTag( PMA_getTagArray( '<tr class="group-header group-header-4">', array( 'child' => PMA_getTagArray( '<th colspan="3">', array( 'content' => 'headerText' ) ) ) ), $result ); // without PMA_SETUP runkit_constant_remove('PMA_SETUP'); $GLOBALS['_FormDisplayGroup'] = 3; ob_start(); PMA_displayGroupHeader('headerText'); $result = ob_get_clean(); $this->assertTag( PMA_getTagArray( '<tr class="group-header group-header-4">', array( 'child' => PMA_getTagArray( '<th colspan="2">', array( 'content' => 'headerText' ) ) ) ), $result ); }