Skip to content

Commit

Permalink
[FEATURE] Add possibility to define TypoScript constants (#100)
Browse files Browse the repository at this point in the history
* [FEATURE] Add possibility to define TypoScript constants

* [TASK] Use property `setup` instead of `typoScript`
  • Loading branch information
ohader authored Sep 17, 2018
1 parent 487197e commit 32f7d2e
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,22 @@ protected function getDifferentFields(array $assertion, array $record)
}

/**
* Sets up a root-page containing TypoScript settings for frontend testing.
*
* Parameter `$typoScriptFiles` can either be
* + `[
* 'path/first.typoscript',
* 'path/second.typoscript'
* ]`
* which just loads files to the setup setion of the TypoScript template
* record (legacy behavior of this method)
* + `[
* 'constants' => ['path/constants.typoscript'],
* 'setup' => ['path/setup.typoscript']
* ]`
* which allows to define contents for the `contants` and `setup` part
* of the TypoScript template record at the same time
*
* @param int $pageId
* @param array $typoScriptFiles
*/
Expand All @@ -697,6 +713,14 @@ protected function setUpFrontendRootPage($pageId, array $typoScriptFiles = [], a
$this->fail('Cannot set up frontend root page "' . $pageId . '"');
}

// migrate legacy definition to support `constants` and `setup`
if (!empty($typoScriptFiles)
&& empty($typoScriptFiles['constants'])
&& empty($typoScriptFiles['setup'])
) {
$typoScriptFiles = ['setup' => $typoScriptFiles];
}

$databasePlatform = 'mysql';
if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
$databasePlatform = 'postgresql';
Expand All @@ -723,10 +747,14 @@ protected function setUpFrontendRootPage($pageId, array $typoScriptFiles = [], a
]
);

foreach ($typoScriptFiles['constants'] ?? [] as $typoScriptFile) {
$templateFields['constants'] .= '<INCLUDE_TYPOSCRIPT: source="FILE:' . $typoScriptFile . '">' . LF;
}
$templateValues['constants'] .= 'databasePlatform = ' . $databasePlatform . LF;
foreach ($typoScriptFiles as $typoScriptFile) {
foreach ($typoScriptFiles['setup'] ?? [] as $typoScriptFile) {
$templateFields['config'] .= '<INCLUDE_TYPOSCRIPT: source="FILE:' . $typoScriptFile . '">' . LF;
}

$connection = $this->getConnectionPool()
->getConnectionForTable('sys_template');
$connection->delete('sys_template', ['pid' => $pageId]);
Expand Down

0 comments on commit 32f7d2e

Please sign in to comment.