aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-06-13 11:22:14 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit818b3193ffabec57501e3bdfa997206e3c0671ef (patch)
treef5a4d3cc23ac367dde617b849561177fc20d767a /tests
parentc22fa57a5505fe95fd01860e3d3dfbb089f869cd (diff)
downloadShaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.tar.gz
Shaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.tar.zst
Shaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.zip
Explicitly define base and asset path in templates
With the new routes, all pages are not all at the same folder level anymore (e.g. /shaare and /shaare/123), so we can't just use './' everywhere. The most consistent way to handle this is to prefix all path with the proper variable, and handle the actual path in controllers.
Diffstat (limited to 'tests')
-rw-r--r--tests/front/ShaarliMiddlewareTest.php15
-rw-r--r--tests/front/controller/admin/PostBookmarkControllerTest.php19
-rw-r--r--tests/front/controller/admin/SessionFilterControllerTest.php60
-rw-r--r--tests/front/controller/visitor/FrontControllerMockHelper.php2
-rw-r--r--tests/front/controller/visitor/ShaarliVisitorControllerTest.php (renamed from tests/front/controller/visitor/ShaarliPublicControllerTest.php)22
5 files changed, 28 insertions, 90 deletions
diff --git a/tests/front/ShaarliMiddlewareTest.php b/tests/front/ShaarliMiddlewareTest.php
index 80974f37..57be1002 100644
--- a/tests/front/ShaarliMiddlewareTest.php
+++ b/tests/front/ShaarliMiddlewareTest.php
@@ -11,6 +11,7 @@ use Shaarli\Front\Exception\LoginBannedException;
11use Shaarli\Render\PageBuilder; 11use Shaarli\Render\PageBuilder;
12use Slim\Http\Request; 12use Slim\Http\Request;
13use Slim\Http\Response; 13use Slim\Http\Response;
14use Slim\Http\Uri;
14 15
15class ShaarliMiddlewareTest extends TestCase 16class ShaarliMiddlewareTest extends TestCase
16{ 17{
@@ -29,6 +30,13 @@ class ShaarliMiddlewareTest extends TestCase
29 public function testMiddlewareExecution(): void 30 public function testMiddlewareExecution(): void
30 { 31 {
31 $request = $this->createMock(Request::class); 32 $request = $this->createMock(Request::class);
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
32 $response = new Response(); 40 $response = new Response();
33 $controller = function (Request $request, Response $response): Response { 41 $controller = function (Request $request, Response $response): Response {
34 return $response->withStatus(418); // I'm a tea pot 42 return $response->withStatus(418); // I'm a tea pot
@@ -44,6 +52,13 @@ class ShaarliMiddlewareTest extends TestCase
44 public function testMiddlewareExecutionWithException(): void 52 public function testMiddlewareExecutionWithException(): void
45 { 53 {
46 $request = $this->createMock(Request::class); 54 $request = $this->createMock(Request::class);
55 $request->method('getUri')->willReturnCallback(function (): Uri {
56 $uri = $this->createMock(Uri::class);
57 $uri->method('getBasePath')->willReturn('/subfolder');
58
59 return $uri;
60 });
61
47 $response = new Response(); 62 $response = new Response();
48 $controller = function (): void { 63 $controller = function (): void {
49 $exception = new LoginBannedException(); 64 $exception = new LoginBannedException();
diff --git a/tests/front/controller/admin/PostBookmarkControllerTest.php b/tests/front/controller/admin/PostBookmarkControllerTest.php
index f00a15c9..69673bd2 100644
--- a/tests/front/controller/admin/PostBookmarkControllerTest.php
+++ b/tests/front/controller/admin/PostBookmarkControllerTest.php
@@ -13,7 +13,6 @@ use Shaarli\Security\SessionManager;
13use Shaarli\Thumbnailer; 13use Shaarli\Thumbnailer;
14use Slim\Http\Request; 14use Slim\Http\Request;
15use Slim\Http\Response; 15use Slim\Http\Response;
16use Slim\Http\Uri;
17 16
18class PostBookmarkControllerTest extends TestCase 17class PostBookmarkControllerTest extends TestCase
19{ 18{
@@ -406,12 +405,6 @@ class PostBookmarkControllerTest extends TestCase
406 return $parameters[$key] ?? null; 405 return $parameters[$key] ?? null;
407 }) 406 })
408 ; 407 ;
409 $request->method('getUri')->willReturnCallback(function (): Uri {
410 $uri = $this->createMock(Uri::class);
411 $uri->method('getBasePath')->willReturn('/subfolder');
412
413 return $uri;
414 });
415 $response = new Response(); 408 $response = new Response();
416 409
417 $checkBookmark = function (Bookmark $bookmark) use ($parameters) { 410 $checkBookmark = function (Bookmark $bookmark) use ($parameters) {
@@ -493,12 +486,6 @@ class PostBookmarkControllerTest extends TestCase
493 return $parameters[$key] ?? null; 486 return $parameters[$key] ?? null;
494 }) 487 })
495 ; 488 ;
496 $request->method('getUri')->willReturnCallback(function (): Uri {
497 $uri = $this->createMock(Uri::class);
498 $uri->method('getBasePath')->willReturn('/subfolder');
499
500 return $uri;
501 });
502 $response = new Response(); 489 $response = new Response();
503 490
504 $checkBookmark = function (Bookmark $bookmark) use ($parameters, $id) { 491 $checkBookmark = function (Bookmark $bookmark) use ($parameters, $id) {
@@ -575,12 +562,6 @@ class PostBookmarkControllerTest extends TestCase
575 return $parameters[$key] ?? null; 562 return $parameters[$key] ?? null;
576 }) 563 })
577 ; 564 ;
578 $request->method('getUri')->willReturnCallback(function (): Uri {
579 $uri = $this->createMock(Uri::class);
580 $uri->method('getBasePath')->willReturn('/subfolder');
581
582 return $uri;
583 });
584 $response = new Response(); 565 $response = new Response();
585 566
586 $this->container->conf = $this->createMock(ConfigManager::class); 567 $this->container->conf = $this->createMock(ConfigManager::class);
diff --git a/tests/front/controller/admin/SessionFilterControllerTest.php b/tests/front/controller/admin/SessionFilterControllerTest.php
index 096963cf..ea07edee 100644
--- a/tests/front/controller/admin/SessionFilterControllerTest.php
+++ b/tests/front/controller/admin/SessionFilterControllerTest.php
@@ -9,7 +9,6 @@ use Shaarli\Security\LoginManager;
9use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
10use Slim\Http\Request; 10use Slim\Http\Request;
11use Slim\Http\Response; 11use Slim\Http\Response;
12use Slim\Http\Uri;
13 12
14class SessionFilterControllerTest extends TestCase 13class SessionFilterControllerTest extends TestCase
15{ 14{
@@ -33,12 +32,6 @@ class SessionFilterControllerTest extends TestCase
33 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 32 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
34 33
35 $request = $this->createMock(Request::class); 34 $request = $this->createMock(Request::class);
36 $request->method('getUri')->willReturnCallback(function (): Uri {
37 $uri = $this->createMock(Uri::class);
38 $uri->method('getBasePath')->willReturn('/subfolder');
39
40 return $uri;
41 });
42 $request->method('getParam')->with('nb')->willReturn('8'); 35 $request->method('getParam')->with('nb')->willReturn('8');
43 $response = new Response(); 36 $response = new Response();
44 37
@@ -61,12 +54,6 @@ class SessionFilterControllerTest extends TestCase
61 public function testLinksPerPageNotValid(): void 54 public function testLinksPerPageNotValid(): void
62 { 55 {
63 $request = $this->createMock(Request::class); 56 $request = $this->createMock(Request::class);
64 $request->method('getUri')->willReturnCallback(function (): Uri {
65 $uri = $this->createMock(Uri::class);
66 $uri->method('getBasePath')->willReturn('/subfolder');
67
68 return $uri;
69 });
70 $request->method('getParam')->with('nb')->willReturn('test'); 57 $request->method('getParam')->with('nb')->willReturn('test');
71 $response = new Response(); 58 $response = new Response();
72 59
@@ -80,7 +67,7 @@ class SessionFilterControllerTest extends TestCase
80 67
81 static::assertInstanceOf(Response::class, $result); 68 static::assertInstanceOf(Response::class, $result);
82 static::assertSame(302, $result->getStatusCode()); 69 static::assertSame(302, $result->getStatusCode());
83 static::assertSame(['/subfolder'], $result->getHeader('location')); 70 static::assertSame(['/subfolder/'], $result->getHeader('location'));
84 } 71 }
85 72
86 /** 73 /**
@@ -100,12 +87,6 @@ class SessionFilterControllerTest extends TestCase
100 ; 87 ;
101 88
102 $request = $this->createMock(Request::class); 89 $request = $this->createMock(Request::class);
103 $request->method('getUri')->willReturnCallback(function (): Uri {
104 $uri = $this->createMock(Uri::class);
105 $uri->method('getBasePath')->willReturn('/subfolder');
106
107 return $uri;
108 });
109 $response = new Response(); 90 $response = new Response();
110 91
111 $result = $this->controller->visibility($request, $response, $arg); 92 $result = $this->controller->visibility($request, $response, $arg);
@@ -141,12 +122,6 @@ class SessionFilterControllerTest extends TestCase
141 ; 122 ;
142 123
143 $request = $this->createMock(Request::class); 124 $request = $this->createMock(Request::class);
144 $request->method('getUri')->willReturnCallback(function (): Uri {
145 $uri = $this->createMock(Uri::class);
146 $uri->method('getBasePath')->willReturn('/subfolder');
147
148 return $uri;
149 });
150 $response = new Response(); 125 $response = new Response();
151 126
152 $result = $this->controller->visibility($request, $response, $arg); 127 $result = $this->controller->visibility($request, $response, $arg);
@@ -176,19 +151,13 @@ class SessionFilterControllerTest extends TestCase
176 ; 151 ;
177 152
178 $request = $this->createMock(Request::class); 153 $request = $this->createMock(Request::class);
179 $request->method('getUri')->willReturnCallback(function (): Uri {
180 $uri = $this->createMock(Uri::class);
181 $uri->method('getBasePath')->willReturn('/subfolder');
182
183 return $uri;
184 });
185 $response = new Response(); 154 $response = new Response();
186 155
187 $result = $this->controller->visibility($request, $response, $arg); 156 $result = $this->controller->visibility($request, $response, $arg);
188 157
189 static::assertInstanceOf(Response::class, $result); 158 static::assertInstanceOf(Response::class, $result);
190 static::assertSame(302, $result->getStatusCode()); 159 static::assertSame(302, $result->getStatusCode());
191 static::assertSame(['/subfolder'], $result->getHeader('location')); 160 static::assertSame(['/subfolder/'], $result->getHeader('location'));
192 } 161 }
193 162
194 /** 163 /**
@@ -212,12 +181,6 @@ class SessionFilterControllerTest extends TestCase
212 ; 181 ;
213 182
214 $request = $this->createMock(Request::class); 183 $request = $this->createMock(Request::class);
215 $request->method('getUri')->willReturnCallback(function (): Uri {
216 $uri = $this->createMock(Uri::class);
217 $uri->method('getBasePath')->willReturn('/subfolder');
218
219 return $uri;
220 });
221 $response = new Response(); 184 $response = new Response();
222 185
223 $result = $this->controller->visibility($request, $response, $arg); 186 $result = $this->controller->visibility($request, $response, $arg);
@@ -249,12 +212,6 @@ class SessionFilterControllerTest extends TestCase
249 ; 212 ;
250 213
251 $request = $this->createMock(Request::class); 214 $request = $this->createMock(Request::class);
252 $request->method('getUri')->willReturnCallback(function (): Uri {
253 $uri = $this->createMock(Uri::class);
254 $uri->method('getBasePath')->willReturn('/subfolder');
255
256 return $uri;
257 });
258 $response = new Response(); 215 $response = new Response();
259 216
260 $result = $this->controller->visibility($request, $response, $arg); 217 $result = $this->controller->visibility($request, $response, $arg);
@@ -272,12 +229,6 @@ class SessionFilterControllerTest extends TestCase
272 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 229 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
273 230
274 $request = $this->createMock(Request::class); 231 $request = $this->createMock(Request::class);
275 $request->method('getUri')->willReturnCallback(function (): Uri {
276 $uri = $this->createMock(Uri::class);
277 $uri->method('getBasePath')->willReturn('/subfolder');
278
279 return $uri;
280 });
281 $response = new Response(); 232 $response = new Response();
282 233
283 $this->container->sessionManager 234 $this->container->sessionManager
@@ -301,13 +252,6 @@ class SessionFilterControllerTest extends TestCase
301 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; 252 $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc'];
302 253
303 $request = $this->createMock(Request::class); 254 $request = $this->createMock(Request::class);
304 $request->method('getUri')->willReturnCallback(function (): Uri {
305 $uri = $this->createMock(Uri::class);
306 $uri->method('getBasePath')->willReturn('/subfolder');
307
308 return $uri;
309 });
310
311 $response = new Response(); 255 $response = new Response();
312 256
313 $this->container->sessionManager 257 $this->container->sessionManager
diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php
index fecd0c82..7f560662 100644
--- a/tests/front/controller/visitor/FrontControllerMockHelper.php
+++ b/tests/front/controller/visitor/FrontControllerMockHelper.php
@@ -81,6 +81,8 @@ trait FrontControllerMockHelper
81 'SERVER_PORT' => '80', 81 'SERVER_PORT' => '80',
82 'REQUEST_URI' => '/daily-rss', 82 'REQUEST_URI' => '/daily-rss',
83 ]; 83 ];
84
85 $this->container->basePath = '/subfolder';
84 } 86 }
85 87
86 /** 88 /**
diff --git a/tests/front/controller/visitor/ShaarliPublicControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
index 899b280b..83d08358 100644
--- a/tests/front/controller/visitor/ShaarliPublicControllerTest.php
+++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
@@ -8,15 +8,14 @@ use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkFilter; 8use Shaarli\Bookmark\BookmarkFilter;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11use Slim\Http\Uri;
12 11
13/** 12/**
14 * Class ShaarliControllerTest 13 * Class ShaarliControllerTest
15 * 14 *
16 * This class is used to test default behavior of ShaarliController abstract class. 15 * This class is used to test default behavior of ShaarliVisitorController abstract class.
17 * It uses a dummy non abstract controller. 16 * It uses a dummy non abstract controller.
18 */ 17 */
19class ShaarliPublicControllerTest extends TestCase 18class ShaarliVisitorControllerTest extends TestCase
20{ 19{
21 use FrontControllerMockHelper; 20 use FrontControllerMockHelper;
22 21
@@ -49,20 +48,15 @@ class ShaarliPublicControllerTest extends TestCase
49 Request $request, 48 Request $request,
50 Response $response, 49 Response $response,
51 array $loopTerms = [], 50 array $loopTerms = [],
52 array $clearParams = [] 51 array $clearParams = [],
52 string $anchor = null
53 ): Response { 53 ): Response {
54 return parent::redirectFromReferer($request, $response, $loopTerms, $clearParams); 54 return parent::redirectFromReferer($request, $response, $loopTerms, $clearParams, $anchor);
55 } 55 }
56 }; 56 };
57 $this->assignedValues = []; 57 $this->assignedValues = [];
58 58
59 $this->request = $this->createMock(Request::class); 59 $this->request = $this->createMock(Request::class);
60 $this->request->method('getUri')->willReturnCallback(function (): Uri {
61 $uri = $this->createMock(Uri::class);
62 $uri->method('getBasePath')->willReturn('/subfolder');
63
64 return $uri;
65 });
66 } 60 }
67 61
68 public function testAssignView(): void 62 public function testAssignView(): void
@@ -102,6 +96,8 @@ class ShaarliPublicControllerTest extends TestCase
102 static::assertSame(10, $this->assignedValues['linkcount']); 96 static::assertSame(10, $this->assignedValues['linkcount']);
103 static::assertSame(5, $this->assignedValues['privateLinkcount']); 97 static::assertSame(5, $this->assignedValues['privateLinkcount']);
104 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']);
105 101
106 static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']); 102 static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']);
107 static::assertTrue($this->assignedValues['plugins_includes']['render_includes']['loggedin']); 103 static::assertTrue($this->assignedValues['plugins_includes']['render_includes']['loggedin']);
@@ -153,7 +149,7 @@ class ShaarliPublicControllerTest extends TestCase
153 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'controller']); 149 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'controller']);
154 150
155 static::assertSame(302, $result->getStatusCode()); 151 static::assertSame(302, $result->getStatusCode());
156 static::assertSame(['/subfolder'], $result->getHeader('location')); 152 static::assertSame(['/subfolder/'], $result->getHeader('location'));
157 } 153 }
158 154
159 /** 155 /**
@@ -168,7 +164,7 @@ class ShaarliPublicControllerTest extends TestCase
168 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'other']); 164 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'other']);
169 165
170 static::assertSame(302, $result->getStatusCode()); 166 static::assertSame(302, $result->getStatusCode());
171 static::assertSame(['/subfolder'], $result->getHeader('location')); 167 static::assertSame(['/subfolder/'], $result->getHeader('location'));
172 } 168 }
173 169
174 /** 170 /**