TASK: Provide compatible TypoScriptService for both TYPO3 versions

This commit is contained in:
Daniel Siepmann 2018-03-13 12:18:00 +01:00
parent 16bc22aa44
commit 9e80574361
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
7 changed files with 111 additions and 7 deletions

View file

@ -0,0 +1,31 @@
<?php
namespace Codappix\SearchCore\Compatibility;
/*
* Copyright (C) 2018 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 TYPO3\CMS\Core\TypoScript\TypoScriptService as CoreTypoScriptService;
/**
* Used since TYPO3 CMS 8.7.
*/
class TypoScriptService extends CoreTypoScriptService implements TypoScriptServiceInterface
{
}

View file

@ -0,0 +1,31 @@
<?php
namespace Codappix\SearchCore\Compatibility;
/*
* Copyright (C) 2018 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 TYPO3\CMS\Extbase\Service\TypoScriptService as CoreTypoScriptService;
/**
* Used before TYPO3 CMS 8.7.
*/
class TypoScriptService76 extends CoreTypoScriptService implements TypoScriptServiceInterface
{
}

View file

@ -0,0 +1,30 @@
<?php
namespace Codappix\SearchCore\Compatibility;
/*
* Copyright (C) 2018 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.
*/
/**
* Allows to use DI configuration to switch concrete implementation, depending
* on current TYPO3 Version.
*/
interface TypoScriptServiceInterface
{
public function convertPlainArrayToTypoScriptArray(array $plainArray);
}

View file

@ -20,8 +20,8 @@ namespace Codappix\SearchCore\DataProcessing;
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use Codappix\SearchCore\Compatibility\TypoScriptServiceInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/** /**
@ -30,11 +30,11 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
class ContentObjectDataProcessorAdapterProcessor implements ProcessorInterface class ContentObjectDataProcessorAdapterProcessor implements ProcessorInterface
{ {
/** /**
* @var TypoScriptService * @var TypoScriptServiceInterface
*/ */
protected $typoScriptService; protected $typoScriptService;
public function __construct(TypoScriptService $typoScriptService) public function __construct(TypoScriptServiceInterface $typoScriptService)
{ {
$this->typoScriptService = $typoScriptService; $this->typoScriptService = $typoScriptService;
} }

View file

@ -66,4 +66,9 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase
{ {
return ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts']; return ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts'];
} }
protected function useLegacyVersion() : bool
{
return \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < 8000000;
}
} }

View file

@ -20,9 +20,10 @@ namespace Codappix\SearchCore\Tests\Functional\DataProcessing;
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use Codappix\SearchCore\Compatibility\TypoScriptService76;
use Codappix\SearchCore\Compatibility\TypoScriptService;
use Codappix\SearchCore\DataProcessing\ContentObjectDataProcessorAdapterProcessor; use Codappix\SearchCore\DataProcessing\ContentObjectDataProcessorAdapterProcessor;
use Codappix\SearchCore\Tests\Functional\AbstractFunctionalTestCase; use Codappix\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Extbase\Service\TypoScriptService;
use TYPO3\CMS\Frontend\DataProcessing\SplitProcessor; use TYPO3\CMS\Frontend\DataProcessing\SplitProcessor;
class ContentObjectDataProcessorAdapterProcessorTest extends AbstractFunctionalTestCase class ContentObjectDataProcessorAdapterProcessorTest extends AbstractFunctionalTestCase
@ -44,7 +45,13 @@ class ContentObjectDataProcessorAdapterProcessorTest extends AbstractFunctionalT
'new_content' => ['value1', 'value2'], 'new_content' => ['value1', 'value2'],
]; ];
$subject = new ContentObjectDataProcessorAdapterProcessor(new TypoScriptService); if ($this->useLegacyVersion()) {
$typoScriptService = new TypoScriptService76();
} else {
$typoScriptService = new TypoScriptService();
}
$subject = new ContentObjectDataProcessorAdapterProcessor($typoScriptService);
$processedData = $subject->processData($record, $configuration); $processedData = $subject->processData($record, $configuration);
$this->assertSame( $this->assertSame(
$expectedData, $expectedData,

View file

@ -43,12 +43,12 @@ call_user_func(
if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) { if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
$container->registerImplementation( $container->registerImplementation(
\Codappix\SearchCore\Compatibility\TypoScriptServiceInterface::class, \Codappix\SearchCore\Compatibility\TypoScriptServiceInterface::class,
\TYPO3\CMS\Core\TypoScript\TypoScriptService::class \Codappix\SearchCore\Compatibility\TypoScriptService::class
); );
} else { } else {
$container->registerImplementation( $container->registerImplementation(
\Codappix\SearchCore\Compatibility\TypoScriptServiceInterface::class, \Codappix\SearchCore\Compatibility\TypoScriptServiceInterface::class,
\TYPO3\CMS\Extbase\Service\TypoScriptService::class \Codappix\SearchCore\Compatibility\TypoScriptService76::class
); );
} }