/** * Test for FormDisplay::fixErrors * * @return void */ public function testFixErrors() { $reflection = new \ReflectionClass('PMA\\libraries\\config\\FormDisplay'); $attrIsValidated = $reflection->getProperty('_isValidated'); $attrIsValidated->setAccessible(true); $attrIsValidated->setValue($this->object, true); $attrIsValidated = $reflection->getProperty('_errors'); $attrIsValidated->setAccessible(true); $attrIsValidated->setValue($this->object, array()); $this->assertNull($this->object->fixErrors()); $arr = array("Servers/1/test" => array('e1'), "Servers/2/test" => array('e2', 'e3'), "Servers/3/test" => array()); $sysArr = array("Servers/1/test" => "Servers/1/connect_type"); $attrSystemPaths = $reflection->getProperty('_systemPaths'); $attrSystemPaths->setAccessible(true); $attrSystemPaths->setValue($this->object, $sysArr); $attrIsValidated->setValue($this->object, $arr); $this->object->fixErrors(); $this->assertEquals(array('Servers' => array('1' => array('test' => 'tcp'))), $_SESSION['ConfigFile0']); }
} $new_config = $cf->getFlatDefaultConfig(); if (!empty($_POST['import_merge'])) { $new_config = array_merge($new_config, $cf->getConfigArray()); } $new_config = array_merge($new_config, $config); $_POST_bak = $_POST; foreach ($new_config as $k => $v) { $_POST[str_replace('/', '-', $k)] = $v; } $cf->resetConfigData(); $all_ok = $form_display->process(true, false); $all_ok = $all_ok && !$form_display->hasErrors(); $_POST = $_POST_bak; if (!$all_ok && isset($_POST['fix_errors'])) { $form_display->fixErrors(); $all_ok = true; } if (!$all_ok) { // mimic original form and post json in a hidden field include 'libraries/user_preferences.inc.php'; $msg = Message::error(__('Configuration contains incorrect data for some fields.')); $msg->display(); echo '<div class="config-form">'; echo $form_display->displayErrors(); echo '</div>'; echo '<form action="prefs_manage.php" method="post">'; echo PMA_URL_getHiddenInputs(), "\n"; echo '<input type="hidden" name="json" value="', htmlspecialchars($json), '" />'; echo '<input type="hidden" name="fix_errors" value="1" />'; if (!empty($_POST['import_merge'])) {
/** * Processes forms registered in $form_display, handles error correction * * @param FormDisplay $form_display Form to display * * @return void */ function PMA_Process_formset(FormDisplay $form_display) { if (isset($_GET['mode']) && $_GET['mode'] == 'revert') { // revert erroneous fields to their default values $form_display->fixErrors(); PMA_generateHeader303(); } if (!$form_display->process(false)) { // handle form view and failed POST echo $form_display->getDisplay(true, true); return; } // check for form errors if (!$form_display->hasErrors()) { PMA_generateHeader303(); return; } // form has errors, show warning $separator = PMA_URL_getArgSeparator('html'); $page = isset($_GET['page']) ? $_GET['page'] : null; $formset = isset($_GET['formset']) ? $_GET['formset'] : null; $formset = $formset ? "{$separator}formset={$formset}" : ''; $formId = PMA_isValid($_GET['id'], 'numeric') ? $_GET['id'] : null; if ($formId === null && $page == 'servers') { // we've just added a new server, get its id $formId = $form_display->getConfigFile()->getServerCount(); } $formId = $formId ? "{$separator}id={$formId}" : ''; ?> <div class="error"> <h4><?php echo __('Warning'); ?> </h4> <?php echo __('Submitted form contains errors'); ?> <br /> <a href="<?php echo PMA_URL_getCommon(), $separator; ?> page=<?php echo $page, $formset, $formId, $separator; ?> mode=revert"> <?php echo __('Try to revert erroneous fields to their default values'); ?> </a> </div> <?php echo $form_display->displayErrors(); ?> <a class="btn" href="index.php<?php echo PMA_URL_getCommon(); ?> "> <?php echo __('Ignore errors'); ?> </a> <a class="btn" href="<?php echo PMA_URL_getCommon() . $separator; ?> page=<?php echo $page . $formset . $formId . $separator; ?> mode=edit"> <?php echo __('Show form'); ?> </a> <?php }