]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/front/controller/admin/ToolsControllerTest.php
Process tools page through Slim controller
[github/shaarli/Shaarli.git] / tests / front / controller / admin / ToolsControllerTest.php
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 }