BUGFIX: Also handle data processor without configuration

This commit is contained in:
Daniel Siepmann 2017-10-14 13:35:44 +02:00
parent efeb5d1e07
commit 6c01abe5a5
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 41 additions and 2 deletions

View file

@ -150,7 +150,14 @@ class TcaTableService
try { try {
foreach ($this->configuration->get('indexing.' . $this->tableName . '.dataProcessing') as $configuration) { foreach ($this->configuration->get('indexing.' . $this->tableName . '.dataProcessing') as $configuration) {
$dataProcessor = GeneralUtility::makeInstance($configuration['_typoScriptNodeValue']); $className = '';
if (is_string($configuration)) {
$className = $configuration;
$configuration = [];
} else {
$className = $configuration['_typoScriptNodeValue'];
}
$dataProcessor = GeneralUtility::makeInstance($className);
if ($dataProcessor instanceof ProcessorInterface) { if ($dataProcessor instanceof ProcessorInterface) {
$record = $dataProcessor->processRecord($record, $configuration); $record = $dataProcessor->processRecord($record, $configuration);
} }

View file

@ -104,7 +104,7 @@ class TcaTableServiceTest extends AbstractUnitTestCase
/** /**
* @test * @test
*/ */
public function executesConfiguredDataProcessing() public function executesConfiguredDataProcessingWithConfiguration()
{ {
$this->configuration->expects($this->exactly(1)) $this->configuration->expects($this->exactly(1))
->method('get') ->method('get')
@ -141,4 +141,36 @@ class TcaTableServiceTest extends AbstractUnitTestCase
'Dataprocessing is not executed by TcaTableService as expected.' 'Dataprocessing is not executed by TcaTableService as expected.'
); );
} }
/**
* @test
*/
public function executesConfiguredDataProcessingWithoutConfiguration()
{
$this->configuration->expects($this->exactly(1))
->method('get')
->with('indexing.testTable.dataProcessing')
->will($this->returnValue([CopyToProcessor::class]));
$subject = $this->getMockBuilder(TcaTableService::class)
->disableOriginalConstructor()
->setMethodsExcept(['prepareRecord'])
->getMock();
$this->inject($subject, 'configuration', $this->configuration);
$this->inject($subject, 'tableName', 'testTable');
$this->inject($subject, 'relationResolver', $this->getMockBuilder(RelationResolver::class)->getMock());
$record = ['field 1' => 'test'];
$expectedRecord = $record;
$expectedRecord[''] = 'test';
$expectedRecord['search_title'] = 'test';
$subject->prepareRecord($record);
$this->assertSame(
$expectedRecord,
$record,
'Dataprocessing is not executed by TcaTableService as expected.'
);
}
} }