File: ToolsControllerTest.php

package info (click to toggle)
shaarli 0.15.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,640 kB
  • sloc: php: 30,003; javascript: 2,061; makefile: 135; xml: 69; python: 42; sh: 35
file content (69 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

declare(strict_types=1);

namespace Shaarli\Front\Controller\Admin;

use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

class ToolsControllerTest extends TestCase
{
    use FrontAdminControllerMockHelper;

    /** @var ToolsController */
    protected $controller;

    public function setUp(): void
    {
        $this->createContainer();

        $this->controller = new ToolsController($this->container);
    }

    public function testDefaultInvokeWithHttps(): void
    {
        $request = $this->createMock(Request::class);
        $response = new Response();

        $this->container->environment = [
            'SERVER_NAME' => 'shaarli',
            'SERVER_PORT' => 443,
            'HTTPS' => 'on',
        ];

        // Save RainTPL assigned variables
        $assignedVariables = [];
        $this->assignTemplateVars($assignedVariables);

        $result = $this->controller->index($request, $response);

        static::assertSame(200, $result->getStatusCode());
        static::assertSame('tools', (string) $result->getBody());
        static::assertSame('https://shaarli/', $assignedVariables['pageabsaddr']);
        static::assertTrue($assignedVariables['sslenabled']);
    }

    public function testDefaultInvokeWithoutHttps(): void
    {
        $request = $this->createMock(Request::class);
        $response = new Response();

        $this->container->environment = [
            'SERVER_NAME' => 'shaarli',
            'SERVER_PORT' => 80,
        ];

        // Save RainTPL assigned variables
        $assignedVariables = [];
        $this->assignTemplateVars($assignedVariables);

        $result = $this->controller->index($request, $response);

        static::assertSame(200, $result->getStatusCode());
        static::assertSame('tools', (string) $result->getBody());
        static::assertSame('http://shaarli/', $assignedVariables['pageabsaddr']);
        static::assertFalse($assignedVariables['sslenabled']);
    }
}