[TASK] Clarify reset in page renderer comment 82/29582/4
authorHelmut Hummel <helmut.hummel@typo3.org>
Sun, 20 Apr 2014 10:44:34 +0000 (12:44 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 6 May 2014 20:33:14 +0000 (22:33 +0200)
Also add tests to enforce this behavior.

Resolves: #58581
Releases: 6.2
Change-Id: Ife3894fe6dd5fc476bba9c9c74ae26bf310b9245
Reviewed-on: https://review.typo3.org/29582
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Tests/Unit/Page/PageRendererTest.php

index fd4d2b4..9a0218b 100644 (file)
@@ -1949,6 +1949,10 @@ 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);
+
+               // The page renderer needs a full reset, even when only rendering one part of the page
+               // This means that you can only register footer files *after* the header has been already rendered.
+               // In case you render the footer part first, header files can only be added *after* the footer has been rendered
                $this->reset();
                return trim(\TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markerArray, '###|###'));
        }
@@ -2144,7 +2148,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 94e8c47..ac0655a 100644 (file)
@@ -23,6 +23,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Page;
  *
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Page\PageRenderer;
 
 /**
  * Unit test case
@@ -32,6 +33,18 @@ namespace TYPO3\CMS\Core\Tests\Unit\Page;
 class PageRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
+        * @test
+        */
+       public function renderMethodCallsResetInAnyCase() {
+               $pageRenderer = $this->getMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('reset', 'prepareRendering', 'renderJavaScriptAndCss', 'getPreparedMarkerArray', 'getTemplateForPart'));
+               $pageRenderer->expects($this->exactly(3))->method('reset');
+
+               $pageRenderer->render(PageRenderer::PART_COMPLETE);
+               $pageRenderer->render(PageRenderer::PART_HEADER);
+               $pageRenderer->render(PageRenderer::PART_FOOTER);
+       }
+
+       /**
         * @expectedException \UnexpectedValueException
         * @test
         */