aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/admin/LogoutControllerTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur.hoareau@wizacha.com>2020-07-07 10:15:56 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commitc4ad3d4f061d05a01db25aa54dda830ba776792d (patch)
tree691d91a5b0bbac62cee41f7b95ad1daa38d610b3 /tests/front/controller/admin/LogoutControllerTest.php
parent1a8ac737e52cb25a5c346232ee398f5908cee7d7 (diff)
downloadShaarli-c4ad3d4f061d05a01db25aa54dda830ba776792d.tar.gz
Shaarli-c4ad3d4f061d05a01db25aa54dda830ba776792d.tar.zst
Shaarli-c4ad3d4f061d05a01db25aa54dda830ba776792d.zip
Process Shaarli install through Slim controller
Diffstat (limited to 'tests/front/controller/admin/LogoutControllerTest.php')
-rw-r--r--tests/front/controller/admin/LogoutControllerTest.php18
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
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7/** Override PHP builtin setcookie function in the local namespace to mock it... more or less */
8if (!function_exists('Shaarli\Front\Controller\Admin\setcookie')) {
9 function setcookie(string $name, string $value): void {
10 $_COOKIE[$name] = $value;
11 }
12}
13
14use PHPUnit\Framework\TestCase; 7use PHPUnit\Framework\TestCase;
8use Shaarli\Security\CookieManager;
15use Shaarli\Security\LoginManager; 9use Shaarli\Security\LoginManager;
16use Shaarli\Security\SessionManager; 10use Shaarli\Security\SessionManager;
17use Slim\Http\Request; 11use 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}