diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-05-22 13:20:31 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 2899ebb5b5e82890c877151f5c02045266ac9973 (patch) | |
tree | 0c4e2684c7f6d161f92a21181bfa4b2f78d6a82f /tests/front/controller/admin/LogoutControllerTest.php | |
parent | af290059d10319e76d1e7d78b592cab99c26d91a (diff) | |
download | Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.gz Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.zst Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.zip |
Initialize admin Slim controllers
- Reorganize visitor controllers
- Fix redirection with Slim's requests base path
- Fix daily links
Diffstat (limited to 'tests/front/controller/admin/LogoutControllerTest.php')
-rw-r--r-- | tests/front/controller/admin/LogoutControllerTest.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php new file mode 100644 index 00000000..239e39b2 --- /dev/null +++ b/tests/front/controller/admin/LogoutControllerTest.php | |||
@@ -0,0 +1,57 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Admin; | ||
6 | |||
7 | /** Override PHP builtin setcookie function in the local namespace to mock it... more or less */ | ||
8 | if (!function_exists('Shaarli\Front\Controller\setcookie')) { | ||
9 | function setcookie(string $name, string $value): void { | ||
10 | $_COOKIE[$name] = $value; | ||
11 | } | ||
12 | } | ||
13 | |||
14 | use PHPUnit\Framework\TestCase; | ||
15 | use Shaarli\Security\LoginManager; | ||
16 | use Shaarli\Security\SessionManager; | ||
17 | use Slim\Http\Request; | ||
18 | use Slim\Http\Response; | ||
19 | |||
20 | class LogoutControllerTest extends TestCase | ||
21 | { | ||
22 | use FrontAdminControllerMockHelper; | ||
23 | |||
24 | /** @var LogoutController */ | ||
25 | protected $controller; | ||
26 | |||
27 | public function setUp(): void | ||
28 | { | ||
29 | $this->createContainer(); | ||
30 | |||
31 | $this->controller = new LogoutController($this->container); | ||
32 | |||
33 | setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, $cookie = 'hi there'); | ||
34 | } | ||
35 | |||
36 | public function testValidControllerInvoke(): void | ||
37 | { | ||
38 | $this->createValidContainerMockSet(); | ||
39 | |||
40 | $request = $this->createMock(Request::class); | ||
41 | $response = new Response(); | ||
42 | |||
43 | $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches'); | ||
44 | |||
45 | $this->container->sessionManager = $this->createMock(SessionManager::class); | ||
46 | $this->container->sessionManager->expects(static::once())->method('logout'); | ||
47 | |||
48 | static::assertSame('hi there', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); | ||
49 | |||
50 | $result = $this->controller->index($request, $response); | ||
51 | |||
52 | static::assertInstanceOf(Response::class, $result); | ||
53 | static::assertSame(302, $result->getStatusCode()); | ||
54 | static::assertContains('./', $result->getHeader('Location')); | ||
55 | static::assertSame('false', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); | ||
56 | } | ||
57 | } | ||