aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/visitor
diff options
context:
space:
mode:
Diffstat (limited to 'tests/front/controller/visitor')
-rw-r--r--tests/front/controller/visitor/BookmarkListControllerTest.php2
-rw-r--r--tests/front/controller/visitor/DailyControllerTest.php60
-rw-r--r--tests/front/controller/visitor/ErrorControllerTest.php2
-rw-r--r--tests/front/controller/visitor/ErrorNotFoundControllerTest.php81
-rw-r--r--tests/front/controller/visitor/FeedControllerTest.php38
-rw-r--r--tests/front/controller/visitor/FrontControllerMockHelper.php7
-rw-r--r--tests/front/controller/visitor/InstallControllerTest.php37
-rw-r--r--tests/front/controller/visitor/LoginControllerTest.php2
-rw-r--r--tests/front/controller/visitor/OpenSearchControllerTest.php4
-rw-r--r--tests/front/controller/visitor/PictureWallControllerTest.php18
-rw-r--r--tests/front/controller/visitor/PublicSessionFilterControllerTest.php8
-rw-r--r--tests/front/controller/visitor/ShaarliVisitorControllerTest.php47
-rw-r--r--tests/front/controller/visitor/TagCloudControllerTest.php74
-rw-r--r--tests/front/controller/visitor/TagControllerTest.php2
14 files changed, 274 insertions, 108 deletions
diff --git a/tests/front/controller/visitor/BookmarkListControllerTest.php b/tests/front/controller/visitor/BookmarkListControllerTest.php
index 5daaa2c4..0c95df97 100644
--- a/tests/front/controller/visitor/BookmarkListControllerTest.php
+++ b/tests/front/controller/visitor/BookmarkListControllerTest.php
@@ -4,11 +4,11 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
10use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
11use Shaarli\Security\LoginManager; 10use Shaarli\Security\LoginManager;
11use Shaarli\TestCase;
12use Shaarli\Thumbnailer; 12use Shaarli\Thumbnailer;
13use Slim\Http\Request; 13use Slim\Http\Request;
14use Slim\Http\Response; 14use Slim\Http\Response;
diff --git a/tests/front/controller/visitor/DailyControllerTest.php b/tests/front/controller/visitor/DailyControllerTest.php
index b802c62c..fc78bc13 100644
--- a/tests/front/controller/visitor/DailyControllerTest.php
+++ b/tests/front/controller/visitor/DailyControllerTest.php
@@ -4,9 +4,9 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Feed\CachedPage; 8use Shaarli\Feed\CachedPage;
9use Shaarli\TestCase;
10use Slim\Http\Request; 10use Slim\Http\Request;
11use Slim\Http\Response; 11use Slim\Http\Response;
12 12
@@ -78,19 +78,20 @@ class DailyControllerTest extends TestCase
78 78
79 // Make sure that PluginManager hook is triggered 79 // Make sure that PluginManager hook is triggered
80 $this->container->pluginManager 80 $this->container->pluginManager
81 ->expects(static::at(0)) 81 ->expects(static::atLeastOnce())
82 ->method('executeHooks') 82 ->method('executeHooks')
83 ->withConsecutive(['render_daily'])
83 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array { 84 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array {
84 static::assertSame('render_daily', $hook); 85 if ('render_daily' === $hook) {
86 static::assertArrayHasKey('linksToDisplay', $data);
87 static::assertCount(3, $data['linksToDisplay']);
88 static::assertSame(1, $data['linksToDisplay'][0]['id']);
89 static::assertSame($currentDay->getTimestamp(), $data['day']);
90 static::assertSame('20200510', $data['previousday']);
91 static::assertSame('20200516', $data['nextday']);
85 92
86 static::assertArrayHasKey('linksToDisplay', $data); 93 static::assertArrayHasKey('loggedin', $param);
87 static::assertCount(3, $data['linksToDisplay']); 94 }
88 static::assertSame(1, $data['linksToDisplay'][0]['id']);
89 static::assertSame($currentDay->getTimestamp(), $data['day']);
90 static::assertSame('20200510', $data['previousday']);
91 static::assertSame('20200516', $data['nextday']);
92
93 static::assertArrayHasKey('loggedin', $param);
94 95
95 return $data; 96 return $data;
96 }) 97 })
@@ -203,19 +204,20 @@ class DailyControllerTest extends TestCase
203 204
204 // Make sure that PluginManager hook is triggered 205 // Make sure that PluginManager hook is triggered
205 $this->container->pluginManager 206 $this->container->pluginManager
206 ->expects(static::at(0)) 207 ->expects(static::atLeastOnce())
207 ->method('executeHooks') 208 ->method('executeHooks')
209 ->withConsecutive(['render_daily'])
208 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array { 210 ->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array {
209 static::assertSame('render_daily', $hook); 211 if ('render_daily' === $hook) {
210 212 static::assertArrayHasKey('linksToDisplay', $data);
211 static::assertArrayHasKey('linksToDisplay', $data); 213 static::assertCount(1, $data['linksToDisplay']);
212 static::assertCount(1, $data['linksToDisplay']); 214 static::assertSame(1, $data['linksToDisplay'][0]['id']);
213 static::assertSame(1, $data['linksToDisplay'][0]['id']); 215 static::assertSame($currentDay->getTimestamp(), $data['day']);
214 static::assertSame($currentDay->getTimestamp(), $data['day']); 216 static::assertEmpty($data['previousday']);
215 static::assertEmpty($data['previousday']); 217 static::assertEmpty($data['nextday']);
216 static::assertEmpty($data['nextday']);
217 218
218 static::assertArrayHasKey('loggedin', $param); 219 static::assertArrayHasKey('loggedin', $param);
220 }
219 221
220 return $data; 222 return $data;
221 }); 223 });
@@ -281,7 +283,7 @@ class DailyControllerTest extends TestCase
281 283
282 // Make sure that PluginManager hook is triggered 284 // Make sure that PluginManager hook is triggered
283 $this->container->pluginManager 285 $this->container->pluginManager
284 ->expects(static::at(0)) 286 ->expects(static::atLeastOnce())
285 ->method('executeHooks') 287 ->method('executeHooks')
286 ->willReturnCallback(function (string $hook, array $data, array $param): array { 288 ->willReturnCallback(function (string $hook, array $data, array $param): array {
287 return $data; 289 return $data;
@@ -333,7 +335,7 @@ class DailyControllerTest extends TestCase
333 335
334 // Make sure that PluginManager hook is triggered 336 // Make sure that PluginManager hook is triggered
335 $this->container->pluginManager 337 $this->container->pluginManager
336 ->expects(static::at(0)) 338 ->expects(static::atLeastOnce())
337 ->method('executeHooks') 339 ->method('executeHooks')
338 ->willReturnCallback(function (string $hook, array $data, array $param): array { 340 ->willReturnCallback(function (string $hook, array $data, array $param): array {
339 return $data; 341 return $data;
@@ -392,8 +394,8 @@ class DailyControllerTest extends TestCase
392 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); 394 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
393 static::assertSame('dailyrss', (string) $result->getBody()); 395 static::assertSame('dailyrss', (string) $result->getBody());
394 static::assertSame('Shaarli', $assignedVariables['title']); 396 static::assertSame('Shaarli', $assignedVariables['title']);
395 static::assertSame('http://shaarli', $assignedVariables['index_url']); 397 static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']);
396 static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); 398 static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']);
397 static::assertFalse($assignedVariables['hide_timestamps']); 399 static::assertFalse($assignedVariables['hide_timestamps']);
398 static::assertCount(2, $assignedVariables['days']); 400 static::assertCount(2, $assignedVariables['days']);
399 401
@@ -402,7 +404,7 @@ class DailyControllerTest extends TestCase
402 static::assertEquals($dates[0], $day['date']); 404 static::assertEquals($dates[0], $day['date']);
403 static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']); 405 static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']);
404 static::assertSame(format_date($dates[0], false), $day['date_human']); 406 static::assertSame(format_date($dates[0], false), $day['date_human']);
405 static::assertSame('http://shaarli/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']); 407 static::assertSame('http://shaarli/subfolder/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']);
406 static::assertCount(1, $day['links']); 408 static::assertCount(1, $day['links']);
407 static::assertSame(1, $day['links'][0]['id']); 409 static::assertSame(1, $day['links'][0]['id']);
408 static::assertSame('http://domain.tld/1', $day['links'][0]['url']); 410 static::assertSame('http://domain.tld/1', $day['links'][0]['url']);
@@ -413,7 +415,7 @@ class DailyControllerTest extends TestCase
413 static::assertEquals($dates[1], $day['date']); 415 static::assertEquals($dates[1], $day['date']);
414 static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']); 416 static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']);
415 static::assertSame(format_date($dates[1], false), $day['date_human']); 417 static::assertSame(format_date($dates[1], false), $day['date_human']);
416 static::assertSame('http://shaarli/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']); 418 static::assertSame('http://shaarli/subfolder/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']);
417 static::assertCount(2, $day['links']); 419 static::assertCount(2, $day['links']);
418 420
419 static::assertSame(2, $day['links'][0]['id']); 421 static::assertSame(2, $day['links'][0]['id']);
@@ -468,8 +470,8 @@ class DailyControllerTest extends TestCase
468 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); 470 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
469 static::assertSame('dailyrss', (string) $result->getBody()); 471 static::assertSame('dailyrss', (string) $result->getBody());
470 static::assertSame('Shaarli', $assignedVariables['title']); 472 static::assertSame('Shaarli', $assignedVariables['title']);
471 static::assertSame('http://shaarli', $assignedVariables['index_url']); 473 static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']);
472 static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); 474 static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']);
473 static::assertFalse($assignedVariables['hide_timestamps']); 475 static::assertFalse($assignedVariables['hide_timestamps']);
474 static::assertCount(0, $assignedVariables['days']); 476 static::assertCount(0, $assignedVariables['days']);
475 } 477 }
diff --git a/tests/front/controller/visitor/ErrorControllerTest.php b/tests/front/controller/visitor/ErrorControllerTest.php
index e497bfef..75408cf4 100644
--- a/tests/front/controller/visitor/ErrorControllerTest.php
+++ b/tests/front/controller/visitor/ErrorControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Front\Exception\ShaarliFrontException; 7use Shaarli\Front\Exception\ShaarliFrontException;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
diff --git a/tests/front/controller/visitor/ErrorNotFoundControllerTest.php b/tests/front/controller/visitor/ErrorNotFoundControllerTest.php
new file mode 100644
index 00000000..a1cbbecf
--- /dev/null
+++ b/tests/front/controller/visitor/ErrorNotFoundControllerTest.php
@@ -0,0 +1,81 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Visitor;
6
7use Shaarli\TestCase;
8use Slim\Http\Request;
9use Slim\Http\Response;
10use Slim\Http\Uri;
11
12class ErrorNotFoundControllerTest extends TestCase
13{
14 use FrontControllerMockHelper;
15
16 /** @var ErrorNotFoundController */
17 protected $controller;
18
19 public function setUp(): void
20 {
21 $this->createContainer();
22
23 $this->controller = new ErrorNotFoundController($this->container);
24 }
25
26 /**
27 * Test displaying 404 error
28 */
29 public function testDisplayNotFoundError(): void
30 {
31 $request = $this->createMock(Request::class);
32 $request->expects(static::once())->method('getRequestTarget')->willReturn('/');
33 $request->method('getUri')->willReturnCallback(function (): Uri {
34 $uri = $this->createMock(Uri::class);
35 $uri->method('getBasePath')->willReturn('/subfolder');
36
37 return $uri;
38 });
39
40 $response = new Response();
41
42 // Save RainTPL assigned variables
43 $assignedVariables = [];
44 $this->assignTemplateVars($assignedVariables);
45
46 $result = ($this->controller)(
47 $request,
48 $response
49 );
50
51 static::assertSame(404, $result->getStatusCode());
52 static::assertSame('404', (string) $result->getBody());
53 static::assertSame('Requested page could not be found.', $assignedVariables['error_message']);
54 }
55
56 /**
57 * Test displaying 404 error from REST API
58 */
59 public function testDisplayNotFoundErrorFromAPI(): void
60 {
61 $request = $this->createMock(Request::class);
62 $request->expects(static::once())->method('getRequestTarget')->willReturn('/sufolder/api/v1/links');
63 $request->method('getUri')->willReturnCallback(function (): Uri {
64 $uri = $this->createMock(Uri::class);
65 $uri->method('getBasePath')->willReturn('/subfolder');
66
67 return $uri;
68 });
69
70 $response = new Response();
71
72 // Save RainTPL assigned variables
73 $assignedVariables = [];
74 $this->assignTemplateVars($assignedVariables);
75
76 $result = ($this->controller)($request, $response);
77
78 static::assertSame(404, $result->getStatusCode());
79 static::assertSame([], $assignedVariables);
80 }
81}
diff --git a/tests/front/controller/visitor/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php
index fb417e2a..4ae7c925 100644
--- a/tests/front/controller/visitor/FeedControllerTest.php
+++ b/tests/front/controller/visitor/FeedControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Feed\FeedBuilder; 7use Shaarli\Feed\FeedBuilder;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -45,14 +45,16 @@ class FeedControllerTest extends TestCase
45 45
46 // Make sure that PluginManager hook is triggered 46 // Make sure that PluginManager hook is triggered
47 $this->container->pluginManager 47 $this->container->pluginManager
48 ->expects(static::at(0)) 48 ->expects(static::atLeastOnce())
49 ->method('executeHooks') 49 ->method('executeHooks')
50 ->withConsecutive(['render_feed'])
50 ->willReturnCallback(function (string $hook, array $data, array $param): void { 51 ->willReturnCallback(function (string $hook, array $data, array $param): void {
51 static::assertSame('render_feed', $hook); 52 if ('render_feed' === $hook) {
52 static::assertSame('data', $data['content']); 53 static::assertSame('data', $data['content']);
53 54
54 static::assertArrayHasKey('loggedin', $param); 55 static::assertArrayHasKey('loggedin', $param);
55 static::assertSame('rss', $param['target']); 56 static::assertSame('feed.rss', $param['target']);
57 }
56 }) 58 })
57 ; 59 ;
58 60
@@ -84,14 +86,16 @@ class FeedControllerTest extends TestCase
84 86
85 // Make sure that PluginManager hook is triggered 87 // Make sure that PluginManager hook is triggered
86 $this->container->pluginManager 88 $this->container->pluginManager
87 ->expects(static::at(0)) 89 ->expects(static::atLeastOnce())
88 ->method('executeHooks') 90 ->method('executeHooks')
91 ->withConsecutive(['render_feed'])
89 ->willReturnCallback(function (string $hook, array $data, array $param): void { 92 ->willReturnCallback(function (string $hook, array $data, array $param): void {
90 static::assertSame('render_feed', $hook); 93 if ('render_feed' === $hook) {
91 static::assertSame('data', $data['content']); 94 static::assertSame('data', $data['content']);
92 95
93 static::assertArrayHasKey('loggedin', $param); 96 static::assertArrayHasKey('loggedin', $param);
94 static::assertSame('atom', $param['target']); 97 static::assertSame('feed.atom', $param['target']);
98 }
95 }) 99 })
96 ; 100 ;
97 101
@@ -124,14 +128,16 @@ class FeedControllerTest extends TestCase
124 128
125 // Make sure that PluginManager hook is triggered 129 // Make sure that PluginManager hook is triggered
126 $this->container->pluginManager 130 $this->container->pluginManager
127 ->expects(static::at(0)) 131 ->expects(static::atLeastOnce())
128 ->method('executeHooks') 132 ->method('executeHooks')
133 ->withConsecutive(['render_feed'])
129 ->willReturnCallback(function (string $hook, array $data, array $param): void { 134 ->willReturnCallback(function (string $hook, array $data, array $param): void {
130 static::assertSame('render_feed', $hook); 135 if ('render_feed' === $hook) {
131 static::assertSame('data', $data['content']); 136 static::assertSame('data', $data['content']);
132 137
133 static::assertArrayHasKey('loggedin', $param); 138 static::assertArrayHasKey('loggedin', $param);
134 static::assertSame('atom', $param['target']); 139 static::assertSame('feed.atom', $param['target']);
140 }
135 }) 141 })
136 ; 142 ;
137 143
diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php
index e0bd4ecf..fc0bb7d1 100644
--- a/tests/front/controller/visitor/FrontControllerMockHelper.php
+++ b/tests/front/controller/visitor/FrontControllerMockHelper.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\MockObject\MockObject;
8use Shaarli\Bookmark\BookmarkServiceInterface; 7use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Container\ShaarliTestContainer; 9use Shaarli\Container\ShaarliTestContainer;
@@ -79,8 +78,9 @@ trait FrontControllerMockHelper
79 $this->container->environment = [ 78 $this->container->environment = [
80 'SERVER_NAME' => 'shaarli', 79 'SERVER_NAME' => 'shaarli',
81 'SERVER_PORT' => '80', 80 'SERVER_PORT' => '80',
82 'REQUEST_URI' => '/daily-rss', 81 'REQUEST_URI' => '/subfolder/daily-rss',
83 'REMOTE_ADDR' => '1.2.3.4', 82 'REMOTE_ADDR' => '1.2.3.4',
83 'SCRIPT_NAME' => '/subfolder/index.php',
84 ]; 84 ];
85 85
86 $this->container->basePath = '/subfolder'; 86 $this->container->basePath = '/subfolder';
@@ -94,7 +94,6 @@ trait FrontControllerMockHelper
94 protected function assignTemplateVars(array &$variables): void 94 protected function assignTemplateVars(array &$variables): void
95 { 95 {
96 $this->container->pageBuilder 96 $this->container->pageBuilder
97 ->expects(static::atLeastOnce())
98 ->method('assign') 97 ->method('assign')
99 ->willReturnCallback(function ($key, $value) use (&$variables) { 98 ->willReturnCallback(function ($key, $value) use (&$variables) {
100 $variables[$key] = $value; 99 $variables[$key] = $value;
@@ -115,5 +114,5 @@ trait FrontControllerMockHelper
115 /** 114 /**
116 * Force to be used in PHPUnit context. 115 * Force to be used in PHPUnit context.
117 */ 116 */
118 protected abstract function createMock($originalClassName): MockObject; 117 protected abstract function isInTestsContext(): bool;
119} 118}
diff --git a/tests/front/controller/visitor/InstallControllerTest.php b/tests/front/controller/visitor/InstallControllerTest.php
index 3b855365..345ad544 100644
--- a/tests/front/controller/visitor/InstallControllerTest.php
+++ b/tests/front/controller/visitor/InstallControllerTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\AlreadyInstalledException; 8use Shaarli\Front\Exception\AlreadyInstalledException;
10use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
10use Shaarli\TestCase;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13 13
@@ -257,6 +257,39 @@ class InstallControllerTest extends TestCase
257 static::assertSame('/subfolder/login', $result->getHeader('location')[0]); 257 static::assertSame('/subfolder/login', $result->getHeader('location')[0]);
258 258
259 static::assertSame('UTC', $confSettings['general.timezone']); 259 static::assertSame('UTC', $confSettings['general.timezone']);
260 static::assertSame('Shared bookmarks on http://shaarli', $confSettings['general.title']); 260 static::assertSame('Shared bookmarks on http://shaarli/subfolder/', $confSettings['general.title']);
261 }
262
263 /**
264 * Same test as testSaveInstallDefaultValues() but for an instance install in root directory.
265 */
266 public function testSaveInstallDefaultValuesWithoutSubfolder(): void
267 {
268 $confSettings = [];
269
270 $this->container->environment = [
271 'SERVER_NAME' => 'shaarli',
272 'SERVER_PORT' => '80',
273 'REQUEST_URI' => '/install',
274 'REMOTE_ADDR' => '1.2.3.4',
275 'SCRIPT_NAME' => '/index.php',
276 ];
277
278 $this->container->basePath = '';
279
280 $request = $this->createMock(Request::class);
281 $response = new Response();
282
283 $this->container->conf->method('set')->willReturnCallback(function (string $key, $value) use (&$confSettings) {
284 $confSettings[$key] = $value;
285 });
286
287 $result = $this->controller->save($request, $response);
288
289 static::assertSame(302, $result->getStatusCode());
290 static::assertSame('/login', $result->getHeader('location')[0]);
291
292 static::assertSame('UTC', $confSettings['general.timezone']);
293 static::assertSame('Shared bookmarks on http://shaarli/', $confSettings['general.title']);
261 } 294 }
262} 295}
diff --git a/tests/front/controller/visitor/LoginControllerTest.php b/tests/front/controller/visitor/LoginControllerTest.php
index 0a21f938..1312ccb7 100644
--- a/tests/front/controller/visitor/LoginControllerTest.php
+++ b/tests/front/controller/visitor/LoginControllerTest.php
@@ -4,13 +4,13 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\LoginBannedException; 8use Shaarli\Front\Exception\LoginBannedException;
10use Shaarli\Front\Exception\WrongTokenException; 9use Shaarli\Front\Exception\WrongTokenException;
11use Shaarli\Render\TemplatePage; 10use Shaarli\Render\TemplatePage;
12use Shaarli\Security\CookieManager; 11use Shaarli\Security\CookieManager;
13use Shaarli\Security\SessionManager; 12use Shaarli\Security\SessionManager;
13use Shaarli\TestCase;
14use Slim\Http\Request; 14use Slim\Http\Request;
15use Slim\Http\Response; 15use Slim\Http\Response;
16 16
diff --git a/tests/front/controller/visitor/OpenSearchControllerTest.php b/tests/front/controller/visitor/OpenSearchControllerTest.php
index 5f9f5b12..42d876c3 100644
--- a/tests/front/controller/visitor/OpenSearchControllerTest.php
+++ b/tests/front/controller/visitor/OpenSearchControllerTest.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase; 7use Shaarli\TestCase;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10
@@ -39,6 +39,6 @@ class OpenSearchControllerTest extends TestCase
39 $result->getHeader('Content-Type')[0] 39 $result->getHeader('Content-Type')[0]
40 ); 40 );
41 static::assertSame('opensearch', (string) $result->getBody()); 41 static::assertSame('opensearch', (string) $result->getBody());
42 static::assertSame('http://shaarli', $assignedVariables['serverurl']); 42 static::assertSame('http://shaarli/subfolder/', $assignedVariables['serverurl']);
43 } 43 }
44} 44}
diff --git a/tests/front/controller/visitor/PictureWallControllerTest.php b/tests/front/controller/visitor/PictureWallControllerTest.php
index 3dc3f292..b868231d 100644
--- a/tests/front/controller/visitor/PictureWallControllerTest.php
+++ b/tests/front/controller/visitor/PictureWallControllerTest.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Front\Exception\ThumbnailsDisabledException; 9use Shaarli\Front\Exception\ThumbnailsDisabledException;
10use Shaarli\TestCase;
11use Shaarli\Thumbnailer; 11use Shaarli\Thumbnailer;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
@@ -67,15 +67,17 @@ class PictureWallControllerTest extends TestCase
67 67
68 // Make sure that PluginManager hook is triggered 68 // Make sure that PluginManager hook is triggered
69 $this->container->pluginManager 69 $this->container->pluginManager
70 ->expects(static::at(0)) 70 ->expects(static::atLeastOnce())
71 ->method('executeHooks') 71 ->method('executeHooks')
72 ->withConsecutive(['render_picwall'])
72 ->willReturnCallback(function (string $hook, array $data, array $param): array { 73 ->willReturnCallback(function (string $hook, array $data, array $param): array {
73 static::assertSame('render_picwall', $hook); 74 if ('render_picwall' === $hook) {
74 static::assertArrayHasKey('linksToDisplay', $data); 75 static::assertArrayHasKey('linksToDisplay', $data);
75 static::assertCount(2, $data['linksToDisplay']); 76 static::assertCount(2, $data['linksToDisplay']);
76 static::assertSame(1, $data['linksToDisplay'][0]['id']); 77 static::assertSame(1, $data['linksToDisplay'][0]['id']);
77 static::assertSame(3, $data['linksToDisplay'][1]['id']); 78 static::assertSame(3, $data['linksToDisplay'][1]['id']);
78 static::assertArrayHasKey('loggedin', $param); 79 static::assertArrayHasKey('loggedin', $param);
80 }
79 81
80 return $data; 82 return $data;
81 }); 83 });
diff --git a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php
index 06352750..7e3b00af 100644
--- a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php
+++ b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Security\SessionManager; 7use Shaarli\Security\SessionManager;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -28,7 +28,7 @@ class PublicSessionFilterControllerTest extends TestCase
28 */ 28 */
29 public function testLinksPerPage(): void 29 public function testLinksPerPage(): void
30 { 30 {
31 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 31 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
32 32
33 $request = $this->createMock(Request::class); 33 $request = $this->createMock(Request::class);
34 $request->method('getParam')->with('nb')->willReturn('8'); 34 $request->method('getParam')->with('nb')->willReturn('8');
@@ -74,7 +74,7 @@ class PublicSessionFilterControllerTest extends TestCase
74 */ 74 */
75 public function testUntaggedOnly(): void 75 public function testUntaggedOnly(): void
76 { 76 {
77 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 77 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
78 78
79 $request = $this->createMock(Request::class); 79 $request = $this->createMock(Request::class);
80 $response = new Response(); 80 $response = new Response();
@@ -97,7 +97,7 @@ class PublicSessionFilterControllerTest extends TestCase
97 */ 97 */
98 public function testUntaggedOnlyToggleOff(): void 98 public function testUntaggedOnlyToggleOff(): void
99 { 99 {
100 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 100 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
101 101
102 $request = $this->createMock(Request::class); 102 $request = $this->createMock(Request::class);
103 $response = new Response(); 103 $response = new Response();
diff --git a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
index 316ce49c..935ec24e 100644
--- a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
+++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkFilter; 7use Shaarli\Bookmark\BookmarkFilter;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -110,7 +110,7 @@ class ShaarliVisitorControllerTest extends TestCase
110 */ 110 */
111 public function testRedirectFromRefererDefault(): void 111 public function testRedirectFromRefererDefault(): void
112 { 112 {
113 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 113 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
114 114
115 $response = new Response(); 115 $response = new Response();
116 116
@@ -125,7 +125,7 @@ class ShaarliVisitorControllerTest extends TestCase
125 */ 125 */
126 public function testRedirectFromRefererWithUnmatchedLoopTerm(): void 126 public function testRedirectFromRefererWithUnmatchedLoopTerm(): void
127 { 127 {
128 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 128 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
129 129
130 $response = new Response(); 130 $response = new Response();
131 131
@@ -140,7 +140,7 @@ class ShaarliVisitorControllerTest extends TestCase
140 */ 140 */
141 public function testRedirectFromRefererWithMatchingLoopTermInPath(): void 141 public function testRedirectFromRefererWithMatchingLoopTermInPath(): void
142 { 142 {
143 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 143 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
144 144
145 $response = new Response(); 145 $response = new Response();
146 146
@@ -155,7 +155,7 @@ class ShaarliVisitorControllerTest extends TestCase
155 */ 155 */
156 public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void 156 public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void
157 { 157 {
158 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 158 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
159 159
160 $response = new Response(); 160 $response = new Response();
161 161
@@ -171,7 +171,7 @@ class ShaarliVisitorControllerTest extends TestCase
171 */ 171 */
172 public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void 172 public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void
173 { 173 {
174 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 174 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
175 175
176 $response = new Response(); 176 $response = new Response();
177 177
@@ -187,7 +187,7 @@ class ShaarliVisitorControllerTest extends TestCase
187 */ 187 */
188 public function testRedirectFromRefererWithLoopTermInDomain(): void 188 public function testRedirectFromRefererWithLoopTermInDomain(): void
189 { 189 {
190 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 190 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
191 191
192 $response = new Response(); 192 $response = new Response();
193 193
@@ -203,7 +203,7 @@ class ShaarliVisitorControllerTest extends TestCase
203 */ 203 */
204 public function testRedirectFromRefererWithMatchingClearedParam(): void 204 public function testRedirectFromRefererWithMatchingClearedParam(): void
205 { 205 {
206 $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; 206 $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2';
207 207
208 $response = new Response(); 208 $response = new Response();
209 209
@@ -212,4 +212,35 @@ class ShaarliVisitorControllerTest extends TestCase
212 static::assertSame(302, $result->getStatusCode()); 212 static::assertSame(302, $result->getStatusCode());
213 static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location')); 213 static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location'));
214 } 214 }
215
216 /**
217 * Test redirectFromReferer() - From another domain -> we ignore the given referrer.
218 */
219 public function testRedirectExternalReferer(): void
220 {
221 $this->container->environment['HTTP_REFERER'] = 'http://other.domain.tld/controller?query=param&other=2';
222
223 $response = new Response();
224
225 $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']);
226
227 static::assertSame(302, $result->getStatusCode());
228 static::assertSame(['/subfolder/'], $result->getHeader('location'));
229 }
230
231 /**
232 * Test redirectFromReferer() - From another domain -> we ignore the given referrer.
233 */
234 public function testRedirectExternalRefererExplicitDomainName(): void
235 {
236 $this->container->environment['SERVER_NAME'] = 'my.shaarli.tld';
237 $this->container->environment['HTTP_REFERER'] = 'http://your.shaarli.tld/controller?query=param&other=2';
238
239 $response = new Response();
240
241 $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']);
242
243 static::assertSame(302, $result->getStatusCode());
244 static::assertSame(['/subfolder/'], $result->getHeader('location'));
245 }
215} 246}
diff --git a/tests/front/controller/visitor/TagCloudControllerTest.php b/tests/front/controller/visitor/TagCloudControllerTest.php
index 9a6a4bc0..9305612e 100644
--- a/tests/front/controller/visitor/TagCloudControllerTest.php
+++ b/tests/front/controller/visitor/TagCloudControllerTest.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkFilter; 7use Shaarli\Bookmark\BookmarkFilter;
8use Shaarli\TestCase;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11 11
@@ -53,14 +53,16 @@ class TagCloudControllerTest extends TestCase
53 53
54 // Make sure that PluginManager hook is triggered 54 // Make sure that PluginManager hook is triggered
55 $this->container->pluginManager 55 $this->container->pluginManager
56 ->expects(static::at(0)) 56 ->expects(static::atLeastOnce())
57 ->method('executeHooks') 57 ->method('executeHooks')
58 ->withConsecutive(['render_tagcloud'])
58 ->willReturnCallback(function (string $hook, array $data, array $param): array { 59 ->willReturnCallback(function (string $hook, array $data, array $param): array {
59 static::assertSame('render_tagcloud', $hook); 60 if ('render_tagcloud' === $hook) {
60 static::assertSame('', $data['search_tags']); 61 static::assertSame('', $data['search_tags']);
61 static::assertCount(3, $data['tags']); 62 static::assertCount(3, $data['tags']);
62 63
63 static::assertArrayHasKey('loggedin', $param); 64 static::assertArrayHasKey('loggedin', $param);
65 }
64 66
65 return $data; 67 return $data;
66 }) 68 })
@@ -124,14 +126,16 @@ class TagCloudControllerTest extends TestCase
124 126
125 // Make sure that PluginManager hook is triggered 127 // Make sure that PluginManager hook is triggered
126 $this->container->pluginManager 128 $this->container->pluginManager
127 ->expects(static::at(0)) 129 ->expects(static::atLeastOnce())
128 ->method('executeHooks') 130 ->method('executeHooks')
131 ->withConsecutive(['render_tagcloud'])
129 ->willReturnCallback(function (string $hook, array $data, array $param): array { 132 ->willReturnCallback(function (string $hook, array $data, array $param): array {
130 static::assertSame('render_tagcloud', $hook); 133 if ('render_tagcloud' === $hook) {
131 static::assertSame('ghi def', $data['search_tags']); 134 static::assertSame('ghi def', $data['search_tags']);
132 static::assertCount(1, $data['tags']); 135 static::assertCount(1, $data['tags']);
133 136
134 static::assertArrayHasKey('loggedin', $param); 137 static::assertArrayHasKey('loggedin', $param);
138 }
135 139
136 return $data; 140 return $data;
137 }) 141 })
@@ -175,14 +179,16 @@ class TagCloudControllerTest extends TestCase
175 179
176 // Make sure that PluginManager hook is triggered 180 // Make sure that PluginManager hook is triggered
177 $this->container->pluginManager 181 $this->container->pluginManager
178 ->expects(static::at(0)) 182 ->expects(static::atLeastOnce())
179 ->method('executeHooks') 183 ->method('executeHooks')
184 ->withConsecutive(['render_tagcloud'])
180 ->willReturnCallback(function (string $hook, array $data, array $param): array { 185 ->willReturnCallback(function (string $hook, array $data, array $param): array {
181 static::assertSame('render_tagcloud', $hook); 186 if ('render_tagcloud' === $hook) {
182 static::assertSame('', $data['search_tags']); 187 static::assertSame('', $data['search_tags']);
183 static::assertCount(0, $data['tags']); 188 static::assertCount(0, $data['tags']);
184 189
185 static::assertArrayHasKey('loggedin', $param); 190 static::assertArrayHasKey('loggedin', $param);
191 }
186 192
187 return $data; 193 return $data;
188 }) 194 })
@@ -227,14 +233,16 @@ class TagCloudControllerTest extends TestCase
227 233
228 // Make sure that PluginManager hook is triggered 234 // Make sure that PluginManager hook is triggered
229 $this->container->pluginManager 235 $this->container->pluginManager
230 ->expects(static::at(0)) 236 ->expects(static::atLeastOnce())
231 ->method('executeHooks') 237 ->method('executeHooks')
238 ->withConsecutive(['render_taglist'])
232 ->willReturnCallback(function (string $hook, array $data, array $param): array { 239 ->willReturnCallback(function (string $hook, array $data, array $param): array {
233 static::assertSame('render_taglist', $hook); 240 if ('render_taglist' === $hook) {
234 static::assertSame('', $data['search_tags']); 241 static::assertSame('', $data['search_tags']);
235 static::assertCount(3, $data['tags']); 242 static::assertCount(3, $data['tags']);
236 243
237 static::assertArrayHasKey('loggedin', $param); 244 static::assertArrayHasKey('loggedin', $param);
245 }
238 246
239 return $data; 247 return $data;
240 }) 248 })
@@ -297,14 +305,16 @@ class TagCloudControllerTest extends TestCase
297 305
298 // Make sure that PluginManager hook is triggered 306 // Make sure that PluginManager hook is triggered
299 $this->container->pluginManager 307 $this->container->pluginManager
300 ->expects(static::at(0)) 308 ->expects(static::atLeastOnce())
301 ->method('executeHooks') 309 ->method('executeHooks')
310 ->withConsecutive(['render_taglist'])
302 ->willReturnCallback(function (string $hook, array $data, array $param): array { 311 ->willReturnCallback(function (string $hook, array $data, array $param): array {
303 static::assertSame('render_taglist', $hook); 312 if ('render_taglist' === $hook) {
304 static::assertSame('ghi def', $data['search_tags']); 313 static::assertSame('ghi def', $data['search_tags']);
305 static::assertCount(1, $data['tags']); 314 static::assertCount(1, $data['tags']);
306 315
307 static::assertArrayHasKey('loggedin', $param); 316 static::assertArrayHasKey('loggedin', $param);
317 }
308 318
309 return $data; 319 return $data;
310 }) 320 })
@@ -344,14 +354,16 @@ class TagCloudControllerTest extends TestCase
344 354
345 // Make sure that PluginManager hook is triggered 355 // Make sure that PluginManager hook is triggered
346 $this->container->pluginManager 356 $this->container->pluginManager
347 ->expects(static::at(0)) 357 ->expects(static::atLeastOnce())
348 ->method('executeHooks') 358 ->method('executeHooks')
359 ->withConsecutive(['render_taglist'])
349 ->willReturnCallback(function (string $hook, array $data, array $param): array { 360 ->willReturnCallback(function (string $hook, array $data, array $param): array {
350 static::assertSame('render_taglist', $hook); 361 if ('render_taglist' === $hook) {
351 static::assertSame('', $data['search_tags']); 362 static::assertSame('', $data['search_tags']);
352 static::assertCount(0, $data['tags']); 363 static::assertCount(0, $data['tags']);
353 364
354 static::assertArrayHasKey('loggedin', $param); 365 static::assertArrayHasKey('loggedin', $param);
366 }
355 367
356 return $data; 368 return $data;
357 }) 369 })
diff --git a/tests/front/controller/visitor/TagControllerTest.php b/tests/front/controller/visitor/TagControllerTest.php
index 43076086..750ea02d 100644
--- a/tests/front/controller/visitor/TagControllerTest.php
+++ b/tests/front/controller/visitor/TagControllerTest.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use PHPUnit\Framework\TestCase; 7use Shaarli\TestCase;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10