[BUGFIX] Fix rootline translation 75/17475/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Thu, 6 Dec 2012 14:20:04 +0000 (15:20 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Sat, 12 Jan 2013 11:28:08 +0000 (12:28 +0100)
The fix in #42029 introduced a regression
as TSFE->tmpl->rootLine holds a reversed
rootline array, while in TSFE->rootLine
the order is "normal"

Additionally the call to getPageOverlay was wrong
because the result of the overlay was never used.

Lastly use the correct uid for looking up the
relation fields.

This change also cleans up the unit tests for
RootlineUtility and adds regression tests for
these issues.

Fixes: #43668
Fixes: #44312
Releases: 6.0, 6.1

Change-Id: I4a577ad749bde397a572ca48ae810e3dfe8a5740
Reviewed-on: https://review.typo3.org/17475
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Utility/RootlineUtility.php
typo3/sysext/core/Tests/Unit/Utility/Fixtures/RootlineUtilityTestAccessibleFixture.php [deleted file]
typo3/sysext/core/Tests/Unit/Utility/RootlineUtilityTest.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index 0d46110..7dd7cf6 100644 (file)
@@ -114,6 +114,11 @@ class RootlineUtility {
        static protected $pageRecordCache = array();
 
        /**
+        * @var \TYPO3\CMS\Core\Database\DatabaseConnection
+        */
+       protected $databaseConnection;
+
+       /**
         * @param int $uid
         * @param string $mountPointParameter
         * @param \TYPO3\CMS\Frontend\Page\PageRepository $context
@@ -156,6 +161,7 @@ class RootlineUtility {
                }
                self::$rootlineFields = array_merge(self::$rootlineFields, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'], TRUE));
                array_unique(self::$rootlineFields);
+               $this->databaseConnection = $GLOBALS['TYPO3_DB'];
        }
 
        /**
@@ -206,15 +212,17 @@ class RootlineUtility {
                                }
                                \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('pages');
                        }
-                       $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(implode(',', self::$rootlineFields), 'pages', 'uid = ' . intval($uid) . ' AND pages.deleted = 0 AND pages.doktype <> ' . \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER);
+                       $row = $this->databaseConnection->exec_SELECTgetSingleRow(implode(',', self::$rootlineFields), 'pages', 'uid = ' . intval($uid) . ' AND pages.deleted = 0 AND pages.doktype <> ' . \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER);
                        if (empty($row)) {
                                throw new \RuntimeException('Could not fetch page data for uid ' . $uid . '.', 1343589451);
                        }
                        $this->pageContext->versionOL('pages', $row, FALSE, TRUE);
                        $this->pageContext->fixVersioningPid('pages', $row);
                        if (is_array($row)) {
-                               $this->pageContext->getPageOverlay($row, $this->languageUid);
-                               $row = $this->enrichWithRelationFields($uid, $row);
+                               if ($this->languageUid > 0) {
+                                       $row = $this->pageContext->getPageOverlay($row, $this->languageUid);
+                               }
+                               $row = $this->enrichWithRelationFields(isset($row['_PAGES_OVERLAY_UID']) ? $row['_PAGES_OVERLAY_UID'] : $uid, $row);
                                self::$pageRecordCache[$this->getCacheIdentifier($uid)] = $row;
                        }
                }
@@ -241,13 +249,13 @@ class RootlineUtility {
                                        $loadDBGroup = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler');
                                        $loadDBGroup->start($pageRecord[$column], $configuration['foreign_table'], $configuration['MM'], $uid, 'pages', $configuration);
                                        $relatedUids = $loadDBGroup->tableArray[$configuration['foreign_table']];
-                               } elseif ($configuration['foreign_field']) {
+                               } else {
                                        $table = $configuration['foreign_table'];
                                        $field = $configuration['foreign_field'];
                                        $whereClauseParts = array($field . ' = ' . intval($uid));
                                        if (isset($configuration['foreign_match_fields']) && is_array($configuration['foreign_match_fields'])) {
                                                foreach ($configuration['foreign_match_fields'] as $field => $value) {
-                                                       $whereClauseParts[] = $field . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $table);
+                                                       $whereClauseParts[] = $field . ' = ' . $this->databaseConnection->fullQuoteStr($value, $table);
                                                }
                                        }
                                        if (isset($configuration['foreign_table_field'])) {
@@ -259,7 +267,7 @@ class RootlineUtility {
                                        }
                                        $whereClause = implode(' AND ', $whereClauseParts);
                                        $whereClause .= $this->pageContext->deleteClause($table);
-                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $table, $whereClause);
+                                       $rows = $this->databaseConnection->exec_SELECTgetRows('uid', $table, $whereClause);
                                        if (!is_array($rows)) {
                                                throw new \RuntimeException('Could to resolve related records for page ' . $uid . ' and foreign_table ' . htmlspecialchars($configuration['foreign_table']), 1343589452);
                                        }
@@ -283,10 +291,10 @@ class RootlineUtility {
         */
        protected function columnHasRelationToResolve(array $configuration) {
                $configuration = $configuration['config'];
-               if (isset($configuration['MM']) && isset($configuration['type']) && in_array($configuration['type'], array('select', 'inline', 'group'))) {
+               if (!empty($configuration['MM']) && !empty($configuration['type']) && in_array($configuration['type'], array('select', 'inline', 'group'))) {
                        return TRUE;
                }
-               if (isset($configuration['foreign_field']) && isset($configuration['type']) && in_array($configuration['type'], array('select', 'inline'))) {
+               if (!empty($configuration['foreign_field']) && !empty($configuration['type']) && in_array($configuration['type'], array('select', 'inline'))) {
                        return TRUE;
                }
                return FALSE;
diff --git a/typo3/sysext/core/Tests/Unit/Utility/Fixtures/RootlineUtilityTestAccessibleFixture.php b/typo3/sysext/core/Tests/Unit/Utility/Fixtures/RootlineUtilityTestAccessibleFixture.php
deleted file mode 100644 (file)
index 6b4db4b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Steffen Ritter <steffen.ritter@typo3.org>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Make method public
- *
- * @author Steffen Ritter <steffen.ritter@typo3.org>
- */
-class RootlineUtilityTestAccessibleFixture extends \TYPO3\CMS\Core\Utility\RootlineUtility {
-
-       public function processMountedPage($mountedPageData, $mountPointPageData) {
-               return parent::processMountedPage($mountedPageData, $mountPointPageData);
-       }
-
-       public function columnHasRelationToResolve($configuration) {
-               return parent::columnHasRelationToResolve($configuration);
-       }
-
-}
-
-?>
\ No newline at end of file
index 5d0e87b..7876e33 100644 (file)
@@ -24,8 +24,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
-require_once __DIR__ . '/Fixtures/RootlineUtilityTestAccessibleFixture.php';
-
 /**
  * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
  *
@@ -33,6 +31,22 @@ require_once __DIR__ . '/Fixtures/RootlineUtilityTestAccessibleFixture.php';
  */
 class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
+       /**
+        * @var \TYPO3\CMS\Core\Utility\RootlineUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $fixture;
+
+       /**
+        * @var \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $pageContextMock;
+
+       public function setUp() {
+               $this->pageContextMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
+               $this->fixture = $this->getAccessibleMock('\TYPO3\CMS\Core\Utility\RootlineUtility', array('enrichWithRelationFields'), array(1, '', $this->pageContextMock));
+       }
+
+
        /***
         *
         *              UTILITY FUNCTIONS
@@ -59,24 +73,24 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function isMountedPageWithoutMountPointsReturnsFalse() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertFalse($fixture->isMountedPage());
+               $this->fixture->__construct(1);
+               $this->assertFalse($this->fixture->isMountedPage());
        }
 
        /**
         * @test
         */
        public function isMountedPageWithMatchingMountPointParameterReturnsTrue() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $this->assertTrue($fixture->isMountedPage());
+               $this->fixture->__construct(1, '1-99');
+               $this->assertTrue($this->fixture->isMountedPage());
        }
 
        /**
         * @test
         */
        public function isMountedPageWithNonMatchingMountPointParameterReturnsFalse() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '99-99');
-               $this->assertFalse($fixture->isMountedPage());
+               $this->fixture->__construct(1, '99-99');
+               $this->assertFalse($this->fixture->isMountedPage());
        }
 
        /**
@@ -84,24 +98,24 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @expectedException \RuntimeException
         */
        public function processMountedPageWithNonMountedPageThrowsException() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
+               $this->fixture->__construct(1, '1-99');
+               $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
        }
 
        /**
         * @test
         */
        public function processMountedPageWithMountedPageNotThrowsException() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
+               $this->fixture->__construct(1, '1-99');
+               $this->assertNotEmpty($this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1)));
        }
 
        /**
         * @test
         */
        public function processMountedPageWithMountedPageAddsMountedFromParameter() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
