Replace static methods with instance methods
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
abf2e115e7
commit
92beb1a4f4
@ -13,16 +13,18 @@ require_once 'libraries/common.inc.php';
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
$designer = new Designer();
|
||||
|
||||
if (isset($_REQUEST['dialog'])) {
|
||||
|
||||
if ($_REQUEST['dialog'] == 'edit') {
|
||||
$html = Designer::getHtmlForEditOrDeletePages($GLOBALS['db'], 'editPage');
|
||||
$html = $designer->getHtmlForEditOrDeletePages($GLOBALS['db'], 'editPage');
|
||||
} elseif ($_REQUEST['dialog'] == 'delete') {
|
||||
$html = Designer::getHtmlForEditOrDeletePages($GLOBALS['db'], 'deletePage');
|
||||
$html = $designer->getHtmlForEditOrDeletePages($GLOBALS['db'], 'deletePage');
|
||||
} elseif ($_REQUEST['dialog'] == 'save_as') {
|
||||
$html = Designer::getHtmlForPageSaveAs($GLOBALS['db']);
|
||||
$html = $designer->getHtmlForPageSaveAs($GLOBALS['db']);
|
||||
} elseif ($_REQUEST['dialog'] == 'export') {
|
||||
$html = Designer::getHtmlForSchemaExport(
|
||||
$html = $designer->getHtmlForSchemaExport(
|
||||
$GLOBALS['db'], $_REQUEST['selected_page']
|
||||
);
|
||||
} elseif ($_REQUEST['dialog'] == 'add_table') {
|
||||
@ -41,7 +43,7 @@ if (isset($_REQUEST['dialog'])) {
|
||||
$GLOBALS['PMD']['TABLE_TYPE'] = array($GLOBALS['PMD_URL']['TABLE_TYPE'][$req_key]);
|
||||
$GLOBALS['PMD_OUT']['OWNER'] = array($GLOBALS['PMD_OUT']['OWNER'][$req_key]);
|
||||
|
||||
$html = Designer::getDatabaseTables(
|
||||
$html = $designer->getDatabaseTables(
|
||||
array(), -1, $tab_column,
|
||||
$tables_all_keys, $tables_pk_or_unique_keys
|
||||
);
|
||||
@ -110,7 +112,7 @@ $tab_column = PmdCommon::getColumnsInfo();
|
||||
$script_tables = PmdCommon::getScriptTabs();
|
||||
$tables_pk_or_unique_keys = PmdCommon::getPkOrUniqueKeys();
|
||||
$tables_all_keys = PmdCommon::getAllKeys();
|
||||
$classes_side_menu = Designer::returnClassNamesFromMenuButtons();
|
||||
$classes_side_menu = $designer->returnClassNamesFromMenuButtons();
|
||||
|
||||
$display_page = -1;
|
||||
$selected_page = null;
|
||||
@ -164,12 +166,12 @@ list(
|
||||
// Embed some data into HTML, later it will be read
|
||||
// by pmd/init.js and converted to JS variables.
|
||||
$response->addHTML(
|
||||
Designer::getHtmlForJsFields(
|
||||
$designer->getHtmlForJsFields(
|
||||
$script_tables, $script_contr, $script_display_field, $display_page
|
||||
)
|
||||
);
|
||||
$response->addHTML(
|
||||
Designer::getPageMenu(
|
||||
$designer->getPageMenu(
|
||||
isset($_REQUEST['query']),
|
||||
$selected_page,
|
||||
$classes_side_menu
|
||||
@ -183,11 +185,11 @@ $response->addHTML(
|
||||
'<form action="" id="container-form" method="post" name="form1">'
|
||||
);
|
||||
|
||||
$response->addHTML(Designer::getHtmlCanvas());
|
||||
$response->addHTML(Designer::getHtmlTableList($tab_pos, $display_page));
|
||||
$response->addHTML($designer->getHtmlCanvas());
|
||||
$response->addHTML($designer->getHtmlTableList($tab_pos, $display_page));
|
||||
|
||||
$response->addHTML(
|
||||
Designer::getDatabaseTables(
|
||||
$designer->getDatabaseTables(
|
||||
$tab_pos, $display_page, $tab_column,
|
||||
$tables_all_keys, $tables_pk_or_unique_keys
|
||||
)
|
||||
@ -197,16 +199,16 @@ $response->addHTML('</div>'); // end canvas_outer
|
||||
|
||||
$response->addHTML('<div id="pmd_hint"></div>');
|
||||
|
||||
$response->addHTML(Designer::getNewRelationPanel());
|
||||
$response->addHTML(Designer::getDeleteRelationPanel());
|
||||
$response->addHTML($designer->getNewRelationPanel());
|
||||
$response->addHTML($designer->getDeleteRelationPanel());
|
||||
|
||||
if (isset($_REQUEST['query'])) {
|
||||
$response->addHTML(Designer::getOptionsPanel());
|
||||
$response->addHTML(Designer::getRenameToPanel());
|
||||
$response->addHTML(Designer::getHavingQueryPanel());
|
||||
$response->addHTML(Designer::getAggregateQueryPanel());
|
||||
$response->addHTML(Designer::getWhereQueryPanel());
|
||||
$response->addHTML(Designer::getQueryDetails($_GET['db']));
|
||||
$response->addHTML($designer->getOptionsPanel());
|
||||
$response->addHTML($designer->getRenameToPanel());
|
||||
$response->addHTML($designer->getHavingQueryPanel());
|
||||
$response->addHTML($designer->getAggregateQueryPanel());
|
||||
$response->addHTML($designer->getWhereQueryPanel());
|
||||
$response->addHTML($designer->getQueryDetails($_GET['db']));
|
||||
}
|
||||
|
||||
$response->addHTML('<div id="PMA_disable_floating_menubar"></div>');
|
||||
|
||||
@ -30,14 +30,14 @@ class Designer
|
||||
*
|
||||
* @return string html content
|
||||
*/
|
||||
public static function getHtmlForEditOrDeletePages($db, $operation)
|
||||
public function getHtmlForEditOrDeletePages($db, $operation)
|
||||
{
|
||||
$cfgRelation = Relation::getRelationsParam();
|
||||
return Template::get('database/designer/edit_delete_pages')->render([
|
||||
'db' => $db,
|
||||
'operation' => $operation,
|
||||
'pdfwork' => $cfgRelation['pdfwork'],
|
||||
'pages' => self::getPageIdsAndNames($db),
|
||||
'pages' => $this->getPageIdsAndNames($db),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -48,13 +48,13 @@ class Designer
|
||||
*
|
||||
* @return string html content
|
||||
*/
|
||||
public static function getHtmlForPageSaveAs($db)
|
||||
public function getHtmlForPageSaveAs($db)
|
||||
{
|
||||
$cfgRelation = Relation::getRelationsParam();
|
||||
return Template::get('database/designer/page_save_as')->render([
|
||||
'db' => $db,
|
||||
'pdfwork' => $cfgRelation['pdfwork'],
|
||||
'pages' => self::getPageIdsAndNames($db),
|
||||
'pages' => $this->getPageIdsAndNames($db),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ class Designer
|
||||
*
|
||||
* @return array array of schema page id and names
|
||||
*/
|
||||
public static function getPageIdsAndNames($db)
|
||||
private function getPageIdsAndNames($db)
|
||||
{
|
||||
$cfgRelation = Relation::getRelationsParam();
|
||||
$page_query = "SELECT `page_nr`, `page_descr` FROM "
|
||||
@ -92,7 +92,7 @@ class Designer
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForSchemaExport($db, $page)
|
||||
public function getHtmlForSchemaExport($db, $page)
|
||||
{
|
||||
/* Scan for schema plugins */
|
||||
/* @var $export_list SchemaPlugin[] */
|
||||
@ -129,7 +129,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getHtmlForJsFields(
|
||||
public function getHtmlForJsFields(
|
||||
array $script_tables, array $script_contr, array $script_display_field, $display_page
|
||||
) {
|
||||
$cfgRelation = Relation::getRelationsParam();
|
||||
@ -154,7 +154,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getPageMenu($visualBuilder, $selectedPage, array $paramsArray)
|
||||
public function getPageMenu($visualBuilder, $selectedPage, array $paramsArray)
|
||||
{
|
||||
return Template::get('database/designer/side_menu')->render([
|
||||
'visual_builder' => $visualBuilder,
|
||||
@ -169,7 +169,7 @@ class Designer
|
||||
*
|
||||
* @return array stored values
|
||||
*/
|
||||
public static function getSideMenuParamsArray()
|
||||
private function getSideMenuParamsArray()
|
||||
{
|
||||
$params = array();
|
||||
|
||||
@ -196,10 +196,10 @@ class Designer
|
||||
*
|
||||
* @return array class names of various buttons
|
||||
*/
|
||||
public static function returnClassNamesFromMenuButtons()
|
||||
public function returnClassNamesFromMenuButtons()
|
||||
{
|
||||
$classes_array = array();
|
||||
$params_array = self::getSideMenuParamsArray();
|
||||
$params_array = $this->getSideMenuParamsArray();
|
||||
|
||||
if (isset($params_array['angular_direct'])
|
||||
&& $params_array['angular_direct'] == 'angular'
|
||||
@ -257,7 +257,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getHtmlCanvas()
|
||||
public function getHtmlCanvas()
|
||||
{
|
||||
return Template::get('database/designer/canvas')->render();
|
||||
}
|
||||
@ -270,7 +270,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getHtmlTableList(array $tab_pos, $display_page)
|
||||
public function getHtmlTableList(array $tab_pos, $display_page)
|
||||
{
|
||||
return Template::get('database/designer/table_list')->render([
|
||||
'tab_pos' => $tab_pos,
|
||||
@ -294,7 +294,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getDatabaseTables(
|
||||
public function getDatabaseTables(
|
||||
array $tab_pos,
|
||||
$display_page,
|
||||
array $tab_column,
|
||||
@ -326,7 +326,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getNewRelationPanel()
|
||||
public function getNewRelationPanel()
|
||||
{
|
||||
return Template::get('database/designer/new_relation_panel')
|
||||
->render();
|
||||
@ -337,7 +337,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getDeleteRelationPanel()
|
||||
public function getDeleteRelationPanel()
|
||||
{
|
||||
return Template::get('database/designer/delete_relation_panel')
|
||||
->render();
|
||||
@ -348,7 +348,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getOptionsPanel()
|
||||
public function getOptionsPanel()
|
||||
{
|
||||
return Template::get('database/designer/options_panel')->render();
|
||||
}
|
||||
@ -358,7 +358,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getRenameToPanel()
|
||||
public function getRenameToPanel()
|
||||
{
|
||||
return Template::get('database/designer/rename_to_panel')
|
||||
->render();
|
||||
@ -369,7 +369,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getHavingQueryPanel()
|
||||
public function getHavingQueryPanel()
|
||||
{
|
||||
return Template::get('database/designer/having_query_panel')
|
||||
->render();
|
||||
@ -380,7 +380,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getAggregateQueryPanel()
|
||||
public function getAggregateQueryPanel()
|
||||
{
|
||||
return Template::get('database/designer/aggregate_query_panel')
|
||||
->render();
|
||||
@ -391,7 +391,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getWhereQueryPanel()
|
||||
public function getWhereQueryPanel()
|
||||
{
|
||||
return Template::get('database/designer/where_query_panel')
|
||||
->render();
|
||||
@ -404,7 +404,7 @@ class Designer
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public static function getQueryDetails($db)
|
||||
public function getQueryDetails($db)
|
||||
{
|
||||
return Template::get('database/designer/query_details')->render([
|
||||
'db' => $db,
|
||||
|
||||
@ -9,6 +9,7 @@ namespace PhpMyAdmin\Tests\Database;
|
||||
use PhpMyAdmin\Database\Designer;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Tests for PhpMyAdmin\Database\Designer
|
||||
@ -17,13 +18,17 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class DesignerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Designer
|
||||
*/
|
||||
private $designer;
|
||||
|
||||
/**
|
||||
* Setup for test cases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['ServerDefault'] = 1;
|
||||
@ -43,6 +48,8 @@ class DesignerTest extends TestCase
|
||||
),
|
||||
' PMA_token ' => 'token'
|
||||
);
|
||||
|
||||
$this->designer = new Designer();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +92,7 @@ class DesignerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Designer::getPageIdsAndNames()
|
||||
* Test for getPageIdsAndNames()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -94,7 +101,9 @@ class DesignerTest extends TestCase
|
||||
$db = 'db';
|
||||
$this->_mockDatabaseInteraction($db);
|
||||
|
||||
$result = Designer::getPageIdsAndNames($db);
|
||||
$method = new ReflectionMethod(Designer::class, 'getPageIdsAndNames');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invokeArgs($this->designer, [$db]);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
@ -106,7 +115,7 @@ class DesignerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Designer::getHtmlForEditOrDeletePages()
|
||||
* Test for getHtmlForEditOrDeletePages()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -116,7 +125,7 @@ class DesignerTest extends TestCase
|
||||
$operation = 'edit';
|
||||
$this->_mockDatabaseInteraction($db);
|
||||
|
||||
$result = Designer::getHtmlForEditOrDeletePages($db, $operation);
|
||||
$result = $this->designer->getHtmlForEditOrDeletePages($db, $operation);
|
||||
$this->assertContains(
|
||||
'<input type="hidden" name="operation" value="' . $operation . '" />',
|
||||
$result
|
||||
@ -133,7 +142,7 @@ class DesignerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Designer::getHtmlForPageSaveAs()
|
||||
* Test for getHtmlForPageSaveAs()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -142,7 +151,7 @@ class DesignerTest extends TestCase
|
||||
$db = 'db';
|
||||
$this->_mockDatabaseInteraction($db);
|
||||
|
||||
$result = Designer::getHtmlForPageSaveAs($db);
|
||||
$result = $this->designer->getHtmlForPageSaveAs($db);
|
||||
$this->assertContains(
|
||||
'<input type="hidden" name="operation" value="savePage" />',
|
||||
$result
|
||||
@ -173,7 +182,7 @@ class DesignerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Designer::getHtmlForSchemaExport()
|
||||
* Test for getHtmlForSchemaExport()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -182,7 +191,7 @@ class DesignerTest extends TestCase
|
||||
$db = 'db';
|
||||
$page = 2;
|
||||
|
||||
$result = Designer::getHtmlForSchemaExport($db, $page);
|
||||
$result = $this->designer->getHtmlForSchemaExport($db, $page);
|
||||
// export type
|
||||
$this->assertContains(
|
||||
'<select id="plugins" name="export_type">',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user