‪TYPO3CMS  9.5
WorkspaceServiceTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
20 
24 class ‪WorkspaceServiceTest extends FunctionalTestCase
25 {
29  protected ‪$coreExtensionsToLoad = ['workspaces'];
30 
34  protected function ‪setUp()
35  {
36  parent::setUp();
37  $this->setUpBackendUserFromFixture(1);
39  $this->importDataSet(__DIR__ . '/../Fixtures/sys_workspace.xml');
40  }
41 
45  public function ‪emptyWorkspaceReturnsEmptyArray()
46  {
47  $this->markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
48  $service = new ‪WorkspaceService();
49  $result = $service->selectVersionsInWorkspace(90);
50  $this->assertEmpty($result, 'The workspace 90 contains no changes and the result was supposed to be empty');
51  $this->assertTrue(is_array($result), 'Even the empty result from workspace 90 is supposed to be an array');
52  }
53 
58  {
59  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
60  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
61  $service = new ‪WorkspaceService();
62  $result = $service->selectVersionsInWorkspace(91, 0, -99, 2);
63  $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
64  $this->assertCount(
65  1,
66  $result['pages'],
67  'The result is supposed to contain one version for this page in workspace 91'
68  );
69  $this->assertEquals(102, $result['pages'][0]['uid'], 'Wrong workspace overlay record picked');
70  $this->assertEquals(1, $result['pages'][0]['livepid'], 'Real pid wasn\'t resolved correctly');
71  }
72 
77  {
78  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
79  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
80  $service = new ‪WorkspaceService();
81  $result = $service->selectVersionsInWorkspace(‪WorkspaceService::SELECT_ALL_WORKSPACES, 0, -99, 2);
82  $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
83  $this->assertCount(
84  2,
85  $result['pages'],
86  'The result is supposed to contain one version for this page in workspace 91'
87  );
88  }
89 
93  public function ‪versionsCanBeFoundRecursive()
94  {
95  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
96  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
97  $service = new ‪WorkspaceService();
98  $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
99  $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
100  $this->assertCount(
101  4,
102  $result['pages'],
103  'The result is supposed to contain four versions for this page in workspace 91'
104  );
105  }
106 
111  {
112  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
113  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
114  $service = new ‪WorkspaceService();
115  // testing stage 1
116  $result = $service->selectVersionsInWorkspace(91, 0, 1, 1, 99);
117  $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
118  $this->assertCount(
119  2,
120  $result['pages'],
121  'The result is supposed to contain two versions for this page in workspace 91'
122  );
123  $this->assertEquals(102, $result['pages'][0]['uid'], 'First records is supposed to have the uid 102');
124  $this->assertEquals(105, $result['pages'][1]['uid'], 'First records is supposed to have the uid 105');
125  // testing stage 2
126  $result = $service->selectVersionsInWorkspace(91, 0, 2, 1, 99);
127  $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
128  $this->assertCount(
129  2,
130  $result['pages'],
131  'The result is supposed to contain two versions for this page in workspace 91'
132  );
133  $this->assertEquals(104, $result['pages'][0]['uid'], 'First records is supposed to have the uid 106');
134  $this->assertEquals(106, $result['pages'][1]['uid'], 'First records is supposed to have the uid 106');
135  }
136 
141  {
142  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
143  $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
144  $service = new ‪WorkspaceService();
145  // testing all "draft" records
146  $result = $service->selectVersionsInWorkspace(91, 1, -99, 1, 99);
147  $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
148  $this->assertCount(
149  2,
150  $result['pages'],
151  'The result is supposed to contain three versions for this page in workspace 91'
152  );
153  // testing all "archive" records
154  $result = $service->selectVersionsInWorkspace(91, 2, -99, 1, 99);
155  $this->assertCount(
156  2,
157  $result['pages'],
158  'The result is supposed to contain two versions for this page in workspace 91'
159  );
160  // testing both types records
161  $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
162  $this->assertCount(
163  4,
164  $result['pages'],
165  'The result is supposed to contain two versions for this page in workspace 91'
166  );
167  }
168 
176  {
177  $this->markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
178  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
179  // Test if the placeholder can be found when we ask using recursion (same result)
180  $service = new ‪WorkspaceService();
181  $result = $service->selectVersionsInWorkspace(91, 0, -99, 2, 99);
182  $this->assertCount(
183  0,
184  $result['pages'],
185  'Changes should not show up in this branch of the tree within workspace 91'
186  );
187  $this->assertCount(
188  0,
189  $result['tt_content'],
190  'Changes should not show up in this branch of the tree within workspace 91'
191  );
192  }
193 
198  {
199  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
200  // Test if the placeholder can be found when we ask using recursion (same result)
201  $service = new ‪WorkspaceService();
202  $result = $service->selectVersionsInWorkspace(91, 0, -99, 5, 99);
203  $this->assertCount(1, $result['pages'], 'Wrong amount of page versions found within workspace 91');
204  $this->assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
205  $this->assertEquals(5, $result['pages'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
206  $this->assertEquals(2, $result['pages'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
207  $this->assertCount(1, $result['tt_content'], 'Wrong amount of tt_content versions found within workspace 91');
208  $this->assertEquals(106, $result['tt_content'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
209  $this->assertEquals(7, $result['tt_content'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
210  $this->assertEquals(2, $result['tt_content'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
211  }
212 
217  {
218  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
219  // Test if the placeholder can be found when we ask using recursion (same result)
220  $service = new ‪WorkspaceService();
221  $result = $service->selectVersionsInWorkspace(91, 0, -99, 3, 99);
222  $this->assertCount(1, $result, 'Wrong amount of versions found within workspace 91');
223  $this->assertCount(1, $result['pages'], 'Wrong amount of page versions found within workspace 91');
224  $this->assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
225  }
226 
231  {
232  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
233  $workspaceService = new ‪WorkspaceService();
234  $result = $workspaceService->getPagesWithVersionsInTable(91);
235  $expected = [
236  'sys_category' => [],
237  'sys_collection' => [],
238  'sys_file_collection' => [],
239  'sys_file_metadata' => [],
240  'sys_file_reference' => [],
241  'backend_layout' => [],
242  'sys_template' => [],
243  'tt_content' => [
244  1 => true,
245  7 => true,
246  ]
247  ];
248  self::assertSame($expected, $result);
249  }
250 
255  {
256  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
257  $workspaceService = new ‪WorkspaceService();
258  $result = $workspaceService->hasPageRecordVersions(91, 7);
259  self::assertTrue($result);
260  }
261 
266  {
267  $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
268  $workspaceService = new ‪WorkspaceService();
269  $result = $workspaceService->hasPageRecordVersions(91, 3);
270  self::assertFalse($result);
271  }
272 }
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\hasPageRecordVersionsReturnsTrueForPageWithVersions
‪hasPageRecordVersionsReturnsTrueForPageWithVersions()
Definition: WorkspaceServiceTest.php:253
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsFromAllWorkspaceCanBeFound
‪versionsFromAllWorkspaceCanBeFound()
Definition: WorkspaceServiceTest.php:75
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest
Definition: WorkspaceServiceTest.php:25
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsCanBeFoundRecursive
‪versionsCanBeFoundRecursive()
Definition: WorkspaceServiceTest.php:92
‪TYPO3\CMS\Workspaces\Tests\Functional\Service
Definition: WorkspaceServiceTest.php:2
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\setUp
‪setUp()
Definition: WorkspaceServiceTest.php:33
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\movedElementsCanBeFoundUsingTheirLiveUid
‪movedElementsCanBeFoundUsingTheirLiveUid()
Definition: WorkspaceServiceTest.php:215
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\hasPageRecordVersionsReturnsFalseForPageWithoutVersions
‪hasPageRecordVersionsReturnsFalseForPageWithoutVersions()
Definition: WorkspaceServiceTest.php:264
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsCanBeFilteredToSpecificStage
‪versionsCanBeFilteredToSpecificStage()
Definition: WorkspaceServiceTest.php:109
‪TYPO3\CMS\Workspaces\Service\WorkspaceService\SELECT_ALL_WORKSPACES
‪const SELECT_ALL_WORKSPACES
Definition: WorkspaceService.php:44
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\movedElementsCanBeFoundAtTheirDestination
‪movedElementsCanBeFoundAtTheirDestination()
Definition: WorkspaceServiceTest.php:196
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: WorkspaceServiceTest.php:28
‪TYPO3\CMS\Workspaces\Service\WorkspaceService
Definition: WorkspaceService.php:34
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\movedElementsCanNotBeFoundAtTheirOrigin
‪movedElementsCanNotBeFoundAtTheirOrigin()
Definition: WorkspaceServiceTest.php:174
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\emptyWorkspaceReturnsEmptyArray
‪emptyWorkspaceReturnsEmptyArray()
Definition: WorkspaceServiceTest.php:44
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsFromSpecificWorkspaceCanBeFound
‪versionsFromSpecificWorkspaceCanBeFound()
Definition: WorkspaceServiceTest.php:56
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\getPagesWithVersionsInTableReturnsPagesWithVersionsInTable
‪getPagesWithVersionsInTableReturnsPagesWithVersionsInTable()
Definition: WorkspaceServiceTest.php:229
‪TYPO3\CMS\Workspaces\Tests\Functional\Service\WorkspaceServiceTest\versionsCanBeFilteredToSpecificLifecycleStep
‪versionsCanBeFilteredToSpecificLifecycleStep()
Definition: WorkspaceServiceTest.php:139
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986