‪TYPO3CMS  10.4
WorkspaceServiceTest.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 
20 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
21 
25 class ‪WorkspaceServiceTest extends FunctionalTestCase
26 {
30  protected ‪$coreExtensionsToLoad = ['workspaces'];
31 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->setUpBackendUserFromFixture(1);
40  $this->importDataSet(__DIR__ . '/../Fixtures/sys_workspace.xml');
41  }
42 
46  public function ‪emptyWorkspaceReturnsEmptyArray()
47  {
48  self::markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
49  $service = new ‪WorkspaceService();
50  $result = $service->selectVersionsInWorkspace(90);
51  self::assertEmpty($result, 'The workspace 90 contains no changes and the result was supposed to be empty');
52  self::assertTrue(is_array($result), 'Even the empty result from workspace 90 is supposed to be an array');
53  }
54 
59  {
60  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
61  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
62  $service = new ‪WorkspaceService();
63  $result = $service->selectVersionsInWorkspace(91, 0, -99, 2);
64  self::assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
65  self::assertCount(
66  1,
67  $result['pages'],
68  'The result is supposed to contain one version for this page in workspace 91'
69  );
70  self::assertEquals(102, $result['pages'][0]['uid'], 'Wrong workspace overlay record picked');
71  self::assertEquals(1, $result['pages'][0]['livepid'], 'Real pid wasn\'t resolved correctly');
72  }
73 
77  public function ‪versionsCanBeFoundRecursive()
78  {
79  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
80  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
81  $service = new ‪WorkspaceService();
82  $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
83  self::assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
84  self::assertCount(
85  4,
86  $result['pages'],
87  'The result is supposed to contain four versions for this page in workspace 91'
88  );
89  }
90 
95  {
96  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
97  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
98  $service = new ‪WorkspaceService();
99  // testing stage 1
100  $result = $service->selectVersionsInWorkspace(91, 0, 1, 1, 99);
101  self::assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
102  self::assertCount(
103  2,
104  $result['pages'],
105  'The result is supposed to contain two versions for this page in workspace 91'
106  );
107  self::assertEquals(102, $result['pages'][0]['uid'], 'First records is supposed to have the uid 102');
108  self::assertEquals(105, $result['pages'][1]['uid'], 'First records is supposed to have the uid 105');
109  // testing stage 2
110  $result = $service->selectVersionsInWorkspace(91, 0, 2, 1, 99);
111  self::assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
112  self::assertCount(
113  2,
114  $result['pages'],
115  'The result is supposed to contain two versions for this page in workspace 91'
116  );
117  self::assertEquals(104, $result['pages'][0]['uid'], 'First records is supposed to have the uid 106');
118  self::assertEquals(106, $result['pages'][1]['uid'], 'First records is supposed to have the uid 106');
119  }
120 
125  {
126  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
127  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
128  $service = new ‪WorkspaceService();
129  // testing all "draft" records
130  $result = $service->selectVersionsInWorkspace(91, 1, -99, 1, 99);
131  self::assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
132  self::assertCount(
133  2,
134  $result['pages'],
135  'The result is supposed to contain three versions for this page in workspace 91'
136  );
137  // testing all "archive" records
138  $result = $service->selectVersionsInWorkspace(91, 2, -99, 1, 99);
139  self::assertCount(
140  2,
141  $result['pages'],
142  'The result is supposed to contain two versions for this page in workspace 91'
143  );
144  // testing both types records
145  $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
146  self::assertCount(
147  4,
148  $result['pages'],
149  'The result is supposed to contain two versions for this page in workspace 91'
150  );
151  }
152 
160  {
161  self::markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
162  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
163  // Test if the placeholder can be found when we ask using recursion (same result)
164  $service = new ‪WorkspaceService();
165  $result = $service->selectVersionsInWorkspace(91, 0, -99, 2, 99);
166  self::assertCount(
167  0,
168  $result['pages'],
169  'Changes should not show up in this branch of the tree within workspace 91'
170  );
171  self::assertCount(
172  0,
173  $result['tt_content'],
174  'Changes should not show up in this branch of the tree within workspace 91'
175  );
176  }
177 
182  {
183  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
184  // Test if the placeholder can be found when we ask using recursion (same result)
185  $service = new ‪WorkspaceService();
186  $result = $service->selectVersionsInWorkspace(91, 0, -99, 5, 99);
187  self::assertCount(1, $result['pages'], 'Wrong amount of page versions found within workspace 91');
188  self::assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
189  self::assertEquals(5, $result['pages'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
190  self::assertEquals(2, $result['pages'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
191  self::assertCount(1, $result['tt_content'], 'Wrong amount of tt_content versions found within workspace 91');
192  self::assertEquals(106, $result['tt_content'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
193  self::assertEquals(7, $result['tt_content'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
194  self::assertEquals(2, $result['tt_content'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
195  }
196 
201  {
202  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
203  // Test if the placeholder can be found when we ask using recursion (same result)
204  $service = new ‪WorkspaceService();
205  $result = $service->selectVersionsInWorkspace(91, 0, -99, 3, 99);
206  self::assertCount(1, $result, 'Wrong amount of versions found within workspace 91');
207  self::assertCount(1, $result['pages'], 'Wrong amount of page versions found within workspace 91');
208  self::assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
209  }
210 
215  {
216  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
217  $workspaceService = new ‪WorkspaceService();
218  $result = $workspaceService->getPagesWithVersionsInTable(91);
219  $expected = [
220  'sys_category' => [],
221  'sys_collection' => [],
222  'sys_file_collection' => [],
223  'sys_file_metadata' => [],
224  'sys_file_reference' => [],
225  'backend_layout' => [],
226  'sys_template' => [],
227  'tt_content' => [
228  1 => true,
229  7 => true,
230  ]
231  ];
232  self::assertSame($expected, $result);
233  }
234 
239  {
240  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
241  $workspaceService = new ‪WorkspaceService();
242  $result = $workspaceService->hasPageRecordVersions(91, 7);
243  self::assertTrue($result);
244  }
245 
250  {
251  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
252  $workspaceService = new ‪WorkspaceService();
253  $result = $workspaceService->hasPageRecordVersions(91, 3);
254  self::assertFalse($result);
255  }
256 }
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\hasPageRecordVersionsReturnsTrueForPageWithVersions
‪hasPageRecordVersionsReturnsTrueForPageWithVersions()
Definition: WorkspaceServiceTest.php:237
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest
Definition: WorkspaceServiceTest.php:26
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsCanBeFoundRecursive
‪versionsCanBeFoundRecursive()
Definition: WorkspaceServiceTest.php:76
‪TYPO3\CMS\Workspaces\Tests\Functional\Service
Definition: WorkspaceServiceTest.php:16
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\setUp
‪setUp()
Definition: WorkspaceServiceTest.php:34
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\movedElementsCanBeFoundUsingTheirLiveUid
‪movedElementsCanBeFoundUsingTheirLiveUid()
Definition: WorkspaceServiceTest.php:199
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\hasPageRecordVersionsReturnsFalseForPageWithoutVersions
‪hasPageRecordVersionsReturnsFalseForPageWithoutVersions()
Definition: WorkspaceServiceTest.php:248
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsCanBeFilteredToSpecificStage
‪versionsCanBeFilteredToSpecificStage()
Definition: WorkspaceServiceTest.php:93
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\movedElementsCanBeFoundAtTheirDestination
‪movedElementsCanBeFoundAtTheirDestination()
Definition: WorkspaceServiceTest.php:180
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: WorkspaceServiceTest.php:29
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:36
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\movedElementsCanNotBeFoundAtTheirOrigin
‪movedElementsCanNotBeFoundAtTheirOrigin()
Definition: WorkspaceServiceTest.php:158
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\emptyWorkspaceReturnsEmptyArray
‪emptyWorkspaceReturnsEmptyArray()
Definition: WorkspaceServiceTest.php:45
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsFromSpecificWorkspaceCanBeFound
‪versionsFromSpecificWorkspaceCanBeFound()
Definition: WorkspaceServiceTest.php:57
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\getPagesWithVersionsInTableReturnsPagesWithVersionsInTable
‪getPagesWithVersionsInTableReturnsPagesWithVersionsInTable()
Definition: WorkspaceServiceTest.php:213
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsCanBeFilteredToSpecificLifecycleStep
‪versionsCanBeFilteredToSpecificLifecycleStep()
Definition: WorkspaceServiceTest.php:123