From e23827f67f8632815ea2e92367535a2ec57de5b3 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:01:12 +1100 Subject: [PATCH 01/12] Create a controller class for server plugins page Signed-off-by: Madhura Jayaratne --- .../server/ServerPluginsController.php | 154 ++++++++++++++++++ libraries/server_plugins.lib.php | 120 -------------- server_plugins.php | 48 +++--- 3 files changed, 175 insertions(+), 147 deletions(-) create mode 100644 libraries/controllers/server/ServerPluginsController.php delete mode 100644 libraries/server_plugins.lib.php diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php new file mode 100644 index 0000000000..25ba468865 --- /dev/null +++ b/libraries/controllers/server/ServerPluginsController.php @@ -0,0 +1,154 @@ +response->getHeader(); + $scripts = $header->getScripts(); + $scripts->addFile('jquery/jquery.tablesorter.js'); + $scripts->addFile('server_plugins.js'); + + $plugins = $this->_getServerPlugins(); + + /** + * Displays the page + */ + $this->response->addHTML(PMA_getHtmlForSubPageHeader('plugins')); + $this->response->addHTML($this->_getPluginTab($plugins)); + } + + /** + * Returns the common SQL used to retrieve plugin data + * + * @return string SQL + */ + private function _getServerPluginSQL() + { + return "SELECT plugin_name, plugin_type, (plugin_status = 'ACTIVE') AS is_active, + plugin_type_version, plugin_author, plugin_description, plugin_license + FROM information_schema.plugins + ORDER BY plugin_type, plugin_name"; + } + + /** + * Returns details about server plugins + * + * @return array server plugins data + */ + private function _getServerPlugins() + { + $sql = $this->_getServerPluginSQL(); + $res = $GLOBALS['dbi']->query($sql); + $plugins = array(); + while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { + $plugins[$row['plugin_type']][] = $row; + } + $GLOBALS['dbi']->freeResult($res); + ksort($plugins); + return $plugins; + } + + /** + * Returns the html for plugin Tab. + * + * @param array $plugins list + * + * @return string + */ + private function _getPluginTab($plugins) + { + $html = '
'; + $html .= ''; + $html .= '
'; + + foreach ($plugins as $plugin_type => $plugin_list) { + $key = 'plugins-' + . preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type)); + sort($plugin_list); + + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + + $html .= $this->_getPluginList($plugin_list); + + $html .= ''; + $html .= '
'; + $html .= htmlspecialchars($plugin_type); + $html .= '
' . __('Plugin') . '' . __('Description') . '' . __('Version') . '' . __('Author') . '' . __('License') . '
'; + } + $html .= '
'; + return $html; + } + + /** + * Returns the html for plugin List. + * + * @param array $plugin_list list + * + * @return string + */ + private function _getPluginList($plugin_list) + { + $html = ""; + $odd_row = false; + foreach ($plugin_list as $plugin) { + $odd_row = !$odd_row; + $html .= ''; + $html .= ''; + $html .= htmlspecialchars($plugin['plugin_name']); + if (! $plugin['is_active']) { + $html .= ' ' . __('disabled') . ''; + } + $html .= ''; + $html .= '' . htmlspecialchars($plugin['plugin_description']) . ''; + $html .= '' . htmlspecialchars($plugin['plugin_type_version']) . ''; + $html .= '' . htmlspecialchars($plugin['plugin_author']) . ''; + $html .= '' . htmlspecialchars($plugin['plugin_license']) . ''; + $html .= ''; + } + return $html; + } +} \ No newline at end of file diff --git a/libraries/server_plugins.lib.php b/libraries/server_plugins.lib.php deleted file mode 100644 index 350dd8a3aa..0000000000 --- a/libraries/server_plugins.lib.php +++ /dev/null @@ -1,120 +0,0 @@ -query($sql); - $plugins = array(); - while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { - $plugins[$row['plugin_type']][] = $row; - } - $GLOBALS['dbi']->freeResult($res); - ksort($plugins); - return $plugins; -} - -/** - * Returns the html for plugin Tab. - * - * @param array $plugins list - * - * @return string - */ -function PMA_getPluginTab($plugins) -{ - $html = '
'; - $html .= ''; - $html .= '
'; - - foreach ($plugins as $plugin_type => $plugin_list) { - $key = 'plugins-' - . preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type)); - sort($plugin_list); - - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - - $html .= PMA_getPluginList($plugin_list); - - $html .= ''; - $html .= '
'; - $html .= htmlspecialchars($plugin_type); - $html .= '
' . __('Plugin') . '' . __('Description') . '' . __('Version') . '' . __('Author') . '' . __('License') . '
'; - } - $html .= '
'; - return $html; -} - -/** - * Returns the html for plugin List. - * - * @param array $plugin_list list - * - * @return string - */ -function PMA_getPluginList($plugin_list) -{ - $html = ""; - $odd_row = false; - foreach ($plugin_list as $plugin) { - $odd_row = !$odd_row; - $html .= ''; - $html .= ''; - $html .= htmlspecialchars($plugin['plugin_name']); - if (! $plugin['is_active']) { - $html .= ' ' . __('disabled') . ''; - } - $html .= ''; - $html .= '' . htmlspecialchars($plugin['plugin_description']) . ''; - $html .= '' . htmlspecialchars($plugin['plugin_type_version']) . ''; - $html .= '' . htmlspecialchars($plugin['plugin_author']) . ''; - $html .= '' . htmlspecialchars($plugin['plugin_license']) . ''; - $html .= ''; - } - return $html; -} \ No newline at end of file diff --git a/server_plugins.php b/server_plugins.php index c7860ab192..892e11d0c4 100644 --- a/server_plugins.php +++ b/server_plugins.php @@ -1,38 +1,32 @@ getHeader(); -$scripts = $header->getScripts(); -$scripts->addFile('jquery/jquery.tablesorter.js'); -$scripts->addFile('server_plugins.js'); +$container = libraries\di\Container::getDefaultContainer(); +$container->factory( + 'PMA\libraries\controllers\server\ServerPluginsController' +); +$container->alias( + 'ServerPluginsController', + 'PMA\libraries\controllers\server\ServerPluginsController' +); +$container->set('PMA\libraries\Response', Response::getInstance()); +$container->alias('response', 'PMA\libraries\Response'); -/** - * Does the common work - */ -require 'libraries/server_common.inc.php'; -require 'libraries/server_plugins.lib.php'; - -$plugins = PMA_getServerPlugins(); - -/** - * Displays the page - */ -$response->addHTML(PMA_getHtmlForSubPageHeader('plugins')); -$response->addHTML(PMA_getPluginTab($plugins)); - -exit; +/** @var ServerPluginsController $controller */ +$controller = $container->get( + 'ServerPluginsController', array() +); +$controller->indexAction(); From 3d1a52c1b01fc11de108eead65a9016b27de8d6a Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:02:16 +1100 Subject: [PATCH 02/12] Use own dbi Signed-off-by: Madhura Jayaratne --- libraries/controllers/server/ServerPluginsController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index 25ba468865..757593bb6c 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -62,12 +62,12 @@ class ServerPluginsController extends Controller private function _getServerPlugins() { $sql = $this->_getServerPluginSQL(); - $res = $GLOBALS['dbi']->query($sql); + $res = $this->dbi->query($sql); $plugins = array(); - while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { + while ($row = $this->dbi->fetchAssoc($res)) { $plugins[$row['plugin_type']][] = $row; } - $GLOBALS['dbi']->freeResult($res); + $this->dbi->freeResult($res); ksort($plugins); return $plugins; } From 25c7812120ea234abaf52abf9dde84655a41f4e7 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:04:19 +1100 Subject: [PATCH 03/12] It does not really require a separate method to get the SQL Signed-off-by: Madhura Jayaratne --- .../server/ServerPluginsController.php | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index 757593bb6c..8ba24b3216 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -41,19 +41,6 @@ class ServerPluginsController extends Controller $this->response->addHTML($this->_getPluginTab($plugins)); } - /** - * Returns the common SQL used to retrieve plugin data - * - * @return string SQL - */ - private function _getServerPluginSQL() - { - return "SELECT plugin_name, plugin_type, (plugin_status = 'ACTIVE') AS is_active, - plugin_type_version, plugin_author, plugin_description, plugin_license - FROM information_schema.plugins - ORDER BY plugin_type, plugin_name"; - } - /** * Returns details about server plugins * @@ -61,7 +48,16 @@ class ServerPluginsController extends Controller */ private function _getServerPlugins() { - $sql = $this->_getServerPluginSQL(); + $sql = "SELECT plugin_name, + plugin_type, + (plugin_status = 'ACTIVE') AS is_active, + plugin_type_version, + plugin_author, + plugin_description, + plugin_license + FROM information_schema.plugins + ORDER BY plugin_type, plugin_name"; + $res = $this->dbi->query($sql); $plugins = array(); while ($row = $this->dbi->fetchAssoc($res)) { From 07c9d21162850264b7c5e6698385ebbda06c2a2a Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:10:32 +1100 Subject: [PATCH 04/12] Plugin list of centralized to this controller. Make it an instance variable Signed-off-by: Madhura Jayaratne --- .../server/ServerPluginsController.php | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index 8ba24b3216..d38eeedc3a 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -18,6 +18,20 @@ use PMA\libraries\controllers\Controller; */ class ServerPluginsController extends Controller { + /** + * @var array plugin details + */ + protected $plugins; + + /** + * Constructs ServerPluginsController + */ + public function __construct() + { + parent::__construct(); + $this->plugins = $this->_getServerPlugins(); + } + /** * Index action * @@ -27,18 +41,16 @@ class ServerPluginsController extends Controller { include 'libraries/server_common.inc.php'; - $header = $this->response->getHeader(); - $scripts = $header->getScripts(); + $header = $this->response->getHeader(); + $scripts = $header->getScripts(); $scripts->addFile('jquery/jquery.tablesorter.js'); $scripts->addFile('server_plugins.js'); - $plugins = $this->_getServerPlugins(); - /** * Displays the page */ $this->response->addHTML(PMA_getHtmlForSubPageHeader('plugins')); - $this->response->addHTML($this->_getPluginTab($plugins)); + $this->response->addHTML($this->_getPluginTab()); } /** @@ -71,16 +83,14 @@ class ServerPluginsController extends Controller /** * Returns the html for plugin Tab. * - * @param array $plugins list - * * @return string */ - private function _getPluginTab($plugins) + private function _getPluginTab() { $html = '
'; $html .= ''; $html .= '
'; - foreach ($plugins as $plugin_type => $plugin_list) { + foreach ($this->plugins as $plugin_type => $plugin_list) { $key = 'plugins-' . preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type)); sort($plugin_list); From ff647fd63b30a1168a1e98ab5cae8ecf5ab5e2d0 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:12:27 +1100 Subject: [PATCH 05/12] Set the variable directly Signed-off-by: Madhura Jayaratne --- .../controllers/server/ServerPluginsController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index d38eeedc3a..b33499623f 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -29,7 +29,7 @@ class ServerPluginsController extends Controller public function __construct() { parent::__construct(); - $this->plugins = $this->_getServerPlugins(); + $this->_setServerPlugins(); } /** @@ -54,11 +54,11 @@ class ServerPluginsController extends Controller } /** - * Returns details about server plugins + * Sets details about server plugins * - * @return array server plugins data + * @return void */ - private function _getServerPlugins() + private function _setServerPlugins() { $sql = "SELECT plugin_name, plugin_type, @@ -77,7 +77,8 @@ class ServerPluginsController extends Controller } $this->dbi->freeResult($res); ksort($plugins); - return $plugins; + + $this->plugins = $plugins; } /** From ca44bbd93b991cf6634db4f5351c1ebc838a6844 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:36:51 +1100 Subject: [PATCH 06/12] Template plugins page Signed-off-by: Madhura Jayaratne --- .../server/ServerPluginsController.php | 73 +++---------------- templates/server/plugins/section.phtml | 33 +++++++++ templates/server/plugins/section_links.phtml | 8 ++ 3 files changed, 51 insertions(+), 63 deletions(-) create mode 100644 templates/server/plugins/section.phtml create mode 100644 templates/server/plugins/section_links.phtml diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index b33499623f..247b26807a 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -10,6 +10,7 @@ namespace PMA\libraries\controllers\server; use PMA\libraries\controllers\Controller; +use PMA\libraries\Template; /** * Handles viewing server plugin details @@ -89,73 +90,19 @@ class ServerPluginsController extends Controller private function _getPluginTab() { $html = '
'; - $html .= ''; - $html .= '
'; - - foreach ($this->plugins as $plugin_type => $plugin_list) { - $key = 'plugins-' - . preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type)); - sort($plugin_list); - - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - - $html .= $this->_getPluginList($plugin_list); - - $html .= ''; - $html .= '
'; - $html .= htmlspecialchars($plugin_type); - $html .= '
' . __('Plugin') . '' . __('Description') . '' . __('Version') . '' . __('Author') . '' . __('License') . '
'; + $html .= Template::get('server/plugins/section') + ->render( + array( + 'plugin_type' => $plugin_type, + 'plugin_list' => $plugin_list, + ) + ); } $html .= '
'; return $html; } - - /** - * Returns the html for plugin List. - * - * @param array $plugin_list list - * - * @return string - */ - private function _getPluginList($plugin_list) - { - $html = ""; - $odd_row = false; - foreach ($plugin_list as $plugin) { - $odd_row = !$odd_row; - $html .= ''; - $html .= ''; - $html .= htmlspecialchars($plugin['plugin_name']); - if (! $plugin['is_active']) { - $html .= ' ' . __('disabled') . ''; - } - $html .= ''; - $html .= '' . htmlspecialchars($plugin['plugin_description']) . ''; - $html .= '' . htmlspecialchars($plugin['plugin_type_version']) . ''; - $html .= '' . htmlspecialchars($plugin['plugin_author']) . ''; - $html .= '' . htmlspecialchars($plugin['plugin_license']) . ''; - $html .= ''; - } - return $html; - } } \ No newline at end of file diff --git a/templates/server/plugins/section.phtml b/templates/server/plugins/section.phtml new file mode 100644 index 0000000000..fdd1e77e65 --- /dev/null +++ b/templates/server/plugins/section.phtml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
\ No newline at end of file diff --git a/templates/server/plugins/section_links.phtml b/templates/server/plugins/section_links.phtml new file mode 100644 index 0000000000..054d6b37f8 --- /dev/null +++ b/templates/server/plugins/section_links.phtml @@ -0,0 +1,8 @@ + +
\ No newline at end of file From e199708ff2285c52ffe9772db70a87fe449f1ed3 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:38:31 +1100 Subject: [PATCH 07/12] Simplify Signed-off-by: Madhura Jayaratne --- libraries/controllers/server/ServerPluginsController.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index 247b26807a..ae7828759c 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -72,14 +72,12 @@ class ServerPluginsController extends Controller ORDER BY plugin_type, plugin_name"; $res = $this->dbi->query($sql); - $plugins = array(); + $this->plugins = array(); while ($row = $this->dbi->fetchAssoc($res)) { - $plugins[$row['plugin_type']][] = $row; + $this->plugins[$row['plugin_type']][] = $row; } $this->dbi->freeResult($res); - ksort($plugins); - - $this->plugins = $plugins; + ksort($this->plugins); } /** From a624f09e241819b6f06db61a8e54d993f6409ad3 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 22:49:23 +1100 Subject: [PATCH 08/12] Update tests Signed-off-by: Madhura Jayaratne --- .../server/ServerPluginsController.php | 4 +-- .../ServerPluginsControllerTest.php} | 30 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) rename test/{libraries/PMA_server_plugins_test.php => classes/controllers/ServerPluginsControllerTest.php} (82%) diff --git a/libraries/controllers/server/ServerPluginsController.php b/libraries/controllers/server/ServerPluginsController.php index ae7828759c..a824eb37d6 100644 --- a/libraries/controllers/server/ServerPluginsController.php +++ b/libraries/controllers/server/ServerPluginsController.php @@ -51,7 +51,7 @@ class ServerPluginsController extends Controller * Displays the page */ $this->response->addHTML(PMA_getHtmlForSubPageHeader('plugins')); - $this->response->addHTML($this->_getPluginTab()); + $this->response->addHTML($this->_getPluginsHtml()); } /** @@ -85,7 +85,7 @@ class ServerPluginsController extends Controller * * @return string */ - private function _getPluginTab() + private function _getPluginsHtml() { $html = '
'; $html .= Template::get('server/plugins/section_links') diff --git a/test/libraries/PMA_server_plugins_test.php b/test/classes/controllers/ServerPluginsControllerTest.php similarity index 82% rename from test/libraries/PMA_server_plugins_test.php rename to test/classes/controllers/ServerPluginsControllerTest.php index a0ee8d0d69..df51710078 100644 --- a/test/libraries/PMA_server_plugins_test.php +++ b/test/classes/controllers/ServerPluginsControllerTest.php @@ -1,7 +1,7 @@ getMockBuilder('PMA_DatabaseInterface') ->disableOriginalConstructor() ->getMock(); - $GLOBALS['dbi'] = $dbi; - //Call the test function /** * Prepare plugin list */ - - $plugins = array(); - $row = array(); $row["plugin_name"] = "plugin_name1"; $row["plugin_type"] = "plugin_type1"; @@ -86,9 +78,19 @@ class PMA_ServerPlugins_Test extends PHPUnit_Framework_TestCase $row["plugin_license"] = "plugin_license1"; $row["plugin_description"] = "plugin_description1"; $row["is_active"] = true; + + $plugins = array(); $plugins[$row['plugin_type']][] = $row; - $html = PMA_getPluginTab($plugins); + $class = new ReflectionClass('\PMA\libraries\controllers\server\ServerPluginsController'); + $method = $class->getMethod('_getPluginsHtml'); + $method->setAccessible(true); + $prop = $class->getProperty('plugins'); + $prop->setAccessible(true); + + $ctrl = new ServerPluginsController(); + $prop->setValue($ctrl, $plugins); + $html = $method->invoke(); //validate 1:Items $this->assertContains( From 9e19e168ea45af0cfd8c0121faced2b937f77887 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 23:09:49 +1100 Subject: [PATCH 09/12] Correctly mock dbi Signed-off-by: Madhura Jayaratne --- test/classes/controllers/ServerPluginsControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/classes/controllers/ServerPluginsControllerTest.php b/test/classes/controllers/ServerPluginsControllerTest.php index df51710078..6d0802463d 100644 --- a/test/classes/controllers/ServerPluginsControllerTest.php +++ b/test/classes/controllers/ServerPluginsControllerTest.php @@ -62,7 +62,7 @@ class ServerPluginsControllerTest extends PHPUnit_Framework_TestCase public function testPMAGetPluginAndModuleInfo() { //Mock DBI - $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') ->disableOriginalConstructor() ->getMock(); $GLOBALS['dbi'] = $dbi; From 5b5b694a3a615ed2a6bb63e68451a245c81c9b7f Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 16 Dec 2015 23:25:43 +1100 Subject: [PATCH 10/12] Fix typo Signed-off-by: Madhura Jayaratne --- test/classes/controllers/ServerPluginsControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/classes/controllers/ServerPluginsControllerTest.php b/test/classes/controllers/ServerPluginsControllerTest.php index 6d0802463d..2beb8169e0 100644 --- a/test/classes/controllers/ServerPluginsControllerTest.php +++ b/test/classes/controllers/ServerPluginsControllerTest.php @@ -90,7 +90,7 @@ class ServerPluginsControllerTest extends PHPUnit_Framework_TestCase $ctrl = new ServerPluginsController(); $prop->setValue($ctrl, $plugins); - $html = $method->invoke(); + $html = $method->invoke($ctrl); //validate 1:Items $this->assertContains( From e3041f3b7a2be5d8a68c0964f11a85f2be7c707f Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Thu, 17 Dec 2015 08:30:53 +1100 Subject: [PATCH 11/12] Use full namespace Signed-off-by: Madhura Jayaratne --- server_plugins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_plugins.php b/server_plugins.php index 892e11d0c4..4392eed835 100644 --- a/server_plugins.php +++ b/server_plugins.php @@ -14,7 +14,7 @@ use PMA\libraries\Response; require_once 'libraries/common.inc.php'; -$container = libraries\di\Container::getDefaultContainer(); +$container = \PMA\libraries\di\Container::getDefaultContainer(); $container->factory( 'PMA\libraries\controllers\server\ServerPluginsController' ); From 65d2413c0f0c96a942ad52caf3e806fd6da98971 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Thu, 17 Dec 2015 09:56:36 +1100 Subject: [PATCH 12/12] Properly mock dbi Signed-off-by: Madhura Jayaratne --- .../ServerPluginsControllerTest.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/test/classes/controllers/ServerPluginsControllerTest.php b/test/classes/controllers/ServerPluginsControllerTest.php index 2beb8169e0..e2a5dd00f8 100644 --- a/test/classes/controllers/ServerPluginsControllerTest.php +++ b/test/classes/controllers/ServerPluginsControllerTest.php @@ -11,6 +11,7 @@ */ use PMA\libraries\Theme; use PMA\libraries\controllers\server\ServerPluginsController; +use PMA\libraries\di\Container; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/database_interface.inc.php'; @@ -61,12 +62,6 @@ class ServerPluginsControllerTest extends PHPUnit_Framework_TestCase */ public function testPMAGetPluginAndModuleInfo() { - //Mock DBI - $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') - ->disableOriginalConstructor() - ->getMock(); - $GLOBALS['dbi'] = $dbi; - /** * Prepare plugin list */ @@ -79,17 +74,32 @@ class ServerPluginsControllerTest extends PHPUnit_Framework_TestCase $row["plugin_description"] = "plugin_description1"; $row["is_active"] = true; - $plugins = array(); - $plugins[$row['plugin_type']][] = $row; + //Mock DBI + $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->will($this->returnValue(true)); + $dbi->expects($this->at(1)) + ->method('fetchAssoc') + ->will($this->returnValue($row)); + $dbi->expects($this->at(2)) + ->method('fetchAssoc') + ->will($this->returnValue(false)); + $dbi->expects($this->once()) + ->method('freeResult') + ->will($this->returnValue(true)); + + $container = Container::getDefaultContainer(); + $container->set('dbi', $dbi); $class = new ReflectionClass('\PMA\libraries\controllers\server\ServerPluginsController'); $method = $class->getMethod('_getPluginsHtml'); $method->setAccessible(true); - $prop = $class->getProperty('plugins'); - $prop->setAccessible(true); $ctrl = new ServerPluginsController(); - $prop->setValue($ctrl, $plugins); $html = $method->invoke($ctrl); //validate 1:Items