[TASK] Migrate BackendWorkspaceRestriction to Context API 84/58484/5
authorBenni Mack <benni@typo3.org>
Sun, 30 Sep 2018 09:50:44 +0000 (11:50 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Sun, 30 Sep 2018 19:38:36 +0000 (21:38 +0200)
This patch also streamlines the Context API usage of
Workspaces in the main AbstractDataHandlerActionTestCase
class.

Resolves: #86465
Releases: master
Change-Id: I99e2a379e745494f9c23cca40ca4ad7ee1fc887f
Reviewed-on: https://review.typo3.org/58484
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
18 files changed:
typo3/sysext/core/Classes/Database/Query/Restriction/BackendWorkspaceRestriction.php
typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/FAL/AbstractActionTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/FlexformIrre/ActionTest.php
typo3/sysext/core/Tests/Functional/DataHandling/IRRE/CSV/AbstractActionTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/IRRE/ForeignField/AbstractActionTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/ManyToMany/AbstractActionTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/Regular/AbstractActionTestCase.php
typo3/sysext/extbase/Tests/Functional/Persistence/TranslatedContentLegacyTest.php
typo3/sysext/extbase/Tests/Functional/Persistence/TranslatedContentTest.php
typo3/sysext/frontend/Tests/Functional/Rendering/LocalizedContentRenderingTest.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/FAL/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Group/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/IRRE/CSV/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/IRRE/ForeignField/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/ManyToMany/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Select/AbstractActionTestCase.php

index 7979979..147c861 100644 (file)
@@ -15,8 +15,10 @@ namespace TYPO3\CMS\Core\Database\Query\Restriction;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
@@ -40,7 +42,11 @@ class BackendWorkspaceRestriction implements QueryRestrictionInterface
      */
     public function __construct(int $workspaceId = null, $includeRowsForWorkspaceOverlay = true)
     {
-        $this->workspaceId = $workspaceId ?? $GLOBALS['BE_USER']->workspace;
+        if ($workspaceId === null) {
+            $this->workspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
+        } else {
+            $this->workspaceId = $workspaceId;
+        }
         $this->includeRowsForWorkspaceOverlay = $includeRowsForWorkspaceOverlay;
     }
 
index 57409ec..4f79634 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Functional\DataHandling;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Context\Context;
+use TYPO3\CMS\Core\Context\WorkspaceAspect;
 use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -84,7 +86,7 @@ abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
 
         $this->backendUser = $this->setUpBackendUserFromFixture(self::VALUE_BackendUserId);
         // By default make tests on live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $this->actionService = $this->getActionService();
         Bootstrap::initializeLanguageObject();
@@ -99,6 +101,15 @@ abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
     }
 
     /**
+     * @param int $workspaceId
+     */
+    protected function setWorkspaceId(int $workspaceId)
+    {
+        $this->backendUser->workspace = $workspaceId;
+        GeneralUtility::makeInstance(Context::class)->setAspect('workspace', new WorkspaceAspect($workspaceId));
+    }
+
+    /**
      * @return ActionService
      */
     protected function getActionService()
index 4cef5b2..4b7467a 100644 (file)
@@ -55,7 +55,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
 
         $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
