Remove $dbi global from Database classes

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2018-05-22 22:46:41 -03:00
parent dce862d41b
commit 66f2e4a2dc
12 changed files with 142 additions and 92 deletions

View File

@ -15,8 +15,8 @@ require_once 'libraries/common.inc.php';
$response = Response::getInstance();
$databaseDesigner = new Designer();
$designerCommon = new Common();
$databaseDesigner = new Designer($GLOBALS['dbi']);
$designerCommon = new Common($GLOBALS['dbi']);
if (isset($_REQUEST['dialog'])) {

View File

@ -138,7 +138,7 @@ if ($message_to_display) {
unset($message_to_display);
// create new qbe search instance
$db_qbe = new Qbe($GLOBALS['db'], $savedSearchList, $savedSearch);
$db_qbe = new Qbe($GLOBALS['dbi'], $GLOBALS['db'], $savedSearchList, $savedSearch);
$url = 'db_designer.php' . Url::getCommon(
array_merge(

View File

@ -37,7 +37,7 @@ $url_query .= '&amp;goto=db_search.php';
$url_params['goto'] = 'db_search.php';
// Create a database search instance
$db_search = new Search($GLOBALS['db']);
$db_search = new Search($GLOBALS['dbi'], $GLOBALS['db']);
// Display top links if we are not in an Ajax request
if (! $response->isAjax()) {

View File

@ -24,16 +24,24 @@ use PhpMyAdmin\Util;
*/
class Designer
{
/**
* @var DatabaseInterface
*/
private $dbi;
/**
* @var Relation $relation
*/
private $relation;
/**
* Constructor
* Designer constructor.
*
* @param DatabaseInterface $dbi DatabaseInterface object
*/
public function __construct()
public function __construct(DatabaseInterface $dbi)
{
$this->dbi = $dbi;
$this->relation = new Relation();
}
@ -86,7 +94,7 @@ class Designer
$page_query = "SELECT `page_nr`, `page_descr` FROM "
. Util::backquote($cfgRelation['db']) . "."
. Util::backquote($cfgRelation['pdf_pages'])
. " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($db) . "'"
. " WHERE db_name = '" . $this->dbi->escapeString($db) . "'"
. " ORDER BY `page_descr`";
$page_rs = $this->relation->queryAsControlUser(
$page_query,
@ -95,7 +103,7 @@ class Designer
);
$result = [];
while ($curr_page = $GLOBALS['dbi']->fetchAssoc($page_rs)) {
while ($curr_page = $this->dbi->fetchAssoc($page_rs)) {
$result[intval($curr_page['page_nr'])] = $curr_page['page_descr'];
}
return $result;
@ -202,7 +210,7 @@ class Designer
. ' WHERE ' . Util::backquote('username') . ' = "'
. $GLOBALS['cfg']['Server']['user'] . '";';
$result = $GLOBALS['dbi']->fetchSingleRow($query);
$result = $this->dbi->fetchSingleRow($query);
$params = json_decode($result['settings_data'], true);
}

View File

@ -28,10 +28,18 @@ class Common
private $relation;
/**
* Constructor
* @var \PhpMyAdmin\DatabaseInterface
*/
public function __construct()
private $dbi;
/**
* Common constructor.
*
* @param DatabaseInterface $dbi DatabaseInterface object
*/
public function __construct(DatabaseInterface $dbi)
{
$this->dbi = $dbi;
$this->relation = new Relation();
}
@ -48,9 +56,9 @@ class Common
$GLOBALS['designer']['OWNER'] = array();
$GLOBALS['designer']['TABLE_NAME_SMALL'] = array();
$tables = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']);
$tables = $this->dbi->getTablesFull($GLOBALS['db']);
// seems to be needed later
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$this->dbi->selectDb($GLOBALS['db']);
$i = 0;
foreach ($tables as $one_table) {
$GLOBALS['designer']['TABLE_NAME'][$i]
@ -98,11 +106,11 @@ class Common
*/
public function getColumnsInfo()
{
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$this->dbi->selectDb($GLOBALS['db']);
$tab_column = array();
for ($i = 0, $cnt = count($GLOBALS['designer']["TABLE_NAME"]); $i < $cnt; $i++) {
$fields_rs = $GLOBALS['dbi']->query(
$GLOBALS['dbi']->getColumnsSql(
$fields_rs = $this->dbi->query(
$this->dbi->getColumnsSql(
$GLOBALS['db'],
$GLOBALS['designer_url']["TABLE_NAME_SMALL"][$i],
null,
@ -113,7 +121,7 @@ class Common
);
$tbl_name_i = $GLOBALS['designer']['TABLE_NAME'][$i];
$j = 0;
while ($row = $GLOBALS['dbi']->fetchAssoc($fields_rs)) {
while ($row = $this->dbi->fetchAssoc($fields_rs)) {
$tab_column[$tbl_name_i]['COLUMN_ID'][$j] = $j;
$tab_column[$tbl_name_i]['COLUMN_NAME'][$j] = $row['Field'];
$tab_column[$tbl_name_i]['TYPE'][$j] = $row['Type'];
@ -131,16 +139,16 @@ class Common
*/
public function getScriptContr()
{
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$this->dbi->selectDb($GLOBALS['db']);
$con = array();
$con["C_NAME"] = array();
$i = 0;
$alltab_rs = $GLOBALS['dbi']->query(
$alltab_rs = $this->dbi->query(
'SHOW TABLES FROM ' . Util::backquote($GLOBALS['db']),
DatabaseInterface::CONNECT_USER,
DatabaseInterface::QUERY_STORE
);
while ($val = @$GLOBALS['dbi']->fetchRow($alltab_rs)) {
while ($val = @$this->dbi->fetchRow($alltab_rs)) {
$row = $this->relation->getForeigners($GLOBALS['db'], $val[0], '', 'internal');
if ($row !== false) {
@ -280,7 +288,7 @@ class Common
. "." . Util::backquote($cfgRelation['table_coords']) . "
WHERE pdf_page_number = " . intval($pg);
$tab_pos = $GLOBALS['dbi']->fetchResult(
$tab_pos = $this->dbi->fetchResult(
$query,
'name',
null,
@ -308,7 +316,7 @@ class Common
. " FROM " . Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['pdf_pages'])
. " WHERE " . Util::backquote('page_nr') . " = " . intval($pg);
$page_name = $GLOBALS['dbi']->fetchResult(
$page_name = $this->dbi->fetchResult(
$query,
null,
null,
@ -369,10 +377,10 @@ class Common
$query = "SELECT `page_nr`"
. " FROM " . Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['pdf_pages'])
. " WHERE `db_name` = '" . $GLOBALS['dbi']->escapeString($db) . "'"
. " AND `page_descr` = '" . $GLOBALS['dbi']->escapeString($db) . "'";
. " WHERE `db_name` = '" . $this->dbi->escapeString($db) . "'"
. " AND `page_descr` = '" . $this->dbi->escapeString($db) . "'";
$default_page_no = $GLOBALS['dbi']->fetchResult(
$default_page_no = $this->dbi->fetchResult(
$query,
null,
null,
@ -410,9 +418,9 @@ class Common
$query = "SELECT MIN(`page_nr`)"
. " FROM " . Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['pdf_pages'])
. " WHERE `db_name` = '" . $GLOBALS['dbi']->escapeString($db) . "'";
. " WHERE `db_name` = '" . $this->dbi->escapeString($db) . "'";
$min_page_no = $GLOBALS['dbi']->fetchResult(
$min_page_no = $this->dbi->fetchResult(
$query,
null,
null,
@ -467,9 +475,9 @@ class Common
. "." . Util::backquote(
$GLOBALS['cfgRelation']['table_coords']
)
. " WHERE `db_name` = '" . $GLOBALS['dbi']->escapeString($_REQUEST['db'])
. " WHERE `db_name` = '" . $this->dbi->escapeString($_REQUEST['db'])
. "'"
. " AND `pdf_page_number` = '" . $GLOBALS['dbi']->escapeString($pg)
. " AND `pdf_page_number` = '" . $this->dbi->escapeString($pg)
. "'";
$res = $this->relation->queryAsControlUser(
@ -493,11 +501,11 @@ class Common
. Util::backquote($GLOBALS['cfgRelation']['table_coords'])
. " (`db_name`, `table_name`, `pdf_page_number`, `x`, `y`)"
. " VALUES ("
. "'" . $GLOBALS['dbi']->escapeString($DB) . "', "
. "'" . $GLOBALS['dbi']->escapeString($TAB) . "', "
. "'" . $GLOBALS['dbi']->escapeString($pg) . "', "
. "'" . $GLOBALS['dbi']->escapeString($_REQUEST['t_x'][$key]) . "', "
. "'" . $GLOBALS['dbi']->escapeString($_REQUEST['t_y'][$key]) . "')";
. "'" . $this->dbi->escapeString($DB) . "', "
. "'" . $this->dbi->escapeString($TAB) . "', "
. "'" . $this->dbi->escapeString($pg) . "', "
. "'" . $this->dbi->escapeString($_REQUEST['t_x'][$key]) . "', "
. "'" . $this->dbi->escapeString($_REQUEST['t_y'][$key]) . "')";
$res = $this->relation->queryAsControlUser(
$query, true, DatabaseInterface::QUERY_STORE
@ -523,7 +531,7 @@ class Common
return false;
}
$upd_query = new Table($table, $db, $GLOBALS['dbi']);
$upd_query = new Table($table, $db, $this->dbi);
$upd_query->updateDisplayField($field, $cfgRelation);
return true;
@ -546,9 +554,9 @@ class Common
*/
public function addNewRelation($db, $T1, $F1, $T2, $F2, $on_delete, $on_update, $DB1, $DB2)
{
$tables = $GLOBALS['dbi']->getTablesFull($DB1, $T1);
$tables = $this->dbi->getTablesFull($DB1, $T1);
$type_T1 = mb_strtoupper($tables[$T1]['ENGINE']);
$tables = $GLOBALS['dbi']->getTablesFull($DB2, $T2);
$tables = $this->dbi->getTablesFull($DB2, $T2);
$type_T2 = mb_strtoupper($tables[$T2]['ENGINE']);
// native foreign key
@ -567,28 +575,28 @@ class Common
// note: in InnoDB, the index does not requires to be on a PRIMARY
// or UNIQUE key
// improve: check all other requirements for InnoDB relations
$result = $GLOBALS['dbi']->query(
$result = $this->dbi->query(
'SHOW INDEX FROM ' . Util::backquote($DB1)
. '.' . Util::backquote($T1) . ';'
);
// will be use to emphasis prim. keys in the table view
$index_array1 = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
while ($row = $this->dbi->fetchAssoc($result)) {
$index_array1[$row['Column_name']] = 1;
}
$GLOBALS['dbi']->freeResult($result);
$this->dbi->freeResult($result);
$result = $GLOBALS['dbi']->query(
$result = $this->dbi->query(
'SHOW INDEX FROM ' . Util::backquote($DB2)
. '.' . Util::backquote($T2) . ';'
);
// will be used to emphasis prim. keys in the table view
$index_array2 = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
while ($row = $this->dbi->fetchAssoc($result)) {
$index_array2[$row['Column_name']] = 1;
}
$GLOBALS['dbi']->freeResult($result);
$this->dbi->freeResult($result);
if (! empty($index_array1[$F1]) && ! empty($index_array2[$F2])) {
$upd_query = 'ALTER TABLE ' . Util::backquote($DB2)
@ -607,11 +615,11 @@ class Common
$upd_query .= ' ON UPDATE ' . $on_update;
}
$upd_query .= ';';
if ($GLOBALS['dbi']->tryQuery($upd_query)) {
if ($this->dbi->tryQuery($upd_query)) {
return array(true, __('FOREIGN KEY relationship has been added.'));
}
$error = $GLOBALS['dbi']->getError();
$error = $this->dbi->getError();
return array(
false,
__('Error: FOREIGN KEY relationship could not be added!')
@ -637,19 +645,19 @@ class Common
. "(master_db, master_table, master_field, "
. "foreign_db, foreign_table, foreign_field)"
. " values("
. "'" . $GLOBALS['dbi']->escapeString($DB2) . "', "
. "'" . $GLOBALS['dbi']->escapeString($T2) . "', "
. "'" . $GLOBALS['dbi']->escapeString($F2) . "', "
. "'" . $GLOBALS['dbi']->escapeString($DB1) . "', "
. "'" . $GLOBALS['dbi']->escapeString($T1) . "', "
. "'" . $GLOBALS['dbi']->escapeString($F1) . "')";
. "'" . $this->dbi->escapeString($DB2) . "', "
. "'" . $this->dbi->escapeString($T2) . "', "
. "'" . $this->dbi->escapeString($F2) . "', "
. "'" . $this->dbi->escapeString($DB1) . "', "
. "'" . $this->dbi->escapeString($T1) . "', "
. "'" . $this->dbi->escapeString($F1) . "')";
if ($this->relation->queryAsControlUser($q, false, DatabaseInterface::QUERY_STORE)
) {
return array(true, __('Internal relationship has been added.'));
}
$error = $GLOBALS['dbi']->getError(DatabaseInterface::CONNECT_CONTROL);
$error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL);
return array(
false,
__('Error: Internal relationship could not be added!')
@ -672,9 +680,9 @@ class Common
list($DB1, $T1) = explode(".", $T1);
list($DB2, $T2) = explode(".", $T2);
$tables = $GLOBALS['dbi']->getTablesFull($DB1, $T1);
$tables = $this->dbi->getTablesFull($DB1, $T1);
$type_T1 = mb_strtoupper($tables[$T1]['ENGINE']);
$tables = $GLOBALS['dbi']->getTablesFull($DB2, $T2);
$tables = $this->dbi->getTablesFull($DB2, $T2);
$type_T2 = mb_strtoupper($tables[$T2]['ENGINE']);
if (Util::isForeignKeySupported($type_T1)
@ -689,11 +697,11 @@ class Common
$upd_query = 'ALTER TABLE ' . Util::backquote($DB2)
. '.' . Util::backquote($T2) . ' DROP FOREIGN KEY '
. Util::backquote($foreigner['constraint']) . ';';
if ($GLOBALS['dbi']->query($upd_query)) {
if ($this->dbi->query($upd_query)) {
return array(true, __('FOREIGN KEY relationship has been removed.'));
}
$error = $GLOBALS['dbi']->getError();
$error = $this->dbi->getError();
return array(
false,
__('Error: FOREIGN KEY relationship could not be removed!')
@ -706,12 +714,12 @@ class Common
$delete_query = "DELETE FROM "
. Util::backquote($GLOBALS['cfgRelation']['db']) . "."
. $GLOBALS['cfgRelation']['relation'] . " WHERE "
. "master_db = '" . $GLOBALS['dbi']->escapeString($DB2) . "'"
. " AND master_table = '" . $GLOBALS['dbi']->escapeString($T2) . "'"
. " AND master_field = '" . $GLOBALS['dbi']->escapeString($F2) . "'"
. " AND foreign_db = '" . $GLOBALS['dbi']->escapeString($DB1) . "'"
. " AND foreign_table = '" . $GLOBALS['dbi']->escapeString($T1) . "'"
. " AND foreign_field = '" . $GLOBALS['dbi']->escapeString($F1) . "'";
. "master_db = '" . $this->dbi->escapeString($DB2) . "'"
. " AND master_table = '" . $this->dbi->escapeString($T2) . "'"
. " AND master_field = '" . $this->dbi->escapeString($F2) . "'"
. " AND foreign_db = '" . $this->dbi->escapeString($DB1) . "'"
. " AND foreign_table = '" . $this->dbi->escapeString($T1) . "'"
. " AND foreign_field = '" . $this->dbi->escapeString($F1) . "'";
$result = $this->relation->queryAsControlUser(
$delete_query,
@ -720,7 +728,7 @@ class Common
);
if (!$result) {
$error = $GLOBALS['dbi']->getError(DatabaseInterface::CONNECT_CONTROL);
$error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL);
return array(
false,
__('Error: Internal relationship could not be removed!') . "<br/>" . $error
@ -754,9 +762,9 @@ class Common
. " FROM " . Util::backquote($cfgDesigner['db'])
. "." . Util::backquote($cfgDesigner['table'])
. " WHERE username = '"
. $GLOBALS['dbi']->escapeString($cfgDesigner['user']) . "';";
. $this->dbi->escapeString($cfgDesigner['user']) . "';";
$orig_data = $GLOBALS['dbi']->fetchSingleRow(
$orig_data = $this->dbi->fetchSingleRow(
$orig_data_query, 'ASSOC', DatabaseInterface::CONNECT_CONTROL
);
@ -770,7 +778,7 @@ class Common
. "." . Util::backquote($cfgDesigner['table'])
. " SET settings_data = '" . $orig_data . "'"
. " WHERE username = '"
. $GLOBALS['dbi']->escapeString($cfgDesigner['user']) . "';";
. $this->dbi->escapeString($cfgDesigner['user']) . "';";
$success = $this->relation->queryAsControlUser($save_query);
} else {

View File

@ -11,6 +11,7 @@ namespace PhpMyAdmin\Database;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Message;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Table;
use PhpMyAdmin\Template;
@ -219,14 +220,21 @@ class Qbe
*/
private $relation;
/**
* @var DatabaseInterface
*/
public $dbi;
/**
* Public Constructor
*
* @param string $dbname Database name
* @param array $savedSearchList List of saved searches
* @param SavedSearches $currentSearch Current search id
* @param DatabaseInterface $dbi DatabaseInterface object
* @param string $dbname Database name
* @param array $savedSearchList List of saved searches
* @param SavedSearches $currentSearch Current search id
*/
public function __construct(
$dbi,
$dbname,
array $savedSearchList = array(),
$currentSearch = null
@ -234,11 +242,13 @@ class Qbe
$this->_db = $dbname;
$this->_savedSearchList = $savedSearchList;
$this->_currentSearch = $currentSearch;
$this->relation = new Relation();
$this->dbi = $dbi;
$this->_loadCriterias();
// Sets criteria parameters
$this->_setSearchParams();
$this->_setCriteriaTablesAndColumns();
$this->relation = new Relation();
}
/**
@ -332,19 +342,19 @@ class Qbe
$this->_criteriaTables[$each_table] = ' selected="selected"';
}
} // end if
$all_tables = $GLOBALS['dbi']->query(
$all_tables = $this->dbi->query(
'SHOW TABLES FROM ' . Util::backquote($this->_db) . ';',
DatabaseInterface::CONNECT_USER,
DatabaseInterface::QUERY_STORE
);
$all_tables_count = $GLOBALS['dbi']->numRows($all_tables);
$all_tables_count = $this->dbi->numRows($all_tables);
if (0 == $all_tables_count) {
Message::error(__('No tables found in database.'))->display();
exit;
}
// The tables list gets from MySQL
while (list($table) = $GLOBALS['dbi']->fetchRow($all_tables)) {
$columns = $GLOBALS['dbi']->getColumns($this->_db, $table);
while (list($table) = $this->dbi->fetchRow($all_tables)) {
$columns = $this->dbi->getColumns($this->_db, $table);
if (empty($this->_criteriaTables[$table])
&& ! empty($_REQUEST['TableList'])
@ -370,7 +380,7 @@ class Qbe
} // end foreach
} // end if
} // end while
$GLOBALS['dbi']->freeResult($all_tables);
$this->dbi->freeResult($all_tables);
// sets the largest width found
$this->_realwidth = $this->_form_column_width . 'ex';
@ -1286,7 +1296,7 @@ class Qbe
$index_columns = array();
foreach ($search_tables as $table) {
$indexes = $GLOBALS['dbi']->getTableIndexes($this->_db, $table);
$indexes = $this->dbi->getTableIndexes($this->_db, $table);
foreach ($indexes as $index) {
$column = $table . '.' . $index['Column_name'];
if (isset($search_columns[$column])) {
@ -1325,7 +1335,7 @@ class Qbe
private function _getLeftJoinColumnCandidates(array $search_tables, array $search_columns,
array $where_clause_columns
) {
$GLOBALS['dbi']->selectDb($this->_db);
$this->dbi->selectDb($this->_db);
// Get unique columns and index columns
$indexes = $this->_getIndexes(

View File

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Database;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
@ -83,14 +84,21 @@ class Search
*/
private $criteriaColumnName;
/**
* @var DatabaseInterface
*/
private $dbi;
/**
* Public Constructor
*
* @param string $db Database name
* @param DatabaseInterface $dbi DatabaseInterface object
* @param string $db Database name
*/
public function __construct($db)
public function __construct(DatabaseInterface $dbi, $db)
{
$this->db = $db;
$this->dbi = $dbi;
$this->searchTypes = array(
'1' => __('at least one of the words'),
'2' => __('all of the words'),
@ -109,7 +117,7 @@ class Search
*/
private function setSearchParams()
{
$this->tablesNamesOnly = $GLOBALS['dbi']->getTables($this->db);
$this->tablesNamesOnly = $this->dbi->getTables($this->db);
if (empty($_REQUEST['criteriaSearchType'])
|| ! is_string($_REQUEST['criteriaSearchType'])
@ -151,7 +159,7 @@ class Search
) {
unset($this->criteriaColumnName);
} else {
$this->criteriaColumnName = $GLOBALS['dbi']->escapeString(
$this->criteriaColumnName = $this->dbi->escapeString(
$_REQUEST['criteriaColumnName']
);
}
@ -207,7 +215,7 @@ class Search
private function getWhereClause($table)
{
// Columns to select
$allColumns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
$allColumns = $this->dbi->getColumns($GLOBALS['db'], $table);
$likeClauses = array();
// Based on search type, decide like/regex & '%'/''
$like_or_regex = (($this->criteriaSearchType == 5) ? 'REGEXP' : 'LIKE');
@ -215,7 +223,7 @@ class Search
// For "as regular expression" (search option 5), LIKE won't be used
// Usage example: If user is searching for a literal $ in a regexp search,
// he should enter \$ as the value.
$criteriaSearchStringEscaped = $GLOBALS['dbi']->escapeString(
$criteriaSearchStringEscaped = $this->dbi->escapeString(
$this->criteriaSearchString
);
// Extract search words or pattern
@ -275,7 +283,7 @@ class Search
// Gets the SQL statements
$newSearchSqls = $this->getSearchSqls($eachTable);
// Executes the "COUNT" statement
$resultCount = intval($GLOBALS['dbi']->fetchValue(
$resultCount = intval($this->dbi->fetchValue(
$newSearchSqls['select_count']
));
$resultTotal += $resultCount;

View File

@ -127,7 +127,7 @@ class DbiDummy implements DbiExtension
public function fetchAny($result)
{
$query_data = &$this->getQueryData($result);
if ($query_data['pos'] >= count($query_data['result'])) {
if ($query_data['pos'] >= count((array) $query_data['result'])) {
return false;
}
$ret = $query_data['result'][$query_data['pos']];

View File

@ -44,7 +44,6 @@ class CommonTest extends TestCase
)
)
);
$this->designerCommon = new Common();
}
/**
@ -80,6 +79,8 @@ class CommonTest extends TestCase
);
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$this->designerCommon->getTablePositions($pg);
}
@ -112,6 +113,8 @@ class CommonTest extends TestCase
->will($this->returnValue(array($pageName)));
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$result = $this->designerCommon->getPageName($pg);
$this->assertEquals($pageName, $result);
@ -140,6 +143,7 @@ class CommonTest extends TestCase
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$result = $this->designerCommon->deletePage($pg);
$this->assertEquals(true, $result);
@ -176,6 +180,7 @@ class CommonTest extends TestCase
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$result = $this->designerCommon->getDefaultPage($db);
$this->assertEquals($default_pg, $result);
@ -210,6 +215,7 @@ class CommonTest extends TestCase
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$result = $this->designerCommon->getDefaultPage($db);
$this->assertEquals(-1, $result);
@ -245,6 +251,7 @@ class CommonTest extends TestCase
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$result = $this->designerCommon->getLoadingPage($db);
$this->assertEquals($default_pg, $result);
@ -274,6 +281,7 @@ class CommonTest extends TestCase
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->designerCommon = new Common($GLOBALS['dbi']);
$result = $this->designerCommon->getLoadingPage($db);
$this->assertEquals($first_pg, $result);

View File

@ -50,8 +50,6 @@ class DesignerTest extends TestCase
],
' PMA_token ' => 'token'
];
$this->designer = new Designer();
}
/**
@ -103,6 +101,8 @@ class DesignerTest extends TestCase
$db = 'db';
$this->_mockDatabaseInteraction($db);
$this->designer = new Designer($GLOBALS['dbi']);
$method = new ReflectionMethod(Designer::class, 'getPageIdsAndNames');
$method->setAccessible(true);
$result = $method->invokeArgs($this->designer, [$db]);
@ -127,6 +127,8 @@ class DesignerTest extends TestCase
$operation = 'edit';
$this->_mockDatabaseInteraction($db);
$this->designer = new Designer($GLOBALS['dbi']);
$result = $this->designer->getHtmlForEditOrDeletePages($db, $operation);
$this->assertContains(
'<input type="hidden" name="operation" value="' . $operation . '" />',
@ -153,6 +155,8 @@ class DesignerTest extends TestCase
$db = 'db';
$this->_mockDatabaseInteraction($db);
$this->designer = new Designer($GLOBALS['dbi']);
$result = $this->designer->getHtmlForPageSaveAs($db);
$this->assertContains(
'<input type="hidden" name="operation" value="savePage" />',
@ -193,6 +197,8 @@ class DesignerTest extends TestCase
$db = 'db';
$page = 2;
$this->designer = new Designer($GLOBALS['dbi']);
$result = $this->designer->getHtmlForSchemaExport($db, $page);
// export type
$this->assertContains(

View File

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Database;
use PhpMyAdmin\Database\Qbe;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Tests\PmaTestCase;
use ReflectionClass;
@ -33,11 +34,11 @@ class QbeTest extends PmaTestCase
*/
protected function setUp()
{
$this->object = new Qbe('pma_test');
$this->object = new Qbe($GLOBALS['dbi'], 'pma_test');
$GLOBALS['server'] = 0;
$GLOBALS['db'] = 'pma_test';
//mock DBI
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@ -58,6 +59,7 @@ class QbeTest extends PmaTestCase
->will($this->returnValue(array()));
$GLOBALS['dbi'] = $dbi;
$this->object->dbi = $dbi;
}
/**

View File

@ -34,7 +34,6 @@ class SearchTest extends PmaTestCase
*/
protected function setUp()
{
$this->object = new Search('pma_test');
$GLOBALS['server'] = 0;
$GLOBALS['db'] = 'pma';
@ -56,6 +55,7 @@ class SearchTest extends PmaTestCase
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->object = new Search($dbi, 'pma_test');
}
/**
@ -101,7 +101,7 @@ class SearchTest extends PmaTestCase
$_REQUEST['criteriaSearchType'] = $type;
$_REQUEST['criteriaSearchString'] = 'search string';
$this->object = new Search('pma_test');
$this->object = new Search($GLOBALS['dbi'], 'pma_test');
$this->assertEquals(
$expected,
$this->callProtectedFunction(