]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/front/controller/admin/LogoutControllerTest.php
Use multi-level routes for existing controllers instead of 1 level everywhere
[github/shaarli/Shaarli.git] / tests / front / controller / admin / LogoutControllerTest.php
CommitLineData
8e47af2b
A
1<?php
2
3declare(strict_types=1);
4
2899ebb5 5namespace Shaarli\Front\Controller\Admin;
8e47af2b
A
6
7/** Override PHP builtin setcookie function in the local namespace to mock it... more or less */
ba43064d 8if (!function_exists('Shaarli\Front\Controller\Admin\setcookie')) {
8e47af2b
A
9 function setcookie(string $name, string $value): void {
10 $_COOKIE[$name] = $value;
11 }
12}
13
14use PHPUnit\Framework\TestCase;
8e47af2b
A
15use Shaarli\Security\LoginManager;
16use Shaarli\Security\SessionManager;
17use Slim\Http\Request;
18use Slim\Http\Response;
19
20class LogoutControllerTest extends TestCase
21{
2899ebb5 22 use FrontAdminControllerMockHelper;
8e47af2b
A
23
24 /** @var LogoutController */
25 protected $controller;
26
27 public function setUp(): void
28 {
dd09ec52
A
29 $this->createContainer();
30
8e47af2b
A
31 $this->controller = new LogoutController($this->container);
32
33 setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there');
34 }
35
36 public function testValidControllerInvoke(): void
37 {
38 $request = $this->createMock(Request::class);
39 $response = new Response();
40
dd09ec52 41 $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches');
8e47af2b 42
dd09ec52
A
43 $this->container->sessionManager = $this->createMock(SessionManager::class);
44 $this->container->sessionManager->expects(static::once())->method('logout');
8e47af2b
A
45
46 static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]);
47
48 $result = $this->controller->index($request, $response);
49
50 static::assertInstanceOf(Response::class, $result);
51 static::assertSame(302, $result->getStatusCode());
9c75f877 52 static::assertSame(['/subfolder/'], $result->getHeader('location'));
8e47af2b
A
53 static::assertSame('false', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]);
54 }
55}