]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/front/controller/admin/LogoutControllerTest.php
45e84dc035b65d89984377bb507bdcbc5d7d27d4
[github/shaarli/Shaarli.git] / tests / front / controller / admin / LogoutControllerTest.php
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Shaarli\Front\Controller\Admin;
6
7 use PHPUnit\Framework\TestCase;
8 use Shaarli\Security\CookieManager;
9 use Shaarli\Security\LoginManager;
10 use Shaarli\Security\SessionManager;
11 use Slim\Http\Request;
12 use Slim\Http\Response;
13
14 class LogoutControllerTest extends TestCase
15 {
16 use FrontAdminControllerMockHelper;
17
18 /** @var LogoutController */
19 protected $controller;
20
21 public function setUp(): void
22 {
23 $this->createContainer();
24
25 $this->controller = new LogoutController($this->container);
26 }
27
28 public function testValidControllerInvoke(): void
29 {
30 $request = $this->createMock(Request::class);
31 $response = new Response();
32
33 $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches');
34
35 $this->container->sessionManager = $this->createMock(SessionManager::class);
36 $this->container->sessionManager->expects(static::once())->method('logout');
37
38 $this->container->cookieManager = $this->createMock(CookieManager::class);
39 $this->container->cookieManager
40 ->expects(static::once())
41 ->method('setCookieParameter')
42 ->with(CookieManager::STAY_SIGNED_IN, 'false', 0, '/subfolder/')
43 ;
44
45 $result = $this->controller->index($request, $response);
46
47 static::assertInstanceOf(Response::class, $result);
48 static::assertSame(302, $result->getStatusCode());
49 static::assertSame(['/subfolder/'], $result->getHeader('location'));
50 }
51 }