2020-01-23 21:52:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-05-22 13:20:31 +02:00
|
|
|
namespace Shaarli\Front\Controller\Admin;
|
2020-01-23 21:52:03 +01:00
|
|
|
|
2020-07-07 10:15:56 +02:00
|
|
|
use Shaarli\Security\CookieManager;
|
2020-01-23 21:52:03 +01:00
|
|
|
use Shaarli\Security\SessionManager;
|
2020-09-29 14:41:40 +02:00
|
|
|
use Shaarli\TestCase;
|
2020-01-23 21:52:03 +01:00
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
|
|
|
class LogoutControllerTest extends TestCase
|
|
|
|
{
|
2020-05-22 13:20:31 +02:00
|
|
|
use FrontAdminControllerMockHelper;
|
2020-01-23 21:52:03 +01:00
|
|
|
|
|
|
|
/** @var LogoutController */
|
|
|
|
protected $controller;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
2020-05-20 12:43:40 +02:00
|
|
|
$this->createContainer();
|
|
|
|
|
2020-01-23 21:52:03 +01:00
|
|
|
$this->controller = new LogoutController($this->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidControllerInvoke(): void
|
|
|
|
{
|
|
|
|
$request = $this->createMock(Request::class);
|
|
|
|
$response = new Response();
|
|
|
|
|
2020-05-20 12:43:40 +02:00
|
|
|
$this->container->pageCacheManager->expects(static::once())->method('invalidateCaches');
|
2020-01-23 21:52:03 +01:00
|
|
|
|
2020-05-20 12:43:40 +02:00
|
|
|
$this->container->sessionManager = $this->createMock(SessionManager::class);
|
|
|
|
$this->container->sessionManager->expects(static::once())->method('logout');
|
2020-01-23 21:52:03 +01:00
|
|
|
|
2020-07-07 10:15:56 +02:00
|
|
|
$this->container->cookieManager = $this->createMock(CookieManager::class);
|
|
|
|
$this->container->cookieManager
|
|
|
|
->expects(static::once())
|
|
|
|
->method('setCookieParameter')
|
|
|
|
->with(CookieManager::STAY_SIGNED_IN, 'false', 0, '/subfolder/')
|
|
|
|
;
|
2020-01-23 21:52:03 +01:00
|
|
|
|
|
|
|
$result = $this->controller->index($request, $response);
|
|
|
|
|
|
|
|
static::assertInstanceOf(Response::class, $result);
|
|
|
|
static::assertSame(302, $result->getStatusCode());
|
2020-06-13 13:08:01 +02:00
|
|
|
static::assertSame(['/subfolder/'], $result->getHeader('location'));
|
2020-01-23 21:52:03 +01:00
|
|
|
}
|
|
|
|
}
|