persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); /** @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); } } /** * @test */ public function findAllForNoRecordsReturnsEmptyContainer(): void { $container = $this->subject->findAll(); self::assertCount(0, $container); } /** * @test */ public function findAllWithRecordsFindsRecordsFromAllPages(): void { $this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml'); $container = $this->subject->findAll(); self::assertGreaterThanOrEqual(1, \count($container)); } /** * @test */ public function findAllSortsByTitleInAscendingOrder(): void { $this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml'); $container = $this->subject->findAll(); $container->rewind(); self::assertSame(2, $container->current()->getUid()); } /** * @test */ public function findByUidForExistingRecordReturnsModelWithData(): void { $this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml'); $uid = 1; /** @var Tea $model */ $model = $this->subject->findByUid($uid); self::assertNotNull($model); self::assertSame('Earl Grey', $model->getTitle()); self::assertSame('Fresh and hot.', $model->getDescription()); } /** * @test */ public function fillsImageRelation(): void { $this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml'); $uid = 3; /** @var Tea $model */ $model = $this->subject->findByUid($uid); $image = $model->getImage(); self::assertInstanceOf(FileReference::class, $image); self::assertSame(1, $image->getUid()); } /** * @test */ public function addAndPersistAllCreatesNewRecord(): void { $title = 'Godesberger Burgtee'; $model = new Tea(); $model->setTitle($title); $this->subject->add($model); $this->persistenceManager->persistAll(); $connection = $this->getConnectionPool()->getConnectionForTable('tx_tea_domain_model_product_tea'); $databaseRow = $connection ->executeQuery( 'SELECT * FROM tx_tea_domain_model_product_tea WHERE uid = :uid', ['uid' => $model->getUid()] ) ->fetchAssociative(); self::assertIsArray($databaseRow); self::assertSame($title, $databaseRow['title']); } }