Merge pull request #1551 from ArthurHoaro/fix/plugin-save-metadata
Plugins: do not save metadata along plugin parameters
This commit is contained in:
commit
4af591ff3c
5 changed files with 50 additions and 30 deletions
|
@ -62,6 +62,7 @@ public function save(Request $request, Response $response): Response
|
||||||
|
|
||||||
if (isset($parameters['parameters_form'])) {
|
if (isset($parameters['parameters_form'])) {
|
||||||
unset($parameters['parameters_form']);
|
unset($parameters['parameters_form']);
|
||||||
|
unset($parameters['token']);
|
||||||
foreach ($parameters as $param => $value) {
|
foreach ($parameters as $param => $value) {
|
||||||
$this->container->conf->set('plugins.'. $param, escape($value));
|
$this->container->conf->set('plugins.'. $param, escape($value));
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,20 +100,17 @@ public function load($authorizedPlugins)
|
||||||
*/
|
*/
|
||||||
public function executeHooks($hook, &$data, $params = array())
|
public function executeHooks($hook, &$data, $params = array())
|
||||||
{
|
{
|
||||||
if (!empty($params['target'])) {
|
$metadataParameters = [
|
||||||
$data['_PAGE_'] = $params['target'];
|
'target' => '_PAGE_',
|
||||||
}
|
'loggedin' => '_LOGGEDIN_',
|
||||||
|
'basePath' => '_BASE_PATH_',
|
||||||
|
'bookmarkService' => '_BOOKMARK_SERVICE_',
|
||||||
|
];
|
||||||
|
|
||||||
if (isset($params['loggedin'])) {
|
foreach ($metadataParameters as $parameter => $metaKey) {
|
||||||
$data['_LOGGEDIN_'] = $params['loggedin'];
|
if (array_key_exists($parameter, $params)) {
|
||||||
|
$data[$metaKey] = $params[$parameter];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['basePath'])) {
|
|
||||||
$data['_BASE_PATH_'] = $params['basePath'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($params['bookmarkService'])) {
|
|
||||||
$data['_BOOKMARK_SERVICE_'] = $params['bookmarkService'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->loadedPlugins as $plugin) {
|
foreach ($this->loadedPlugins as $plugin) {
|
||||||
|
@ -128,6 +125,10 @@ public function executeHooks($hook, &$data, $params = array())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($metadataParameters as $metaKey) {
|
||||||
|
unset($data[$metaKey]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,17 +41,31 @@ public function testPlugin(): void
|
||||||
|
|
||||||
$this->assertTrue(function_exists('hook_test_random'));
|
$this->assertTrue(function_exists('hook_test_random'));
|
||||||
|
|
||||||
$data = array(0 => 'woot');
|
$data = [0 => 'woot'];
|
||||||
$this->pluginManager->executeHooks('random', $data);
|
$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->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->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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,8 +92,8 @@ public function testPluginWithPhpError(): void
|
||||||
*/
|
*/
|
||||||
public function testPluginNotFound(): void
|
public function testPluginNotFound(): void
|
||||||
{
|
{
|
||||||
$this->pluginManager->load(array());
|
$this->pluginManager->load([]);
|
||||||
$this->pluginManager->load(array('nope', 'renope'));
|
$this->pluginManager->load(['nope', 'renope']);
|
||||||
$this->addToAssertionCount(1);
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,18 +103,18 @@ public function testPluginNotFound(): void
|
||||||
public function testGetPluginsMeta(): void
|
public function testGetPluginsMeta(): void
|
||||||
{
|
{
|
||||||
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
||||||
$this->pluginManager->load(array(self::$pluginName));
|
$this->pluginManager->load([self::$pluginName]);
|
||||||
|
|
||||||
$expectedParameters = array(
|
$expectedParameters = [
|
||||||
'pop' => array(
|
'pop' => [
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'desc' => 'pop description',
|
'desc' => 'pop description',
|
||||||
),
|
],
|
||||||
'hip' => array(
|
'hip' => [
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'desc' => '',
|
'desc' => '',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$meta = $this->pluginManager->getPluginsMeta();
|
$meta = $this->pluginManager->getPluginsMeta();
|
||||||
$this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
|
$this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
|
||||||
$this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
|
$this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
|
||||||
|
|
|
@ -32,7 +32,7 @@ public function setUp(): void
|
||||||
array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
|
array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
$path = __DIR__ . '/folder';
|
$path = __DIR__ . '/folder';
|
||||||
array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
|
array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
|
||||||
|
@ -125,6 +125,7 @@ public function testSavePluginParameters(): void
|
||||||
'parameters_form' => true,
|
'parameters_form' => true,
|
||||||
'parameter1' => 'blip',
|
'parameter1' => 'blip',
|
||||||
'parameter2' => 'blop',
|
'parameter2' => 'blop',
|
||||||
|
'token' => 'this parameter should not be saved'
|
||||||
];
|
];
|
||||||
|
|
||||||
$request = $this->createMock(Request::class);
|
$request = $this->createMock(Request::class);
|
||||||
|
@ -143,7 +144,7 @@ public function testSavePluginParameters(): void
|
||||||
->with('save_plugin_parameters', $parameters)
|
->with('save_plugin_parameters', $parameters)
|
||||||
;
|
;
|
||||||
$this->container->conf
|
$this->container->conf
|
||||||
->expects(static::atLeastOnce())
|
->expects(static::exactly(2))
|
||||||
->method('set')
|
->method('set')
|
||||||
->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop'])
|
->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop'])
|
||||||
;
|
;
|
||||||
|
|
|
@ -13,6 +13,9 @@ function hook_test_random($data)
|
||||||
$data[1] = 'page test';
|
$data[1] = 'page test';
|
||||||
} elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
|
} elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
|
||||||
$data[1] = 'loggedin';
|
$data[1] = 'loggedin';
|
||||||
|
} elseif (array_key_exists('_LOGGEDIN_', $data)) {
|
||||||
|
$data[1] = 'loggedin';
|
||||||
|
$data[2] = $data['_LOGGEDIN_'];
|
||||||
} else {
|
} else {
|
||||||
$data[1] = $data[0];
|
$data[1] = $data[0];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue