2018-05-25 16:19:12 +02:00
|
|
|
<?php
|
2019-12-07 12:13:32 +01:00
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-01-16 15:21:21 +01:00
|
|
|
namespace TTN\Tea\Tests\Functional\Domain\Repository;
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2024-01-16 15:21:21 +01:00
|
|
|
use TTN\Tea\Domain\Model\Tea;
|
|
|
|
use TTN\Tea\Domain\Repository\TeaRepository;
|
2018-05-25 22:39:33 +02:00
|
|
|
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
2023-11-01 20:24:26 +01:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
|
2022-02-20 15:18:46 +01:00
|
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
2018-05-25 16:19:12 +02:00
|
|
|
|
|
|
|
/**
|
2024-01-16 15:21:21 +01:00
|
|
|
* @covers \TTN\Tea\Domain\Repository\TeaRepository
|
|
|
|
* @covers \TTN\Tea\Domain\Model\Tea
|
2018-05-25 16:19:12 +02:00
|
|
|
*/
|
2023-04-06 16:34:15 +02:00
|
|
|
final class TeaRepositoryTest extends FunctionalTestCase
|
2018-05-25 16:19:12 +02:00
|
|
|
{
|
2023-11-27 12:10:13 +01:00
|
|
|
protected array $testExtensionsToLoad = ['ttn/tea'];
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2022-10-03 19:00:55 +02:00
|
|
|
private TeaRepository $subject;
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2023-11-01 20:24:26 +01:00
|
|
|
private PersistenceManagerInterface $persistenceManager;
|
2018-05-28 15:17:19 +02:00
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
protected function setUp(): void
|
2018-05-25 16:19:12 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2023-11-01 20:24:26 +01:00
|
|
|
$this->persistenceManager = $this->get(PersistenceManagerInterface::class);
|
2018-05-28 15:17:19 +02:00
|
|
|
|
2023-11-01 20:24:26 +01:00
|
|
|
$this->subject = $this->get(TeaRepository::class);
|
2018-05-25 16:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function findAllForNoRecordsReturnsEmptyContainer(): void
|
2018-05-25 16:19:12 +02:00
|
|
|
{
|
2022-06-28 23:52:02 +02:00
|
|
|
$result = $this->subject->findAll();
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2022-06-28 23:52:02 +02:00
|
|
|
self::assertCount(0, $result);
|
2018-05-25 16:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function findAllWithRecordsFindsRecordsFromAllPages(): void
|
2018-05-25 16:19:12 +02:00
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaOnPage.csv');
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2022-06-28 23:52:02 +02:00
|
|
|
$result = $this->subject->findAll();
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2023-11-19 22:36:32 +01:00
|
|
|
self::assertCount(1, $result);
|
2018-05-25 16:19:12 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 17:38:51 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function findAllSortsByTitleInAscendingOrder(): void
|
2018-05-25 17:38:51 +02:00
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TwoUnsortedTeas.csv');
|
2018-05-25 17:38:51 +02:00
|
|
|
|
2022-06-28 23:52:02 +02:00
|
|
|
$result = $this->subject->findAll();
|
2018-05-25 17:38:51 +02:00
|
|
|
|
2022-06-28 23:52:02 +02:00
|
|
|
$result->rewind();
|
|
|
|
self::assertSame(2, $result->current()->getUid());
|
2018-05-25 17:38:51 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 13:36:42 +01:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByUidForInexistentRecordReturnsNull(): void
|
|
|
|
{
|
|
|
|
$model = $this->subject->findByUid(1);
|
|
|
|
|
|
|
|
self::assertNull($model);
|
|
|
|
}
|
|
|
|
|
2018-05-25 16:19:12 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2023-06-20 09:10:31 +02:00
|
|
|
public function findByUidForExistingRecordReturnsModel(): void
|
2018-05-25 16:19:12 +02:00
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithAllScalarData.csv');
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2023-11-18 06:44:40 +01:00
|
|
|
$model = $this->subject->findByUid(1);
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2023-06-20 09:10:31 +02:00
|
|
|
self::assertInstanceOf(Tea::class, $model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByUidForExistingRecordMapsAllScalarData(): void
|
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithAllScalarData.csv');
|
2023-06-20 09:10:31 +02:00
|
|
|
|
2023-11-18 06:44:40 +01:00
|
|
|
$model = $this->subject->findByUid(1);
|
2023-06-20 09:10:31 +02:00
|
|
|
self::assertInstanceOf(Tea::class, $model);
|
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
self::assertSame('Earl Grey', $model->getTitle());
|
|
|
|
self::assertSame('Fresh and hot.', $model->getDescription());
|
2023-06-21 09:16:13 +02:00
|
|
|
self::assertSame(2, $model->getOwnerUid());
|
2018-05-25 16:19:12 +02:00
|
|
|
}
|
2018-05-25 22:39:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function fillsImageRelation(): void
|
2018-05-25 22:39:33 +02:00
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithImage.csv');
|
2018-05-25 22:39:33 +02:00
|
|
|
|
2023-11-19 22:36:32 +01:00
|
|
|
$model = $this->subject->findByUid(1);
|
2018-05-25 22:39:33 +02:00
|
|
|
|
|
|
|
$image = $model->getImage();
|
2019-08-12 17:25:59 +02:00
|
|
|
self::assertInstanceOf(FileReference::class, $image);
|
|
|
|
self::assertSame(1, $image->getUid());
|
2018-05-25 22:39:33 +02:00
|
|
|
}
|
2018-05-28 15:17:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function addAndPersistAllCreatesNewRecord(): void
|
2018-05-28 15:17:19 +02:00
|
|
|
{
|
|
|
|
$title = 'Godesberger Burgtee';
|
|
|
|
$model = new Tea();
|
|
|
|
$model->setTitle($title);
|
|
|
|
|
|
|
|
$this->subject->add($model);
|
|
|
|
$this->persistenceManager->persistAll();
|
|
|
|
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->assertCSVDataSet(__DIR__ . '/Fixtures/PersistedTea.csv');
|
2018-05-28 15:17:19 +02:00
|
|
|
}
|
2023-06-21 09:16:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByOwnerUidFindsTeaWithTheGivenOwnerUid(): void
|
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwner.csv');
|
2023-06-21 09:16:13 +02:00
|
|
|
|
|
|
|
$result = $this->subject->findByOwnerUid(1);
|
|
|
|
|
|
|
|
self::assertCount(1, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByOwnerUidFindsIgnoresTeaWithNonMatchingOwnerUid(): void
|
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithOwner.csv');
|
2023-06-21 09:16:13 +02:00
|
|
|
|
|
|
|
$result = $this->subject->findByOwnerUid(2);
|
|
|
|
|
|
|
|
self::assertCount(0, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByOwnerUidFindsIgnoresTeaWithZeroOwnerUid(): void
|
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TeaWithoutOwner.csv');
|
2023-06-21 09:16:13 +02:00
|
|
|
|
|
|
|
$result = $this->subject->findByOwnerUid(1);
|
|
|
|
|
|
|
|
self::assertCount(0, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByOwnerUidSortsByTitleInAscendingOrder(): void
|
|
|
|
{
|
2024-01-16 15:21:21 +01:00
|
|
|
$this->importCSVDataSet(__DIR__ . '/Fixtures/TwoTeasWithOwner.csv');
|
2023-06-21 09:16:13 +02:00
|
|
|
|
|
|
|
$result = $this->subject->findByOwnerUid(1);
|
|
|
|
|
|
|
|
$result->rewind();
|
2024-01-24 07:38:51 +01:00
|
|
|
self::assertSame('Assam', $result->current()->getTitle());
|
2023-06-21 09:16:13 +02:00
|
|
|
}
|
2018-05-25 16:19:12 +02:00
|
|
|
}
|