mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-21 23:56:11 +01:00
CLEANUP: Refactor tests to save code
* Make data sets configurable. * Refactor same setup to abstract parent.
This commit is contained in:
parent
03cc77f336
commit
eaa23e77ce
6 changed files with 100 additions and 81 deletions
|
@ -36,12 +36,25 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase
|
|||
$this->setUpBackendUserFromFixture(1);
|
||||
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
|
||||
|
||||
// Provide necessary configuration for extension
|
||||
$this->importDataSet('Tests/Functional/Fixtures/BasicSetup.xml');
|
||||
foreach ($this->getDataSets() as $dataSet) {
|
||||
$this->importDataSet($dataSet);
|
||||
}
|
||||
|
||||
$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.
|
||||
*
|
||||
|
|
|
@ -28,11 +28,12 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|||
*/
|
||||
class IndexTcaTableTest extends AbstractFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
protected function getDataSets()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml');
|
||||
return array_merge(
|
||||
parent::getDataSets(),
|
||||
['Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -23,56 +23,32 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
|
|||
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;
|
||||
|
||||
class IgnoresUnkownOperationTest extends AbstractFunctionalTestCase
|
||||
class IgnoresUnkownOperationTest extends AbstractDataHandlerTest
|
||||
{
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function deletionWillBeTriggeredForTtContent()
|
||||
public function dataHandlerCommandSomethingIsIgnored()
|
||||
{
|
||||
$this->subject->expects($this->exactly(0))->method('add');
|
||||
$this->subject->expects($this->exactly(0))->method('update');
|
||||
$this->subject->expects($this->exactly(0))->method('delete');
|
||||
|
||||
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
|
||||
$tce->stripslashes_values = 0;
|
||||
$tce->start([], [
|
||||
'tt_content' => [
|
||||
'1' => [
|
||||
'something' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
$tce->process_cmdmap();
|
||||
$subject = new DataHandlerHook($this->subject);
|
||||
$this->assertFalse(
|
||||
$subject->processDatamap_afterDatabaseOperations(
|
||||
'something',
|
||||
'tt_content',
|
||||
1,
|
||||
[],
|
||||
new Typo3DataHandler
|
||||
),
|
||||
'Hook processed status "something".'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,37 +23,23 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
|
|||
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;
|
||||
|
||||
class NonAllowedTablesTest extends AbstractFunctionalTestCase
|
||||
class NonAllowedTablesTest extends AbstractDataHandlerTest
|
||||
{
|
||||
/**
|
||||
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
public function setUp()
|
||||
protected function getDataSets()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->importDataSet('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)]
|
||||
return array_merge(
|
||||
parent::getDataSets(),
|
||||
['Tests/Functional/Fixtures/Hooks/DataHandler/NonAllowedTables.xml']
|
||||
);
|
||||
|
||||
// This way TYPO3 will use our mock instead of a new instance.
|
||||
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,37 +23,23 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
|
|||
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;
|
||||
|
||||
class ProcessesAllowedTablesTest extends AbstractFunctionalTestCase
|
||||
class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
|
||||
{
|
||||
/**
|
||||
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
public function setUp()
|
||||
protected function getDataSets()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->importDataSet('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)]
|
||||
return array_merge(
|
||||
parent::getDataSets(),
|
||||
['Tests/Functional/Fixtures/Hooks/DataHandler/AllowedTables.xml']
|
||||
);
|
||||
|
||||
// This way TYPO3 will use our mock instead of a new instance.
|
||||
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue