[BUGFIX] Make old style Widgets work again
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 16 Oct 2012 18:34:03 +0000 (20:34 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Thu, 18 Oct 2012 11:50:43 +0000 (13:50 +0200)
Widgets with underscores in class names do not
work because the subpackage key is not handled
correctly.

Fixes: #42123
Releases: 6.0

Change-Id: I39336881858438c4f5f241cc9f965de0dabf13a2
Reviewed-on: http://review.typo3.org/15745
Reviewed-by: Stefan Neufeind
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/fluid/Classes/View/TemplateView.php
typo3/sysext/fluid/Tests/Unit/View/TemplateViewTest.php

index 5a04ebf..2c7a7fd 100644 (file)
@@ -436,7 +436,16 @@ class TemplateView extends \TYPO3\CMS\Fluid\View\AbstractTemplateView {
                $pattern = str_replace('@layoutRoot', $this->getLayoutRootPath(), $pattern);
                $subpackageKey = $this->controllerContext->getRequest()->getControllerSubpackageKey();
                $controllerName = $this->controllerContext->getRequest()->getControllerName();
-               $subpackageParts = $subpackageKey !== NULL ? explode(\TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR, $subpackageKey) : array();
+               if ($subpackageKey !== NULL) {
+                       if (strpos($subpackageKey, \TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR) !== FALSE) {
+                               $namespaceSeparator = \TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR;
+                       } else {
+                               $namespaceSeparator = \TYPO3\CMS\Fluid\Fluid::LEGACY_NAMESPACE_SEPARATOR;
+                       }
+                       $subpackageParts = explode($namespaceSeparator, $subpackageKey);
+               } else {
+                       $subpackageParts = array();
+               }
                $results = array();
                $i = $controllerName === NULL ? 0 : -1;
                do {
index cfe0f02..0bfbe0b 100644 (file)
@@ -23,6 +23,32 @@ class TemplateViewTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
+       public function expandGenericPathPatternWorksWithOldNamingSchemeOfSubPackage() {
+               $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'ViewHelpers_Widget', 'Paginate', 'html');
+               $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
+               $templateView->_set('controllerContext', $mockControllerContext);
+               $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
+               $expected = array('Resources/Private/Templates/ViewHelpers/Widget/Paginate/@action.html');
+               $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
+               $this->assertEquals($expected, $actual);
+       }
+
+       /**
+        * @test
+        */
+       public function expandGenericPathPatternWorksWithNewNamingSchemeOfSubPackage() {
+               $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'ViewHelpers\\Widget', 'Paginate', 'html');
+               $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
+               $templateView->_set('controllerContext', $mockControllerContext);
+               $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
+               $expected = array('Resources/Private/Templates/ViewHelpers/Widget/Paginate/@action.html');
+               $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
+               $this->assertEquals($expected, $actual);
+       }
+
+       /**
+        * @test
+        */
        public function expandGenericPathPatternWorksWithBubblingDisabledAndFormatNotOptional() {
                $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', NULL, 'My', 'html');
                $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);