Send DBI to SqlQueryForm using DI
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
parent
828a5f7137
commit
15915a45e0
@ -31,12 +31,16 @@ class SqlQueryForm
|
||||
/** @var Template */
|
||||
private $template;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Template $template Template object
|
||||
*/
|
||||
public function __construct(Template $template)
|
||||
public function __construct(Template $template, DatabaseInterface $dbi)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,14 +94,14 @@ class SqlQueryForm
|
||||
[$legend, $query, $columns_list] = $this->init($query);
|
||||
}
|
||||
|
||||
$relation = new Relation($GLOBALS['dbi']);
|
||||
$relation = new Relation($this->dbi);
|
||||
$bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
|
||||
|
||||
$bookmarks = [];
|
||||
if ($display_tab === 'full' && $bookmarkFeature !== null) {
|
||||
$bookmark_list = Bookmark::getList(
|
||||
$bookmarkFeature,
|
||||
$GLOBALS['dbi'],
|
||||
$this->dbi,
|
||||
$GLOBALS['cfg']['Server']['user'],
|
||||
$db
|
||||
);
|
||||
@ -173,7 +177,7 @@ class SqlQueryForm
|
||||
// Get the list and number of fields
|
||||
// we do a try_query here, because we could be in the query window,
|
||||
// trying to synchronize and the table has not yet been created
|
||||
$columns_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], true);
|
||||
$columns_list = $this->dbi->getColumns($db, $GLOBALS['table'], true);
|
||||
|
||||
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$tmp_tbl_link = '<a href="' . $scriptName . Url::getCommon(['db' => $db, 'table' => $table], '&') . '">';
|
||||
|
||||
@ -197,7 +197,7 @@ return [
|
||||
],
|
||||
'sql_query_form' => [
|
||||
'class' => PhpMyAdmin\SqlQueryForm::class,
|
||||
'arguments' => ['$template' => '@template'],
|
||||
'arguments' => ['$template' => '@template', '$dbi' => '@dbi'],
|
||||
],
|
||||
'status_data' => [
|
||||
'class' => PhpMyAdmin\Server\Status\Data::class,
|
||||
|
||||
@ -81,7 +81,9 @@ class SqlControllerTest extends AbstractTestCase
|
||||
]);
|
||||
|
||||
$response = new ResponseRenderer();
|
||||
(new SqlController($response, $template, new SqlQueryForm($template)))($this->createStub(ServerRequest::class));
|
||||
(
|
||||
new SqlController($response, $template, new SqlQueryForm($template, $this->dbi))
|
||||
)($this->createStub(ServerRequest::class));
|
||||
$this->assertSame($expected, $response->getHTMLResult());
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ class TrackingControllerTest extends AbstractTestCase
|
||||
(new TrackingController(
|
||||
$response,
|
||||
$template,
|
||||
new Tracking(new SqlQueryForm($template), $template, new Relation($this->dbi), $this->dbi)
|
||||
new Tracking(new SqlQueryForm($template, $this->dbi), $template, new Relation($this->dbi), $this->dbi)
|
||||
))($this->createStub(ServerRequest::class));
|
||||
|
||||
$main = $template->render('table/tracking/main', [
|
||||
|
||||
@ -39,9 +39,28 @@ class SqlQueryFormTest extends AbstractTestCase
|
||||
parent::setUp();
|
||||
parent::setLanguage();
|
||||
$this->dummyDbi = $this->createDbiDummy();
|
||||
$this->dummyDbi = $this->createDbiDummy();
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW FULL COLUMNS FROM `PMA_db`.`PMA_table`',
|
||||
[
|
||||
[
|
||||
'field1',
|
||||
'Comment1',
|
||||
],
|
||||
],
|
||||
[
|
||||
'Field',
|
||||
'Comment',
|
||||
]
|
||||
);
|
||||
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW INDEXES FROM `PMA_db`.`PMA_table`',
|
||||
[]
|
||||
);
|
||||
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
|
||||
$GLOBALS['dbi'] = $this->dbi;
|
||||
$this->sqlQueryForm = new SqlQueryForm(new Template());
|
||||
$this->sqlQueryForm = new SqlQueryForm(new Template(), $this->dbi);
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['PMA_PHP_SELF'] = Core::getenv('PHP_SELF');
|
||||
@ -77,28 +96,6 @@ class SqlQueryFormTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['user'] = 'user';
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = 'pmadb';
|
||||
$GLOBALS['cfg']['Server']['bookmarktable'] = 'bookmarktable';
|
||||
|
||||
$this->dummyDbi = $this->createDbiDummy();
|
||||
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
|
||||
$GLOBALS['dbi'] = $this->dbi;
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW FULL COLUMNS FROM `PMA_db`.`PMA_table`',
|
||||
[
|
||||
[
|
||||
'field1',
|
||||
'Comment1',
|
||||
],
|
||||
],
|
||||
[
|
||||
'Field',
|
||||
'Comment',
|
||||
]
|
||||
);
|
||||
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW INDEXES FROM `PMA_db`.`PMA_table`',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -51,7 +51,7 @@ class TrackingTest extends AbstractTestCase
|
||||
|
||||
$template = new Template();
|
||||
$this->tracking = new Tracking(
|
||||
new SqlQueryForm($template),
|
||||
new SqlQueryForm($template, $GLOBALS['dbi']),
|
||||
$template,
|
||||
new Relation($GLOBALS['dbi']),
|
||||
$GLOBALS['dbi']
|
||||
|
||||
Loading…
Reference in New Issue
Block a user