CLEANUP: Refactor tests to save code

* Make data sets configurable.
* Refactor same setup to abstract parent.
This commit is contained in:
Daniel Siepmann 2016-12-15 14:28:40 +01:00
parent 03cc77f336
commit eaa23e77ce
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
6 changed files with 100 additions and 81 deletions

View file

@ -36,12 +36,25 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase
$this->setUpBackendUserFromFixture(1); $this->setUpBackendUserFromFixture(1);
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject(); \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
// Provide necessary configuration for extension foreach ($this->getDataSets() as $dataSet) {
$this->importDataSet('Tests/Functional/Fixtures/BasicSetup.xml'); $this->importDataSet($dataSet);
}
$this->setUpFrontendRootPage(1, $this->getTypoScriptFilesForFrontendRootPage()); $this->setUpFrontendRootPage(1, $this->getTypoScriptFilesForFrontendRootPage());
} }
/**
* Overwrite to import different files.
*
* Defines which DataSet Files should be imported.
*
* @return array<String>
*/
protected function getDataSets()
{
return ['Tests/Functional/Fixtures/BasicSetup.xml'];
}
/** /**
* Overwrite to import different files. * Overwrite to import different files.
* *

View file

@ -28,11 +28,12 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
*/ */
class IndexTcaTableTest extends AbstractFunctionalTestCase class IndexTcaTableTest extends AbstractFunctionalTestCase
{ {
public function setUp() protected function getDataSets()
{ {
parent::setUp(); return array_merge(
parent::getDataSets(),
$this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml'); ['Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml']
);
} }
/** /**

View file

@ -0,0 +1,57 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface;
use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
abstract class AbstractDataHandlerTest extends AbstractFunctionalTestCase
{
/**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
public function setUp()
{
parent::setUp();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
);
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
}
}

View file

@ -23,56 +23,32 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface; use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface;
use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService; use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook; use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler; use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
class IgnoresUnkownOperationTest extends AbstractFunctionalTestCase class IgnoresUnkownOperationTest extends AbstractDataHandlerTest
{ {
/** /**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface * @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/ */
protected $subject; protected $subject;
public function setUp()
{
parent::setUp();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
);
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
}
/** /**
* @test * @test
*/ */
public function deletionWillBeTriggeredForTtContent() public function dataHandlerCommandSomethingIsIgnored()
{ {
$this->subject->expects($this->exactly(0))->method('add'); $subject = new DataHandlerHook($this->subject);
$this->subject->expects($this->exactly(0))->method('update'); $this->assertFalse(
$this->subject->expects($this->exactly(0))->method('delete'); $subject->processDatamap_afterDatabaseOperations(
'something',
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); 'tt_content',
$tce->stripslashes_values = 0; 1,
$tce->start([], [ [],
'tt_content' => [ new Typo3DataHandler
'1' => [ ),
'something' => 1, 'Hook processed status "something".'
], );
],
]);
$tce->process_cmdmap();
} }
} }

View file

@ -23,37 +23,23 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface; use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface;
use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService; use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook; use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler; use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
class NonAllowedTablesTest extends AbstractFunctionalTestCase class NonAllowedTablesTest extends AbstractDataHandlerTest
{ {
/** /**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface * @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/ */
protected $subject; protected $subject;
public function setUp() protected function getDataSets()
{ {
parent::setUp(); return array_merge(
$this->importDataSet('Tests/Functional/Fixtures/Hooks/DataHandler/NonAllowedTables.xml'); parent::getDataSets(),
['Tests/Functional/Fixtures/Hooks/DataHandler/NonAllowedTables.xml']
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
); );
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
} }
/** /**

View file

@ -23,37 +23,23 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface; use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface;
use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService; use Leonmrni\SearchCore\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook; use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler; use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
class ProcessesAllowedTablesTest extends AbstractFunctionalTestCase class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
{ {
/** /**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface * @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/ */
protected $subject; protected $subject;
public function setUp() protected function getDataSets()
{ {
parent::setUp(); return array_merge(
$this->importDataSet('Tests/Functional/Fixtures/Hooks/DataHandler/AllowedTables.xml'); parent::getDataSets(),
['Tests/Functional/Fixtures/Hooks/DataHandler/AllowedTables.xml']
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
); );
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
} }
/** /**