[TASK] Streamline initialization of PageRepository 31/57431/5
authorBenni Mack <benni@typo3.org>
Sun, 1 Jul 2018 15:24:21 +0000 (17:24 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Mon, 2 Jul 2018 12:10:30 +0000 (14:10 +0200)
PageRepository ($TSFE->sys_page) has an init() function, which sets
some public properties, but is also called from the constructor.

However, there is the ominous $TSFE->setSysPageWhereClause()
which can only be set once the frontend user groups have been resolved.

In order to achieve that, the usergroup initialization within TSFE has
been moved before the intantiation of $TSFE->sys_page, allowing the
pagerepository constructor to set the variables directly, moving all
of the initialization code into PageRepository itself.

Resolves: #85450
Releases: master
Change-Id: I53dbdc0531076a47bcdf04617bfb1eae70e74279
Reviewed-on: https://review.typo3.org/57431
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/frontend/Tests/Functional/Page/PageRepositoryTest.php
typo3/sysext/viewpage/Classes/Controller/ViewModuleController.php

index b6b8ad6..36637f5 100644 (file)
@@ -2772,9 +2772,8 @@ class BackendUtility
         }
 
         // Check a mount point needs to be previewed
-        $sys_page = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
-        $sys_page->init(false);
-        $mountPointInfo = $sys_page->getMountPointInfo($pageUid);
+        $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
+        $mountPointInfo = $pageRepository->getMountPointInfo($pageUid);
 
         if ($mountPointInfo && $mountPointInfo['overlay']) {
             $pageUid = $mountPointInfo['mount_pid'];
index 1e886aa..c7e0c06 100644 (file)
@@ -32,7 +32,6 @@ use TYPO3\CMS\Core\Context\WorkspaceAspect;
 use TYPO3\CMS\Core\Controller\ErrorPageController;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\Query\QueryHelper;
 use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
@@ -1320,12 +1319,11 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     {
         $timeTracker = $this->getTimeTracker();
         $timeTracker->push('fetch_the_id initialize/');
-        // Initialize the page-select functions.
-        $this->sys_page = GeneralUtility::makeInstance(PageRepository::class, $this->context);
         // Set the valid usergroups for FE
         $this->initUserGroups();
-        // Sets sys_page where-clause
-        $this->setSysPageWhereClause();
+        // Initialize the PageRepository has to be done after the frontend usergroups are initialized / resolved, as
+        // frontend group aspect is modified before
+        $this->sys_page = GeneralUtility::makeInstance(PageRepository::class, $this->context);
         // If $this->id is a string, it's an alias
         $this->checkAndSetAlias();
         // The id and type is set to the integer-value - just to be sure...
@@ -1867,21 +1865,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     }
 
     /**
-     * Sets sys_page where-clause
-     */
-    protected function setSysPageWhereClause()
-    {
-        $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-            ->getConnectionForTable('pages')
-            ->getExpressionBuilder();
-        $this->sys_page->where_hid_del = ' AND ' . (string)$expressionBuilder->andX(
-            QueryHelper::stripLogicalOperatorPrefix($this->sys_page->where_hid_del),
-            $expressionBuilder->lt('pages.doktype', 200)
-        );
-        $this->sys_page->where_groupAccess = $this->sys_page->getMultipleGroupsWhereClause('pages.fe_group', 'pages');
-    }
-
-    /**
      * Page unavailable handler for use in frontend plugins from extensions.
      *
      * @param string $reason Reason text
index ecfb6f0..ed3ba69 100644 (file)
@@ -195,7 +195,12 @@ class PageRepository implements LoggerAwareInterface
     {
         $this->context = $context ?? GeneralUtility::makeInstance(Context::class);
         $this->versioningWorkspaceId = $this->context->getPropertyFromAspect('workspace', 'id');
-        $this->init($this->context->getPropertyFromAspect('visibility', 'includeHiddenPages'));
+        // Only set up the where clauses for pages when TCA is set. This usually happens only in tests.
+        // Once all tests are written very well, this can be removed again
+        if (isset($GLOBALS['TCA']['pages'])) {
+            $this->init($this->context->getPropertyFromAspect('visibility', 'includeHiddenPages'));
+            $this->where_groupAccess = $this->getMultipleGroupsWhereClause('pages.fe_group', 'pages');
+        }
     }
 
     /**
@@ -209,32 +214,34 @@ class PageRepository implements LoggerAwareInterface
      */
     public function init($show_hidden)
     {
-        // This usually happens only in tests.
-        if (!isset($GLOBALS['TCA']['pages'])) {
-            return;
-        }
         $this->where_groupAccess = '';
 
+        $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable('pages')
+            ->expr();
         if ($this->versioningWorkspaceId) {
             // For version previewing, make sure that enable-fields are not
             // de-selecting hidden pages - we need versionOL() to unset them only
             // if the overlay record instructs us to.
             // Clear where_hid_del and restrict to live and current workspaces
-            $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-                ->getQueryBuilderForTable('pages')
-                ->expr();
             $this->where_hid_del = ' AND ' . $expressionBuilder->andX(
                 $expressionBuilder->eq('pages.deleted', 0),
                 $expressionBuilder->orX(
                     $expressionBuilder->eq('pages.t3ver_wsid', 0),
                     $expressionBuilder->eq('pages.t3ver_wsid', (int)$this->versioningWorkspaceId)
-                )
+                ),
+                $expressionBuilder->lt('pages.doktype', 200)
             );
         } else {
             // add starttime / endtime, and check for hidden/deleted
             // Filter out new/deleted place-holder pages in case we are NOT in a
             // versioning preview (that means we are online!)
-            $this->where_hid_del = $this->enableFields('pages', $show_hidden, ['fe_group' => true], true);
+            $this->where_hid_del = ' AND ' . (string)$expressionBuilder->andX(
+                QueryHelper::stripLogicalOperatorPrefix(
+                    $this->enableFields('pages', $show_hidden, ['fe_group' => true], true)
+                ),
+                $expressionBuilder->lt('pages.doktype', 200)
+            );
         }
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class]['init'] ?? false)) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class]['init'] as $classRef) {
@@ -267,7 +274,6 @@ class PageRepository implements LoggerAwareInterface
      *
      * @see PageRepository::where_groupAccess
      * @see PageRepository::where_hid_del
-     * @see PageRepository::init()
      *
      * By default the usergroup access check is enabled. Use the second method argument
      * to disable the usergroup access check.
@@ -1518,12 +1524,16 @@ class PageRepository implements LoggerAwareInterface
      */
     public function getMultipleGroupsWhereClause($field, $table)
     {
-        $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-            ->getQueryBuilderForTable($table)
-            ->expr();
+        if (!$this->context->hasAspect('frontend.user')) {
+            return '';
+        }
         /** @var UserAspect $userAspect */
         $userAspect = $this->context->getAspect('frontend.user');
         $memberGroups = $userAspect->getGroupIds();
+
+        $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable($table)
+            ->expr();
         $orChecks = [];
         // If the field is empty, then OK
         $orChecks[] = $expressionBuilder->eq($field, $expressionBuilder->literal(''));
index e501526..d7fee33 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Frontend\Tests\Functional\Page;
  */
 
 use Prophecy\Argument;
+use TYPO3\CMS\Core\Context\Context;
+use TYPO3\CMS\Core\Context\WorkspaceAspect;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\Page\PageRepository;
@@ -27,17 +29,10 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
 {
     protected $coreExtensionsToLoad = ['frontend'];
 
-    /**
-     * @var \TYPO3\CMS\Frontend\Page\PageRepository
-     */
-    protected $pageRepo;
-
     protected function setUp()
     {
         parent::setUp();
         $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
-        $this->pageRepo = new PageRepository();
-        $this->pageRepo->init(false);
     }
 
     /**
@@ -45,7 +40,8 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getMenuSingleUidRoot()
     {
-        $rows = $this->pageRepo->getMenu(1, 'uid, title');
+        $subject = new PageRepository();
+        $rows = $subject->getMenu(1, 'uid, title');
         $this->assertArrayHasKey(2, $rows);
         $this->assertArrayHasKey(3, $rows);
         $this->assertArrayHasKey(4, $rows);
@@ -57,7 +53,8 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getMenuSingleUidSubpage()
     {
-        $rows = $this->pageRepo->getMenu(2, 'uid, title');
+        $subject = new PageRepository();
+        $rows = $subject->getMenu(2, 'uid, title');
         $this->assertArrayHasKey(5, $rows);
         $this->assertArrayHasKey(6, $rows);
         $this->assertArrayHasKey(7, $rows);
@@ -69,7 +66,8 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getMenuMultipleUid()
     {
-        $rows = $this->pageRepo->getMenu([2, 3], 'uid, title');
+        $subject = new PageRepository();
+        $rows = $subject->getMenu([2, 3], 'uid, title');
         $this->assertArrayHasKey(5, $rows);
         $this->assertArrayHasKey(6, $rows);
         $this->assertArrayHasKey(7, $rows);
@@ -83,9 +81,10 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getMenuPageOverlay()
     {
-        $this->pageRepo->sys_language_uid = 1;
+        $subject = new PageRepository();
+        $subject->sys_language_uid = 1;
 
-        $rows = $this->pageRepo->getMenu([2, 3], 'uid, title');
+        $rows = $subject->getMenu([2, 3], 'uid, title');
         $this->assertEquals('Attrappe 1-2-5', $rows[5]['title']);
         $this->assertEquals('Attrappe 1-2-6', $rows[6]['title']);
         $this->assertEquals('Dummy 1-2-7', $rows[7]['title']);
@@ -99,7 +98,8 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPageOverlayById()
     {
-        $row = $this->pageRepo->getPageOverlay(1, 1);
+        $subject = new PageRepository();
+        $row = $subject->getPageOverlay(1, 1);
         $this->assertOverlayRow($row);
         $this->assertEquals('Wurzel 1', $row['title']);
         $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
@@ -111,7 +111,8 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPageOverlayByIdWithoutTranslation()
     {
-        $row = $this->pageRepo->getPageOverlay(4, 1);
+        $subject = new PageRepository();
+        $row = $subject->getPageOverlay(4, 1);
         $this->assertInternalType('array', $row);
         $this->assertCount(0, $row);
     }
@@ -121,8 +122,9 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPageOverlayByRow()
     {
-        $orig = $this->pageRepo->getPage(1);
-        $row = $this->pageRepo->getPageOverlay($orig, 1);
+        $subject = new PageRepository();
+        $orig = $subject->getPage(1);
+        $row = $subject->getPageOverlay($orig, 1);
         $this->assertOverlayRow($row);
         $this->assertEquals(1, $row['uid']);
         $this->assertEquals('Wurzel 1', $row['title']);
@@ -135,8 +137,9 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPageOverlayByRowWithoutTranslation()
     {
-        $orig = $this->pageRepo->getPage(4);
-        $row = $this->pageRepo->getPageOverlay($orig, 1);
+        $subject = new PageRepository();
+        $orig = $subject->getPage(4);
+        $row = $subject->getPageOverlay($orig, 1);
         $this->assertInternalType('array', $row);
         $this->assertEquals(4, $row['uid']);
         $this->assertEquals('Dummy 1-4', $row['title']);//original title
@@ -147,8 +150,9 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPagesOverlayByIdSingle()
     {
-        $this->pageRepo->sys_language_uid = 1;
-        $rows = $this->pageRepo->getPagesOverlay([1]);
+        $subject = new PageRepository();
+        $subject->sys_language_uid = 1;
+        $rows = $subject->getPagesOverlay([1]);
         $this->assertInternalType('array', $rows);
         $this->assertCount(1, $rows);
         $this->assertArrayHasKey(0, $rows);
@@ -165,8 +169,9 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPagesOverlayByIdMultiple()
     {
-        $this->pageRepo->sys_language_uid = 1;
-        $rows = $this->pageRepo->getPagesOverlay([1, 5]);
+        $subject = new PageRepository();
+        $subject->sys_language_uid = 1;
+        $rows = $subject->getPagesOverlay([1, 5]);
         $this->assertInternalType('array', $rows);
         $this->assertCount(2, $rows);
         $this->assertArrayHasKey(0, $rows);
@@ -190,8 +195,9 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPagesOverlayByIdMultipleSomeNotOverlaid()
     {
-        $this->pageRepo->sys_language_uid = 1;
-        $rows = $this->pageRepo->getPagesOverlay([1, 4, 5, 8]);
+        $subject = new PageRepository();
+        $subject->sys_language_uid = 1;
+        $rows = $subject->getPagesOverlay([1, 4, 5, 8]);
         $this->assertInternalType('array', $rows);
         $this->assertCount(2, $rows);
         $this->assertArrayHasKey(0, $rows);
@@ -211,10 +217,11 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPagesOverlayByRowSingle()
     {
-        $origRow = $this->pageRepo->getPage(1);
+        $subject = new PageRepository();
+        $origRow = $subject->getPage(1);
 
-        $this->pageRepo->sys_language_uid = 1;
-        $rows = $this->pageRepo->getPagesOverlay([$origRow]);
+        $subject->sys_language_uid = 1;
+        $rows = $subject->getPagesOverlay([$origRow]);
         $this->assertInternalType('array', $rows);
         $this->assertCount(1, $rows);
         $this->assertArrayHasKey(0, $rows);
@@ -231,11 +238,12 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPagesOverlayByRowMultiple()
     {
-        $orig1 = $this->pageRepo->getPage(1);
-        $orig2 = $this->pageRepo->getPage(5);
+        $subject = new PageRepository();
+        $orig1 = $subject->getPage(1);
+        $orig2 = $subject->getPage(5);
 
-        $this->pageRepo->sys_language_uid = 1;
-        $rows = $this->pageRepo->getPagesOverlay([1 => $orig1, 5 => $orig2]);
+        $subject->sys_language_uid = 1;
+        $rows = $subject->getPagesOverlay([1 => $orig1, 5 => $orig2]);
         $this->assertInternalType('array', $rows);
         $this->assertCount(2, $rows);
         $this->assertArrayHasKey(1, $rows);
@@ -259,12 +267,13 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function getPagesOverlayByRowMultipleSomeNotOverlaid()
     {
-        $orig1 = $this->pageRepo->getPage(1);
-        $orig2 = $this->pageRepo->getPage(7);
-        $orig3 = $this->pageRepo->getPage(9);
+        $subject = new PageRepository();
+        $orig1 = $subject->getPage(1);
+        $orig2 = $subject->getPage(7);
+        $orig3 = $subject->getPage(9);
 
-        $this->pageRepo->sys_language_uid = 1;
-        $rows = $this->pageRepo->getPagesOverlay([$orig1, $orig2, $orig3]);
+        $subject->sys_language_uid = 1;
+        $rows = $subject->getPagesOverlay([$orig1, $orig2, $orig3]);
         $this->assertInternalType('array', $rows);
         $this->assertCount(3, $rows);
         $this->assertArrayHasKey(0, $rows);
@@ -301,7 +310,8 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
         // Register hook mock object
         GeneralUtility::addInstance($className, $getPageHookMock);
         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
-        $this->pageRepo->getPage(42, false);
+        $subject = new PageRepository();
+        $subject->getPage(42, false);
     }
 
     /**
@@ -309,19 +319,22 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
      */
     public function initSetsPublicPropertyCorrectlyForWorkspacePreview()
     {
-        $this->pageRepo->versioningWorkspaceId = 2;
-        $this->pageRepo->init(false);
+        $workspaceId = 2;
+        $subject = new PageRepository(new Context([
+            'workspace' => new WorkspaceAspect($workspaceId)
+        ]));
 
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
 
         $expectedSQL = sprintf(
-            ' AND (%s = 0) AND ((%s = 0) OR (%s = 2))',
+            ' AND (%s = 0) AND ((%s = 0) OR (%s = 2)) AND (%s < 200)',
             $connection->quoteIdentifier('pages.deleted'),
             $connection->quoteIdentifier('pages.t3ver_wsid'),
-            $connection->quoteIdentifier('pages.t3ver_wsid')
+            $connection->quoteIdentifier('pages.t3ver_wsid'),
+            $connection->quoteIdentifier('pages.doktype')
         );
 
-        $this->assertSame($expectedSQL, $this->pageRepo->where_hid_del);
+        $this->assertSame($expectedSQL, $subject->where_hid_del);
     }
 
     /**
@@ -331,21 +344,21 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
     {
         $GLOBALS['SIM_ACCESS_TIME'] = 123;
 
-        $this->pageRepo->versioningWorkspaceId = 0;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context());
 
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
         $expectedSQL = sprintf(
-            ' AND (%s = 0) AND (%s <= 0) AND (%s = 0) AND (%s <= 123) AND ((%s = 0) OR (%s > 123))',
+            ' AND ((%s = 0) AND (%s <= 0) AND (%s = 0) AND (%s <= 123) AND ((%s = 0) OR (%s > 123))) AND (%s < 200)',
             $connection->quoteIdentifier('pages.deleted'),
             $connection->quoteIdentifier('pages.t3ver_state'),
             $connection->quoteIdentifier('pages.hidden'),
             $connection->quoteIdentifier('pages.starttime'),
             $connection->quoteIdentifier('pages.endtime'),
-            $connection->quoteIdentifier('pages.endtime')
+            $connection->quoteIdentifier('pages.endtime'),
+            $connection->quoteIdentifier('pages.doktype')
         );
 
-        $this->assertSame($expectedSQL, $this->pageRepo->where_hid_del);
+        $this->assertSame($expectedSQL, $subject->where_hid_del);
     }
 
     ////////////////////////////////
@@ -359,12 +372,12 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
     {
         // initialization
         $wsid = 987654321;
-
         // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
-        $this->pageRepo->versioningWorkspaceId = $wsid;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context([
+            'workspace' => new WorkspaceAspect($wsid)
+        ]));
 
-        $pageRec = $this->pageRepo->getPage(11);
+        $pageRec = $subject->getPage(11);
 
         $this->assertEquals(11, $pageRec['uid']);
         $this->assertEquals(11, $pageRec['t3ver_oid']);
@@ -382,10 +395,11 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
         $wsid = 987654321;
 
         // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
-        $this->pageRepo->versioningWorkspaceId = $wsid;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context([
+            'workspace' => new WorkspaceAspect($wsid)
+        ]));
 
-        $pageRec = $this->pageRepo->getWorkspaceVersionOfRecord($wsid, 'pages', 11);
+        $pageRec = $subject->getWorkspaceVersionOfRecord($wsid, 'pages', 11);
 
         $this->assertEquals(12, $pageRec['uid']);
         $this->assertEquals(11, $pageRec['t3ver_oid']);
@@ -410,10 +424,9 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
             ]
         ];
 
-        $this->pageRepo->versioningWorkspaceId = 0;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context());
 
-        $conditions = $this->pageRepo->enableFields($table);
+        $conditions = $subject->enableFields($table);
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
 
         $this->assertThat(
@@ -440,10 +453,11 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
             ]
         ];
 
-        $this->pageRepo->versioningWorkspaceId = 13;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context([
+            'workspace' => new WorkspaceAspect(13)
+        ]));
 
-        $conditions = $this->pageRepo->enableFields($table);
+        $conditions = $subject->enableFields($table);
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
 
         $this->assertThat(
@@ -470,10 +484,11 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
             ]
         ];
 
-        $this->pageRepo->versioningWorkspaceId = 2;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context([
+            'workspace' => new WorkspaceAspect(2)
+        ]));
 
-        $conditions = $this->pageRepo->enableFields($table);
+        $conditions = $subject->enableFields($table);
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
 
         $this->assertThat(
@@ -495,10 +510,11 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
             ]
         ];
 
-        $this->pageRepo->versioningWorkspaceId = 23;
-        $this->pageRepo->init(false);
+        $subject = new PageRepository(new Context([
+            'workspace' => new WorkspaceAspect(23)
+        ]));
 
-        $conditions = $this->pageRepo->enableFields($table, -1, [], true);
+        $conditions = $subject->enableFields($table, -1, [], true);
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
 
         $this->assertThat(
index 1481861..2fd0133 100644 (file)
@@ -33,6 +33,7 @@ use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
 use TYPO3\CMS\Fluid\View\StandaloneView;
+use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * Controller for viewing the frontend
@@ -208,12 +209,10 @@ class ViewModuleController
             $domainName = $this->getDomainName($pageId);
             $languageParameter = $languageId ? '&L=' . $languageId : '';
             // Mount point overlay: Set new target page id and mp parameter
-            /** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPage */
-            $sysPage = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
-            $sysPage->init(false);
+            $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
             $mountPointMpParameter = '';
             $finalPageIdToShow = $pageId;
-            $mountPointInformation = $sysPage->getMountPointInfo($pageId);
+            $mountPointInformation = $pageRepository->getMountPointInfo($pageId);
             if ($mountPointInformation && $mountPointInformation['overlay']) {
                 // New page id
                 $finalPageIdToShow = $mountPointInformation['mount_pid'];