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;
|
|
|
|
use TTN\Tea\Domain\Model\Product\Tea;
|
|
|
|
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
2022-10-03 16:02:32 +02:00
|
|
|
use TYPO3\CMS\Core\Http\HtmlResponse;
|
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
|
|
|
*/
|
|
|
|
class TeaControllerTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
/**
|
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();
|
|
|
|
|
|
|
|
// We need to create an accessible mock in order to be able to set the protected `view`.
|
2022-10-03 16:02:32 +02:00
|
|
|
$this->subject = $this->getAccessibleMock(
|
|
|
|
TeaController::class,
|
|
|
|
['forward', 'redirect', 'redirectToUri', 'htmlResponse']
|
|
|
|
);
|
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
|
|
|
|
2022-11-05 17:08:32 +01:00
|
|
|
$this->teaRepositoryMock = $this->getMockBuilder(TeaRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$this->subject->injectTeaRepository($this->teaRepositoryMock);
|
2022-10-03 16:02:32 +02:00
|
|
|
|
2022-11-05 17:08:32 +01:00
|
|
|
$responseMock = $this->createMock(HtmlResponse::class);
|
|
|
|
$this->subject->method('htmlResponse')->willReturn($responseMock);
|
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
|
|
|
{
|
2022-11-05 17:08:32 +01:00
|
|
|
$teas = $this->createMock(QueryResultInterface::class);
|
|
|
|
$this->teaRepositoryMock->method('findAll')->willReturn($teas);
|
|
|
|
$this->viewMock->expects(self::once())->method('assign')->with('teas', $teas);
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2022-10-03 16:02:32 +02:00
|
|
|
self::assertInstanceOf(
|
|
|
|
HtmlResponse::class,
|
|
|
|
$this->subject->indexAction()
|
|
|
|
);
|
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
|
|
|
|
2022-10-03 16:02:32 +02:00
|
|
|
self::assertInstanceOf(
|
|
|
|
HtmlResponse::class,
|
|
|
|
$this->subject->showAction($tea)
|
|
|
|
);
|
2018-05-28 17:05:39 +02:00
|
|
|
}
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|