Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo3 v8 #5

Merged
merged 9 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ matrix:

sudo: false

services:
- mysql

addons:
apt:
packages:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You can download and install this extension or use composer.

## Copyright / License

Copyright: (c) 2015 - 2018, AOE GmbH
Copyright: (c) 2015 - 2019, AOE GmbH
License: GPLv3, <http://www.gnu.org/licenses/gpl-3.0.en.html>

## Contributing
Expand Down
166 changes: 109 additions & 57 deletions Tests/Functional/System/Typo3/TCATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
***************************************************************/

use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Lang\LanguageService;

/**
* @package FeatureFlag
Expand All @@ -45,19 +48,23 @@ public function setUp()
{
parent::setUp();

$this->tca = $this->getMock(
'Tx_FeatureFlag_System_Typo3_TCA',
[
'getMappingRepository', 'getFeatureFlagRepository',
'getFeatureFlagByUid', 'getPersistenceManager', 'getLanguageService'
]
);
$persistenceManager = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)
$this->tca = $this
->getMockBuilder(Tx_FeatureFlag_System_Typo3_TCA::class)
->setMethods([
'getMappingRepository',
'getFeatureFlagRepository',
'getFeatureFlagByUid',
'getPersistenceManager',
'getLanguageService'
])
->getMock();
$persistenceManager = $this
->getMockBuilder(PersistenceManager::class)
->disableOriginalConstructor()
->setMethods(['persistAll'])
->getMock();

$languageService = $this->getMockBuilder(\TYPO3\CMS\Lang\LanguageService::class)
$languageService = $this->getMockBuilder(LanguageService::class)
->disableOriginalConstructor()
->setMethods(['sL'])
->getMock();
Expand All @@ -81,19 +88,38 @@ protected function tearDown()
*/
public function selectRendersCorrectly()
{
$featureFlag = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid']);
$featureFlag = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Model_FeatureFlag::class)
->setMethods(['getUid'])
->getMock();
$featureFlag->expects($this->any())->method('getUid')->willReturn(4711);
$mapping = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping', ['getFeatureFlag']);
$mapping = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Model_Mapping::class)
->setMethods(['getFeatureFlag'])
->getMock();
$mapping->expects($this->any())->method('getFeatureFlag')->willReturn($featureFlag);
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid']
);
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn($mapping);
$featureFlagRepository = $this->getMock('Tx_FeatureFlag_Domain_Repository_FeatureFlag', ['findAll']);
$featureFlagRepository->expects($this->once())->method('findAll')->willReturn($this->getListOfFeatureFlags());
$this->tca->expects($this->once())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->once())->method('getFeatureFlagRepository')->willReturn($featureFlagRepository);
$mappingRepository = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Repository_Mapping::class)
->setMethods(['findOneByForeignTableNameAndUid'])
->getMock();
$mappingRepository
->expects($this->once())
->method('findOneByForeignTableNameAndUid')
->willReturn($mapping);
$featureFlagRepository = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Repository_FeatureFlag::class)
->setMethods(['findAll'])
->getMock();
$featureFlagRepository
->expects($this->once())
->method('findAll')
->willReturn($this->getListOfFeatureFlags());
$this->tca->expects($this->once())
->method('getMappingRepository')
->willReturn($mappingRepository);
$this->tca->expects($this->once())
->method('getFeatureFlagRepository')
->willReturn($featureFlagRepository);

