3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Visitor
;
7 use Shaarli\Security\SessionManager
;
10 use Slim\Http\Response
;
12 class PublicSessionFilterControllerTest
extends TestCase
14 use FrontControllerMockHelper
;
16 /** @var PublicSessionFilterController */
17 protected $controller;
19 public function setUp(): void
21 $this->createContainer();
23 $this->controller
= new PublicSessionFilterController($this->container
);
27 * Link per page - Default call with valid parameter and a referer.
29 public function testLinksPerPage(): void
31 $this->container
->environment
['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
33 $request = $this->createMock(Request
::class);
34 $request->method('getParam')->with('nb')->willReturn('8');
35 $response = new Response();
37 $this->container
->sessionManager
38 ->expects(static::once())
39 ->method('setSessionParameter')
40 ->with(SessionManager
::KEY_LINKS_PER_PAGE
, 8)
43 $result = $this->controller
->linksPerPage($request, $response);
45 static::assertInstanceOf(Response
::class, $result);
46 static::assertSame(302, $result->getStatusCode());
47 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location'));
51 * Link per page - Invalid value, should use default value (20)
53 public function testLinksPerPageNotValid(): void
55 $request = $this->createMock(Request
::class);
56 $request->method('getParam')->with('nb')->willReturn('test');
57 $response = new Response();
59 $this->container
->sessionManager
60 ->expects(static::once())
61 ->method('setSessionParameter')
62 ->with(SessionManager
::KEY_LINKS_PER_PAGE
, 20)
65 $result = $this->controller
->linksPerPage($request, $response);
67 static::assertInstanceOf(Response
::class, $result);
68 static::assertSame(302, $result->getStatusCode());
69 static::assertSame(['/subfolder/'], $result->getHeader('location'));
73 * Untagged only - valid call
75 public function testUntaggedOnly(): void
77 $this->container
->environment
['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
79 $request = $this->createMock(Request
::class);
80 $response = new Response();
82 $this->container
->sessionManager
83 ->expects(static::once())
84 ->method('setSessionParameter')
85 ->with(SessionManager
::KEY_UNTAGGED_ONLY
, true)
88 $result = $this->controller
->untaggedOnly($request, $response);
90 static::assertInstanceOf(Response
::class, $result);
91 static::assertSame(302, $result->getStatusCode());
92 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location'));
96 * Untagged only - toggle off
98 public function testUntaggedOnlyToggleOff(): void
100 $this->container
->environment
['HTTP_REFERER'] = 'http://shaarli/subfolder/controller/?searchtag=abc';
102 $request = $this->createMock(Request
::class);
103 $response = new Response();
105 $this->container
->sessionManager
106 ->method('getSessionParameter')
107 ->with(SessionManager
::KEY_UNTAGGED_ONLY
)
110 $this->container
->sessionManager
111 ->expects(static::once())
112 ->method('setSessionParameter')
113 ->with(SessionManager
::KEY_UNTAGGED_ONLY
, false)
116 $result = $this->controller
->untaggedOnly($request, $response);
118 static::assertInstanceOf(Response
::class, $result);
119 static::assertSame(302, $result->getStatusCode());
120 static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location'));