diff options
Diffstat (limited to 'tests/front/controller/admin/LogoutControllerTest.php')
-rw-r--r-- | tests/front/controller/admin/LogoutControllerTest.php | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php index ca177085..45e84dc0 100644 --- a/tests/front/controller/admin/LogoutControllerTest.php +++ b/tests/front/controller/admin/LogoutControllerTest.php | |||
@@ -4,14 +4,8 @@ declare(strict_types=1); | |||
4 | 4 | ||
5 | namespace Shaarli\Front\Controller\Admin; | 5 | namespace Shaarli\Front\Controller\Admin; |
6 | 6 | ||
7 | /** Override PHP builtin setcookie function in the local namespace to mock it... more or less */ | ||
8 | if (!function_exists('Shaarli\Front\Controller\Admin\setcookie')) { | ||
9 | function setcookie(string $name, string $value): void { | ||
10 | $_COOKIE[$name] = $value; | ||
11 | } | ||
12 | } | ||
13 | |||
14 | use PHPUnit\Framework\TestCase; | 7 | use PHPUnit\Framework\TestCase; |
8 | use Shaarli\Security\CookieManager; | ||
15 | use Shaarli\Security\LoginManager; | 9 | use Shaarli\Security\LoginManager; |
16 | use Shaarli\Security\SessionManager; | 10 | use Shaarli\Security\SessionManager; |
17 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
@@ -29,8 +23,6 @@ class LogoutControllerTest extends TestCase | |||
29 | $this->createContainer(); | 23 | $this->createContainer(); |
30 | 24 | ||
31 | $this->controller = new LogoutController($this->container); | 25 | $this->controller = new LogoutController($this->container); |
32 | |||
33 | setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there'); | ||
34 | } | 26 | } |
35 | 27 | ||
36 | public function testValidControllerInvoke(): void | 28 | public function testValidControllerInvoke(): void |
@@ -43,13 +35,17 @@ class LogoutControllerTest extends TestCase | |||
43 | $this->container->sessionManager = $this->createMock(SessionManager::class); | 35 | $this->container->sessionManager = $this->createMock(SessionManager::class); |
44 | $this->container->sessionManager->expects(static::once())->method('logout'); | 36 | $this->container->sessionManager->expects(static::once())->method('logout'); |
45 | 37 | ||
46 | static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); | 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 | ; | ||
47 | 44 | ||
48 | $result = $this->controller->index($request, $response); | 45 | $result = $this->controller->index($request, $response); |
49 | 46 | ||
50 | static::assertInstanceOf(Response::class, $result); | 47 | static::assertInstanceOf(Response::class, $result); |
51 | static::assertSame(302, $result->getStatusCode()); | 48 | static::assertSame(302, $result->getStatusCode()); |
52 | static::assertSame(['/subfolder/'], $result->getHeader('location')); | 49 | static::assertSame(['/subfolder/'], $result->getHeader('location')); |
53 | static::assertSame('false', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); | ||
54 | } | 50 | } |
55 | } | 51 | } |