-        $this->backendUser->workspace = 0;
     }
 
     /**
index 6fd1d34..de00663 100644 (file)
@@ -41,8 +41,7 @@ class ActionTest extends AbstractDataHandlerActionTestCase
     {
         $this->importScenarioDataSet('LiveDefaultPages');
         $this->importScenarioDataSet('LiveDefaultElements');
-        $this->backendUser->workspace = 1;
-        $GLOBALS['BE_USER']->workspace = 1;
+        $this->setWorkspaceId(1);
         $this->getActionService()->modifyRecords(1, [
             //'sys_file_reference' => ['uid' => 10, 'hidden' => 0],
             'tt_content' => ['uid' => 100, 'header' => 'Content #1 (WS)']
index 796ba82..61959c7 100644 (file)
@@ -49,7 +49,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->importScenarioDataSet('LiveDefaultElements');
 
         $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
-        $this->backendUser->workspace = 0;
     }
 
     /**
index 57b32e0..b47e17d 100644 (file)
@@ -62,7 +62,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
                 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/ExtbaseJsonRenderer.typoscript',
             ]
         );
-        $this->backendUser->workspace = 0;
     }
 
     /**
index 524fd88..07aa2e7 100644 (file)
@@ -49,7 +49,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->importScenarioDataSet('LiveDefaultElements');
 
         $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
-        $this->backendUser->workspace = 0;
     }
 
     /**
index ef53941..82fafe4 100644 (file)
@@ -46,7 +46,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->importScenarioDataSet('LiveDefaultElements');
 
         $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
     }
 
     /**
index cf77d34..4e149fb 100644 (file)
@@ -84,7 +84,6 @@ class TranslatedContentLegacyTest extends AbstractDataHandlerActionTestCase
         $this->importScenarioDataSet('LiveDefaultPages');
         $this->importScenarioDataSet('LiveDefaultElements');
 
-        $this->backendUser->workspace = 0;
         $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $this->contentRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository::class);
         $this->setUpFrontendRootPage(1, [
index 4507d67..df8c6e9 100644 (file)
@@ -87,7 +87,6 @@ class TranslatedContentTest extends AbstractDataHandlerActionTestCase
         $this->importScenarioDataSet('LiveDefaultPages');
         $this->importScenarioDataSet('LiveDefaultElements');
 
-        $this->backendUser->workspace = 0;
         $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $this->contentRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository::class);
         $this->setUpFrontendRootPage(1, [
index d075958..3e1dab5 100644 (file)
@@ -112,7 +112,6 @@ class LocalizedContentRenderingTest extends \TYPO3\CMS\Core\Tests\Functional\Dat
         $this->setUpFrontendRootPage(1, [
             'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript',
         ]);
-        $this->backendUser->workspace = 0;
     }
 
     public function defaultLanguageConfigurationDataProvider(): array
index 65704a6..46a31fc 100644 (file)
@@ -38,6 +38,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     {
         parent::setUp();
         $this->importScenarioDataSet('ReferenceIndex');
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 }
index f36c84d..fd568c5 100644 (file)
@@ -37,6 +37,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     protected function setUp()
     {
         parent::setUp();
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 }
index 68220e1..3d4aa2f 100644 (file)
@@ -38,7 +38,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     {
         parent::setUp();
         $this->importScenarioDataSet('ReferenceIndex');
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
index ec59a4b..555a7d4 100644 (file)
@@ -38,7 +38,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     {
         parent::setUp();
         $this->importScenarioDataSet('ReferenceIndex');
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
index 5f75a2c..e757dab 100644 (file)
@@ -39,7 +39,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     {
         parent::setUp();
         $this->importScenarioDataSet('ReferenceIndex');
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
index dd26a06..a8e6f98 100644 (file)
@@ -47,7 +47,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->importScenarioDataSet('LivePageFreeModeElements');
         $this->importScenarioDataSet('VersionDefaultElements');
         $this->importScenarioDataSet('ReferenceIndex');
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -94,10 +94,10 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     {
         $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
         $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdFirst);
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -157,13 +157,13 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
         $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -189,13 +189,13 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->recordIds['newPageId'] = $newTableIds[static::TABLE_Page][0];
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
         $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -228,7 +228,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->recordIds['newPageIdSecond'] = $newTableIds[static::TABLE_Page][0];
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
         $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
@@ -236,7 +236,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->recordIds['copiedPageIdSecond'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdSecond']];
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -257,13 +257,13 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
         $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -284,13 +284,13 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
         $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -313,13 +313,13 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdZero, self::VALUE_PageId);
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
         $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 
     /**
@@ -346,11 +346,11 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
         $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_ParentPageId, ['title' => 'Testing #1']);
 
         // Switch to live workspace
-        $this->backendUser->workspace = 0;
+        $this->setWorkspaceId(0);
 
         $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_ParentPageId);
 
         // Switch back to draft workspace
-        $this->backendUser->workspace = static::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 }
index 86f0005..45b0c46 100644 (file)
@@ -37,6 +37,6 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     protected function setUp()
     {
         parent::setUp();
-        $this->backendUser->workspace = self::VALUE_WorkspaceId;
+        $this->setWorkspaceId(self::VALUE_WorkspaceId);
     }
 }