From 8e47af2b3620c920116ec056173277c039163ec1 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 23 Jan 2020 21:52:03 +0100 Subject: Process logout through Slim controller --- tests/front/controller/LogoutControllerTest.php | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/front/controller/LogoutControllerTest.php (limited to 'tests/front') diff --git a/tests/front/controller/LogoutControllerTest.php b/tests/front/controller/LogoutControllerTest.php new file mode 100644 index 00000000..d9ca1c25 --- /dev/null +++ b/tests/front/controller/LogoutControllerTest.php @@ -0,0 +1,60 @@ +container = $this->createMock(ShaarliContainer::class); + $this->controller = new LogoutController($this->container); + + setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there'); + } + + public function testValidControllerInvoke(): void + { + $request = $this->createMock(Request::class); + $response = new Response(); + + $pageCacheManager = $this->createMock(PageCacheManager::class); + $pageCacheManager->expects(static::once())->method('invalidateCaches'); + $this->container->pageCacheManager = $pageCacheManager; + + $sessionManager = $this->createMock(SessionManager::class); + $sessionManager->expects(static::once())->method('logout'); + $this->container->sessionManager = $sessionManager; + + static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); + + $result = $this->controller->index($request, $response); + + static::assertInstanceOf(Response::class, $result); + static::assertSame(302, $result->getStatusCode()); + static::assertContains('./', $result->getHeader('Location')); + static::assertSame('false', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); + } +} -- cgit v1.2.3