‪TYPO3CMS  10.4
DataHandlerHookTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
29 class ‪DataHandlerHookTest extends FunctionalTestCase
30 {
34  protected ‪$coreExtensionsToLoad = ['workspaces'];
35 
39  protected ‪$backendUser;
40 
44  protected ‪$actionService;
45 
49  protected ‪$scenarioDataSetDirectory = 'typo3/sysext/workspaces/Tests/Functional/Hook/DataSet/';
50 
54  protected ‪$assertionDataSetDirectory = 'typo3/sysext/workspaces/Tests/Functional/Hook/DataSet/';
55 
59  protected function ‪setUp(): void
60  {
61  parent::setUp();
62  $this->backendUser = $this->setUpBackendUserFromFixture(1);
64  $this->actionService = $this->‪getActionService();
65  $this->‪setWorkspaceId(0);
66  }
67 
71  protected function ‪tearDown(): void
72  {
73  unset($this->actionService);
74  parent::tearDown();
75  }
76 
80  protected function ‪setWorkspaceId(int $workspaceId)
81  {
82  $this->backendUser->workspace = $workspaceId;
83  GeneralUtility::makeInstance(Context::class)->setAspect('workspace', new ‪WorkspaceAspect($workspaceId));
84  }
85 
89  protected function ‪getActionService()
90  {
91  return GeneralUtility::makeInstance(ActionService::class);
92  }
93 
97  protected function ‪importScenarioDataSet($dataSetName)
98  {
99  $fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
100  $fileName = GeneralUtility::getFileAbsFileName($fileName);
101  $this->importCSVDataSet($fileName);
102  }
103 
107  protected function ‪assertAssertionDataSet($dataSetName)
108  {
109  $fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
110  $fileName = GeneralUtility::getFileAbsFileName($fileName);
111  $this->assertCSVDataSet($fileName);
112  }
113 
118  {
119  $this->‪importScenarioDataSet('deletingSysWorkspaceDeletesWorkspaceRecords');
120 
121  $this->‪setWorkspaceId(1);
122  // Create a pages move placeholder uid:93 and a versioned record uid:94 - both should be fully deleted after deleting ws1
123  $this->actionService->moveRecord('pages', 92, -1);
124  // Create a new placeholder uid:311 and a versioned record uid:312 - both should be fully deleted after deleting ws1
125  $this->actionService->createNewRecord('tt_content', 89, ['header' => 'Testing #1']);
126  // Create a versioned record of a translated record uid:313 - should be fully deleted after deleting ws1
127  $this->actionService->modifyRecord('tt_content', 301, ['header' => '[Translate to Dansk:] Regular Element #1 Changed']);
128  // Create a delete placeholder uid:314 - should be fully deleted after deleting ws1
129  $this->actionService->deleteRecord('tt_content', 310);
130 
131  $this->‪setWorkspaceId(2);
132  // Create a versioned record uid:315 in ws2 - should be kept after deleting ws1
133  $this->actionService->modifyRecord('tt_content', 301, ['header' => '[Translate to Dansk:] Regular Element #1 Changed in ws2']);
134 
135  // Switch to live and delete sys_workspace record 1
136  $this->‪setWorkspaceId(0);
137  $this->actionService->deleteRecord('sys_workspace', 1);
138 
139  $this->‪assertAssertionDataSet('deletingSysWorkspaceDeletesWorkspaceRecordsResult');
140  }
141 }
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook
Definition: DataHandlerHookTest.php:16
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest
Definition: DataHandlerHookTest.php:30
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\getActionService
‪ActionService getActionService()
Definition: DataHandlerHookTest.php:84
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\setUp
‪setUp()
Definition: DataHandlerHookTest.php:54
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\assertAssertionDataSet
‪assertAssertionDataSet($dataSetName)
Definition: DataHandlerHookTest.php:102
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\$scenarioDataSetDirectory
‪string $scenarioDataSetDirectory
Definition: DataHandlerHookTest.php:45
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\$actionService
‪ActionService $actionService
Definition: DataHandlerHookTest.php:41
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\$assertionDataSetDirectory
‪string $assertionDataSetDirectory
Definition: DataHandlerHookTest.php:49
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\$backendUser
‪BackendUserAuthentication $backendUser
Definition: DataHandlerHookTest.php:37
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: DataHandlerHookTest.php:33
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\deletingSysWorkspaceDeletesWorkspaceRecords
‪deletingSysWorkspaceDeletesWorkspaceRecords()
Definition: DataHandlerHookTest.php:112
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\tearDown
‪tearDown()
Definition: DataHandlerHookTest.php:66
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\setWorkspaceId
‪setWorkspaceId(int $workspaceId)
Definition: DataHandlerHookTest.php:75
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Workspaces\Tests\Functional\Hook\DataHandlerHookTest\importScenarioDataSet
‪importScenarioDataSet($dataSetName)
Definition: DataHandlerHookTest.php:92