* Core libraries. */ require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; require './libraries/config/setup.forms.php'; $mode = filter_input(INPUT_GET, 'mode'); $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); $cf = ConfigFile::getInstance(); $server_exists = !empty($id) && $cf->get("Servers/{$id}") !== null; if ($mode == 'edit' && $server_exists) { $page_title = __('Edit server') . ' ' . $id . ' <small>(' . htmlspecialchars($cf->getServerDSN($id)) . ')</small>'; } elseif ($mode == 'remove' && $server_exists) { $cf->removeServer($id); header('Location: index.php'); exit; } elseif ($mode == 'revert' && $server_exists) { // handled by process_formset() } else { $page_title = __('Add a new server'); $id = 0; } if (isset($page_title)) { echo '<h2>' . $page_title . '</h2>'; } $form_display = new FormDisplay(); foreach ($forms['Servers'] as $form_name => $form) { $form_display->registerForm($form_name, $form, $id); } process_formset($form_display);
/** * Test for process_formset() * * @return void */ public function testProcessFormSet() { if (!defined('PMA_TEST_HEADERS')) { $this->markTestSkipped( 'Cannot redefine constant/function - missing runkit extension' ); } // case 1 $formDisplay = $this->getMockBuilder('FormDisplay') ->disableOriginalConstructor() ->setMethods(array('process', 'display')) ->getMock(); $formDisplay->expects($this->once()) ->method('process') ->with(false) ->will($this->returnValue(false)); $formDisplay->expects($this->once()) ->method('display') ->with(true, true); process_formset($formDisplay); // case 2 $formDisplay = $this->getMockBuilder('FormDisplay') ->disableOriginalConstructor() ->setMethods(array('process', 'hasErrors', 'displayErrors')) ->getMock(); $formDisplay->expects($this->once()) ->method('process') ->with(false) ->will($this->returnValue(true)); $formDisplay->expects($this->once()) ->method('hasErrors') ->with() ->will($this->returnValue(true)); ob_start(); process_formset($formDisplay); $result = ob_get_clean(); $this->assertContains( '<div class="error">', $result ); $this->assertContains( '<a href="?page=&mode=revert">', $result ); $this->assertContains( '<a class="btn" href="index.php">', $result ); $this->assertContains( '<a class="btn" href="?page=&mode=edit">', $result ); // case 3 $formDisplay = $this->getMockBuilder('FormDisplay') ->disableOriginalConstructor() ->setMethods(array('process', 'hasErrors')) ->getMock(); $formDisplay->expects($this->once()) ->method('process') ->with(false) ->will($this->returnValue(true)); $formDisplay->expects($this->once()) ->method('hasErrors') ->with() ->will($this->returnValue(false)); process_formset($formDisplay); $this->assertEquals( array('HTTP/1.1 303 See Other', 'Location: index.php'), $GLOBALS['header'] ); }