X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FPluginManagerTest.php;h=75b3ae0082138568d753b8b9ab5cfc75b2286be3;hb=refs%2Fpull%2F1698%2Fhead;hp=bbd2e142feb7b21f84f73869f4225e43e5c80c07;hpb=ab58f2542072e6bf34acd862f6cfed84b33feb29;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index bbd2e142..75b3ae00 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -1,6 +1,8 @@ pluginManager->executeHooks('error', $data); - $this->assertMatchesRegularExpression( + $this->assertRegExp( '/test \[plugin incompatibility\]: Class [\'"]Unknown[\'"] not found/', $this->pluginManager->getErrors()[0] ); @@ -119,4 +121,58 @@ class PluginManagerTest extends \Shaarli\TestCase $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); } + + /** + * Test plugin custom routes - note that there is no check on callable functions + */ + public function testRegisteredRoutes(): void + { + PluginManager::$PLUGINS_PATH = self::$pluginPath; + $this->pluginManager->load([self::$pluginName]); + + $expectedParameters = [ + [ + 'method' => 'GET', + 'route' => '/test', + 'callable' => 'getFunction', + ], + [ + 'method' => 'POST', + 'route' => '/custom', + 'callable' => 'postFunction', + ], + ]; + $meta = $this->pluginManager->getRegisteredRoutes(); + static::assertSame($expectedParameters, $meta[self::$pluginName]); + } + + /** + * Test plugin custom routes with invalid route + */ + public function testRegisteredRoutesInvalid(): void + { + $plugin = 'test_route_invalid'; + $this->pluginManager->load([$plugin]); + + $meta = $this->pluginManager->getRegisteredRoutes(); + static::assertSame([], $meta); + + $errors = $this->pluginManager->getErrors(); + static::assertSame(['test_route_invalid [plugin incompatibility]: trying to register invalid route.'], $errors); + } + + public function testSearchFilterPlugin(): void + { + PluginManager::$PLUGINS_PATH = self::$pluginPath; + $this->pluginManager->load([self::$pluginName]); + + static::assertNull($this->pluginManager->getFilterSearchEntryHooks()); + + static::assertTrue($this->pluginManager->filterSearchEntry(new Bookmark(), ['_result' => true])); + + static::assertCount(1, $this->pluginManager->getFilterSearchEntryHooks()); + static::assertSame('hook_test_filter_search_entry', $this->pluginManager->getFilterSearchEntryHooks()[0]); + + static::assertFalse($this->pluginManager->filterSearchEntry(new Bookmark(), ['_result' => false])); + } }