From 21a747cfbef0dee398a0049aece37c1c0ce3bf57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 3 Jul 2019 20:19:00 -0300 Subject: [PATCH] Add tests for Server\Plugin and Server\Plugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Server/Plugins.php | 4 +- test/classes/Server/PluginTest.php | 84 +++++++++++++++++++++++++ test/classes/Server/PluginsTest.php | 92 ++++++++++++++++++++++++++++ test/classes/Stubs/DbiDummy.php | 30 ++++++++- 4 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 test/classes/Server/PluginTest.php create mode 100644 test/classes/Server/PluginsTest.php diff --git a/libraries/classes/Server/Plugins.php b/libraries/classes/Server/Plugins.php index be6856996d..eb8e85ae8d 100644 --- a/libraries/classes/Server/Plugins.php +++ b/libraries/classes/Server/Plugins.php @@ -35,9 +35,9 @@ class Plugins { global $cfg; - $sql = 'SHOW PLUGINS;'; + $sql = 'SHOW PLUGINS'; if (! $cfg['Server']['DisableIS']) { - $sql = 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME;'; + $sql = 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME'; } $result = $this->dbi->query($sql); $plugins = []; diff --git a/test/classes/Server/PluginTest.php b/test/classes/Server/PluginTest.php new file mode 100644 index 0000000000..845360b84c --- /dev/null +++ b/test/classes/Server/PluginTest.php @@ -0,0 +1,84 @@ + 'BLACKHOLE', + 'version' => '1.0', + 'status' => 'ACTIVE', + 'type' => 'STORAGE ENGINE', + 'typeVersion' => '100316.0', + 'library' => 'ha_blackhole.so', + 'libraryVersion' => '1.13', + 'author' => 'MySQL AB', + 'description' => '/dev/null storage engine (anything you write to it disappears)', + 'license' => 'GPL', + 'loadOption' => 'ON', + 'maturity' => 'Stable', + 'authVersion' => '1.0', + ]); + + $this->assertInstanceOf(Plugin::class, $plugin); + $this->assertSame('BLACKHOLE', $plugin->getName()); + $this->assertSame('1.0', $plugin->getVersion()); + $this->assertSame('ACTIVE', $plugin->getStatus()); + $this->assertSame('STORAGE ENGINE', $plugin->getType()); + $this->assertSame('100316.0', $plugin->getTypeVersion()); + $this->assertSame('ha_blackhole.so', $plugin->getLibrary()); + $this->assertSame('1.13', $plugin->getLibraryVersion()); + $this->assertSame('MySQL AB', $plugin->getAuthor()); + $this->assertSame('GPL', $plugin->getLicense()); + $this->assertSame('ON', $plugin->getLoadOption()); + $this->assertSame('Stable', $plugin->getMaturity()); + $this->assertSame('1.0', $plugin->getAuthVersion()); + $this->assertSame( + '/dev/null storage engine (anything you write to it disappears)', + $plugin->getDescription() + ); + + return $plugin; + } + + /** + * @param Plugin $plugin Plugin object to be tested + * + * @return void + * + * @depends testFromState + */ + public function testToArray(Plugin $plugin): void + { + $this->assertSame([ + 'name' => 'BLACKHOLE', + 'version' => '1.0', + 'status' => 'ACTIVE', + 'type' => 'STORAGE ENGINE', + 'type_version' => '100316.0', + 'library' => 'ha_blackhole.so', + 'library_version' => '1.13', + 'author' => 'MySQL AB', + 'description' => '/dev/null storage engine (anything you write to it disappears)', + 'license' => 'GPL', + 'load_option' => 'ON', + 'maturity' => 'Stable', + 'auth_version' => '1.0', + ], $plugin->toArray()); + } +} diff --git a/test/classes/Server/PluginsTest.php b/test/classes/Server/PluginsTest.php new file mode 100644 index 0000000000..dfa25d1d4a --- /dev/null +++ b/test/classes/Server/PluginsTest.php @@ -0,0 +1,92 @@ +plugins = new Plugins($GLOBALS['dbi']); + + $plugins = $this->plugins->getAll(); + + $this->assertIsArray($plugins); + $this->assertNotEmpty($plugins); + + $plugin = $plugins[0]; + + $this->assertInstanceOf(Plugin::class, $plugin); + $this->assertSame([ + 'name' => 'BLACKHOLE', + 'version' => '1.0', + 'status' => 'ACTIVE', + 'type' => 'STORAGE ENGINE', + 'type_version' => '100316.0', + 'library' => 'ha_blackhole.so', + 'library_version' => '1.13', + 'author' => 'MySQL AB', + 'description' => '/dev/null storage engine (anything you write to it disappears)', + 'license' => 'GPL', + 'load_option' => 'ON', + 'maturity' => 'Stable', + 'auth_version' => '1.0', + ], $plugin->toArray()); + } + + /** + * @return void + */ + public function testGetAllWithoutInformationSchema(): void + { + $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000; + $GLOBALS['cfg']['Server']['DisableIS'] = true; + + $this->plugins = new Plugins($GLOBALS['dbi']); + + $plugins = $this->plugins->getAll(); + + $this->assertIsArray($plugins); + $this->assertNotEmpty($plugins); + + $plugin = $plugins[0]; + + $this->assertInstanceOf(Plugin::class, $plugin); + $this->assertSame([ + 'name' => 'partition', + 'version' => null, + 'status' => 'ACTIVE', + 'type' => 'STORAGE ENGINE', + 'type_version' => null, + 'library' => null, + 'library_version' => null, + 'author' => null, + 'description' => null, + 'license' => 'GPL', + 'load_option' => null, + 'maturity' => null, + 'auth_version' => null, + ], $plugin->toArray()); + } +} diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index 03b89e9953..a53586566d 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -1307,9 +1307,35 @@ class DbiDummy implements DbiExtension 'result' => [], ], [ - 'query' => "SHOW PLUGINS", + 'query' => 'SHOW PLUGINS', 'result' => [ - ['Name' => 'partition'], + [ + 'Name' => 'partition', + 'Status' => 'ACTIVE', + 'Type' => 'STORAGE ENGINE', + 'Library' => null, + 'License' => 'GPL', + ], + ], + ], + [ + 'query' => 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME', + 'result' => [ + [ + 'PLUGIN_NAME' => 'BLACKHOLE', + 'PLUGIN_VERSION' => '1.0', + 'PLUGIN_STATUS' => 'ACTIVE', + 'PLUGIN_TYPE' => 'STORAGE ENGINE', + 'PLUGIN_TYPE_VERSION' => '100316.0', + 'PLUGIN_LIBRARY' => 'ha_blackhole.so', + 'PLUGIN_LIBRARY_VERSION' => '1.13', + 'PLUGIN_AUTHOR' => 'MySQL AB', + 'PLUGIN_DESCRIPTION' => '/dev/null storage engine (anything you write to it disappears)', + 'PLUGIN_LICENSE' => 'GPL', + 'LOAD_OPTION' => 'ON', + 'PLUGIN_MATURITY' => 'Stable', + 'PLUGIN_AUTH_VERSION' => '1.0', + ], ], ], [