From b68b570773c97211a9343515aa7e4f4ea22bffe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 14 Sep 2017 14:34:01 -0300 Subject: [PATCH] Refactor setup/form_processing to static methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- setup/frames/form.inc.php | 8 +- setup/frames/servers.inc.php | 8 +- setup/lib/FormProcessing.php | 77 +++++++++++++++++++ setup/lib/form_processing.lib.php | 67 ---------------- .../Setup/FormProcessingTest.php} | 17 ++-- 5 files changed, 87 insertions(+), 90 deletions(-) create mode 100644 setup/lib/FormProcessing.php delete mode 100644 setup/lib/form_processing.lib.php rename test/{libraries/PMA_Form_Processing_test.php => classes/Setup/FormProcessingTest.php} (91%) diff --git a/setup/frames/form.inc.php b/setup/frames/form.inc.php index 91535983666b..f2ea6d202e8e 100644 --- a/setup/frames/form.inc.php +++ b/setup/frames/form.inc.php @@ -8,16 +8,12 @@ use PhpMyAdmin\Config\Forms\Setup\SetupFormList; use PhpMyAdmin\Core; +use PhpMyAdmin\Setup\FormProcessing; if (!defined('PHPMYADMIN')) { exit; } -/** - * Core libraries. - */ -require_once './setup/lib/form_processing.lib.php'; - $formset_id = Core::isValid($_GET['formset'], 'scalar') ? $_GET['formset'] : null; $mode = isset($_GET['mode']) ? $_GET['mode'] : null; $form_class = SetupFormList::get($formset_id); @@ -26,4 +22,4 @@ } echo '

' , $form_class::getName() , '

'; $form_display = new $form_class($GLOBALS['ConfigFile']); -PMA_Process_formset($form_display); +FormProcessing::process($form_display); diff --git a/setup/frames/servers.inc.php b/setup/frames/servers.inc.php index dd31c4661b1b..1cb690a077de 100644 --- a/setup/frames/servers.inc.php +++ b/setup/frames/servers.inc.php @@ -9,17 +9,13 @@ use PhpMyAdmin\Config\ConfigFile; use PhpMyAdmin\Config\Forms\Setup\ServersForm; use PhpMyAdmin\Core; +use PhpMyAdmin\Setup\FormProcessing; use PhpMyAdmin\Url; if (!defined('PHPMYADMIN')) { exit; } -/** - * Core libraries. - */ -require_once './setup/lib/form_processing.lib.php'; - $mode = isset($_GET['mode']) ? $_GET['mode'] : null; $id = Core::isValid($_GET['id'], 'numeric') ? intval($_GET['id']) : null; @@ -45,4 +41,4 @@ echo '

' , $page_title . '

'; } $form_display = new ServersForm($cf, $id); -PMA_Process_formset($form_display); +FormProcessing::process($form_display); diff --git a/setup/lib/FormProcessing.php b/setup/lib/FormProcessing.php new file mode 100644 index 000000000000..35aaf4c4c654 --- /dev/null +++ b/setup/lib/FormProcessing.php @@ -0,0 +1,77 @@ +fixErrors(); + $response = Response::getInstance(); + $response->generateHeader303('index.php' . Url::getCommonRaw()); + } + + 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()) { + $response = Response::getInstance(); + $response->generateHeader303('index.php' . Url::getCommonRaw()); + return; + } + + // form has errors, show warning + $page = isset($_GET['page']) ? $_GET['page'] : ''; + $formset = isset($_GET['formset']) ? $_GET['formset'] : ''; + $formId = Core::isValid($_GET['id'], 'numeric') ? $_GET['id'] : ''; + if ($formId === null && $page == 'servers') { + // we've just added a new server, get its id + $formId = $form_display->getConfigFile()->getServerCount(); + } + ?> +
+

+
+ + + +
+ displayErrors() ?> + + + +   + + + + fixErrors(); - $response = Response::getInstance(); - $response->generateHeader303('index.php' . Url::getCommonRaw()); - } - - 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()) { - $response = Response::getInstance(); - $response->generateHeader303('index.php' . Url::getCommonRaw()); - return; - } - - // form has errors, show warning - $page = isset($_GET['page']) ? $_GET['page'] : ''; - $formset = isset($_GET['formset']) ? $_GET['formset'] : ''; - $formId = Core::isValid($_GET['id'], 'numeric') ? $_GET['id'] : ''; - if ($formId === null && $page == 'servers') { - // we've just added a new server, get its id - $formId = $form_display->getConfigFile()->getServerCount(); - } - ?> -
-

-
- - - -
- displayErrors() ?> - - - -   - - - - method('getDisplay') ->with(true, true); - PMA_Process_formset($formDisplay); + FormProcessing::process($formDisplay); // case 2 $formDisplay = $this->getMockBuilder('PhpMyAdmin\Config\FormDisplay') @@ -79,7 +76,7 @@ public function testProcessFormSet() ->will($this->returnValue(true)); ob_start(); - PMA_Process_formset($formDisplay); + FormProcessing::process($formDisplay); $result = ob_get_clean(); $this->assertContains( @@ -118,8 +115,6 @@ public function testProcessFormSet() ->with() ->will($this->returnValue(false)); - PMA_Process_formset($formDisplay); - + FormProcessing::process($formDisplay); } - }