Refactor Config/FormDisplayTemplate

Replaces $GLOBALS['PMA_Config'] with DI

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2018-06-06 15:47:00 -03:00
parent 8cad698ead
commit f24545e633
5 changed files with 36 additions and 19 deletions

View File

@ -102,7 +102,7 @@ class FormDisplay
*/
public function __construct(ConfigFile $cf)
{
$this->formDisplayTemplate = new FormDisplayTemplate();
$this->formDisplayTemplate = new FormDisplayTemplate($GLOBALS['PMA_Config']);
$this->_jsLangStrings = [
'error_nan_p' => __('Not a positive number!'),
'error_nan_nneg' => __('Not a non-negative number!'),

View File

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Config;
use PhpMyAdmin\Config;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
@ -26,6 +27,21 @@ class FormDisplayTemplate
*/
public $group;
/**
* @var Config
*/
protected $config;
/**
* FormDisplayTemplate constructor.
*
* @param Config $config
*/
public function __construct(Config $config)
{
$this->config = $config;
}
/**
* Displays top part of the form
*
@ -165,7 +181,7 @@ class FormDisplayTemplate
$icons = null;
}
$isSetupScript = $GLOBALS['PMA_Config']->get('is_setup');
$isSetupScript = $this->config->get('is_setup');
if ($icons === null) { // if the static variables have not been initialised
$icons = [];
// Icon definitions:
@ -389,7 +405,7 @@ class FormDisplayTemplate
if ($headerText === '') {
return '';
}
$colspan = $GLOBALS['PMA_Config']->get('is_setup') ? 3 : 2;
$colspan = $this->config->get('is_setup') ? 3 : 2;
return Template::get('config/form_display/group_header')->render([
'group' => $this->group,
@ -419,7 +435,7 @@ class FormDisplayTemplate
{
return Template::get('config/form_display/fieldset_bottom')->render([
'show_buttons' => $showButtons,
'is_setup' => $GLOBALS['PMA_Config']->get('is_setup'),
'is_setup' => $this->config->get('is_setup'),
]);
}

View File

@ -15,7 +15,7 @@ if (!defined('PHPMYADMIN')) {
exit;
}
$formDisplayTemplate = new FormDisplayTemplate();
$formDisplayTemplate = new FormDisplayTemplate($GLOBALS['PMA_Config']);
echo '<h2>' , __('Configuration file') , '</h2>';

View File

@ -43,7 +43,7 @@ if (isset($_GET['version_check'])) {
$configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
$configChecker->performConfigChecks();
$formDisplayTemplate = new FormDisplayTemplate();
$formDisplayTemplate = new FormDisplayTemplate($GLOBALS['PMA_Config']);
//
// Https connection warning (check done on the client side)

View File

@ -1,7 +1,7 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for FromDisplay.tpl.php
* tests for FormDisplayTemplate
*
* @package PhpMyAdmin-test
*/
@ -11,11 +11,10 @@ namespace PhpMyAdmin\Tests\Config;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\FormDisplayTemplate;
use PhpMyAdmin\Theme;
use PHPUnit\Framework\TestCase;
/**
* Tests for FromDisplay.tpl.php
* Tests for FormDisplayTemplate
*
* @package PhpMyAdmin-test
*/
@ -26,6 +25,11 @@ class FormDisplayTemplateTest extends TestCase
*/
protected $formDisplayTemplate;
/**
* @var Config
*/
protected $config;
/**
* Setup tests
*
@ -33,8 +37,8 @@ class FormDisplayTemplateTest extends TestCase
*/
protected function setUp()
{
$this->formDisplayTemplate = new FormDisplayTemplate();
$GLOBALS['PMA_Config'] = new Config();
$this->config = new Config();
$this->formDisplayTemplate = new FormDisplayTemplate($this->config);
}
/**
@ -155,7 +159,6 @@ class FormDisplayTemplateTest extends TestCase
*/
public function testDisplayInput()
{
$GLOBALS['_FormDislayGroup'] = 1;
$opts = [];
$opts['errors'] = ['e1'];
$opts['userprefs_allow'] = false;
@ -229,8 +232,7 @@ class FormDisplayTemplateTest extends TestCase
// second case
$GLOBALS['PMA_Config']->set('is_setup', true);
$GLOBALS['_FormDislayGroup'] = 0;
$this->config->set('is_setup', true);
$opts = [];
$opts['errors'] = [];
$opts['setvalue'] = 'setVal';
@ -278,7 +280,6 @@ class FormDisplayTemplateTest extends TestCase
);
// short_text
$GLOBALS['_FormDislayGroup'] = 0;
$opts = [];
$opts['errors'] = [];
@ -412,7 +413,7 @@ class FormDisplayTemplateTest extends TestCase
$this->formDisplayTemplate->group = 3;
$GLOBALS['PMA_Config']->set('is_setup', true);
$this->config->set('is_setup', true);
$result = $this->formDisplayTemplate->displayGroupHeader('headerText');
@ -422,7 +423,7 @@ class FormDisplayTemplateTest extends TestCase
);
// without PMA_SETUP
$GLOBALS['PMA_Config']->set('is_setup', false);
$this->config->set('is_setup', false);
$this->formDisplayTemplate->group = 3;
@ -457,7 +458,7 @@ class FormDisplayTemplateTest extends TestCase
public function testDisplayFieldsetBottom()
{
// with PMA_SETUP
$GLOBALS['PMA_Config']->set('is_setup', true);
$this->config->set('is_setup', true);
$result = $this->formDisplayTemplate->displayFieldsetBottom();
@ -482,7 +483,7 @@ class FormDisplayTemplateTest extends TestCase
);
// without PMA_SETUP
$GLOBALS['PMA_Config']->set('is_setup', false);
$this->config->set('is_setup', false);
$result = $this->formDisplayTemplate->displayFieldsetBottom();