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);
|
|
|
|
|
2019-12-01 12:16:06 +01:00
|
|
|
namespace TTN\Tea\Tests\Functional\Domain\Repository\Product;
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2019-12-01 12:16:06 +01:00
|
|
|
use TTN\Tea\Domain\Model\Product\Tea;
|
|
|
|
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
2022-03-02 02:07:25 +01:00
|
|
|
use TYPO3\CMS\Core\Information\Typo3Version;
|
2018-05-25 16:19:12 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2018-05-25 22:39:33 +02:00
|
|
|
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
2018-05-25 16:19:12 +02:00
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
2018-05-28 15:17:19 +02:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
|
2022-02-20 15:18:46 +01:00
|
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
2018-05-25 16:19:12 +02:00
|
|
|
|
|
|
|
/**
|
2021-09-15 02:11:15 +02:00
|
|
|
* @covers \TTN\Tea\Domain\Repository\Product\TeaRepository
|
2022-04-29 14:54:41 +02:00
|
|
|
* @covers \TTN\Tea\Domain\Model\Product\Tea
|
2018-05-25 16:19:12 +02:00
|
|
|
*/
|
|
|
|
class TeaRepositoryTest extends FunctionalTestCase
|
|
|
|
{
|
|
|
|
protected $testExtensionsToLoad = ['typo3conf/ext/tea'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var TeaRepository
|
|
|
|
*/
|
2021-11-17 13:14:43 +01:00
|
|
|
private $subject;
|
2018-05-25 16:19:12 +02:00
|
|
|
|
2018-05-28 15:17:19 +02:00
|
|
|
/**
|
|
|
|
* @var PersistenceManager
|
|
|
|
*/
|
2021-11-17 13:14:43 +01:00
|
|
|
private $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();
|
|
|
|
|
2018-05-28 15:17:19 +02:00
|
|
|
$this->persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
|
|
|
|
|
2022-03-02 02:07:25 +01:00
|
|
|
/** @var Typo3Version $versionInformation */
|
|
|
|
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
|
|
|
|
if ($versionInformation->getMajorVersion() >= 11) {
|
|
|
|
$this->subject = $this->getContainer()->get(TeaRepository::class);
|
|
|
|
} else {
|
|
|
|
/** @var ObjectManager $objectManager */
|
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
|
|
|
$this->subject = $objectManager->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
|
|
|
{
|
|
|
|
$this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml');
|
|
|
|
|
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::assertGreaterThanOrEqual(1, \count($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
|
|
|
{
|
|
|
|
$this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml');
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-25 16:19:12 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function findByUidForExistingRecordReturnsModelWithData(): void
|
2018-05-25 16:19:12 +02:00
|
|
|
{
|
|
|
|
$this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml');
|
|
|
|
|
|
|
|
$uid = 1;
|
|
|
|
/** @var Tea $model */
|
|
|
|
$model = $this->subject->findByUid($uid);
|
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
self::assertNotNull($model);
|
|
|
|
self::assertSame('Earl Grey', $model->getTitle());
|
|
|
|
self::assertSame('Fresh and hot.', $model->getDescription());
|
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
|
|
|
{
|
|
|
|
$this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml');
|
|
|
|
|
|
|
|
$uid = 3;
|
|
|
|
/** @var Tea $model */
|
|
|
|
$model = $this->subject->findByUid($uid);
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
2022-04-29 14:27:47 +02:00
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tea_domain_model_product_tea');
|
2022-04-11 14:15:43 +02:00
|
|
|
$databaseRow = $connection
|
|
|
|
->executeQuery(
|
2022-04-29 14:27:47 +02:00
|
|
|
'SELECT * FROM tx_tea_domain_model_product_tea WHERE uid = :uid',
|
|
|
|
['uid' => $model->getUid()]
|
2022-04-11 14:15:43 +02:00
|
|
|
)
|
2022-02-20 15:18:46 +01:00
|
|
|
->fetchAssociative();
|
|
|
|
|
2022-04-29 14:27:47 +02:00
|
|
|
self::assertIsArray($databaseRow);
|
2019-08-12 17:25:59 +02:00
|
|
|
self::assertSame($title, $databaseRow['title']);
|
2018-05-28 15:17:19 +02:00
|
|
|
}
|
2018-05-25 16:19:12 +02:00
|
|
|
}
|