This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[TASK] Drop legacy support for TypoScript registration

This change:

* Removes support for defining content collections using `plugin.tx_fed.fce.` location
* Removes support for defining content collections using `plugin.tx_fluidcontent.collections.` location.
* Removes the L1 cache used by ConfigurationService
* Cleans up the logic used to retrieve paths for content collections.

As a little bonus, 100% unit test coverage of all class files has been reached.
  • Loading branch information...
NamelessCoder committed Feb 6, 2015
1 parent 97f8d05 commit 0cd6448ebdcb3bdcc82103d5f22eb4d30b475767
Showing with 117 additions and 93 deletions.
  1. +35 −92 Classes/Service/ConfigurationService.php
  2. +82 −1 Tests/Unit/Service/ConfigurationServiceTest.php
@@ -93,71 +93,55 @@ public function initializeObject() {
* @api
*/
public function getContentConfiguration($extensionName = NULL) {
$cacheKey = NULL === $extensionName ? 0 : $extensionName;
$cacheKey = 'content_' . $cacheKey;
if (TRUE === isset(self::$cache[$cacheKey])) {
return self::$cache[$cacheKey];
if (NULL !== $extensionName) {
return $this->getViewConfigurationForExtensionName($extensionName);
}
$newLocation = (array) $this->getTypoScriptSubConfiguration($extensionName, 'collections', 'fluidcontent');
$oldLocation = (array) $this->getTypoScriptSubConfiguration($extensionName, 'fce', 'fed');
$merged = RecursiveArrayUtility::mergeRecursiveOverrule($oldLocation, $newLocation);
$registeredExtensionKeys = Core::getRegisteredProviderExtensionKeys('Content');
if (NULL === $extensionName) {
foreach ($registeredExtensionKeys as $registeredExtensionKey) {
$nativeViewLocation = $this->getContentConfiguration($registeredExtensionKey);
if (FALSE === isset($nativeViewLocation['extensionKey'])) {
$nativeViewLocation['extensionKey'] = ExtensionNamingUtility::getExtensionKey($registeredExtensionKey);
}
self::$cache[$registeredExtensionKey] = $nativeViewLocation;
$merged[$registeredExtensionKey] = $nativeViewLocation;
}
} else {
$nativeViewLocation = $this->getViewConfigurationForExtensionName($extensionName);
if (TRUE === is_array($nativeViewLocation)) {
$merged = RecursiveArrayUtility::mergeRecursiveOverrule($nativeViewLocation, $merged);
}
if (FALSE === isset($merged['extensionKey'])) {
$merged['extensionKey'] = ExtensionNamingUtility::getExtensionKey($extensionName);
}
$registeredExtensionKeys = (array) Core::getRegisteredProviderExtensionKeys('Content');
$configuration = array();
foreach ($registeredExtensionKeys as $registeredExtensionKey) {
$configuration[$registeredExtensionKey] = $this->getContentConfiguration($registeredExtensionKey);
}
self::$cache[$cacheKey] = $merged;
return $merged;
return $configuration;
}
/**
* @return NULL
* @return void
*/
public function writeCachedConfigurationIfMissing() {
/** @var StringFrontend $cache */
$cache = $this->manager->getCache('fluidcontent');
$hasCache = $cache->has('pageTsConfig');
if (TRUE === $hasCache) {
return NULL;
if (FALSE === $hasCache) {
$pageTsConfig = '';
$templates = $this->getAllRootTypoScriptTemplates();
foreach ($templates as $template) {
$pageUid = (integer) $template['pid'];
$pageTsConfig .= $this->renderPageTypoScriptForPageUid($pageUid);
}
$cache->set('pageTsConfig', $pageTsConfig, array(), 806400);
}
$templates = $this->getAllRootTypoScriptTemplates();
$paths = $this->getPathConfigurationsFromRootTypoScriptTemplates($templates);
$pageTsConfig = '';
$this->backupPageUidForConfigurationManager();
}
foreach ($paths as $pageUid => $collection) {
if (FALSE === $collection) {
continue;
}
try {
$this->overrideCurrentPageUidForConfigurationManager($pageUid);
$wizardTabs = $this->buildAllWizardTabGroups($collection);
$collectionPageTsConfig = $this->buildAllWizardTabsPageTsConfig($wizardTabs);
$pageTsConfig .= '[PIDinRootline = ' . strval($pageUid) . ']' . LF;
$pageTsConfig .= $collectionPageTsConfig . LF;
$pageTsConfig .= '[GLOBAL]' . LF;
$this->message('Built content setup for page ' . $pageUid, GeneralUtility::SYSLOG_SEVERITY_INFO, 'Fluidcontent');
} catch (\Exception $error) {
$this->debug($error);
}
/**
* @param $pageUid
* @return string
*/
protected function renderPageTypoScriptForPageUid($pageUid) {
$this->backupPageUidForConfigurationManager();
$this->overrideCurrentPageUidForConfigurationManager($pageUid);
try {
$collection = $this->getContentConfiguration();
$wizardTabs = $this->buildAllWizardTabGroups($collection);
$collectionPageTsConfig = $this->buildAllWizardTabsPageTsConfig($wizardTabs);
$pageTsConfig .= '[PIDinRootline = ' . strval($pageUid) . ']' . LF;
$pageTsConfig .= $collectionPageTsConfig . LF;
$pageTsConfig .= '[GLOBAL]' . LF;
$this->message('Built content setup for page ' . $pageUid, GeneralUtility::SYSLOG_SEVERITY_INFO, 'Fluidcontent');
} catch (\RuntimeException $error) {
$this->debug($error);
}
$this->restorePageUidForConfigurationManager();
$cache->set('pageTsConfig', $pageTsConfig, array(), 806400);
return NULL;
return $pageTsConfig;
}
/**
@@ -188,47 +172,6 @@ protected function restorePageUidForConfigurationManager() {
}
}
/**
* Gets a collection of path configurations for content elements
* based on each root TypoScript template in the provided array
* of templates. Returns an array of paths indexed by the root
* page UID.
*
* @param array $templates
* @return array
*/
protected function getPathConfigurationsFromRootTypoScriptTemplates($templates) {
$allTemplatePaths = array();
$registeredExtensionKeys = Core::getRegisteredProviderExtensionKeys('Content');
foreach ($templates as $templateRecord) {
$pageUid = $templateRecord['pid'];
/** @var \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService $template */
$template = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
$template->tt_track = 0;
$template->init();
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $sys_page */
$sys_page = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
$rootLine = $sys_page->getRootLine($pageUid);
$template->runThroughTemplates($rootLine);
$template->generateConfig();
$oldTemplatePathLocation = (array) $template->setup['plugin.']['tx_fed.']['fce.'];
$newTemplatePathLocation = (array) $template->setup['plugin.']['tx_fluidcontent.']['collections.'];
$registeredPathCollections = array();
foreach ($registeredExtensionKeys as $registeredExtensionKey) {
$nativeViewLocation = $this->getContentConfiguration($registeredExtensionKey);
if (FALSE === isset($nativeViewLocation['extensionKey'])) {
$nativeViewLocation['extensionKey'] = ExtensionNamingUtility::getExtensionKey($registeredExtensionKey);
}
$registeredPathCollections[$registeredExtensionKey] = $nativeViewLocation;
}
$merged = RecursiveArrayUtility::mergeRecursiveOverrule($oldTemplatePathLocation, $newTemplatePathLocation);
$merged = GeneralUtility::removeDotsFromTS($merged);
$merged = RecursiveArrayUtility::merge($merged, $registeredPathCollections);
$allTemplatePaths[$pageUid] = $merged;
}
return $allTemplatePaths;
}
/**
* @return array
*/
@@ -8,8 +8,10 @@
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Fluidcontent\Service\ConfigurationService;
use FluidTYPO3\Flux\Core;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Service\ContentService;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -42,7 +44,13 @@ public function testWriteCachedConfigurationIfMissing() {
$preparedStatementMock->expects($this->any())->method('free');
$preparedStatementMock->expects($this->any())->method('fetch')->willReturn(FALSE);;
$GLOBALS['TYPO3_DB']->expects($this->any())->method('prepare_SELECTquery')->willReturn($preparedStatementMock);
$service = $this->getMock('FluidTYPO3\\Fluidcontent\\Service\\ConfigurationService', array('dummy'), array(), '', FALSE);
$service = $this->getMock(
'FluidTYPO3\\Fluidcontent\\Service\\ConfigurationService',
array('getAllRootTypoScriptTemplates', 'renderPageTypoScriptForPageUid'),
array(), '', FALSE
);
$service->expects($this->once())->method('getAllRootTypoScriptTemplates')->willReturn(array(array('pid' => 1)));
$service->expects($this->once())->method('renderPageTypoScriptForPageUid')->willReturn('test');
$service->injectConfigurationManager(GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')
->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface'));
$service->injectCacheManager(GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')
@@ -147,4 +155,77 @@ public function testBuildAllWizardTabGroups() {
$this->assertArrayHasKey('fluidcontent_DummyContent_html', $result['Content']['elements']);
}
/**
* @dataProvider getTestRenderPageTypoScriptTestValues
* @return void
*/
public function testRenderPageTypoScriptForPageUidCreatesExpectedTypoScript($pageUid) {
$class = substr(str_replace('Tests\\Unit\\', '', get_class($this)), 0, -4);
$instance = $this->getMock(
$class,
array(
'overrideCurrentPageUidForConfigurationManager',
'getContentConfiguration',
'buildAllWizardTabGroups',
'buildAllWizardTabsPageTsConfig',
'message'
)
);
$instance->expects($this->at(0))->method('overrideCurrentPageUidForConfigurationManager')->with($pageUid);
$instance->expects($this->at(1))->method('getContentConfiguration')->willReturn(array('foo' => 'bar'));
$instance->expects($this->at(2))->method('buildAllWizardTabGroups')->with(array('foo' => 'bar'))->willReturn(array());
$instance->expects($this->at(3))->method('buildAllWizardTabsPageTsConfig')->with(array())->willReturn('targetmarker');
$instance->expects($this->at(4))->method('message');
$result = $this->callInaccessibleMethod($instance, 'renderPageTypoScriptForPageUid', $pageUid);
$this->assertContains('targetmarker', $result);
}
/**
* @return array
*/
public function getTestRenderPageTypoScriptTestValues() {
return array(
array(1),
array(2)
);
}
/**
* @return void
*/
public function testRenderPageTypoScriptForPageUidDelegatesExceptionsToDebug() {
$class = substr(str_replace('Tests\\Unit\\', '', get_class($this)), 0, -4);
$instance = $this->getMock($class, array('getContentConfiguration', 'debug', 'message'));
$instance->expects($this->once())->method('getContentConfiguration')
->willThrowException(new \RuntimeException('test'));
$instance->expects($this->never())->method('message');
$instance->expects($this->once())->method('debug');
$this->callInaccessibleMethod($instance, 'renderPageTypoScriptForPageUid', 0, array());
}
/**
* @return void
*/
public function testConfigurationManagerOverrides() {
$instance = new ConfigurationService();
$mock = $this->getMock(
'FluidTYPO3\\Flux\\Configuration\\ConfigurationManager',
array('setCurrentPageUid', 'getCurrentPageId')
);
$mock->expects($this->at(0))->method('setCurrentPageUid')->with(1);
$mock->expects($this->at(1))->method('getCurrentPageId')->willReturn(2);
$mock->expects($this->at(2))->method('setCurrentPageUid')->with(2);
$instance->injectConfigurationManager($mock);
$this->callInaccessibleMethod($instance, 'overrideCurrentPageUidForConfigurationManager', 1);
$this->callInaccessibleMethod($instance, 'backupPageUidForConfigurationManager');
$this->callInaccessibleMethod($instance, 'restorePageUidForConfigurationManager');
}
/**
* @return void
*/
public function testGetPathConfigurationsFromRootTypoScriptTemplates() {
}
}

0 comments on commit 0cd6448

Please sign in to comment.