*/
public function executeHooks($hook, &$data, $params = array())
{
- if (!empty($params['target'])) {
- $data['_PAGE_'] = $params['target'];
- }
-
- if (isset($params['loggedin'])) {
- $data['_LOGGEDIN_'] = $params['loggedin'];
- }
-
- if (isset($params['basePath'])) {
- $data['_BASE_PATH_'] = $params['basePath'];
- }
-
- if (isset($params['bookmarkService'])) {
- $data['_BOOKMARK_SERVICE_'] = $params['bookmarkService'];
+ $metadataParameters = [
+ 'target' => '_PAGE_',
+ 'loggedin' => '_LOGGEDIN_',
+ 'basePath' => '_BASE_PATH_',
+ 'bookmarkService' => '_BOOKMARK_SERVICE_',
+ ];
+
+ foreach ($metadataParameters as $parameter => $metaKey) {
+ if (array_key_exists($parameter, $params)) {
+ $data[$metaKey] = $params[$parameter];
+ }
}
foreach ($this->loadedPlugins as $plugin) {
}
}
}
+
+ foreach ($metadataParameters as $metaKey) {
+ unset($data[$metaKey]);
+ }
}
/**
$this->assertTrue(function_exists('hook_test_random'));
- $data = array(0 => 'woot');
+ $data = [0 => 'woot'];
$this->pluginManager->executeHooks('random', $data);
- $this->assertEquals('woot', $data[1]);
- $data = array(0 => 'woot');
+ static::assertCount(2, $data);
+ static::assertSame('woot', $data[1]);
+
+ $data = [0 => 'woot'];
$this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
- $this->assertEquals('page test', $data[1]);
- $data = array(0 => 'woot');
+ static::assertCount(2, $data);
+ static::assertSame('page test', $data[1]);
+
+ $data = [0 => 'woot'];
$this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
- $this->assertEquals('loggedin', $data[1]);
+
+ static::assertCount(2, $data);
+ static::assertEquals('loggedin', $data[1]);
+
+ $data = [0 => 'woot'];
+ $this->pluginManager->executeHooks('random', $data, array('loggedin' => null));
+
+ static::assertCount(3, $data);
+ static::assertEquals('loggedin', $data[1]);
+ static::assertArrayHasKey(2, $data);
+ static::assertNull($data[2]);
}
/**
*/
public function testPluginNotFound(): void
{
- $this->pluginManager->load(array());
- $this->pluginManager->load(array('nope', 'renope'));
+ $this->pluginManager->load([]);
+ $this->pluginManager->load(['nope', 'renope']);
$this->addToAssertionCount(1);
}
public function testGetPluginsMeta(): void
{
PluginManager::$PLUGINS_PATH = self::$pluginPath;
- $this->pluginManager->load(array(self::$pluginName));
+ $this->pluginManager->load([self::$pluginName]);
- $expectedParameters = array(
- 'pop' => array(
+ $expectedParameters = [
+ 'pop' => [
'value' => '',
'desc' => 'pop description',
- ),
- 'hip' => array(
+ ],
+ 'hip' => [
'value' => '',
'desc' => '',
- ),
- );
+ ],
+ ];
$meta = $this->pluginManager->getPluginsMeta();
$this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
$this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
}
- public function tearDown()
+ public function tearDown(): void
{
$path = __DIR__ . '/folder';
array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
'parameters_form' => true,
'parameter1' => 'blip',
'parameter2' => 'blop',
+ 'token' => 'this parameter should not be saved'
];
$request = $this->createMock(Request::class);
->with('save_plugin_parameters', $parameters)
;
$this->container->conf
- ->expects(static::atLeastOnce())
+ ->expects(static::exactly(2))
->method('set')
->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop'])
;