diff --git a/application/config/ConfigPlugin.php b/application/config/ConfigPlugin.php
index dbb24937..ea8dfbda 100644
--- a/application/config/ConfigPlugin.php
+++ b/application/config/ConfigPlugin.php
@@ -1,6 +1,7 @@
$value) {
// No duplicate order allowed.
- if (in_array($value, $orders)) {
+ if (in_array($value, $orders, true)) {
return false;
}
diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php
index fd978e99..92c0e911 100644
--- a/application/front/ShaarliMiddleware.php
+++ b/application/front/ShaarliMiddleware.php
@@ -60,7 +60,7 @@ class ShaarliMiddleware
$response = $response->withStatus($e->getCode());
- return $response->write($this->container->pageBuilder->render('error'));
+ return $response->write($this->container->pageBuilder->render('error', $this->container->basePath));
} catch (UnauthorizedException $e) {
$returnUrl = urlencode($this->container->environment['REQUEST_URI']);
@@ -80,7 +80,7 @@ class ShaarliMiddleware
$response = $response->withStatus(500);
- return $response->write($this->container->pageBuilder->render('error'));
+ return $response->write($this->container->pageBuilder->render('error', $this->container->basePath));
}
}
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php
index 3aa48423..33e1188e 100644
--- a/application/front/controller/admin/ManageShaareController.php
+++ b/application/front/controller/admin/ManageShaareController.php
@@ -152,7 +152,7 @@ class ManageShaareController extends ShaarliAdminController
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$formatter = $this->container->formatterFactory->getFormatter('raw');
$data = $formatter->format($bookmark);
- $data = $this->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark);
@@ -211,7 +211,7 @@ class ManageShaareController extends ShaarliAdminController
}
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('delete_link', $data);
+ $this->executePageHooks('delete_link', $data);
$this->container->bookmarkService->remove($bookmark, false);
++ $count;
}
@@ -283,7 +283,7 @@ class ManageShaareController extends ShaarliAdminController
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark, false);
@@ -325,7 +325,7 @@ class ManageShaareController extends ShaarliAdminController
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark);
@@ -354,7 +354,7 @@ class ManageShaareController extends ShaarliAdminController
'default_private_links' => $this->container->conf->get('privacy.default_private_links', false),
];
- $data = $this->executeHooks('render_editlink', $data);
+ $this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK);
foreach ($data as $key => $value) {
$this->assignView($key, $value);
@@ -368,19 +368,4 @@ class ManageShaareController extends ShaarliAdminController
return $response->write($this->render(TemplatePage::EDIT_LINK));
}
-
- /**
- * @param mixed[] $data Variables passed to the template engine
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(string $hook, array $data): array
- {
- $this->container->pluginManager->executeHooks(
- $hook,
- $data
- );
-
- return $data;
- }
}
diff --git a/application/front/controller/admin/PluginsController.php b/application/front/controller/admin/PluginsController.php
index 1eb7e635..0e09116e 100644
--- a/application/front/controller/admin/PluginsController.php
+++ b/application/front/controller/admin/PluginsController.php
@@ -58,7 +58,7 @@ class PluginsController extends ShaarliAdminController
try {
$parameters = $request->getParams() ?? [];
- $this->executeHooks($parameters);
+ $this->executePageHooks('save_plugin_parameters', $parameters);
if (isset($parameters['parameters_form'])) {
unset($parameters['parameters_form']);
@@ -81,19 +81,4 @@ class PluginsController extends ShaarliAdminController
return $this->redirect($response, '/admin/plugins');
}
-
- /**
- * @param mixed[] $data Variables passed to the template engine
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(array $data): array
- {
- $this->container->pluginManager->executeHooks(
- 'save_plugin_parameters',
- $data
- );
-
- return $data;
- }
}
diff --git a/application/front/controller/admin/ToolsController.php b/application/front/controller/admin/ToolsController.php
index a476e898..a87f20d2 100644
--- a/application/front/controller/admin/ToolsController.php
+++ b/application/front/controller/admin/ToolsController.php
@@ -22,7 +22,7 @@ class ToolsController extends ShaarliAdminController
'sslenabled' => is_https($this->container->environment),
];
- $data = $this->executeHooks($data);
+ $this->executePageHooks('render_tools', $data, TemplatePage::TOOLS);
foreach ($data as $key => $value) {
$this->assignView($key, $value);
@@ -32,19 +32,4 @@ class ToolsController extends ShaarliAdminController
return $response->write($this->render(TemplatePage::TOOLS));
}
-
- /**
- * @param mixed[] $data Variables passed to the template engine
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(array $data): array
- {
- $this->container->pluginManager->executeHooks(
- 'render_tools',
- $data
- );
-
- return $data;
- }
}
diff --git a/application/front/controller/visitor/BookmarkListController.php b/application/front/controller/visitor/BookmarkListController.php
index a37a7f6b..23c4fbae 100644
--- a/application/front/controller/visitor/BookmarkListController.php
+++ b/application/front/controller/visitor/BookmarkListController.php
@@ -124,7 +124,7 @@ class BookmarkListController extends ShaarliVisitorController
$data['pagetitle'] = ($data['pagetitle'] ?? '') . $this->container->conf->get('general.title', 'Shaarli');
- $this->executeHooks($data);
+ $this->executePageHooks('render_linklist', $data, TemplatePage::LINKLIST);
$this->assignAllView($data);
return $response->write($this->render(TemplatePage::LINKLIST));
@@ -153,7 +153,7 @@ class BookmarkListController extends ShaarliVisitorController
]
);
- $this->executeHooks($data);
+ $this->executePageHooks('render_linklist', $data, TemplatePage::LINKLIST);
$this->assignAllView($data);
return $response->write($this->render(TemplatePage::LINKLIST));
@@ -182,18 +182,6 @@ class BookmarkListController extends ShaarliVisitorController
return false;
}
- /**
- * @param mixed[] $data Template vars to process in plugins, passed as reference.
- */
- protected function executeHooks(array &$data): void
- {
- $this->container->pluginManager->executeHooks(
- 'render_linklist',
- $data,
- ['loggedin' => $this->container->loginManager->isLoggedIn()]
- );
- }
-
/**
* @return string[] Default template variables without values.
*/
diff --git a/application/front/controller/visitor/DailyController.php b/application/front/controller/visitor/DailyController.php
index 05b4f095..808ca5f7 100644
--- a/application/front/controller/visitor/DailyController.php
+++ b/application/front/controller/visitor/DailyController.php
@@ -72,13 +72,11 @@ class DailyController extends ShaarliVisitorController
];
// Hooks are called before column construction so that plugins don't have to deal with columns.
- $data = $this->executeHooks($data);
+ $this->executePageHooks('render_daily', $data, TemplatePage::DAILY);
$data['cols'] = $this->calculateColumns($data['linksToDisplay']);
- foreach ($data as $key => $value) {
- $this->assignView($key, $value);
- }
+ $this->assignAllView($data);
$mainTitle = $this->container->conf->get('general.title', 'Shaarli');
$this->assignView(
@@ -190,20 +188,4 @@ class DailyController extends ShaarliVisitorController
return $columns;
}
-
- /**
- * @param mixed[] $data Variables passed to the template engine
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(array $data): array
- {
- $this->container->pluginManager->executeHooks(
- 'render_daily',
- $data,
- ['loggedin' => $this->container->loginManager->isLoggedIn()]
- );
-
- return $data;
- }
}
diff --git a/application/front/controller/visitor/FeedController.php b/application/front/controller/visitor/FeedController.php
index f76f55fd..da2848c2 100644
--- a/application/front/controller/visitor/FeedController.php
+++ b/application/front/controller/visitor/FeedController.php
@@ -46,7 +46,7 @@ class FeedController extends ShaarliVisitorController
$data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
- $data = $this->executeHooks($data, $feedType);
+ $this->executePageHooks('render_feed', $data, $feedType);
$this->assignAllView($data);
$content = $this->render('feed.'. $feedType);
@@ -55,23 +55,4 @@ class FeedController extends ShaarliVisitorController
return $response->write($content);
}
-
- /**
- * @param mixed[] $data Template data
- *
- * @return mixed[] Template data after active plugins hook execution.
- */
- protected function executeHooks(array $data, string $feedType): array
- {
- $this->container->pluginManager->executeHooks(
- 'render_feed',
- $data,
- [
- 'loggedin' => $this->container->loginManager->isLoggedIn(),
- 'target' => $feedType,
- ]
- );
-
- return $data;
- }
}
diff --git a/application/front/controller/visitor/PictureWallController.php b/application/front/controller/visitor/PictureWallController.php
index 5ef2cb17..3c57f8dd 100644
--- a/application/front/controller/visitor/PictureWallController.php
+++ b/application/front/controller/visitor/PictureWallController.php
@@ -42,30 +42,13 @@ class PictureWallController extends ShaarliVisitorController
}
}
- $data = $this->executeHooks($linksToDisplay);
+ $data = ['linksToDisplay' => $linksToDisplay];
+ $this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);
+
foreach ($data as $key => $value) {
$this->assignView($key, $value);
}
return $response->write($this->render(TemplatePage::PICTURE_WALL));
}
-
- /**
- * @param mixed[] $linksToDisplay List of formatted bookmarks
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(array $linksToDisplay): array
- {
- $data = [
- 'linksToDisplay' => $linksToDisplay,
- ];
- $this->container->pluginManager->executeHooks(
- 'render_picwall',
- $data,
- ['loggedin' => $this->container->loginManager->isLoggedIn()]
- );
-
- return $data;
- }
}
diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php
index b494a8e6..47057d97 100644
--- a/application/front/controller/visitor/ShaarliVisitorController.php
+++ b/application/front/controller/visitor/ShaarliVisitorController.php
@@ -60,22 +60,9 @@ abstract class ShaarliVisitorController
$this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE));
$this->assignView('plugin_errors', $this->container->pluginManager->getErrors());
- /*
- * Define base path (if Shaarli is installed in a domain's subfolder, e.g. `/shaarli`)
- * and the asset path (subfolder/tpl/default for default theme).
- * These MUST be used to create an internal link or to include an asset in templates.
- */
- $this->assignView('base_path', $this->container->basePath);
- $this->assignView(
- 'asset_path',
- $this->container->basePath . '/' .
- rtrim($this->container->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
- $this->container->conf->get('resource.theme', 'default')
- );
-
$this->executeDefaultHooks($template);
- return $this->container->pageBuilder->render($template);
+ return $this->container->pageBuilder->render($template, $this->container->basePath);
}
/**
@@ -97,13 +84,29 @@ abstract class ShaarliVisitorController
$pluginData,
[
'target' => $template,
- 'loggedin' => $this->container->loginManager->isLoggedIn()
+ 'loggedin' => $this->container->loginManager->isLoggedIn(),
+ 'basePath' => $this->container->basePath,
]
);
$this->assignView('plugins_' . $name, $pluginData);
}
}
+ protected function executePageHooks(string $hook, array &$data, string $template = null): void
+ {
+ $params = [
+ 'target' => $template,
+ 'loggedin' => $this->container->loginManager->isLoggedIn(),
+ 'basePath' => $this->container->basePath,
+ ];
+
+ $this->container->pluginManager->executeHooks(
+ $hook,
+ $data,
+ $params
+ );
+ }
+
/**
* Simple helper which prepend the base path to redirect path.
*
diff --git a/application/front/controller/visitor/TagCloudController.php b/application/front/controller/visitor/TagCloudController.php
index 15b6d7b7..f9c529bc 100644
--- a/application/front/controller/visitor/TagCloudController.php
+++ b/application/front/controller/visitor/TagCloudController.php
@@ -71,10 +71,8 @@ class TagCloudController extends ShaarliVisitorController
'search_tags' => $searchTags,
'tags' => $tags,
];
- $data = $this->executeHooks('tag' . $type, $data);
- foreach ($data as $key => $value) {
- $this->assignView($key, $value);
- }
+ $this->executePageHooks('render_tag' . $type, $data, 'tag.' . $type);
+ $this->assignAllView($data);
$searchTags = !empty($searchTags) ? $searchTags .' - ' : '';
$this->assignView(
@@ -82,7 +80,7 @@ class TagCloudController extends ShaarliVisitorController
$searchTags . t('Tag '. $type) .' - '. $this->container->conf->get('general.title', 'Shaarli')
);
- return $response->write($this->render('tag.'. $type));
+ return $response->write($this->render('tag.' . $type));
}
/**
@@ -112,20 +110,4 @@ class TagCloudController extends ShaarliVisitorController
return $tagList;
}
-
- /**
- * @param mixed[] $data Template data
- *
- * @return mixed[] Template data after active plugins hook execution.
- */
- protected function executeHooks(string $template, array $data): array
- {
- $this->container->pluginManager->executeHooks(
- 'render_'. $template,
- $data,
- ['loggedin' => $this->container->loginManager->isLoggedIn()]
- );
-
- return $data;
- }
}
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php
index 591a9180..b3e8b2f8 100644
--- a/application/plugin/PluginManager.php
+++ b/application/plugin/PluginManager.php
@@ -108,6 +108,10 @@ class PluginManager
$data['_LOGGEDIN_'] = $params['loggedin'];
}
+ if (isset($params['basePath'])) {
+ $data['_BASE_PATH_'] = $params['basePath'];
+ }
+
foreach ($this->loadedPlugins as $plugin) {
$hookFunction = $this->buildHookName($hook, $plugin);
diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php
index 471724c0..7a716673 100644
--- a/application/render/PageBuilder.php
+++ b/application/render/PageBuilder.php
@@ -3,6 +3,7 @@
namespace Shaarli\Render;
use Exception;
+use exceptions\MissingBasePathException;
use RainTPL;
use Shaarli\ApplicationUtils;
use Shaarli\Bookmark\BookmarkServiceInterface;
@@ -156,7 +157,7 @@ class PageBuilder
* Affect variable after controller processing.
* Used for alert messages.
*/
- protected function finalize(): void
+ protected function finalize(string $basePath): void
{
// TODO: use the SessionManager
$messageKeys = [
@@ -170,6 +171,14 @@ class PageBuilder
unset($_SESSION[$messageKey]);
}
}
+
+ $this->assign('base_path', $basePath);
+ $this->assign(
+ 'asset_path',
+ $basePath . '/' .
+ rtrim($this->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
+ $this->conf->get('resource.theme', 'default')
+ );
}
/**
@@ -209,23 +218,6 @@ class PageBuilder
return true;
}
- /**
- * Render a specific page (using a template file).
- * e.g. $pb->renderPage('picwall');
- *
- * @param string $page Template filename (without extension).
- */
- public function renderPage($page)
- {
- if ($this->tpl === false) {
- $this->initialize();
- }
-
- $this->finalize();
-
- $this->tpl->draw($page);
- }
-
/**
* Render a specific page as string (using a template file).
* e.g. $pb->render('picwall');
@@ -234,13 +226,13 @@ class PageBuilder
*
* @return string Processed template content
*/
- public function render(string $page): string
+ public function render(string $page, string $basePath): string
{
if ($this->tpl === false) {
$this->initialize();
}
- $this->finalize();
+ $this->finalize($basePath);
return $this->tpl->draw($page, true);
}
diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php
index c3e7abaf..ab6ed6de 100644
--- a/plugins/addlink_toolbar/addlink_toolbar.php
+++ b/plugins/addlink_toolbar/addlink_toolbar.php
@@ -20,7 +20,7 @@ function hook_addlink_toolbar_render_header($data)
$form = array(
'attr' => array(
'method' => 'GET',
- 'action' => '',
+ 'action' => $data['_BASE_PATH_'] . '/admin/shaare',
'name' => 'addform',
'class' => 'addform',
),
diff --git a/plugins/archiveorg/archiveorg.html b/plugins/archiveorg/archiveorg.html
index ad501f47..e37d887e 100644
--- a/plugins/archiveorg/archiveorg.html
+++ b/plugins/archiveorg/archiveorg.html
@@ -1,5 +1,5 @@
-
+
diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php
index 0ee1c73c..f26e6129 100644
--- a/plugins/archiveorg/archiveorg.php
+++ b/plugins/archiveorg/archiveorg.php
@@ -17,12 +17,13 @@ use Shaarli\Plugin\PluginManager;
function hook_archiveorg_render_linklist($data)
{
$archive_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/archiveorg/archiveorg.html');
+ $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
foreach ($data['links'] as &$value) {
if ($value['private'] && preg_match('/^\?[a-zA-Z0-9-_@]{6}($|&|#)/', $value['real_url'])) {
continue;
}
- $archive = sprintf($archive_html, $value['url'], t('View on archive.org'));
+ $archive = sprintf($archive_html, $value['url'], $path, t('View on archive.org'));
$value['link_plugin'][] = $archive;
}
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php
index dd73d6a2..defb01f7 100644
--- a/plugins/demo_plugin/demo_plugin.php
+++ b/plugins/demo_plugin/demo_plugin.php
@@ -118,7 +118,7 @@ function hook_demo_plugin_render_header($data)
$form = array(
'attr' => array(
'method' => 'GET',
- 'action' => '?',
+ 'action' => $data['_BASE_PATH_'] . '/',
'class' => 'addform',
),
'inputs' => array(
diff --git a/plugins/isso/isso_button.html b/plugins/isso/isso_button.html
deleted file mode 100644
index 3f828480..00000000
--- a/plugins/isso/isso_button.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php
index 2ec0cb65..3b5dae34 100644
--- a/plugins/qrcode/qrcode.php
+++ b/plugins/qrcode/qrcode.php
@@ -19,11 +19,12 @@ function hook_qrcode_render_linklist($data)
{
$qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
+ $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
foreach ($data['links'] as &$value) {
$qrcode = sprintf(
$qrcode_html,
$value['url'],
- PluginManager::$PLUGINS_PATH
+ $path
);
$value['link_plugin'][] = $qrcode;
}
@@ -41,7 +42,7 @@ function hook_qrcode_render_linklist($data)
function hook_qrcode_render_footer($data)
{
if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
- $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
+ $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js';
}
return $data;
diff --git a/plugins/qrcode/shaarli-qrcode.js b/plugins/qrcode/shaarli-qrcode.js
index fe77c4cd..3316d6f6 100644
--- a/plugins/qrcode/shaarli-qrcode.js
+++ b/plugins/qrcode/shaarli-qrcode.js
@@ -28,14 +28,15 @@
// Show the QR-Code of a permalink (when the QR-Code icon is clicked).
function showQrCode(caller,loading)
-{
+{
// Dynamic javascript lib loading: We only load qr.js if the QR code icon is clicked:
if (typeof(qr) == 'undefined') // Load qr.js only if not present.
{
if (!loading) // If javascript lib is still loading, do not append script to body.
{
- var element = document.createElement("script");
- element.src = "plugins/qrcode/qr-1.1.3.min.js";
+ var basePath = document.querySelector('input[name="js_base_path"]').value;
+ var element = document.createElement("script");
+ element.src = basePath + "/plugins/qrcode/qr-1.1.3.min.js";
document.body.appendChild(element);
}
setTimeout(function() { showQrCode(caller,true);}, 200); // Retry in 200 milliseconds.
@@ -44,7 +45,7 @@ function showQrCode(caller,loading)
// Remove previous qrcode if present.
removeQrcode();
-
+
// Build the div which contains the QR-Code:
var element = document.createElement('div');
element.id = 'permalinkQrcode';
@@ -57,11 +58,11 @@ function showQrCode(caller,loading)
// Damn IE
element.setAttribute('onclick', 'this.parentNode.removeChild(this);' );
}
-
+
// Build the QR-Code:
var image = qr.image({size: 8,value: caller.dataset.permalink});
if (image)
- {
+ {
element.appendChild(image);
element.innerHTML += "
Click to close";
caller.parentNode.appendChild(element);
@@ -87,4 +88,4 @@ function removeQrcode()
elem.parentNode.removeChild(elem);
}
return false;
-}
\ No newline at end of file
+}
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php
index bc35df08..805c1ad9 100644
--- a/plugins/wallabag/wallabag.php
+++ b/plugins/wallabag/wallabag.php
@@ -45,12 +45,14 @@ function hook_wallabag_render_linklist($data, $conf)
$wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html');
$linkTitle = t('Save to wallabag');
+ $path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
+
foreach ($data['links'] as &$value) {
$wallabag = sprintf(
$wallabagHtml,
$wallabagInstance->getWallabagUrl(),
urlencode($value['url']),
- PluginManager::$PLUGINS_PATH,
+ $path,
$linkTitle
);
$value['link_plugin'][] = $wallabag;
diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php
index d7a70e68..b2cc0045 100644
--- a/tests/config/ConfigPluginTest.php
+++ b/tests/config/ConfigPluginTest.php
@@ -2,6 +2,7 @@
namespace Shaarli\Config;
use Shaarli\Config\Exception\PluginConfigOrderException;
+use Shaarli\Plugin\PluginManager;
require_once 'application/config/ConfigPlugin.php';
@@ -17,23 +18,30 @@ class ConfigPluginTest extends \PHPUnit\Framework\TestCase
*/
public function testSavePluginConfigValid()
{
- $data = array(
+ $data = [
'order_plugin1' => 2, // no plugin related
'plugin2' => 0, // new - at the end
'plugin3' => 0, // 2nd
'order_plugin3' => 8,
'plugin4' => 0, // 1st
'order_plugin4' => 5,
- );
+ ];
- $expected = array(
+ $expected = [
'plugin3',
'plugin4',
'plugin2',
- );
+ ];
+
+ mkdir($path = __DIR__ . '/folder');
+ PluginManager::$PLUGINS_PATH = $path;
+ array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, $expected);
$out = save_plugin_config($data);
$this->assertEquals($expected, $out);
+
+ array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, $expected);
+ rmdir($path);
}
/**
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php
index caaf549d..dee622bb 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php
@@ -59,8 +59,12 @@ class DeleteBookmarkTest extends TestCase
->with('raw')
->willReturnCallback(function () use ($bookmark): BookmarkFormatter {
$formatter = $this->createMock(BookmarkFormatter::class);
-
- $formatter->expects(static::once())->method('format')->with($bookmark);
+ $formatter
+ ->expects(static::once())
+ ->method('format')
+ ->with($bookmark)
+ ->willReturn(['formatted' => $bookmark])
+ ;
return $formatter;
})
@@ -70,7 +74,7 @@ class DeleteBookmarkTest extends TestCase
$this->container->pluginManager
->expects(static::once())
->method('executeHooks')
- ->with('delete_link')
+ ->with('delete_link', ['formatted' => $bookmark])
;
$result = $this->controller->deleteBookmark($request, $response);
@@ -129,6 +133,9 @@ class DeleteBookmarkTest extends TestCase
->withConsecutive(...array_map(function (Bookmark $bookmark): array {
return [$bookmark];
}, $bookmarks))
+ ->willReturnOnConsecutiveCalls(...array_map(function (Bookmark $bookmark): array {
+ return ['formatted' => $bookmark];
+ }, $bookmarks))
;
return $formatter;
@@ -254,6 +261,9 @@ class DeleteBookmarkTest extends TestCase
->withConsecutive(...array_map(function (Bookmark $bookmark): array {
return [$bookmark];
}, $bookmarks))
+ ->willReturnOnConsecutiveCalls(...array_map(function (Bookmark $bookmark): array {
+ return ['formatted' => $bookmark];
+ }, $bookmarks))
;
return $formatter;
@@ -350,7 +360,12 @@ class DeleteBookmarkTest extends TestCase
$this->container->formatterFactory
->expects(static::once())
->method('getFormatter')
- ->willReturn($this->createMock(BookmarkFormatter::class))
+ ->willReturnCallback(function (): BookmarkFormatter {
+ $formatter = $this->createMock(BookmarkFormatter::class);
+ $formatter->method('format')->willReturn(['formatted']);
+
+ return $formatter;
+ })
;
$result = $this->controller->deleteBookmark($request, $response);
diff --git a/tests/front/controller/admin/PluginsControllerTest.php b/tests/front/controller/admin/PluginsControllerTest.php
index ad0cda70..5b59285c 100644
--- a/tests/front/controller/admin/PluginsControllerTest.php
+++ b/tests/front/controller/admin/PluginsControllerTest.php
@@ -7,6 +7,7 @@ namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\WrongTokenException;
+use Shaarli\Plugin\PluginManager;
use Shaarli\Security\SessionManager;
use Slim\Http\Request;
use Slim\Http\Response;
@@ -15,6 +16,8 @@ class PluginsControllerTest extends TestCase
{
use FrontAdminControllerMockHelper;
+ const PLUGIN_NAMES = ['plugin1', 'plugin2', 'plugin3', 'plugin4'];
+
/** @var PluginsController */
protected $controller;
@@ -23,6 +26,17 @@ class PluginsControllerTest extends TestCase
$this->createContainer();
$this->controller = new PluginsController($this->container);
+
+ mkdir($path = __DIR__ . '/folder');
+ PluginManager::$PLUGINS_PATH = $path;
+ array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
+ }
+
+ public function tearDown()
+ {
+ $path = __DIR__ . '/folder';
+ array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
+ rmdir($path);
}
/**
diff --git a/tests/front/controller/admin/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php
index 124b0bf2..7d5511ed 100644
--- a/tests/front/controller/admin/SessionFilterControllerTest.php
+++ b/tests/front/controller/admin/SessionFilterControllerTest.php
@@ -23,7 +23,7 @@ class SessionFilterControllerTest extends TestCase
$this->controller = new SessionFilterController($this->container);
}
-
+
/**
* Visibility - Default call for private filter while logged in without current value
*/
diff --git a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
index 83d08358..316ce49c 100644
--- a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
+++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
@@ -96,8 +96,6 @@ class ShaarliVisitorControllerTest extends TestCase
static::assertSame(10, $this->assignedValues['linkcount']);
static::assertSame(5, $this->assignedValues['privateLinkcount']);
static::assertSame(['error'], $this->assignedValues['plugin_errors']);
- static::assertSame('/subfolder', $this->assignedValues['base_path']);
- static::assertSame('/subfolder/tpl/default', $this->assignedValues['asset_path']);
static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']);
static::assertTrue($this->assignedValues['plugins_includes']['render_includes']['loggedin']);
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index 4018c1a8..aa5c6988 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -28,6 +28,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
$data = array($str => $str);
$data['_PAGE_'] = TemplatePage::LINKLIST;
$data['_LOGGEDIN_'] = true;
+ $data['_BASE_PATH_'] = '/subfolder';
$data = hook_addlink_toolbar_render_header($data);
$this->assertEquals($str, $data[$str]);
@@ -36,6 +37,8 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
$data = array($str => $str);
$data['_PAGE_'] = $str;
$data['_LOGGEDIN_'] = true;
+ $data['_BASE_PATH_'] = '/subfolder';
+
$data = hook_addlink_toolbar_render_header($data);
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('fields_toolbar', $data);
@@ -50,6 +53,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
$data = array($str => $str);
$data['_PAGE_'] = TemplatePage::LINKLIST;
$data['_LOGGEDIN_'] = false;
+ $data['_BASE_PATH_'] = '/subfolder';
$data = hook_addlink_toolbar_render_header($data);
$this->assertEquals($str, $data[$str]);
diff --git a/tpl/vintage/changepassword.html b/tpl/vintage/changepassword.html
index c40daf9d..7e37b9a3 100644
--- a/tpl/vintage/changepassword.html
+++ b/tpl/vintage/changepassword.html
@@ -4,7 +4,7 @@