diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-07-24 12:48:53 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-24 12:48:53 +0200 |
commit | 204035bd3c91b9a5c39fcb6fc470e108b032dbd9 (patch) | |
tree | b3b3c01bd162da4d0672a7fd3b598d8c4580c980 /tests/front/controller/visitor | |
parent | 87ae3c4f08431e02869376cb57add257747910d1 (diff) | |
download | Shaarli-204035bd3c91b9a5c39fcb6fc470e108b032dbd9.tar.gz Shaarli-204035bd3c91b9a5c39fcb6fc470e108b032dbd9.tar.zst Shaarli-204035bd3c91b9a5c39fcb6fc470e108b032dbd9.zip |
Fix: visitor are allowed to chose nb of links per page
Diffstat (limited to 'tests/front/controller/visitor')
-rw-r--r-- | tests/front/controller/visitor/PublicSessionFilterControllerTest.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/front/controller/visitor/PublicSessionFilterControllerTest.php b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php new file mode 100644 index 00000000..3aa1cb99 --- /dev/null +++ b/tests/front/controller/visitor/PublicSessionFilterControllerTest.php | |||
@@ -0,0 +1,71 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Visitor; | ||
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | use Shaarli\Security\SessionManager; | ||
9 | use Slim\Http\Request; | ||
10 | use Slim\Http\Response; | ||
11 | |||
12 | class PublicSessionFilterControllerTest extends TestCase | ||
13 | { | ||
14 | use FrontControllerMockHelper; | ||
15 | |||
16 | /** @var PublicSessionFilterController */ | ||
17 | protected $controller; | ||
18 | |||
19 | public function setUp(): void | ||
20 | { | ||
21 | $this->createContainer(); | ||
22 | |||
23 | $this->controller = new PublicSessionFilterController($this->container); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * Link per page - Default call with valid parameter and a referer. | ||
28 | */ | ||
29 | public function testLinksPerPage(): void | ||
30 | { | ||
31 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/subfolder/controller/?searchtag=abc']; | ||
32 | |||
33 | $request = $this->createMock(Request::class); | ||
34 | $request->method('getParam')->with('nb')->willReturn('8'); | ||
35 | $response = new Response(); | ||
36 | |||
37 | $this->container->sessionManager | ||
38 | ->expects(static::once()) | ||
39 | ->method('setSessionParameter') | ||
40 | ->with(SessionManager::KEY_LINKS_PER_PAGE, 8) | ||
41 | ; | ||
42 | |||
43 | $result = $this->controller->linksPerPage($request, $response); | ||
44 | |||
45 | static::assertInstanceOf(Response::class, $result); | ||
46 | static::assertSame(302, $result->getStatusCode()); | ||
47 | static::assertSame(['/subfolder/controller/?searchtag=abc'], $result->getHeader('location')); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * Link per page - Invalid value, should use default value (20) | ||
52 | */ | ||
53 | public function testLinksPerPageNotValid(): void | ||
54 | { | ||
55 | $request = $this->createMock(Request::class); | ||
56 | $request->method('getParam')->with('nb')->willReturn('test'); | ||
57 | $response = new Response(); | ||
58 | |||
59 | $this->container->sessionManager | ||
60 | ->expects(static::once()) | ||
61 | ->method('setSessionParameter') | ||
62 | ->with(SessionManager::KEY_LINKS_PER_PAGE, 20) | ||
63 | ; | ||
64 | |||
65 | $result = $this->controller->linksPerPage($request, $response); | ||
66 | |||
67 | static::assertInstanceOf(Response::class, $result); | ||
68 | static::assertSame(302, $result->getStatusCode()); | ||
69 | static::assertSame(['/subfolder/'], $result->getHeader('location')); | ||
70 | } | ||
71 | } | ||