2018-05-26 20:46:55 +02:00
|
|
|
<?php
|
2019-12-07 12:13:32 +01:00
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-12-01 12:16:06 +01:00
|
|
|
namespace TTN\Tea\Tests\Unit\Controller;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2022-04-20 15:05:45 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-12-01 12:16:06 +01:00
|
|
|
use TTN\Tea\Controller\TeaController;
|
2024-01-16 15:21:21 +01:00
|
|
|
use TTN\Tea\Domain\Model\Tea;
|
|
|
|
use TTN\Tea\Domain\Repository\TeaRepository;
|
2022-10-03 16:02:32 +02:00
|
|
|
use TYPO3\CMS\Core\Http\HtmlResponse;
|
2023-04-06 14:32:05 +02:00
|
|
|
use TYPO3\CMS\Core\Information\Typo3Version;
|
2018-05-26 20:46:55 +02:00
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
|
|
|
use TYPO3\CMS\Fluid\View\TemplateView;
|
2022-04-20 15:05:45 +02:00
|
|
|
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
|
2022-02-20 15:18:46 +01:00
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
/**
|
2021-09-15 02:11:15 +02:00
|
|
|
* @covers \TTN\Tea\Controller\TeaController
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2023-04-06 16:34:15 +02:00
|
|
|
final class TeaControllerTest extends UnitTestCase
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
|
|
|
/**
|
2022-04-20 15:05:45 +02:00
|
|
|
* @var TeaController&MockObject&AccessibleObjectInterface
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2022-10-10 16:05:06 +02:00
|
|
|
private TeaController $subject;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
/**
|
2022-11-05 17:08:32 +01:00
|
|
|
* @var TemplateView&MockObject
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2022-11-05 17:08:32 +01:00
|
|
|
private TemplateView $viewMock;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
/**
|
2022-11-05 17:08:32 +01:00
|
|
|
* @var TeaRepository&MockObject
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2022-11-05 17:08:32 +01:00
|
|
|
private TeaRepository $teaRepositoryMock;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
protected function setUp(): void
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
2022-02-20 15:18:46 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
2023-11-01 20:59:07 +01:00
|
|
|
$this->teaRepositoryMock = $this->createMock(TeaRepository::class);
|
2022-02-20 15:18:46 +01:00
|
|
|
// We need to create an accessible mock in order to be able to set the protected `view`.
|
2023-06-22 11:49:12 +02:00
|
|
|
$methodsToMock = ['htmlResponse', 'redirect', 'redirectToUri'];
|
2023-11-01 20:56:10 +01:00
|
|
|
if ((new Typo3Version())->getMajorVersion() < 12) {
|
2023-06-22 11:49:12 +02:00
|
|
|
$methodsToMock[] = 'forward';
|
2023-04-06 14:32:05 +02:00
|
|
|
}
|
2023-07-03 14:26:21 +02:00
|
|
|
$this->subject = $this->getAccessibleMock(TeaController::class, $methodsToMock, [$this->teaRepositoryMock]);
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2022-11-05 17:08:32 +01:00
|
|
|
$this->viewMock = $this->createMock(TemplateView::class);
|
|
|
|
$this->subject->_set('view', $this->viewMock);
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2023-11-01 21:15:42 +01:00
|
|
|
$responseStub = $this->createStub(HtmlResponse::class);
|
|
|
|
$this->subject->method('htmlResponse')->willReturn($responseStub);
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function isActionController(): void
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
2019-08-12 17:25:59 +02:00
|
|
|
self::assertInstanceOf(ActionController::class, $this->subject);
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function indexActionAssignsAllTeaAsTeasToView(): void
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
2023-11-18 06:48:56 +01:00
|
|
|
$teas = $this->createStub(QueryResultInterface::class);
|
2022-11-05 17:08:32 +01:00
|
|
|
$this->teaRepositoryMock->method('findAll')->willReturn($teas);
|
|
|
|
$this->viewMock->expects(self::once())->method('assign')->with('teas', $teas);
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2023-06-20 09:19:57 +02:00
|
|
|
$this->subject->indexAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function indexActionReturnsHtmlResponse(): void
|
|
|
|
{
|
|
|
|
$result = $this->subject->indexAction();
|
|
|
|
|
|
|
|
self::assertInstanceOf(HtmlResponse::class, $result);
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|
2018-05-28 17:05:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function showActionAssignsPassedTeaAsTeaToView(): void
|
2018-05-28 17:05:39 +02:00
|
|
|
{
|
|
|
|
$tea = new Tea();
|
2022-11-05 17:08:32 +01:00
|
|
|
$this->viewMock->expects(self::once())->method('assign')->with('tea', $tea);
|
2018-05-28 17:05:39 +02:00
|
|
|
|
2023-06-20 09:19:57 +02:00
|
|
|
$this->subject->showAction($tea);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function showActionAssignsReturnsHtmlResponse(): void
|
|
|
|
{
|
|
|
|
$result = $this->subject->showAction(new Tea());
|
|
|
|
|
|
|
|
self::assertInstanceOf(HtmlResponse::class, $result);
|
2018-05-28 17:05:39 +02:00
|
|
|
}
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|