[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Tests / Functional / Service / WorkspaceServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Tests\Functional\Service;
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
17 /**
18 * Workspace service test
19 */
20 class WorkspaceServiceTest extends \TYPO3\CMS\Components\TestingFramework\Core\FunctionalTestCase
21 {
22 protected $coreExtensionsToLoad = ['version', 'workspaces'];
23
24 /**
25 * Set up
26 */
27 protected function setUp()
28 {
29 parent::setUp();
30 $this->setUpBackendUserFromFixture(1);
31 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
32 $this->importDataSet(__DIR__ . '/../Fixtures/sys_workspace.xml');
33 }
34
35 /**
36 * @test
37 */
38 public function emptyWorkspaceReturnsEmptyArray()
39 {
40 $this->markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
41 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
42 $result = $service->selectVersionsInWorkspace(90);
43 $this->assertTrue(empty($result), 'The workspace 90 contains no changes and the result was supposed to be empty');
44 $this->assertTrue(is_array($result), 'Even the empty result from workspace 90 is supposed to be an array');
45 }
46
47 /**
48 * @test
49 */
50 public function versionsFromSpecificWorkspaceCanBeFound()
51 {
52 $this->importDataSet(ORIGINAL_ROOT . 'components/testing_framework/core/Functional/Fixtures/pages.xml');
53 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
54 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
55 $result = $service->selectVersionsInWorkspace(91, 0, -99, 2);
56 $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
57 $this->assertEquals(1, sizeof($result['pages']), 'The result is supposed to contain one version for this page in workspace 91');
58 $this->assertEquals(102, $result['pages'][0]['uid'], 'Wrong workspace overlay record picked');
59 $this->assertEquals(1, $result['pages'][0]['livepid'], 'Real pid wasn\'t resolved correctly');
60 }
61
62 /**
63 * @test
64 */
65 public function versionsFromAllWorkspaceCanBeFound()
66 {
67 $this->importDataSet(ORIGINAL_ROOT . 'components/testing_framework/core/Functional/Fixtures/pages.xml');
68 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
69 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
70 $result = $service->selectVersionsInWorkspace(\TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES, 0, -99, 2);
71 $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
72 $this->assertEquals(2, sizeof($result['pages']), 'The result is supposed to contain one version for this page in workspace 91');
73 }
74
75 /**
76 * @test
77 */
78 public function versionsCanBeFoundRecursive()
79 {
80 $this->importDataSet(ORIGINAL_ROOT . 'components/testing_framework/core/Functional/Fixtures/pages.xml');
81 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
82 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
83 $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
84 $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
85 $this->assertEquals(4, sizeof($result['pages']), 'The result is supposed to contain four versions for this page in workspace 91');
86 }
87
88 /**
89 * @test
90 */
91 public function versionsCanBeFilteredToSpecificStage()
92 {
93 $this->importDataSet(ORIGINAL_ROOT . 'components/testing_framework/core/Functional/Fixtures/pages.xml');
94 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
95 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
96 // testing stage 1
97 $result = $service->selectVersionsInWorkspace(91, 0, 1, 1, 99);
98 $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
99 $this->assertEquals(2, sizeof($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
100 $this->assertEquals(102, $result['pages'][0]['uid'], 'First records is supposed to have the uid 102');
101 $this->assertEquals(105, $result['pages'][1]['uid'], 'First records is supposed to have the uid 105');
102 // testing stage 2
103 $result = $service->selectVersionsInWorkspace(91, 0, 2, 1, 99);
104 $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
105 $this->assertEquals(2, sizeof($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
106 $this->assertEquals(104, $result['pages'][0]['uid'], 'First records is supposed to have the uid 106');
107 $this->assertEquals(106, $result['pages'][1]['uid'], 'First records is supposed to have the uid 106');
108 }
109
110 /**
111 * @test
112 */
113 public function versionsCanBeFilteredToSpecificLifecycleStep()
114 {
115 $this->importDataSet(ORIGINAL_ROOT . 'components/testing_framework/core/Functional/Fixtures/pages.xml');
116 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
117 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
118 // testing all "draft" records
119 $result = $service->selectVersionsInWorkspace(91, 1, -99, 1, 99);
120 $this->assertTrue(is_array($result), 'The result from workspace 91 is supposed to be an array');
121 $this->assertEquals(2, sizeof($result['pages']), 'The result is supposed to contain three versions for this page in workspace 91');
122 // testing all "archive" records
123 $result = $service->selectVersionsInWorkspace(91, 2, -99, 1, 99);
124 $this->assertEquals(2, sizeof($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
125 // testing both types records
126 $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
127 $this->assertEquals(4, sizeof($result['pages']), 'The result is supposed to contain two versions for this page in workspace 91');
128 }
129
130 /**
131 * The only change which we could find here actually moved away from this
132 * branch of the tree - therefore we're not supposed to find anything here
133 *
134 * @test
135 */
136 public function movedElementsCanNotBeFoundAtTheirOrigin()
137 {
138 $this->markTestSkipped('This test need a review. It is green even if all fixtures are commented out');
139 $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
140 // Test if the placeholder can be found when we ask using recursion (same result)
141 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
142 $result = $service->selectVersionsInWorkspace(91, 0, -99, 2, 99);
143 $this->assertEquals(0, sizeof($result['pages']), 'Changes should not show up in this branch of the tree within workspace 91');
144 $this->assertEquals(0, sizeof($result['tt_content']), 'Changes should not show up in this branch of the tree within workspace 91');
145 }
146
147 /**
148 * @test
149 */
150 public function movedElementsCanBeFoundAtTheirDestination()
151 {
152 $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
153 // Test if the placeholder can be found when we ask using recursion (same result)
154 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
155 $result = $service->selectVersionsInWorkspace(91, 0, -99, 5, 99);
156 $this->assertEquals(1, sizeof($result['pages']), 'Wrong amount of page versions found within workspace 91');
157 $this->assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
158 $this->assertEquals(5, $result['pages'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
159 $this->assertEquals(2, $result['pages'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
160 $this->assertEquals(1, sizeof($result['tt_content']), 'Wrong amount of tt_content versions found within workspace 91');
161 $this->assertEquals(106, $result['tt_content'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
162 $this->assertEquals(7, $result['tt_content'][0]['wspid'], 'Wrong workspace-pointer found for page 3 in workspace 91');
163 $this->assertEquals(2, $result['tt_content'][0]['livepid'], 'Wrong live-pointer found for page 3 in workspace 91');
164 }
165
166 /**
167 * @test
168 */
169 public function movedElementsCanBeFoundUsingTheirLiveUid()
170 {
171 $this->importDataSet(__DIR__ . '/Fixtures/WorkspaceServiceTestMovedContent.xml');
172 // Test if the placeholder can be found when we ask using recursion (same result)
173 $service = new \TYPO3\CMS\Workspaces\Service\WorkspaceService();
174 $result = $service->selectVersionsInWorkspace(91, 0, -99, 3, 99);
175 $this->assertEquals(1, sizeof($result), 'Wrong amount of versions found within workspace 91');
176 $this->assertEquals(1, sizeof($result['pages']), 'Wrong amount of page versions found within workspace 91');
177 $this->assertEquals(103, $result['pages'][0]['uid'], 'Wrong move-to pointer found for page 3 in workspace 91');
178 }
179 }