aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/config/ConfigPluginTest.php16
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/DeleteBookmarkTest.php23
-rw-r--r--tests/front/controller/admin/PluginsControllerTest.php14
-rw-r--r--tests/front/controller/admin/SessionFilterControllerTest.php2
-rw-r--r--tests/front/controller/visitor/ShaarliVisitorControllerTest.php2
-rw-r--r--tests/plugins/PluginAddlinkTest.php4
6 files changed, 50 insertions, 11 deletions
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 @@
2namespace Shaarli\Config; 2namespace Shaarli\Config;
3 3
4use Shaarli\Config\Exception\PluginConfigOrderException; 4use Shaarli\Config\Exception\PluginConfigOrderException;
5use Shaarli\Plugin\PluginManager;
5 6
6require_once 'application/config/ConfigPlugin.php'; 7require_once 'application/config/ConfigPlugin.php';
7 8
@@ -17,23 +18,30 @@ class ConfigPluginTest extends \PHPUnit\Framework\TestCase
17 */ 18 */
18 public function testSavePluginConfigValid() 19 public function testSavePluginConfigValid()
19 { 20 {
20 $data = array( 21 $data = [
21 'order_plugin1' => 2, // no plugin related 22 'order_plugin1' => 2, // no plugin related
22 'plugin2' => 0, // new - at the end 23 'plugin2' => 0, // new - at the end
23 'plugin3' => 0, // 2nd 24 'plugin3' => 0, // 2nd
24 'order_plugin3' => 8, 25 'order_plugin3' => 8,
25 'plugin4' => 0, // 1st 26 'plugin4' => 0, // 1st
26 'order_plugin4' => 5, 27 'order_plugin4' => 5,
27 ); 28 ];
28 29
29 $expected = array( 30 $expected = [
30 'plugin3', 31 'plugin3',
31 'plugin4', 32 'plugin4',
32 'plugin2', 33 'plugin2',
33 ); 34 ];
35
36 mkdir($path = __DIR__ . '/folder');
37 PluginManager::$PLUGINS_PATH = $path;
38 array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, $expected);
34 39
35 $out = save_plugin_config($data); 40 $out = save_plugin_config($data);
36 $this->assertEquals($expected, $out); 41 $this->assertEquals($expected, $out);
42
43 array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, $expected);
44 rmdir($path);
37 } 45 }
38 46
39 /** 47 /**
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
59 ->with('raw') 59 ->with('raw')
60 ->willReturnCallback(function () use ($bookmark): BookmarkFormatter { 60 ->willReturnCallback(function () use ($bookmark): BookmarkFormatter {
61 $formatter = $this->createMock(BookmarkFormatter::class); 61 $formatter = $this->createMock(BookmarkFormatter::class);
62 62 $formatter
63 $formatter->expects(static::once())->method('format')->with($bookmark); 63 ->expects(static::once())
64 ->method('format')
65 ->with($bookmark)
66 ->willReturn(['formatted' => $bookmark])
67 ;
64 68
65 return $formatter; 69 return $formatter;
66 }) 70 })
@@ -70,7 +74,7 @@ class DeleteBookmarkTest extends TestCase
70 $this->container->pluginManager 74 $this->container->pluginManager
71 ->expects(static::once()) 75 ->expects(static::once())
72 ->method('executeHooks') 76 ->method('executeHooks')
73 ->with('delete_link') 77 ->with('delete_link', ['formatted' => $bookmark])
74 ; 78 ;
75 79
76 $result = $this->controller->deleteBookmark($request, $response); 80 $result = $this->controller->deleteBookmark($request, $response);
@@ -129,6 +133,9 @@ class DeleteBookmarkTest extends TestCase
129 ->withConsecutive(...array_map(function (Bookmark $bookmark): array { 133 ->withConsecutive(...array_map(function (Bookmark $bookmark): array {
130 return [$bookmark]; 134 return [$bookmark];
131 }, $bookmarks)) 135 }, $bookmarks))
136 ->willReturnOnConsecutiveCalls(...array_map(function (Bookmark $bookmark): array {
137 return ['formatted' => $bookmark];
138 }, $bookmarks))
132 ; 139 ;
133 140
134 return $formatter; 141 return $formatter;
@@ -254,6 +261,9 @@ class DeleteBookmarkTest extends TestCase
254 ->withConsecutive(...array_map(function (Bookmark $bookmark): array { 261 ->withConsecutive(...array_map(function (Bookmark $bookmark): array {
255 return [$bookmark]; 262 return [$bookmark];
256 }, $bookmarks)) 263 }, $bookmarks))
264 ->willReturnOnConsecutiveCalls(...array_map(function (Bookmark $bookmark): array {
265 return ['formatted' => $bookmark];
266 }, $bookmarks))
257 ; 267 ;
258 268
259 return $formatter; 269 return $formatter;
@@ -350,7 +360,12 @@ class DeleteBookmarkTest extends TestCase
350 $this->container->formatterFactory 360 $this->container->formatterFactory
351 ->expects(static::once()) 361 ->expects(static::once())
352 ->method('getFormatter') 362 ->method('getFormatter')
353 ->willReturn($this->createMock(BookmarkFormatter::class)) 363 ->willReturnCallback(function (): BookmarkFormatter {
364 $formatter = $this->createMock(BookmarkFormatter::class);
365 $formatter->method('format')->willReturn(['formatted']);
366
367 return $formatter;
368 })
354 ; 369 ;
355 370
356 $result = $this->controller->deleteBookmark($request, $response); 371 $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;
7use PHPUnit\Framework\TestCase; 7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\WrongTokenException; 9use Shaarli\Front\Exception\WrongTokenException;
10use Shaarli\Plugin\PluginManager;
10use Shaarli\Security\SessionManager; 11use Shaarli\Security\SessionManager;
11use Slim\Http\Request; 12use Slim\Http\Request;
12use Slim\Http\Response; 13use Slim\Http\Response;
@@ -15,6 +16,8 @@ class PluginsControllerTest extends TestCase
15{ 16{
16 use FrontAdminControllerMockHelper; 17 use FrontAdminControllerMockHelper;
17 18
19 const PLUGIN_NAMES = ['plugin1', 'plugin2', 'plugin3', 'plugin4'];
20
18 /** @var PluginsController */ 21 /** @var PluginsController */
19 protected $controller; 22 protected $controller;
20 23
@@ -23,6 +26,17 @@ class PluginsControllerTest extends TestCase
23 $this->createContainer(); 26 $this->createContainer();
24 27
25 $this->controller = new PluginsController($this->container); 28 $this->controller = new PluginsController($this->container);
29
30 mkdir($path = __DIR__ . '/folder');
31 PluginManager::$PLUGINS_PATH = $path;
32 array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
33 }
34
35 public function tearDown()
36 {
37 $path = __DIR__ . '/folder';
38 array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
39 rmdir($path);
26 } 40 }
27 41
28 /** 42 /**
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
23 23
24 $this->controller = new SessionFilterController($this->container); 24 $this->controller = new SessionFilterController($this->container);
25 } 25 }
26 26
27 /** 27 /**
28 * Visibility - Default call for private filter while logged in without current value 28 * Visibility - Default call for private filter while logged in without current value
29 */ 29 */
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
96 static::assertSame(10, $this->assignedValues['linkcount']); 96 static::assertSame(10, $this->assignedValues['linkcount']);
97 static::assertSame(5, $this->assignedValues['privateLinkcount']); 97 static::assertSame(5, $this->assignedValues['privateLinkcount']);
98 static::assertSame(['error'], $this->assignedValues['plugin_errors']); 98 static::assertSame(['error'], $this->assignedValues['plugin_errors']);
99 static::assertSame('/subfolder', $this->assignedValues['base_path']);
100 static::assertSame('/subfolder/tpl/default', $this->assignedValues['asset_path']);
101 99
102 static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']); 100 static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']);
103 static::assertTrue($this->assignedValues['plugins_includes']['render_includes']['loggedin']); 101 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
28 $data = array($str => $str); 28 $data = array($str => $str);
29 $data['_PAGE_'] = TemplatePage::LINKLIST; 29 $data['_PAGE_'] = TemplatePage::LINKLIST;
30 $data['_LOGGEDIN_'] = true; 30 $data['_LOGGEDIN_'] = true;
31 $data['_BASE_PATH_'] = '/subfolder';
31 32
32 $data = hook_addlink_toolbar_render_header($data); 33 $data = hook_addlink_toolbar_render_header($data);
33 $this->assertEquals($str, $data[$str]); 34 $this->assertEquals($str, $data[$str]);
@@ -36,6 +37,8 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
36 $data = array($str => $str); 37 $data = array($str => $str);
37 $data['_PAGE_'] = $str; 38 $data['_PAGE_'] = $str;
38 $data['_LOGGEDIN_'] = true; 39 $data['_LOGGEDIN_'] = true;
40 $data['_BASE_PATH_'] = '/subfolder';
41
39 $data = hook_addlink_toolbar_render_header($data); 42 $data = hook_addlink_toolbar_render_header($data);
40 $this->assertEquals($str, $data[$str]); 43 $this->assertEquals($str, $data[$str]);
41 $this->assertArrayNotHasKey('fields_toolbar', $data); 44 $this->assertArrayNotHasKey('fields_toolbar', $data);
@@ -50,6 +53,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
50 $data = array($str => $str); 53 $data = array($str => $str);
51 $data['_PAGE_'] = TemplatePage::LINKLIST; 54 $data['_PAGE_'] = TemplatePage::LINKLIST;
52 $data['_LOGGEDIN_'] = false; 55 $data['_LOGGEDIN_'] = false;
56 $data['_BASE_PATH_'] = '/subfolder';
53 57
54 $data = hook_addlink_toolbar_render_header($data); 58 $data = hook_addlink_toolbar_render_header($data);
55 $this->assertEquals($str, $data[$str]); 59 $this->assertEquals($str, $data[$str]);