[BUGFIX] FLUIDTEMPLATE cObj uses wrong template file 00/17800/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 29 Jan 2013 16:09:03 +0000 (17:09 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 29 Jan 2013 16:30:51 +0000 (17:30 +0100)
Due to some weird instance re-usage in the content object renderer
the view object in FLUIDTEMPLATE content object must be re-created
for every call to render() to avoid some nasty cache issues.

Change-Id: If2ec0b171b8227aba9204d343a9e9010b69ecc78
Resolves: #44610
Related: #42182
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/17800
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
typo3/sysext/frontend/Tests/Unit/ContentObject/FluidTemplateContentObjectTest.php

index eddda2f..92c5c6a 100644 (file)
@@ -46,7 +46,6 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
 
        public function __construct(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer) {
                parent::__construct($contentObjectRenderer);
-               $this->view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
        }
 
        /**
@@ -75,6 +74,8 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
         * @return string The HTML output
         */
        public function render($conf = array()) {
+               $this->initializeStandaloneViewInstance();
+
                if (!is_array($conf)) {
                        $conf = array();
                }
@@ -93,6 +94,19 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
        }
 
        /**
+        * Creating standalone view instance must not be done in construct() as
+        * it can lead to a nasty cache issue since content object instances
+        * are not always re-created by the content object rendered for every
+        * usage, but can be re-used. Thus, we need a fresh instance of
+        * StandaloneView every time render() is called.
+        *
+        * @return void
+        */
+       protected function initializeStandaloneViewInstance() {
+               $this->view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
+       }
+
+       /**
         * Set template
         *
         * @param array $conf With possibly set file resource
index f2f8619..19d1916 100644 (file)
@@ -59,7 +59,7 @@ class FluidTemplateContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                );
                $this->fixture = $this->getAccessibleMock(
                        'TYPO3\\CMS\\Frontend\\ContentObject\\FluidTemplateContentObject',
-                       array('dummy'),
+                       array('dummy', 'initializeStandaloneViewInstance'),
                        array($this->contentObjectRenderer)
                );
                /** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
@@ -91,8 +91,12 @@ class FluidTemplateContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
        /**
         * @test
         */
-       public function constructCreatesInstanceOfFluidStandaloneView() {
-               $this->assertInstanceOf('TYPO3\\CMS\\Fluid\\View\\StandaloneView', $this->fixture->_get('view'));
+       public function renderCallsinitializeStandaloneViewInstance() {
+               $this->addMockViewToFixture();
+               $this->fixture
+                       ->expects($this->once())
+                       ->method('initializeStandaloneViewInstance');
+               $this->fixture->render(array());
        }
 
        /**