aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/admin/LogoutControllerTest.php
blob: 94e53019a967d6a5a028850c534bb857843908e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

declare(strict_types=1);

namespace Shaarli\Front\Controller\Admin;

use Shaarli\Security\CookieManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

class LogoutControllerTest extends TestCase
{
    use FrontAdminControllerMockHelper;

    /** @var LogoutController */
    protected $controller;

    public function setUp(): void
    {
        $this->createContainer();

        $this->controller = new LogoutController($this->container);
    }

    public function testValidControllerInvoke(): void
    {
        $request = $this->createMock(Request::class);
        $response = new Response();

        $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches');

        $this->container->sessionManager = $this->createMock(SessionManager::class);
        $this->container->sessionManager->expects(static::once())->method('logout');

        $this->container->cookieManager = $this->createMock(CookieManager::class);
        $this->container->cookieManager
            ->expects(static::once())
            ->method('setCookieParameter')
            ->with(CookieManager::STAY_SIGNED_IN, 'false', 0, '/subfolder/')
        ;

        $result = $this->controller->index($request, $response);

        static::assertInstanceOf(Response::class, $result);
        static::assertSame(302, $result->getStatusCode());
        static::assertSame(['/subfolder/'], $result->getHeader('location'));
    }
}