aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-16 14:56:22 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit60ae241251b753fc052e50ebd95277dfcb074cb0 (patch)
treedfa474c1df6a5f123a31c953d7cb0d157b040b8b /tests/front
parent3772298ee7d8d0708f4e72798600accafa17740b (diff)
downloadShaarli-60ae241251b753fc052e50ebd95277dfcb074cb0.tar.gz
Shaarli-60ae241251b753fc052e50ebd95277dfcb074cb0.tar.zst
Shaarli-60ae241251b753fc052e50ebd95277dfcb074cb0.zip
Process tag list page through Slim controller
Diffstat (limited to 'tests/front')
-rw-r--r--tests/front/controller/TagCloudControllerTest.php203
1 files changed, 191 insertions, 12 deletions
diff --git a/tests/front/controller/TagCloudControllerTest.php b/tests/front/controller/TagCloudControllerTest.php
index 352bdee2..719610d7 100644
--- a/tests/front/controller/TagCloudControllerTest.php
+++ b/tests/front/controller/TagCloudControllerTest.php
@@ -30,6 +30,9 @@ class TagCloudControllerTest extends TestCase
30 $this->controller = new TagCloudController($this->container); 30 $this->controller = new TagCloudController($this->container);
31 } 31 }
32 32
33 /**
34 * Tag Cloud - default parameters
35 */
33 public function testValidCloudControllerInvokeDefault(): void 36 public function testValidCloudControllerInvokeDefault(): void
34 { 37 {
35 $this->createValidContainerMockSet(); 38 $this->createValidContainerMockSet();
@@ -42,7 +45,6 @@ class TagCloudControllerTest extends TestCase
42 $expectedOrder = ['abc', 'def', 'ghi']; 45 $expectedOrder = ['abc', 'def', 'ghi'];
43 46
44 $request = $this->createMock(Request::class); 47 $request = $this->createMock(Request::class);
45 $request->expects(static::once())->method('getQueryParam')->with('searchtags')->willReturn(null);
46 $response = new Response(); 48 $response = new Response();
47 49
48 // Save RainTPL assigned variables 50 // Save RainTPL assigned variables
@@ -92,7 +94,7 @@ class TagCloudControllerTest extends TestCase
92 } 94 }
93 95
94 /** 96 /**
95 * Additional parameters: 97 * Tag Cloud - Additional parameters:
96 * - logged in 98 * - logged in
97 * - visibility private 99 * - visibility private
98 * - search tags: `ghi` and `def` (note that filtered tags are not displayed anymore) 100 * - search tags: `ghi` and `def` (note that filtered tags are not displayed anymore)
@@ -101,18 +103,17 @@ class TagCloudControllerTest extends TestCase
101 { 103 {
102 $this->createValidContainerMockSet(); 104 $this->createValidContainerMockSet();
103 105
104 $allTags = [
105 'ghi' => 1,
106 'abc' => 3,
107 'def' => 12,
108 ];
109
110 $request = $this->createMock(Request::class); 106 $request = $this->createMock(Request::class);
111 $request 107 $request
112 ->expects(static::once())
113 ->method('getQueryParam') 108 ->method('getQueryParam')
114 ->with('searchtags') 109 ->with()
115 ->willReturn('ghi def') 110 ->willReturnCallback(function (string $key): ?string {
111 if ('searchtags' === $key) {
112 return 'ghi def';
113 }
114
115 return null;
116 })
116 ; 117 ;
117 $response = new Response(); 118 $response = new Response();
118 119
@@ -162,12 +163,14 @@ class TagCloudControllerTest extends TestCase
162 static::assertLessThan(5, $assignedVariables['tags']['abc']['size']); 163 static::assertLessThan(5, $assignedVariables['tags']['abc']['size']);
163 } 164 }
164 165
166 /**
167 * Tag Cloud - empty
168 */
165 public function testEmptyCloud(): void 169 public function testEmptyCloud(): void
166 { 170 {
167 $this->createValidContainerMockSet(); 171 $this->createValidContainerMockSet();
168 172
169 $request = $this->createMock(Request::class); 173 $request = $this->createMock(Request::class);
170 $request->expects(static::once())->method('getQueryParam')->with('searchtags')->willReturn(null);
171 $response = new Response(); 174 $response = new Response();
172 175
173 // Save RainTPL assigned variables 176 // Save RainTPL assigned variables
@@ -208,6 +211,182 @@ class TagCloudControllerTest extends TestCase
208 static::assertCount(0, $assignedVariables['tags']); 211 static::assertCount(0, $assignedVariables['tags']);
209 } 212 }
210 213
214 /**
215 * Tag List - Default sort is by usage DESC
216 */
217 public function testValidListControllerInvokeDefault(): void
218 {
219 $this->createValidContainerMockSet();
220
221 $allTags = [
222 'def' => 12,
223 'abc' => 3,
224 'ghi' => 1,
225 ];
226
227 $request = $this->createMock(Request::class);
228 $response = new Response();
229
230 // Save RainTPL assigned variables
231 $assignedVariables = [];
232 $this->assignTemplateVars($assignedVariables);
233
234 $this->container->bookmarkService
235 ->expects(static::once())
236 ->method('bookmarksCountPerTag')
237 ->with([], null)
238 ->willReturnCallback(function () use ($allTags): array {
239 return $allTags;
240 })
241 ;
242
243 // Make sure that PluginManager hook is triggered
244 $this->container->pluginManager
245 ->expects(static::at(0))
246 ->method('executeHooks')
247 ->willReturnCallback(function (string $hook, array $data, array $param): array {
248 static::assertSame('render_taglist', $hook);
249 static::assertSame('', $data['search_tags']);
250 static::assertCount(3, $data['tags']);
251
252 static::assertArrayHasKey('loggedin', $param);
253
254 return $data;
255 })
256 ;
257
258 $result = $this->controller->list($request, $response);
259
260 static::assertSame(200, $result->getStatusCode());
261 static::assertSame('tag.list', (string) $result->getBody());
262 static::assertSame('Tag list - Shaarli', $assignedVariables['pagetitle']);
263
264 static::assertSame('', $assignedVariables['search_tags']);
265 static::assertCount(3, $assignedVariables['tags']);
266
267 foreach ($allTags as $tag => $count) {
268 static::assertSame($count, $assignedVariables['tags'][$tag]);
269 }
270 }
271
272 /**
273 * Tag List - Additional parameters:
274 * - logged in
275 * - visibility private
276 * - search tags: `ghi` and `def` (note that filtered tags are not displayed anymore)
277 * - sort alphabetically
278 */
279 public function testValidListControllerInvokeWithParameters(): void
280 {
281 $this->createValidContainerMockSet();
282
283 $request = $this->createMock(Request::class);
284 $request
285 ->method('getQueryParam')
286 ->with()
287 ->willReturnCallback(function (string $key): ?string {
288 if ('searchtags' === $key) {
289 return 'ghi def';
290 } elseif ('sort' === $key) {
291 return 'alpha';
292 }
293
294 return null;
295 })
296 ;
297 $response = new Response();
298
299 // Save RainTPL assigned variables
300 $assignedVariables = [];
301 $this->assignTemplateVars($assignedVariables);
302
303 $this->container->loginManager->method('isLoggedin')->willReturn(true);
304 $this->container->sessionManager->expects(static::once())->method('getSessionParameter')->willReturn('private');
305
306 $this->container->bookmarkService
307 ->expects(static::once())
308 ->method('bookmarksCountPerTag')
309 ->with(['ghi', 'def'], BookmarkFilter::$PRIVATE)
310 ->willReturnCallback(function (): array {
311 return ['abc' => 3];
312 })
313 ;
314
315 // Make sure that PluginManager hook is triggered
316 $this->container->pluginManager
317 ->expects(static::at(0))
318 ->method('executeHooks')
319 ->willReturnCallback(function (string $hook, array $data, array $param): array {
320 static::assertSame('render_taglist', $hook);
321 static::assertSame('ghi def', $data['search_tags']);
322 static::assertCount(1, $data['tags']);
323
324 static::assertArrayHasKey('loggedin', $param);
325
326 return $data;
327 })
328 ;
329
330 $result = $this->controller->list($request, $response);
331
332 static::assertSame(200, $result->getStatusCode());
333 static::assertSame('tag.list', (string) $result->getBody());
334 static::assertSame('ghi def - Tag list - Shaarli', $assignedVariables['pagetitle']);
335
336 static::assertSame('ghi def', $assignedVariables['search_tags']);
337 static::assertCount(1, $assignedVariables['tags']);
338 static::assertSame(3, $assignedVariables['tags']['abc']);
339 }
340
341 /**
342 * Tag List - empty
343 */
344 public function testEmptyList(): void
345 {
346 $this->createValidContainerMockSet();
347
348 $request = $this->createMock(Request::class);
349 $response = new Response();
350
351 // Save RainTPL assigned variables
352 $assignedVariables = [];
353 $this->assignTemplateVars($assignedVariables);
354
355 $this->container->bookmarkService
356 ->expects(static::once())
357 ->method('bookmarksCountPerTag')
358 ->with([], null)
359 ->willReturnCallback(function (array $parameters, ?string $visibility): array {
360 return [];
361 })
362 ;
363
364 // Make sure that PluginManager hook is triggered
365 $this->container->pluginManager
366 ->expects(static::at(0))
367 ->method('executeHooks')
368 ->willReturnCallback(function (string $hook, array $data, array $param): array {
369 static::assertSame('render_taglist', $hook);
370 static::assertSame('', $data['search_tags']);
371 static::assertCount(0, $data['tags']);
372
373 static::assertArrayHasKey('loggedin', $param);
374
375 return $data;
376 })
377 ;
378
379 $result = $this->controller->list($request, $response);
380
381 static::assertSame(200, $result->getStatusCode());
382 static::assertSame('tag.list', (string) $result->getBody());
383 static::assertSame('Tag list - Shaarli', $assignedVariables['pagetitle']);
384
385 static::assertSame('', $assignedVariables['search_tags']);
386 static::assertCount(0, $assignedVariables['tags']);
387 }
388
389
211 protected function createValidContainerMockSet(): void 390 protected function createValidContainerMockSet(): void
212 { 391 {
213 $loginManager = $this->createMock(LoginManager::class); 392 $loginManager = $this->createMock(LoginManager::class);