[BUGFIX] Do not reset Page Renderer on partial rendering 70/28770/6
authorStefan Froemken <froemken@gmail.com>
Tue, 25 Mar 2014 14:55:19 +0000 (15:55 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 3 Apr 2014 20:00:34 +0000 (22:00 +0200)
Currently the Page Renderer is reset when calling
the render() method, even if only one part (header
or footer) is rendered, which causes a second call
to fail, when rendering another part.
This happens e.g in DocumentTemplate.php where
the render() method is called two times. Because of
the reset, the second call starts pageRenderer with
empty properties.

Solution is to only call reset if everything is rendered.

Resolves: #57294
Releases: 6.2
Change-Id: Ib4800e37ba0760617de71f9ca1181d1664463e33
Reviewed-on: https://review.typo3.org/28770
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Tests/Functional/Page/PageRendererTest.php

index d87b209..3f28ccd 100644 (file)
@@ -1948,7 +1948,9 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                $metaTags = implode(LF, $this->metaTags);
                $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssLibs, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
                $template = $this->getTemplateForPart($part);
-               $this->reset();
+               if ($part === self::PART_COMPLETE) {
+                       $this->reset();
+               }
                return trim(\TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markerArray, '###|###'));
        }
 
@@ -2143,7 +2145,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                if ($this->removeLineBreaksFromTemplate) {
                        $template = strtr($template, array(LF => '', CR => ''));
                }
-               if ($part != self::PART_COMPLETE) {
+               if ($part !== self::PART_COMPLETE) {
                        $templatePart = explode('###BODY###', $template);
                        $template = $templatePart[$part - 1];
                }
index 2e3be15..6e2b2df 100644 (file)
@@ -201,6 +201,56 @@ class PageRendererTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
        /**
         * @test
         */
+       public function pageRendererRendersFooterValuesAfterItRenderedHeaderValues() {
+               $subject = new \TYPO3\CMS\Core\Page\PageRenderer();
+               $subject->setCharSet('utf-8');
+               $subject->setLanguage('default');
+
+               $expectedFooterData = '<tag method="footer" name="test" />';
+               $subject->addFooterData($expectedFooterData);
+
+               $expectedHeaderData = '<tag method="header" name="test" />';
+               $subject->addHeaderData($expectedHeaderData);
+
+               $renderedString = $subject->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_HEADER);
+
+               $this->assertContains($expectedHeaderData, $renderedString);
+               $this->assertNotContains($expectedFooterData, $renderedString);
+
+               $renderedString = $subject->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
+
+               $this->assertContains($expectedFooterData, $renderedString);
+               $this->assertNotContains($expectedHeaderData, $renderedString);
+       }
+
+       /**
+        * @test
+        */
+       public function pageRendererResetsStateWhenRenderingAllParts() {
+               $subject = new \TYPO3\CMS\Core\Page\PageRenderer();
+               $subject->setCharSet('utf-8');
+               $subject->setLanguage('default');
+
+               $expectedFooterData = '<tag method="footer" name="test" />';
+               $subject->addFooterData($expectedFooterData);
+
+               $expectedHeaderData = '<tag method="header" name="test" />';
+               $subject->addHeaderData($expectedHeaderData);
+
+               $renderedString = $subject->render();
+
+               $this->assertContains($expectedHeaderData, $renderedString);
+               $this->assertContains($expectedFooterData, $renderedString);
+
+               $renderedString = $subject->render();
+
+               $this->assertNotContains($expectedHeaderData, $renderedString);
+               $this->assertNotContains($expectedFooterData, $renderedString);
+       }
+
+       /**
+        * @test
+        */
        public function isScriptaculousLoadedCompressedIfConfiguredAndClientIsCapable() {
                $subject = new \TYPO3\CMS\Core\Page\PageRenderer();