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/container/ContainerBuilderTest.php | 10 ++++- tests/front/controller/LogoutControllerTest.php | 60 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/front/controller/LogoutControllerTest.php (limited to 'tests') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index cc2eb37f..65647249 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -10,6 +10,7 @@ use Shaarli\Config\ConfigManager; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; use Shaarli\Render\PageBuilder; +use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; @@ -35,7 +36,12 @@ class ContainerBuilderTest extends TestCase $this->loginManager = $this->createMock(LoginManager::class); $this->loginManager->method('isLoggedIn')->willReturn(true); - $this->containerBuilder = new ContainerBuilder($this->conf, $this->sessionManager, $this->loginManager); + $this->containerBuilder = new ContainerBuilder( + $this->conf, + $this->sessionManager, + $this->loginManager, + 'UT web path' + ); } public function testBuildContainer(): void @@ -45,9 +51,11 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(ConfigManager::class, $container->conf); static::assertInstanceOf(SessionManager::class, $container->sessionManager); static::assertInstanceOf(LoginManager::class, $container->loginManager); + static::assertSame('UT web path', $container->webPath); static::assertInstanceOf(History::class, $container->history); static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); + static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); } } 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