diff options
author | Nisarg Jhaveri <nisargjhaveri@gmail.com> | 2015-05-14 10:24:30 +0300 |
---|---|---|
committer | Nisarg Jhaveri <nisargjhaveri@gmail.com> | 2015-05-14 22:26:26 +0300 |
commit | 431847b39ea32cbd20a7e58117df5029540f0e3c (patch) | |
tree | 85e7bace95ccb23f0dbba04ce5c3eb21e8112c30 | |
parent | 9207b6726406885d487e2e0ed8d066fa01c5383a (diff) |
Return HTML instead of echo-ing directly in FormDisplay
Signed-off-by: Nisarg Jhaveri <nisargjhaveri@gmail.com>
-rw-r--r-- | libraries/config/FormDisplay.class.php | 31 | ||||
-rw-r--r-- | libraries/config/FormDisplay.tpl.php | 173 | ||||
-rw-r--r-- | prefs_forms.php | 4 | ||||
-rw-r--r-- | prefs_manage.php | 2 | ||||
-rw-r--r-- | setup/frames/config.inc.php | 8 | ||||
-rw-r--r-- | setup/frames/index.inc.php | 14 | ||||
-rw-r--r-- | setup/lib/form_processing.lib.php | 4 | ||||
-rw-r--r-- | test/classes/config/PMA_FormDisplay_test.php | 9 | ||||
-rw-r--r-- | test/libraries/PMA_FormDisplay_tpl_test.php | 96 | ||||
-rw-r--r-- | test/libraries/PMA_Form_Processing_test.php | 4 |
10 files changed, 170 insertions, 175 deletions
diff --git a/libraries/config/FormDisplay.class.php b/libraries/config/FormDisplay.class.php index 360fd7790b..81565fe564 100644 --- a/libraries/config/FormDisplay.class.php +++ b/libraries/config/FormDisplay.class.php @@ -213,23 +213,25 @@ class FormDisplay * * @return void */ - public function display($tabbed_form = false, $show_restore_default = false) + public function getDisplay($tabbed_form = false, $show_restore_default = false) { static $js_lang_sent = false; + $htmlOutput = ''; + $js = array(); $js_default = array(); $tabbed_form = $tabbed_form && (count($this->_forms) > 1); $validators = PMA_Validator::getValidators($this->_configFile); - PMA_displayFormTop(); + $htmlOutput .= PMA_displayFormTop(); if ($tabbed_form) { $tabs = array(); foreach ($this->_forms as $form) { $tabs[$form->name] = PMA_lang("Form_$form->name"); } - PMA_displayTabsTop($tabs); + $htmlOutput .= PMA_displayTabsTop($tabs); } // validate only when we aren't displaying a "new server" form @@ -256,7 +258,7 @@ class FormDisplay : ''; $form_errors = isset($this->_errors[$form->name]) ? $this->_errors[$form->name] : null; - PMA_displayFieldsetTop( + $htmlOutput .= PMA_displayFieldsetTop( PMA_lang("Form_$form->name"), $form_desc, $form_errors, @@ -272,7 +274,7 @@ class FormDisplay ? !isset($this->_userprefsDisallow[$path]) : null; // display input - $this->_displayFieldInput( + $htmlOutput .= $this->_displayFieldInput( $form, $field, $path, @@ -287,13 +289,13 @@ class FormDisplay PMA_addJsValidate($translated_path, $validators[$path], $js); } } - PMA_displayFieldsetBottom(); + $htmlOutput .= PMA_displayFieldsetBottom(); } if ($tabbed_form) { - PMA_displayTabsBottom(); + $htmlOutput .= PMA_displayTabsBottom(); } - PMA_displayFormBottom(); + $htmlOutput .= PMA_displayFormBottom(); // if not already done, send strings used for validation to JavaScript if (! $js_lang_sent) { @@ -308,7 +310,9 @@ class FormDisplay $js[] = "$.extend(defaultValues, {\n\t" . implode(",\n\t", $js_default) . '})'; - PMA_displayJavascript($js); + $htmlOutput .= PMA_displayJavascript($js); + + return $htmlOutput; } /** @@ -384,7 +388,7 @@ class FormDisplay case 'group': // :group:end is changed to :group:end:{unique id} in Form class if (/*overload*/mb_substr($field, 7, 4) != 'end:') { - PMA_displayGroupHeader(/*overload*/mb_substr($field, 7)); + echo PMA_displayGroupHeader(/*overload*/mb_substr($field, 7)); } else { PMA_displayGroupFooter(); } @@ -436,7 +440,7 @@ class FormDisplay } $js_default[] = $js_line; - PMA_displayInput( + return PMA_displayInput( $translated_path, $name, $type, $value, $description, $value_is_default, $opts ); @@ -454,6 +458,8 @@ class FormDisplay return; } + $htmlOutput = ''; + foreach ($this->_errors as $system_path => $error_list) { if (isset($this->_systemPaths[$system_path])) { $path = $this->_systemPaths[$system_path]; @@ -461,8 +467,9 @@ class FormDisplay } else { $name = $GLOBALS["strConfigForm_$system_path"]; } - PMA_displayErrors($name, $error_list); + $htmlOutput .= PMA_displayErrors($name, $error_list); } + return $htmlOutput; } /** diff --git a/libraries/config/FormDisplay.tpl.php b/libraries/config/FormDisplay.tpl.php index 451cd675fe..096b6f7e53 100644 --- a/libraries/config/FormDisplay.tpl.php +++ b/libraries/config/FormDisplay.tpl.php @@ -25,18 +25,19 @@ function PMA_displayFormTop($action = null, $method = 'post', $hidden_fields = n if ($method != 'post') { $method = 'get'; } - echo '<form method="' . $method . '" action="' + $htmlOutput = '<form method="' . $method . '" action="' . htmlspecialchars($action) . '" class="config-form disableAjax">'; - echo '<input type="hidden" name="tab_hash" value="" />'; + $htmlOutput .= '<input type="hidden" name="tab_hash" value="" />'; // we do validation on page refresh when browser remembers field values, // add a field with known value which will be used for checks if (! $has_check_page_refresh) { $has_check_page_refresh = true; - echo '<input type="hidden" name="check_page_refresh" ' + $htmlOutput .= '<input type="hidden" name="check_page_refresh" ' . ' id="check_page_refresh" value="" />' . "\n"; } - echo PMA_URL_getHiddenInputs('', '', 0, 'server') . "\n"; - echo PMA_getHiddenFields((array)$hidden_fields); + $htmlOutput .= PMA_URL_getHiddenInputs('', '', 0, 'server') . "\n"; + $htmlOutput .= PMA_getHiddenFields((array)$hidden_fields); + return $htmlOutput; } /** @@ -49,14 +50,15 @@ function PMA_displayFormTop($action = null, $method = 'post', $hidden_fields = n */ function PMA_displayTabsTop($tabs) { - echo '<ul class="tabs">'; + $htmlOutput = '<ul class="tabs">'; foreach ($tabs as $tab_id => $tab_name) { - echo '<li><a href="#' . $tab_id . '">' + $htmlOutput .= '<li><a href="#' . $tab_id . '">' . htmlspecialchars($tab_name) . '</a></li>'; } - echo '</ul>'; - echo '<br clear="right" />'; - echo '<div class="tabs_contents">'; + $htmlOutput .= '</ul>'; + $htmlOutput .= '<br clear="right" />'; + $htmlOutput .= '<div class="tabs_contents">'; + return $htmlOutput; } @@ -82,20 +84,21 @@ function PMA_displayFieldsetTop($title = '', $description = '', $errors = null, $attr = $k . '="' . htmlspecialchars($attr) . '"'; } - echo '<fieldset ' . implode(' ', $attributes) . '>'; - echo '<legend>' . $title . '</legend>'; + $htmlOutput = '<fieldset ' . implode(' ', $attributes) . '>'; + $htmlOutput .= '<legend>' . $title . '</legend>'; if (!empty($description)) { - echo '<p>' . $description . '</p>'; + $htmlOutput .= '<p>' . $description . '</p>'; } // this must match with displayErrors() in scripts.js if (is_array($errors) && count($errors) > 0) { - echo '<dl class="errors">'; + $htmlOutput .= '<dl class="errors">'; foreach ($errors as $error) { - echo '<dd>' . $error . '</dd>'; + $htmlOutput .= '<dd>' . $error . '</dd>'; } - echo '</dl>'; + $htmlOutput .= '</dl>'; } - echo '<table width="100%" cellspacing="0">'; + $htmlOutput .= '<table width="100%" cellspacing="0">'; + return $htmlOutput; } /** @@ -198,56 +201,56 @@ function PMA_displayInput($path, $name, $type, $value, $description = '', } $tr_class = $tr_class ? ' class="' . $tr_class . '"' : ''; - echo '<tr' . $tr_class . '>'; - echo '<th>'; - echo '<label for="' . htmlspecialchars($path) . '">' . $name . '</label>'; + $htmlOutput = '<tr' . $tr_class . '>'; + $htmlOutput .= '<th>'; + $htmlOutput .= '<label for="' . htmlspecialchars($path) . '">' . $name . '</label>'; if (! empty($opts['doc'])) { - echo '<span class="doc">'; - echo '<a href="' . $opts['doc'] + $htmlOutput .= '<span class="doc">'; + $htmlOutput .= '<a href="' . $opts['doc'] . '" target="documentation">' . $icons['help'] . '</a>'; - echo "\n"; - echo '</span>'; + $htmlOutput .= "\n"; + $htmlOutput .= '</span>'; } if ($option_is_disabled) { - echo '<span class="disabled-notice" title="'; - echo __( + $htmlOutput .= '<span class="disabled-notice" title="'; + $htmlOutput .= __( 'This setting is disabled, it will not be applied to your configuration.' ); - echo '">' . __('Disabled') . "</span>"; + $htmlOutput .= '">' . __('Disabled') . "</span>"; } if (!empty($description)) { - echo '<small>' . $description . '</small>'; + $htmlOutput .= '<small>' . $description . '</small>'; } - echo '</th>'; - echo '<td>'; + $htmlOutput .= '</th>'; + $htmlOutput .= '<td>'; switch ($type) { case 'text': - echo '<input type="text" size="60" ' . $name_id . $field_class + $htmlOutput .= '<input type="text" size="60" ' . $name_id . $field_class . ' value="' . htmlspecialchars($value) . '" />'; break; case 'password': - echo '<input type="password" size="60" ' . $name_id . $field_class + $htmlOutput .= '<input type="password" size="60" ' . $name_id . $field_class . ' value="' . htmlspecialchars($value) . '" />'; break; case 'short_text': - echo '<input type="text" size="25" ' . $name_id . $field_class + $htmlOutput .= '<input type="text" size="25" ' . $name_id . $field_class . ' value="' . htmlspecialchars($value) . '" />'; break; case 'number_text': - echo '<input type="number" ' . $name_id . $field_class + $htmlOutput .= '<input type="number" ' . $name_id . $field_class . ' value="' . htmlspecialchars($value) . '" />'; break; case 'checkbox': - echo '<span' . $field_class . '><input type="checkbox" ' . $name_id + $htmlOutput .= '<span' . $field_class . '><input type="checkbox" ' . $name_id . ($value ? ' checked="checked"' : '') . ' /></span>'; break; case 'select': - echo '<select ' . $name_id . $field_class . '>'; + $htmlOutput .= '<select ' . $name_id . $field_class . '>'; $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']); $values_disabled = isset($opts['values_disabled']) ? array_flip($opts['values_disabled']) : array(); @@ -271,19 +274,19 @@ function PMA_displayInput($path, $name, $type, $value, $description = '', $selected = is_bool($value) ? (int) $value === $opt_value_key : $opt_value_key === $value; - echo '<option value="' . $display_value . '"'; + $htmlOutput .= '<option value="' . $display_value . '"'; if ($selected) { - echo ' selected="selected"'; + $htmlOutput .= ' selected="selected"'; } if (isset($values_disabled[$opt_value_key])) { - echo ' disabled="disabled"'; + $htmlOutput .= ' disabled="disabled"'; } - echo '>' . $display . '</option>'; + $htmlOutput .= '>' . $display . '</option>'; } - echo '</select>'; + $htmlOutput .= '</select>'; break; case 'list': - echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>' + $htmlOutput .= '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>' . htmlspecialchars(implode("\n", $value)) . '</textarea>'; break; @@ -293,50 +296,51 @@ function PMA_displayInput($path, $name, $type, $value, $description = '', if (isset($opts['comment_warning']) && $opts['comment_warning']) { $class .= ' field-comment-warning'; } - echo '<span class="' . $class . '" title="' + $htmlOutput .= '<span class="' . $class . '" title="' . htmlspecialchars($opts['comment']) . '">i</span>'; } if ($is_setup_script && isset($opts['userprefs_comment']) && $opts['userprefs_comment'] ) { - echo '<a class="userprefs-comment" title="' + $htmlOutput .= '<a class="userprefs-comment" title="' . htmlspecialchars($opts['userprefs_comment']) . '">' . $icons['tblops'] . '</a>'; } if (isset($opts['setvalue']) && $opts['setvalue']) { - echo '<a class="set-value" href="#' + $htmlOutput .= '<a class="set-value" href="#' . htmlspecialchars("$path={$opts['setvalue']}") . '" title="' . sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue'])) . '" style="display:none">' . $icons['edit'] . '</a>'; } if (isset($opts['show_restore_default']) && $opts['show_restore_default']) { - echo '<a class="restore-default" href="#' . $path . '" title="' + $htmlOutput .= '<a class="restore-default" href="#' . $path . '" title="' . __('Restore default value') . '" style="display:none">' . $icons['reload'] . '</a>'; } // this must match with displayErrors() in scripts/config.js if ($has_errors) { - echo "\n <dl class=\"inline_errors\">"; + $htmlOutput .= "\n <dl class=\"inline_errors\">"; foreach ($opts['errors'] as $error) { - echo '<dd>' . htmlspecialchars($error) . '</dd>'; + $htmlOutput .= '<dd>' . htmlspecialchars($error) . '</dd>'; } - echo '</dl>'; + $htmlOutput .= '</dl>'; } - echo '</td>'; + $htmlOutput .= '</td>'; if ($is_setup_script && isset($opts['userprefs_allow'])) { - echo '<td class="userprefs-allow" title="' . + $htmlOutput .= '<td class="userprefs-allow" title="' . __('Allow users to customize this value') . '">'; - echo '<input type="checkbox" name="' . $path . '-userprefs-allow" '; + $htmlOutput .= '<input type="checkbox" name="' . $path . '-userprefs-allow" '; if ($opts['userprefs_allow']) { - echo 'checked="checked"'; + $htmlOutput .= 'checked="checked"'; }; - echo '/>'; - echo '</td>'; + $htmlOutput .= '/>'; + $htmlOutput .= '</td>'; } else if ($is_setup_script) { - echo '<td> </td>'; + $htmlOutput .= '<td> </td>'; } - echo '</tr>'; + $htmlOutput .= '</tr>'; + return $htmlOutput; } /** @@ -357,11 +361,12 @@ function PMA_displayGroupHeader($header_text) $colspan = defined('PMA_SETUP') ? 3 : 2; - echo '<tr class="group-header group-header-' . $_FormDisplayGroup . '">'; - echo '<th colspan="' . $colspan . '">'; - echo $header_text; - echo '</th>'; - echo '</tr>'; + $htmlOutput = '<tr class="group-header group-header-' . $_FormDisplayGroup . '">'; + $htmlOutput .= '<th colspan="' . $colspan . '">'; + $htmlOutput .= $header_text; + $htmlOutput .= '</th>'; + $htmlOutput .= '</tr>'; + return $htmlOutput; } /** @@ -387,16 +392,17 @@ function PMA_displayFieldsetBottom() if (defined('PMA_SETUP')) { $colspan++; } - echo '<tr>'; - echo '<td colspan="' . $colspan . '" class="lastrow">'; - echo '<input type="submit" name="submit_save" value="' + $htmlOutput = '<tr>'; + $htmlOutput .= '<td colspan="' . $colspan . '" class="lastrow">'; + $htmlOutput .= '<input type="submit" name="submit_save" value="' . __('Apply') . '" class="green" />'; - echo '<input type="button" name="submit_reset" value="' + $htmlOutput .= '<input type="button" name="submit_reset" value="' . __('Reset') . '" />'; - echo '</td>'; - echo '</tr>'; - echo '</table>'; - echo '</fieldset>'; + $htmlOutput .= '</td>'; + $htmlOutput .= '</tr>'; + $htmlOutput .= '</table>'; + $htmlOutput .= '</fieldset>'; + return $htmlOutput; } /** @@ -406,8 +412,9 @@ function PMA_displayFieldsetBottom() */ function PMA_displayFieldsetBottomSimple() { - echo '</table>'; - echo '</fieldset>'; + $htmlOutput = '</table>'; + $htmlOutput .= '</fieldset>'; + return $htmlOutput; } /** @@ -417,7 +424,8 @@ function PMA_displayFieldsetBottomSimple() */ function PMA_displayTabsBottom() { - echo "</div>\n"; + $htmlOutput = "</div>\n"; + return $htmlOutput; } /** @@ -427,7 +435,8 @@ function PMA_displayTabsBottom() */ function PMA_displayFormBottom() { - echo "</form>\n"; + $htmlOutput = "</form>\n"; + return $htmlOutput; } /** @@ -466,9 +475,10 @@ function PMA_displayJavascript($js_array) if (empty($js_array)) { return; } - echo '<script type="text/javascript">' . "\n"; - echo implode(";\n", $js_array) . ";\n"; - echo '</script>' . "\n"; + $htmlOutput = '<script type="text/javascript">' . "\n"; + $htmlOutput .= implode(";\n", $js_array) . ";\n"; + $htmlOutput .= '</script>' . "\n"; + return $htmlOutput; } /** @@ -481,11 +491,12 @@ function PMA_displayJavascript($js_array) */ function PMA_displayErrors($name, $error_list) { - echo '<dl>'; - echo '<dt>' . htmlspecialchars($name) . '</dt>'; + $htmlOutput = '<dl>'; + $htmlOutput .= '<dt>' . htmlspecialchars($name) . '</dt>'; foreach ($error_list as $error) { - echo '<dd>' . htmlspecialchars($error) . '</dd>'; + $htmlOutput .= '<dd>' . htmlspecialchars($error) . '</dd>'; } - echo '</dl>'; + $htmlOutput .= '</dl>'; + return $htmlOutput; } ?> diff --git a/prefs_forms.php b/prefs_forms.php index 1833d9dc27..2167dc54eb 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -84,8 +84,8 @@ if ($form_display->hasErrors()) { ?> <div class="error config-form"> <b><?php echo __('Cannot save settings, submitted form contains errors!') ?></b> - <?php $form_display->displayErrors(); ?> + <?php echo $form_display->displayErrors(); ?> </div> <?php } -$form_display->display(true, true); +echo $form_display->getDisplay(true, true); diff --git a/prefs_manage.php b/prefs_manage.php index 778eecceb4..9bc28dd9cf 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -115,7 +115,7 @@ if (isset($_POST['submit_export']) ); $msg->display(); echo '<div class="config-form">'; - $form_display->displayErrors(); + echo $form_display->displayErrors(); echo '</div>'; echo '<form action="prefs_manage.php" method="post">'; echo PMA_URL_getHiddenInputs() . "\n"; diff --git a/setup/frames/config.inc.php b/setup/frames/config.inc.php index f265160989..04778a04b8 100644 --- a/setup/frames/config.inc.php +++ b/setup/frames/config.inc.php @@ -23,10 +23,10 @@ $config_exists = false; PMA_checkConfigRw($config_readable, $config_writable, $config_exists); echo '<h2>' . __('Configuration file') . '</h2>'; -PMA_displayFormTop('config.php'); +echo PMA_displayFormTop('config.php'); echo '<input type="hidden" name="eol" value="' . htmlspecialchars(PMA_ifSetOr($_GET['eol'], 'unix')) . '" />'; -PMA_displayFieldsetTop('config.inc.php', '', null, array('class' => 'simple')); +echo PMA_displayFieldsetTop('config.inc.php', '', null, array('class' => 'simple')); echo '<tr>'; echo '<td>'; echo '<textarea cols="50" rows="20" name="textconfig" ' @@ -47,6 +47,6 @@ echo '/>'; echo '</td>'; echo '</tr>'; -PMA_displayFieldsetBottomSimple(); -PMA_displayFormBottom(); +echo PMA_displayFieldsetBottomSimple(); +echo PMA_displayFormBottom(); ?> diff --git a/setup/frames/index.inc.php b/setup/frames/index.inc.php index 2c341ec2c9..a07f57ba9d 100644 --- a/setup/frames/index.inc.php +++ b/setup/frames/index.inc.php @@ -147,7 +147,7 @@ echo '</legend>'; // // Display server list // -PMA_displayFormTop( +echo PMA_displayFormTop( 'index.php', 'get', array( 'page' => 'servers', @@ -205,7 +205,7 @@ echo '</tr>'; echo '</table>'; echo '</div>'; -PMA_displayFormBottom(); +echo PMA_displayFormBottom(); echo '</fieldset>'; @@ -216,7 +216,7 @@ echo '<fieldset class="simple"><legend>' . __('Configuration file') . '</legend> // $form_display = new FormDisplay($cf); -PMA_displayFormTop('config.php'); +echo PMA_displayFormTop('config.php'); echo '<table width="100%" cellspacing="0">'; // Display language list @@ -228,7 +228,7 @@ foreach ($all_languages as $each_lang_key => $each_lang) { $lang_name = PMA_languageName($each_lang); $opts['values'][$each_lang_key] = $lang_name; } -PMA_displayInput( +echo PMA_displayInput( 'DefaultLang', __('Default language'), 'select', $cf->getValue('DefaultLang'), '', true, $opts ); @@ -253,7 +253,7 @@ if ($cf->getServerCount() > 0) { $opts['values']['1'] = __('- none -'); $opts['values_escaped'] = true; } -PMA_displayInput( +echo PMA_displayInput( 'ServerDefault', __('Default server'), 'select', $cf->getValue('ServerDefault'), '', true, $opts ); @@ -265,7 +265,7 @@ $opts = array( 'win' => 'Windows (\r\n)'), 'values_escaped' => true); $eol = PMA_ifSetOr($_SESSION['eol'], (PMA_IS_WINDOWS ? 'win' : 'unix')); -PMA_displayInput( +echo PMA_displayInput( 'eol', __('End of line'), 'select', $eol, '', true, $opts ); @@ -301,7 +301,7 @@ echo '</td>'; echo '</tr>'; echo '</table>'; -PMA_displayFormBottom(); +echo PMA_displayFormBottom(); echo '</fieldset>'; echo '<div id="footer">'; diff --git a/setup/lib/form_processing.lib.php b/setup/lib/form_processing.lib.php index d8eadf6610..5a65588021 100644 --- a/setup/lib/form_processing.lib.php +++ b/setup/lib/form_processing.lib.php @@ -23,7 +23,7 @@ function PMA_Process_formset(FormDisplay $form_display) if (!$form_display->process(false)) { // handle form view and failed POST - $form_display->display(true, true); + echo $form_display->getDisplay(true, true); return; } @@ -52,7 +52,7 @@ function PMA_Process_formset(FormDisplay $form_display) <?php echo __('Try to revert erroneous fields to their default values') ?> </a> </div> - <?php $form_display->displayErrors() ?> + <?php echo $form_display->displayErrors() ?> <a class="btn" href="index.php<?php echo PMA_URL_getCommon() ?>"> <?php echo __('Ignore errors') ?> </a> diff --git a/test/classes/config/PMA_FormDisplay_test.php b/test/classes/config/PMA_FormDisplay_test.php index 67bd2bd70e..a49a780020 100644 --- a/test/classes/config/PMA_FormDisplay_test.php +++ b/test/classes/config/PMA_FormDisplay_test.php @@ -190,13 +190,14 @@ class PMA_FormDisplay_Test extends PHPUnit_Framework_TestCase $GLOBALS['strConfigForm_foobar'] = 'foobar123'; - $this->expectOutputString( + $result = $this->object->displayErrors(); + + $this->assertEquals( '<dl><dt>Servers_test2_name</dt>' . '<dd>e1</dd></dl><dl><dt>foobar123</dt><dd>' . - 'e2</dd><dd>e3</dd></dl>' + 'e2</dd><dd>e3</dd></dl>', + $result ); - - $this->object->displayErrors(); } /** diff --git a/test/libraries/PMA_FormDisplay_tpl_test.php b/test/libraries/PMA_FormDisplay_tpl_test.php index 4318a34447..9d071449af 100644 --- a/test/libraries/PMA_FormDisplay_tpl_test.php +++ b/test/libraries/PMA_FormDisplay_tpl_test.php @@ -33,9 +33,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase { $_SERVER['REQUEST_URI'] = 'http://www.phpmyadmin.net'; $GLOBALS['cfg']['ServerDefault'] = ''; - ob_start(); - PMA_displayFormTop(null, 'posted', array(1)); - $result = ob_get_clean(); + $result = PMA_displayFormTop(null, 'posted', array(1)); $this->assertContains( '<form method="get" action="http://www.phpmyadmin.net" ' . @@ -77,9 +75,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase */ public function testDisplayTabsTop() { - ob_start(); - PMA_displayTabsTop(array('one', 'two')); - $result = ob_get_clean(); + $result = PMA_displayTabsTop(array('one', 'two')); $this->assertContains( '<ul class="tabs">', @@ -112,9 +108,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase $attributes = array('name' => 'attrname'); $errors = array('e1', 'e2'); - ob_start(); - PMA_displayFieldsetTop("TitleTest", "DescTest", $errors, $attributes); - $result = ob_get_clean(); + $result = PMA_displayFieldsetTop("TitleTest", "DescTest", $errors, $attributes); $this->assertContains( '<fieldset class="optbox" name="attrname">', @@ -169,12 +163,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase $opts['comment'] = "testComment"; $opts['comment_warning'] = true; $opts['show_restore_default'] = true; - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'text', 'val', 'desc', false, $opts ); - $result = ob_get_clean(); $this->assertContains( '<tr class="group-header-field group-header-1 disabled-field">', @@ -242,12 +234,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase $opts['userprefs_comment'] = 'userprefsComment'; $opts['userprefs_allow'] = true; - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'checkbox', 'val', '', false, $opts ); - $result = ob_get_clean(); $this->assertContains( '<tr class="group-field group-field-1">', @@ -283,12 +273,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase $opts = array(); $opts['errors'] = array(); - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'short_text', 'val', '', true, $opts ); - $result = ob_get_clean(); $this->assertContains( '<input type="text" size="25" name="test/path" id="test/path" ' . @@ -297,12 +285,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase ); // number_text - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'number_text', 'val', '', true, $opts ); - $result = ob_get_clean(); $this->assertContains( '<input type="number" name="test/path" ' . @@ -318,12 +304,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase 'key1' => true, 'key2' => false, ); - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'select', true, '', true, $opts ); - $result = ob_get_clean(); $this->assertContains( '<select name="test/path" id="test/path">', $result @@ -352,12 +336,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase 'key1' => true, 'key2' => false, ); - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'select', false, '', true, $opts ); - $result = ob_get_clean(); $this->assertContains( '<select name="test/path" id="test/path">', @@ -371,13 +353,10 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase ); // list - - ob_start(); - PMA_displayInput( + $result = PMA_displayInput( 'test/path', 'testName', 'list', array('foo', 'bar'), '', true, $opts ); - $result = ob_get_clean(); $this->assertContains( '<textarea cols="40" rows="5" name="test/path" id="test/path">', @@ -407,9 +386,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase define('PMA_SETUP', true); } - ob_start(); - PMA_displayGroupHeader('headerText'); - $result = ob_get_clean(); + $result = PMA_displayGroupHeader('headerText'); $this->assertContains( '<tr class="group-header group-header-4">', @@ -421,9 +398,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase runkit_constant_remove('PMA_SETUP'); $GLOBALS['_FormDisplayGroup'] = 3; - ob_start(); - PMA_displayGroupHeader('headerText'); - $result = ob_get_clean(); + $result = PMA_displayGroupHeader('headerText'); $this->assertContains( '<tr class="group-header group-header-4">', @@ -464,9 +439,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase define('PMA_SETUP', true); } - ob_start(); - PMA_displayFieldsetBottom(); - $result = ob_get_clean(); + $result = PMA_displayFieldsetBottom(); $this->assertContains( '<td colspan="3" class="lastrow">', @@ -492,9 +465,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase runkit_constant_remove('PMA_SETUP'); - ob_start(); - PMA_displayFieldsetBottom(); - $result = ob_get_clean(); + $result = PMA_displayFieldsetBottom(); $this->assertContains( '<td colspan="2" class="lastrow">', @@ -509,10 +480,11 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase */ public function testDisplayFieldsetBottomSimple() { - $this->expectOutputString( - '</table></fieldset>' + $result = PMA_displayFieldsetBottomSimple(); + $this->assertEquals( + '</table></fieldset>', + $result ); - PMA_displayFieldsetBottomSimple(); } /** @@ -522,10 +494,11 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase */ public function testDisplayTabsBottom() { - $this->expectOutputString( - "</div>\n" + $result = PMA_displayTabsBottom(); + $this->assertEquals( + "</div>\n", + $result ); - PMA_displayTabsBottom(); } /** @@ -535,10 +508,11 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase */ public function testDisplayFormBottom() { - $this->expectOutputString( - "</form>\n" + $result = PMA_displayFormBottom(); + $this->assertEquals( + "</form>\n", + $result ); - PMA_displayFormBottom(); } /** @@ -579,14 +553,15 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase PMA_displayJavascript(array()) ); - $this->expectOutputString( + $result = PMA_displayJavascript(array('var i = 1', 'i++')); + + $this->assertEquals( "<script type=\"text/javascript\">\n" . "var i = 1;\n" . "i++;\n" . - "</script>\n" + "</script>\n", + $result ); - - PMA_displayJavascript(array('var i = 1', 'i++')); } /** @@ -598,13 +573,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase { $errors = array('<err1>', '&err2'); - $this->expectOutputString( + $result = PMA_displayErrors('err"Name1"', $errors); + + $this->assertEquals( '<dl><dt>err"Name1"</dt>' . - '<dd><err1></dd><dd>&err2</dd></dl>' + '<dd><err1></dd><dd>&err2</dd></dl>', + $result ); - PMA_displayErrors('err"Name1"', $errors); - } } ?> diff --git a/test/libraries/PMA_Form_Processing_test.php b/test/libraries/PMA_Form_Processing_test.php index 6448c3a108..333e529944 100644 --- a/test/libraries/PMA_Form_Processing_test.php +++ b/test/libraries/PMA_Form_Processing_test.php @@ -38,7 +38,7 @@ class PMA_From_Processing_Test extends PHPUnit_Framework_TestCase // case 1 $formDisplay = $this->getMockBuilder('FormDisplay') ->disableOriginalConstructor() - ->setMethods(array('process', 'display')) + ->setMethods(array('process', 'getDisplay')) ->getMock(); $formDisplay->expects($this->once()) @@ -47,7 +47,7 @@ class PMA_From_Processing_Test extends PHPUnit_Framework_TestCase ->will($this->returnValue(false)); $formDisplay->expects($this->once()) - ->method('display') + ->method('getDisplay') ->with(true, true); PMA_Process_formset($formDisplay); |