$PA = [];
$PA['row'] = [];
Expand All @@ -115,18 +141,21 @@ public function selectRendersCorrectly()
*/
public function processDatamapDoNothingIfNothingSelected()
{
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'add', 'remove', 'update']
);
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn(null);
$mappingRepository = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Repository_Mapping::class)
->setMethods(['findOneByForeignTableNameAndUid', 'add', 'remove', 'update'])
->getMock();
$mappingRepository
->expects($this->once())
->method('findOneByForeignTableNameAndUid')
->willReturn(null);
$mappingRepository->expects($this->never())->method('add');
$mappingRepository->expects($this->never())->method('remove');
$mappingRepository->expects($this->never())->method('update');
$this->tca->expects($this->once())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->never())->method('getFeatureFlagByUid');

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->createMock(DataHandler::class);
$incomingFieldArray = [
'tx_featureflag_flag' => '0',
'tx_featureflag_behavior' => '0',
Expand All @@ -139,18 +168,21 @@ public function processDatamapDoNothingIfNothingSelected()
*/
public function processDatamapDoNothingIfNotInFeatureFlagContext()
{
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'add', 'remove', 'update']
);
$mappingRepository->expects($this->never())->method('findOneByForeignTableNameAndUid')->willReturn(null);
$mappingRepository = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Repository_Mapping::class)
->setMethods(['findOneByForeignTableNameAndUid', 'add', 'remove', 'update'])
->getMock();
$mappingRepository
->expects($this->never())
->method('findOneByForeignTableNameAndUid')
->willReturn(null);
$mappingRepository->expects($this->never())->method('add');
$mappingRepository->expects($this->never())->method('remove');
$mappingRepository->expects($this->never())->method('update');
$this->tca->expects($this->never())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->never())->method('getFeatureFlagByUid');

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->getMockBuilder(DataHandler::class)->getMock();
$incomingFieldArray = ['hidden' => '0'];
$this->tca->processDatamap_preProcessFieldArray($incomingFieldArray, 'my_table', '4711', $tceMainMock);
}
Expand All @@ -160,17 +192,20 @@ public function processDatamapDoNothingIfNotInFeatureFlagContext()
*/
public function processDatamapRemoveMappingIfNothingSelectedAndMappingExists()
{
$mapping = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping');
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'remove', 'update']
);
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn($mapping);
$mapping = $this->createMock(Tx_FeatureFlag_Domain_Model_Mapping::class);
$mappingRepository = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Repository_Mapping::class)
->setMethods(['findOneByForeignTableNameAndUid', 'remove', 'update'])
->getMock();
$mappingRepository
->expects($this->once())
->method('findOneByForeignTableNameAndUid')
->willReturn($mapping);
$mappingRepository->expects($this->once())->method('remove');
$mappingRepository->expects($this->once())->method('update');
$this->tca->expects($this->any())->method('getMappingRepository')->willReturn($mappingRepository);

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->createMock(DataHandler::class);
$incomingFieldArray = [
'tx_featureflag_flag' => '0',
'tx_featureflag_behavior' => '0',
Expand All @@ -183,20 +218,26 @@ public function processDatamapRemoveMappingIfNothingSelectedAndMappingExists()
*/
public function processDatamapCreateNewMappingIfFeatureFlagGivenAndNoMappingPreviouslyCreated()
{
$featureFlag = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid']);
$featureFlag = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Model_FeatureFlag::class)
->setMethods(['getUid'])
->getMock();
$featureFlag->expects($this->any())->method('getUid')->willReturn(4711);

$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'add']
);
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn(null);
$mappingRepository = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Repository_Mapping::class)
->setMethods(['findOneByForeignTableNameAndUid', 'add'])
->getMock();
$mappingRepository
->expects($this->once())
->method('findOneByForeignTableNameAndUid')
->willReturn(null);
$mappingRepository->expects($this->once())->method('add');

