X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FPluginManagerTest.php;h=a5d5dbe988ea22ad525ed74a71b5c3d421c2d7ec;hb=b06fc28aa32f477e1785cd998385fdb490bc5ebf;hp=df2614b557d8cf94a03679531e3a4e125706a440;hpb=d06265fb5785493ee845d4c4a86583402b475b60;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index df2614b5..a5d5dbe9 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -1,15 +1,12 @@ pluginManager = new PluginManager($conf); + } + /** + * Test plugin loading and hook execution. + */ + public function testPlugin(): void + { PluginManager::$PLUGINS_PATH = self::$pluginPath; - $pluginManager->load(array(self::$pluginName)); + $this->pluginManager->load(array(self::$pluginName)); $this->assertTrue(function_exists('hook_test_random')); $data = array(0 => 'woot'); - $pluginManager->executeHooks('random', $data); + $this->pluginManager->executeHooks('random', $data); $this->assertEquals('woot', $data[1]); $data = array(0 => 'woot'); - $pluginManager->executeHooks('random', $data, array('target' => 'test')); + $this->pluginManager->executeHooks('random', $data, array('target' => 'test')); $this->assertEquals('page test', $data[1]); $data = array(0 => 'woot'); - $pluginManager->executeHooks('random', $data, array('loggedin' => true)); + $this->pluginManager->executeHooks('random', $data, array('loggedin' => true)); $this->assertEquals('loggedin', $data[1]); } + /** + * Test plugin loading and hook execution with an error: raise an incompatibility error. + */ + public function testPluginWithPhpError(): void + { + PluginManager::$PLUGINS_PATH = self::$pluginPath; + $this->pluginManager->load(array(self::$pluginName)); + + $this->assertTrue(function_exists('hook_test_error')); + + $data = []; + $this->pluginManager->executeHooks('error', $data); + + $this->assertSame( + 'test [plugin incompatibility]: Class \'Unknown\' not found', + $this->pluginManager->getErrors()[0] + ); + } + /** * Test missing plugin loading. - * - * @return void */ - public function testPluginNotFound() + public function testPluginNotFound(): void { - $pluginManager = PluginManager::getInstance(); + $this->pluginManager->load(array()); + $this->pluginManager->load(array('nope', 'renope')); + $this->addToAssertionCount(1); + } - $pluginManager->load(array()); + /** + * Test plugin metadata loading. + */ + public function testGetPluginsMeta(): void + { + PluginManager::$PLUGINS_PATH = self::$pluginPath; + $this->pluginManager->load(array(self::$pluginName)); - $pluginManager->load(array('nope', 'renope')); + $expectedParameters = array( + 'pop' => array( + 'value' => '', + 'desc' => 'pop description', + ), + 'hip' => array( + 'value' => '', + 'desc' => '', + ), + ); + $meta = $this->pluginManager->getPluginsMeta(); + $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); + $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); } -} \ No newline at end of file +}