Skip to content

Commit

Permalink
[TASK] Clean up TCA loading mechanisms
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Aug 12, 2023
1 parent 6de7295 commit 2a10b07
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
class StaticTypoScriptInclusion
{
protected static bool $recursed = false;
private SpooledConfigurationApplicator $applicator;

public function __construct(SpooledConfigurationApplicator $applicator)
{
$this->applicator = $applicator;
}

public function includeStaticTypoScriptHook(array $parameters, TemplateService $caller): void
{
Expand All @@ -42,9 +48,7 @@ public function includeStaticTypoScriptHook(array $parameters, TemplateService $
// place - and therefore, the negative impact of this is considered very marginal.
static::$recursed = true;

/** @var SpooledConfigurationApplicator $applicator */
$applicator = GeneralUtility::makeInstance(SpooledConfigurationApplicator::class);
$applicator->processData();
$this->applicator->processData();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Table Configuration (TCA) post processor
*
* Simply loads the Flux service and lets methods
* on this Service load necessary configuration.
*
* @codeCoverageIgnore
*/
class TableConfigurationPostProcessor implements TableConfigurationPostProcessingHookInterface
{
protected static bool $recursed = false;
private SpooledConfigurationApplicator $applicator;

public function __construct(SpooledConfigurationApplicator $applicator)
{
$this->applicator = $applicator;
}

public function processData(): void
{
/** @var SpooledConfigurationApplicator $applicator */
$applicator = GeneralUtility::makeInstance(SpooledConfigurationApplicator::class);
$applicator->processData();
$this->applicator->processData();
}
}
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ services:
public: true
FluidTYPO3\Flux\Integration\FormEngine\SiteConfigurationProviderItems:
public: true
FluidTYPO3\Flux\Integration\HookSubscribers\TableConfigurationPostProcessor:
public: true
FluidTYPO3\Flux\Integration\HookSubscribers\StaticTypoScriptInclusion:
public: true
FluidTYPO3\Flux\Builder\ContentTypeBuilder:
public: true
FluidTYPO3\Flux\Builder\FlexFormBuilder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,146 +8,26 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\ContentTypeBuilder;
use FluidTYPO3\Flux\Content\ContentTypeManager;
use FluidTYPO3\Flux\Content\TypeDefinition\FluidFileBased\FluidFileBasedContentTypeDefinition;
use FluidTYPO3\Flux\Core;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Integration\Configuration\SpooledConfigurationApplicator;
use FluidTYPO3\Flux\Integration\HookSubscribers\TableConfigurationPostProcessor;
use FluidTYPO3\Flux\Provider\Provider;
use FluidTYPO3\Flux\Provider\ProviderInterface;
use FluidTYPO3\Flux\Tests\Fixtures\Classes\AccessibleSpooledConfigurationApplicator;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Lang\LanguageService;
use TYPO3Fluid\Fluid\Exception;

/**
* TableConfigurationPostProcessorTest
*/
class TableConfigurationPostProcessorTest extends AbstractTestCase
{
protected $contentTypeBuilder;

protected function setUp(): void
public function testProcessData(): void
{
if (!class_exists(TableConfigurationPostProcessingHookInterface::class)) {
$this->markTestSkipped('Skipping test with TableConfigurationPostProcessingHookInterface dependency');
}
parent::setUp();

$this->contentTypeBuilder = $this->getMockBuilder(ContentTypeBuilder::class)
->setMethods(
[
'addBoilerplateTableConfiguration',
'configureContentTypeFromTemplateFile',
'registerContentType',
]
)
->getMock();
AccessibleSpooledConfigurationApplicator::setContentTypeBuilder($this->contentTypeBuilder);
$GLOBALS['LANG'] = $this->getMockBuilder(LanguageService::class)
->setMethods(['sL'])
->disableOriginalConstructor()
->getMock();
}

protected function tearDown(): void
{
parent::tearDown();

Core::clearQueuedContentTypeRegistrations();
AccessibleSpooledConfigurationApplicator::setContentTypeBuilder(null);
}

public function testProcessData(?Exception $exception1 = null, ?Exception $exception2 = null): void
{
$contentType1 = $this->getMockBuilder(FluidFileBasedContentTypeDefinition::class)
->setMethods(
[
'getExtensionIdentity',
'getTemplatePathAndFilename',
'getContentTypeName',
'getProviderClassName'
]
)
->disableOriginalConstructor()
->getMock();
$contentType1->method('getExtensionIdentity')->willReturn('FluidTYPO3.Flux');
$contentType1->method('getTemplatePathAndFilename')
->willReturn(__DIR__ . '/../../Fixtures/Templates/Content/Default.html');
$contentType1->method('getContentTypeName')->willReturn('flux_default');
$contentType1->method('getProviderClassName')->willReturn(Provider::class);

$contentType2 = clone $contentType1;
$contentType2->method('getContentTypeName')->willReturn('flux_second');

$contentType3 = clone $contentType1;
$contentType3->method('getContentTypeName')->willReturn('flux_third');

$contentTypes = [
'a' => $contentType1,
'b' => $contentType2,
'c' => $contentType3,
];

$contentTypeManager = $this->getMockBuilder(ContentTypeManager::class)
->setMethods(['fetchContentTypes'])
->disableOriginalConstructor()
->getMock();
$contentTypeManager->method('fetchContentTypes')->willReturn($contentTypes);

$provider1 = $this->getMockBuilder(ProviderInterface::class)->getMockForAbstractClass();
$provider1->method('getExtensionKey')->willReturn('FluidTYPO3.Flux');
$provider1->method('getContentObjectType')->willReturn('flux_default');

$provider2 = clone $provider1;
$provider2->method('getContentObjectType')->willReturn('flux_second');
$provider2->method('getForm')->willReturn(null);

$provider3 = clone $provider1;
$provider3->method('getContentObjectType')->willReturn('flux_third');
$provider3->method('getForm')->willReturn(Form::create()->setOption(Form::OPTION_SORTING, ['invalidvalue']));

$provider1->method('getForm')->willReturn(Form::create()->setOption(Form::OPTION_SORTING, 1));

if ($exception1 !== null) {
self::expectExceptionObject($exception1);
$this->contentTypeBuilder->method('configureContentTypeFromTemplateFile')->willThrowException($exception1);
} else {
$this->contentTypeBuilder->method('configureContentTypeFromTemplateFile')
->willReturnOnConsecutiveCalls($provider1, $provider2, $provider3);
}

if ($exception2 !== null) {
self::expectExceptionObject($exception2);
$this->contentTypeBuilder->method('registerContentType')->willThrowException($exception2);
} elseif ($exception1 === null) {
$this->contentTypeBuilder->expects(self::exactly(3))->method('registerContentType');
}

$applicator = $this->getMockBuilder(SpooledConfigurationApplicator::class)
->setMethods(['getContentTypeManager', 'getApplicationContext'])
->onlyMethods(['processData'])
->disableOriginalConstructor()
->getMock();
$applicator->method('getContentTypeManager')->willReturn($contentTypeManager);
$applicator->method('getApplicationContext')->willReturn(new ApplicationContext('Development'));
GeneralUtility::addInstance(SpooledConfigurationApplicator::class, $applicator);

$subject = new TableConfigurationPostProcessor();
$subject->processData();
}

public function testProcessDataWithExeptionInLoop1(): void
{
$this->testProcessData(new Exception('test'));
}

public function testProcessDataWithExeptionInLoop2(): void
{
$this->testProcessData(null, new Exception('test'));
$applicator->expects(self::once())->method('processData');
$subject = new TableConfigurationPostProcessor($applicator);
$subject->processData();;
}
}

0 comments on commit 2a10b07

Please sign in to comment.