+               $this->fixture->__construct(1, '1-99');
+               $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
                $this->assertTrue(isset($result['_MOUNTED_FROM']));
                $this->assertSame(1, $result['_MOUNTED_FROM']);
        }
@@ -110,8 +124,8 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function processMountedPageWithMountedPageAddsMountPointParameterToReturnValue() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
+               $this->fixture->__construct(1, '1-99');
+               $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
                $this->assertTrue(isset($result['_MP_PARAM']));
                $this->assertSame('1-99', $result['_MP_PARAM']);
        }
@@ -120,8 +134,8 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function processMountedPageForMountPageIsOverlayAddsMountOLParameter() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
+               $this->fixture->__construct(1, '1-99');
+               $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
                $this->assertTrue(isset($result['_MOUNT_OL']));
                $this->assertSame(TRUE, $result['_MOUNT_OL']);
        }
@@ -130,8 +144,8 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase'));
+               $this->fixture->__construct(1, '1-99');
+               $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase'));
                $this->assertTrue(isset($result['_MOUNT_PAGE']));
                $this->assertSame(array('uid' => 99, 'pid' => 5, 'title' => 'TestCase'), $result['_MOUNT_PAGE']);
        }
@@ -140,18 +154,17 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage() {
-               $a = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
-               $result = $fixture->processMountedPage(array('uid' => 1), $a);
-               $this->assertIsSubset($a, $result);
+               $mountPointPageData = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
+               $this->fixture->__construct(1, '1-99');
+               $result = $this->fixture->_call('processMountedPage', array('uid' => 1), $mountPointPageData);
+               $this->assertIsSubset($mountPointPageData, $result);
        }
 
        /**
         * @test
         */
        public function columnHasRelationToResolveDetectsGroupFieldAsLocal() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertFalse($fixture->columnHasRelationToResolve(array(
+               $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
                        'type' => 'group'
                )));
        }