$this->tca->expects($this->any())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->any())->method('getFeatureFlagByUid')->willReturn($featureFlag);

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->createMock(DataHandler::class);
$incomingFieldArray = [
'tx_featureflag_flag' => '4711',
'tx_featureflag_behavior' => '0',
Expand All @@ -218,11 +259,13 @@ public function processCmdmapCommandIsNotDelete()
*/
public function processCmdmappostIsDelete()
{
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findAllByForeignTableNameAndUid', 'remove']
);
$mappingRepository->expects($this->once())->method('findAllByForeignTableNameAndUid')->willReturn($this->getListOfMappings());
$mappingRepository = $this->getMockBuilder(Tx_FeatureFlag_Domain_Repository_Mapping::class)
->setMethods(['findAllByForeignTableNameAndUid', 'remove'])
->getMock();
$mappingRepository
->expects($this->once())
->method('findAllByForeignTableNameAndUid')
->willReturn($this->getListOfMappings());
$mappingRepository->expects($this->exactly(2))->method('remove');
$this->tca->expects($this->any())->method('getMappingRepository')->willReturn($mappingRepository);

Expand All @@ -234,9 +277,9 @@ public function processCmdmappostIsDelete()
*/
protected function getListOfMappings()
{
$mapping1 = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping');
$mapping2 = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping');
$mapping3 = $this->getMock('stdClass');
$mapping1 = $this->createMock(Tx_FeatureFlag_Domain_Model_Mapping::class);
$mapping2 = $this->createMock(Tx_FeatureFlag_Domain_Model_Mapping::class);
$mapping3 = $this->createMock('stdClass');

return array($mapping1, $mapping2, $mapping3);
}
Expand All @@ -246,13 +289,22 @@ protected function getListOfMappings()
*/
protected function getListOfFeatureFlags()
{
$featureFlag1 = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid', 'getDescription']);
$featureFlag1 = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Model_FeatureFlag::class)
->setMethods(['getUid', 'getDescription'])
->getMock();
$featureFlag1->expects($this->any())->method('getUid')->willReturn(111);
$featureFlag1->expects($this->any())->method('getDescription')->willReturn('flag 1');
$featureFlag2 = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid', 'getDescription']);
$featureFlag2 = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Model_FeatureFlag::class)
->setMethods(['getUid', 'getDescription'])
->getMock();
$featureFlag2->expects($this->any())->method('getUid')->willReturn(4711);
$featureFlag2->expects($this->any())->method('getDescription')->willReturn('flag 2');
$featureFlag3 = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid', 'getDescription']);
$featureFlag3 = $this
->getMockBuilder(Tx_FeatureFlag_Domain_Model_FeatureFlag::class)
->setMethods(['getUid', 'getDescription'])
->getMock();
$featureFlag3->expects($this->any())->method('getDescription')->willReturn('flag 3');
$featureFlag3->expects($this->any())->method('getUid')->willReturn(222);

Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Domain/Model/MappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function crdate()
*/
public function featureFlag()
{
$featureFlag = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', array('getFlag'));
$featureFlag->expects($this->any())->method('getFlag')->will($this->returnValue('my_awesome_feature_flag'));
$featureFlag = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')->setMethods(['getFlag'])->getMock();
$featureFlag->method('getFlag')->willReturn('my_awesome_feature_flag');
$this->mapping->setFeatureFlag($featureFlag);
$this->assertEquals($this->mapping->getFeatureFlag()->getFlag(), 'my_awesome_feature_flag');
}
Expand Down
21 changes: 14 additions & 7 deletions Tests/Unit/Service/EidProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

use Aoe\FeatureFlag\Service\EidProcessor;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use Tx_FeatureFlag_Service;
use Tx_FeatureFlag_Service_Exception_ActionNotFound;
use Tx_FeatureFlag_System_Typo3_CacheManager;

/**
* @package FeatureFlag
Expand All @@ -39,19 +42,23 @@ class EidProcessorTest extends UnitTestCase
*/
private function getServiceMock()
{
return $this->getMock(
'Tx_FeatureFlag_Service', ['updateFeatureFlag'], [], '', false
);
return $this
->getMockBuilder(Tx_FeatureFlag_Service::class)
->setMethods(['updateFeatureFlag'])
->disableOriginalConstructor()
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getCacheManagerMock()
{
return $this->getMock(
'Tx_FeatureFlag_System_Typo3_CacheManager', ['clearPageCache'], [], '', false
);
return $this
->getMockBuilder(Tx_FeatureFlag_System_Typo3_CacheManager::class)
->setMethods(['clearPageCache'])
->disableOriginalConstructor()
->getMock();
}

/**
Expand Down Expand Up @@ -91,7 +98,7 @@ public function shouldThrowExceptionTest()
$_GET = ['action' => '', 'feature' => 'testfeature'];
$eidProcessor = new EidProcessor($this->getServiceMock(), $this->getCacheManagerMock());

$this->setExpectedException(\Tx_FeatureFlag_Service_Exception_ActionNotFound::class);
$this->expectException(Tx_FeatureFlag_Service_Exception_ActionNotFound::class);
$eidProcessor->processRequest();
}
}
Loading