engelsystem/tests/Unit/Controllers/DesignControllerTest.php

59 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Engelsystem\Test\Unit\Controllers;
2021-04-10 17:02:34 +02:00
use Engelsystem\Config\Config;
use Engelsystem\Controllers\DesignController;
2021-04-10 17:02:34 +02:00
use Engelsystem\Http\Request;
use Engelsystem\Http\Response;
use Engelsystem\Test\Unit\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class DesignControllerTest extends TestCase
{
/**
* @covers \Engelsystem\Controllers\DesignController::__construct
* @covers \Engelsystem\Controllers\DesignController::index
*/
public function testIndex()
{
/** @var Response|MockObject $response */
$response = $this->createMock(Response::class);
$response->expects($this->once())
->method('withView')
->with('pages/design')
->willReturn($response);
2021-04-10 17:02:34 +02:00
$request = new Request(['theme' => 42]);
$config = new Config();
2021-04-10 17:02:34 +02:00
$controller = new DesignController($response, $config);
$return = $controller->index($request);
$this->assertEquals($response, $return);
}
2021-04-10 17:02:34 +02:00
/**
* @covers \Engelsystem\Controllers\DesignController::index
*/
public function testIndexSetTheme()
{
2021-06-19 17:03:18 +02:00
$theme = ['name' => 'Meaning of Live'];
2021-04-10 17:02:34 +02:00
/** @var Response|MockObject $response */
$response = $this->createMock(Response::class);
$response->expects($this->once())
->method('withView')
2021-06-19 17:03:18 +02:00
->willReturnCallback(function (string $view, array $data) use ($response, $theme) {
2021-04-10 17:02:34 +02:00
$this->assertTrue(isset($data['theme']));
2021-06-19 17:03:18 +02:00
$this->assertEquals($theme, $data['theme']);
2021-04-10 17:02:34 +02:00
return $response;
});
$request = new Request();
$request->attributes->set('theme', '42');
2021-06-19 17:03:18 +02:00
$config = new Config(['themes' => [42 => $theme]]);
2021-04-10 17:02:34 +02:00
$controller = new DesignController($response, $config);
$controller->index($request);
}
}