diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-05-22 13:47:02 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | ba43064ddb7771fc97df135a32f9b0d5e373dd36 (patch) | |
tree | b3519775fa4fe573af6980459e486f43837e5594 /tests/front | |
parent | 2899ebb5b5e82890c877151f5c02045266ac9973 (diff) | |
download | Shaarli-ba43064ddb7771fc97df135a32f9b0d5e373dd36.tar.gz Shaarli-ba43064ddb7771fc97df135a32f9b0d5e373dd36.tar.zst Shaarli-ba43064ddb7771fc97df135a32f9b0d5e373dd36.zip |
Process tools page through Slim controller
Diffstat (limited to 'tests/front')
-rw-r--r-- | tests/front/controller/admin/LogoutControllerTest.php | 2 | ||||
-rw-r--r-- | tests/front/controller/admin/ToolsControllerTest.php | 73 |
2 files changed, 74 insertions, 1 deletions
diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php index 239e39b2..ba681b16 100644 --- a/tests/front/controller/admin/LogoutControllerTest.php +++ b/tests/front/controller/admin/LogoutControllerTest.php | |||
@@ -5,7 +5,7 @@ declare(strict_types=1); | |||
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 */ | 7 | /** Override PHP builtin setcookie function in the local namespace to mock it... more or less */ |
8 | if (!function_exists('Shaarli\Front\Controller\setcookie')) { | 8 | if (!function_exists('Shaarli\Front\Controller\Admin\setcookie')) { |
9 | function setcookie(string $name, string $value): void { | 9 | function setcookie(string $name, string $value): void { |
10 | $_COOKIE[$name] = $value; | 10 | $_COOKIE[$name] = $value; |
11 | } | 11 | } |
diff --git a/tests/front/controller/admin/ToolsControllerTest.php b/tests/front/controller/admin/ToolsControllerTest.php new file mode 100644 index 00000000..47c5746e --- /dev/null +++ b/tests/front/controller/admin/ToolsControllerTest.php | |||
@@ -0,0 +1,73 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Admin; | ||
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | use Slim\Http\Request; | ||
9 | use Slim\Http\Response; | ||
10 | |||
11 | class ToolsControllerTestControllerTest extends TestCase | ||
12 | { | ||
13 | use FrontAdminControllerMockHelper; | ||
14 | |||
15 | /** @var ToolsController */ | ||
16 | protected $controller; | ||
17 | |||
18 | public function setUp(): void | ||
19 | { | ||
20 | $this->createContainer(); | ||
21 | |||
22 | $this->controller = new ToolsController($this->container); | ||
23 | } | ||
24 | |||
25 | public function testDefaultInvokeWithHttps(): void | ||
26 | { | ||
27 | $this->createValidContainerMockSet(); | ||
28 | |||
29 | $request = $this->createMock(Request::class); | ||
30 | $response = new Response(); | ||
31 | |||
32 | $this->container->environment = [ | ||
33 | 'SERVER_NAME' => 'shaarli', | ||
34 | 'SERVER_PORT' => 443, | ||
35 | 'HTTPS' => 'on', | ||
36 | ]; | ||
37 | |||
38 | // Save RainTPL assigned variables | ||
39 | $assignedVariables = []; | ||
40 | $this->assignTemplateVars($assignedVariables); | ||
41 | |||
42 | $result = $this->controller->index($request, $response); | ||
43 | |||
44 | static::assertSame(200, $result->getStatusCode()); | ||
45 | static::assertSame('tools', (string) $result->getBody()); | ||
46 | static::assertSame('https://shaarli', $assignedVariables['pageabsaddr']); | ||
47 | static::assertTrue($assignedVariables['sslenabled']); | ||
48 | } | ||
49 | |||
50 | public function testDefaultInvokeWithoutHttps(): void | ||
51 | { | ||
52 | $this->createValidContainerMockSet(); | ||
53 | |||
54 | $request = $this->createMock(Request::class); | ||
55 | $response = new Response(); | ||
56 | |||
57 | $this->container->environment = [ | ||
58 | 'SERVER_NAME' => 'shaarli', | ||
59 | 'SERVER_PORT' => 80, | ||
60 | ]; | ||
61 | |||
62 | // Save RainTPL assigned variables | ||
63 | $assignedVariables = []; | ||
64 | $this->assignTemplateVars($assignedVariables); | ||
65 | |||
66 | $result = $this->controller->index($request, $response); | ||
67 | |||
68 | static::assertSame(200, $result->getStatusCode()); | ||
69 | static::assertSame('tools', (string) $result->getBody()); | ||
70 | static::assertSame('http://shaarli', $assignedVariables['pageabsaddr']); | ||
71 | static::assertFalse($assignedVariables['sslenabled']); | ||
72 | } | ||
73 | } | ||