2020-05-22 13:47:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shaarli\Front\Controller\Admin;
|
|
|
|
|
2020-09-29 14:41:40 +02:00
|
|
|
use Shaarli\TestCase;
|
2020-05-22 13:47:02 +02:00
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
2020-09-03 14:52:34 +02:00
|
|
|
class ToolsControllerTest extends TestCase
|
2020-05-22 13:47:02 +02:00
|
|
|
{
|
|
|
|
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());
|
2020-09-03 14:52:34 +02:00
|
|
|
static::assertSame('https://shaarli/', $assignedVariables['pageabsaddr']);
|
2020-05-22 13:47:02 +02:00
|
|
|
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());
|
2020-09-03 14:52:34 +02:00
|
|
|
static::assertSame('http://shaarli/', $assignedVariables['pageabsaddr']);
|
2020-05-22 13:47:02 +02:00
|
|
|
static::assertFalse($assignedVariables['sslenabled']);
|
|
|
|
}
|
|
|
|
}
|