2020-12-06 00:16:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Controllers;
|
|
|
|
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Controllers\FaqController;
|
|
|
|
use Engelsystem\Http\Response;
|
|
|
|
use Engelsystem\Models\Faq;
|
|
|
|
use Engelsystem\Test\Unit\HasDatabase;
|
|
|
|
use Engelsystem\Test\Unit\TestCase;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
|
|
|
|
|
|
|
class FaqControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
use HasDatabase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Controllers\FaqController::__construct
|
|
|
|
* @covers \Engelsystem\Controllers\FaqController::index
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testIndex(): void
|
2020-12-06 00:16:15 +01:00
|
|
|
{
|
|
|
|
$this->initDatabase();
|
|
|
|
(new Faq(['question' => 'Xyz', 'text' => 'Abc']))->save();
|
|
|
|
(new Faq(['question' => 'Something\'s wrong?', 'text' => 'Nah!']))->save();
|
|
|
|
|
|
|
|
$this->app->instance('session', new Session(new MockArraySessionStorage()));
|
|
|
|
$config = new Config(['faq_text' => 'Some Text']);
|
|
|
|
/** @var Response|MockObject $response */
|
|
|
|
$response = $this->createMock(Response::class);
|
|
|
|
$response->expects($this->once())
|
|
|
|
->method('withView')
|
|
|
|
->willReturnCallback(function (string $view, array $data) use ($response) {
|
|
|
|
$this->assertEquals('pages/faq/overview.twig', $view);
|
|
|
|
$this->assertEquals('Some Text', $data['text']);
|
|
|
|
$this->assertEquals('Nah!', $data['items'][0]->text);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
});
|
|
|
|
|
|
|
|
$controller = new FaqController($config, new Faq(), $response);
|
|
|
|
$controller->index();
|
|
|
|
}
|
|
|
|
}
|