mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-23 04:16:12 +01:00
tea/Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php

102 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace OliverKlee\Tea\Tests\Functional\Domain\Repository;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use OliverKlee\Tea\Domain\Model\Testimonial;
use OliverKlee\Tea\Domain\Repository\TestimonialRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
* Test case.
*
* @author Oliver Klee <typo3-coding@oliverklee.de>
*/
2016-05-07 21:43:25 +02:00
class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
/**
* @var bool
*/
protected $backupGlobals = false;
2016-05-07 21:43:25 +02:00
/**
* @var TestimonialRepository
*/
protected $subject = null;
2016-05-07 21:43:25 +02:00
/**
* @var \Tx_Phpunit_Framework
*/
protected $testingFramework = null;
2016-05-07 21:43:25 +02:00
protected function setUp()
{
$this->testingFramework = new \Tx_Phpunit_Framework('tx_tea');
2016-05-07 21:43:25 +02:00
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
// We are using the object manager instead of new so that the dependencies get injected.
// In a unit test, we would inject the mocked dependencies instead.
$this->subject = $objectManager->get(TestimonialRepository::class);
}
2016-05-07 21:43:25 +02:00
protected function tearDown()
{
$this->testingFramework->cleanUp();
}
2016-05-07 21:43:25 +02:00
/**
* @test
*/
public function findAllForNoRecordsReturnsEmptyContainer()
{
$container = $this->subject->findAll();
self::assertCount(0, $container);
2016-05-07 21:43:25 +02:00
}
2016-05-07 21:43:25 +02:00
/**
* @test
*/
public function findAllWithOneRecordFindsThisRecord()
{
$uid = $this->testingFramework->createRecord('tx_tea_domain_model_testimonial');
2016-05-07 21:43:25 +02:00
$container = $this->subject->findAll();
/** @var Testimonial $first */
$first = $container->getFirst();
self::assertCount(1, $container);
self::assertSame($uid, $first->getUid());
2016-05-07 21:43:25 +02:00
}
2016-05-07 21:43:25 +02:00
/**
* @test
*/
public function findByUidForExistingRecordReturnsModelWithData()
{
$text = 'A very good Early Grey!';
$uid = $this->testingFramework->createRecord(
2016-05-07 21:56:27 +02:00
'tx_tea_domain_model_testimonial', ['text' => $text]
2016-05-07 21:43:25 +02:00
);
2016-05-07 21:43:25 +02:00
/** @var Testimonial $model */
$model = $this->subject->findByUid($uid);
2016-05-07 21:43:25 +02:00
self::assertNotNull($model);
self::assertSame($text, $model->getText());
2016-05-07 21:43:25 +02:00
}
}