@@ -159,9 +172,8 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
-       public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertTrue($fixture->columnHasRelationToResolve(array(
+       public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2() {
+               $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
                        'config' => array(
                                'type' => 'group',
                                'MM' => 'tx_xyz'
@@ -173,8 +185,7 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function columnHasRelationToResolveDetectsInlineFieldAsLocal() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertFalse($fixture->columnHasRelationToResolve(array(
+               $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
                        'config' => array(
                                'type' => 'inline'
                        )
@@ -185,8 +196,7 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertTrue($fixture->columnHasRelationToResolve(array(
+               $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
                        'config' => array(
                                'type' => 'inline',
                                'foreign_field' => 'xyz'
@@ -198,8 +208,7 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertTrue($fixture->columnHasRelationToResolve(array(
+               $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
                        'config' => array(
                                'type' => 'inline',
                                'MM' => 'xyz'
@@ -211,8 +220,7 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function columnHasRelationToResolveDetectsSelectFieldAsLocal() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertFalse($fixture->columnHasRelationToResolve(array(
+               $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
                        'config' => array(
                                'type' => 'select'
                        )
@@ -223,8 +231,7 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote() {
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
-               $this->assertTrue($fixture->columnHasRelationToResolve(array(
+               $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
                        'config' => array(
                                'type' => 'select',
                                'MM' => 'xyz'
@@ -236,20 +243,58 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getCacheIdentifierContainsAllContextParameters() {
-               $pageContext = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
-               $pageContext->sys_language_uid = 8;
-               $pageContext->versioningWorkspaceId = 15;
-               $pageContext->versioningPreview = TRUE;
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
-               $this->assertSame('42_47-11_8_15_1', $fixture->getCacheIdentifier());
-               $pageContext->versioningPreview = FALSE;
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
-               $this->assertSame('42_47-11_8_15_0', $fixture->getCacheIdentifier());
-               $pageContext->versioningWorkspaceId = 0;
-               $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
-               $this->assertSame('42_47-11_8_0_0', $fixture->getCacheIdentifier());
+               $this->pageContextMock->sys_language_uid = 8;
+               $this->pageContextMock->versioningWorkspaceId = 15;
+               $this->pageContextMock->versioningPreview = TRUE;
+               $this->fixture->__construct(42, '47-11', $this->pageContextMock);
+               $this->assertSame('42_47-11_8_15_1', $this->fixture->getCacheIdentifier());
+               $this->pageContextMock->versioningPreview = FALSE;
+               $this->fixture->__construct(42, '47-11', $this->pageContextMock);
+               $this->assertSame('42_47-11_8_15_0', $this->fixture->getCacheIdentifier());
+               $this->pageContextMock->versioningWorkspaceId = 0;
+               $this->fixture->__construct(42, '47-11', $this->pageContextMock);
+               $this->assertSame('42_47-11_8_0_0', $this->fixture->getCacheIdentifier());
        }
 
+       /**
+        * @test
+        */
+       public function getRecordArrayFetchesTranslationWhenLanguageIdIsSet() {
+               $pageData = array(
+                       'uid' => 1,
+                       'title' => 'Original',
+               );
+               $pageDataTranslated = array(
+                       'uid' => 1,
+                       'title' => 'Translated',
+                       '_PAGES_OVERLAY_UID' => '2',
+               );
+
+               $this->fixture
+                       ->expects($this->any())
+                       ->method('enrichWithRelationFields')
+                       ->with(2, $pageDataTranslated)
+                       ->will($this->returnArgument(1));
+
+               $databaseConnectionMock = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
+               $databaseConnectionMock
+                       ->expects($this->once())
+                       ->method('exec_SELECTgetSingleRow')
+                       ->will(
+                               $this->returnValue($pageData)
+                       );
+               $this->fixture->_set('databaseConnection',
+                       $databaseConnectionMock
+               );
+
+               $this->pageContextMock
+                               ->expects($this->any())
+                               ->method('getPageOverlay')
+                               ->will($this->returnValue($pageDataTranslated));
+
+               $this->fixture->_set('languageUid', 1);
+               $this->assertSame($pageDataTranslated, $this->fixture->_call('getRecordArray', 1));
+       }
 }
 
 ?>
\ No newline at end of file
index 6dd0450..b883c0e 100644 (file)
@@ -2580,13 +2580,7 @@ class TypoScriptFrontendController {
                        \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
                        $this->pageNotFoundAndExit($message);
                }
-               // Updating content of the two rootLines IF the language key is set!
-               if ($this->sys_language_uid && is_array($this->tmpl->rootLine)) {
-                       $this->tmpl->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
-               }
-               if ($this->sys_language_uid && is_array($this->rootLine)) {
-                       $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
-               }
+               $this->updateRootLinesWithTranslations();
                // Finding the ISO code:
                if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables') && $this->sys_language_content) {
                        // using sys_language_content because the ISO code only (currently) affect content selection from FlexForms - which should follow "sys_language_content"
@@ -2617,6 +2611,18 @@ class TypoScriptFrontendController {
        }
 
        /**
+        * Updating content of the two rootLines IF the language key is set!
+        */
+       protected function updateRootLinesWithTranslations() {
+               if ($this->sys_language_uid && is_array($this->tmpl->rootLine)) {
+                       $this->tmpl->rootLine = array_reverse($this->sys_page->getRootLine($this->id, $this->MP));
+               }
+               if ($this->sys_language_uid && is_array($this->rootLine)) {
+                       $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
+               }
+       }
+
+       /**
         * Setting locale for frontend rendering
         *
         * @return void
@@ -4760,5 +4766,4 @@ if (version == "n3") {
 
 }
 
-
 ?>
index 7d44ad1..4ccbc4d 100644 (file)
@@ -180,6 +180,32 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
                $this->assertSame($expectedId, $this->fixture->id);
        }
 
+       /**
+        * @test
+        */
+       public function translationOfRootLinesSetsTheTemplateRootLineToReversedVersionOfMainRootLine() {
+               $rootLine = array(
+                                       array('uid' => 1),
+                                       array('uid' => 2)
+                               );
+               $pageContextMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
+               $templateServiceMock = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
+               $pageContextMock
+                       ->expects($this->any())
+                       ->method('getRootline')
+                       ->will($this->returnValue($rootLine));
+               $this->fixture->_set('sys_page', $pageContextMock);
+               $this->fixture->_set('tmpl', $templateServiceMock);
+               $this->fixture->sys_language_uid = 1;
+               $this->fixture->rootLine = array();
+               $this->fixture->tmpl->rootLine = array();
+
+               $this->fixture->_call('updateRootLinesWithTranslations');
+               $this->assertSame($rootLine, $this->fixture->rootLine);
+               $this->assertSame(array_reverse($rootLine), $this->fixture->tmpl->rootLine);
+
+       }
+
 }
 
 ?>
\ No newline at end of file