[BUGFIX] Make class name consistent
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Tests / Service / WorkspaceTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
30 * @package Workspaces
31 * @subpackage Service
32 */
33 class Tx_Workspaces_Service_WorkspacesTest extends tx_phpunit_database_testcase {
34
35 /**
36 * @test
37 **/
38 public function emptyWorkspaceReturnsEmptyArray() {
39 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
40
41 $service = new Tx_Workspaces_Service_Workspaces();
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 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
52 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
53
54 $service = new Tx_Workspaces_Service_Workspaces();
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 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
67 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
68
69 $service = new Tx_Workspaces_Service_Workspaces();
70 $result = $service->selectVersionsInWorkspace(Tx_Workspaces_Service_Workspaces::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 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
80 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
81
82 $service = new Tx_Workspaces_Service_Workspaces();
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 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
93 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
94
95 $service = new Tx_Workspaces_Service_Workspaces();
96
97 // testing stage 1
98 $result = $service->selectVersionsInWorkspace(91, 0, 1, 1, 99);
99 $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
100 $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
101 $this->assertEquals(102, $result['pages'][0]['uid'], "First records is supposed to have the uid 102");
102 $this->assertEquals(105, $result['pages'][1]['uid'], "First records is supposed to have the uid 105");
103
104 // testing stage 2
105 $result = $service->selectVersionsInWorkspace(91, 0, 2, 1, 99);
106 $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
107 $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
108 $this->assertEquals(104, $result['pages'][0]['uid'], "First records is supposed to have the uid 106");
109 $this->assertEquals(106, $result['pages'][1]['uid'], "First records is supposed to have the uid 106");
110 }
111
112 /**
113 * @test
114 **/
115 public function versionsCanBeFilteredToSpecificLifecycleStep() {
116 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
117 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
118
119 $service = new Tx_Workspaces_Service_Workspaces();
120
121 // testing all "draft" records
122 $result = $service->selectVersionsInWorkspace(91, 1, -99, 1, 99);
123 $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
124 $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain three versions for this page in workspace 91");
125
126 // testing all "archive" records
127 $result = $service->selectVersionsInWorkspace(91, 2, -99, 1, 99);
128 $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
129
130 // testing both types records
131 $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
132 $this->assertEquals(4, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
133 }
134
135 /**
136 * The only change which we could find here actually moved away from this
137 * branch of the tree - therefore we're not supposed to find anything here
138 *
139 * @test
140 **/
141 public function movedElementsCanNotBeFoundAtTheirOrigin() {
142 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
143 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbMovedContent.xml');
144
145 // Test if the placeholder can be found when we ask using recursion (same result)
146 $service = new Tx_Workspaces_Service_Workspaces();
147 $result = $service->selectVersionsInWorkspace(91, 0, -99, 2, 99);
148
149 $this->assertEquals(0, sizeof($result['pages']), "Changes should not show up in this branch of the tree within workspace 91");
150 $this->assertEquals(0, sizeof($result['tt_content']), "Changes should not show up in this branch of the tree within workspace 91");
151 }
152
153 /**
154 * @test
155 **/
156 public function movedElementsCanBeFoundAtTheirDestination() {
157 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
158 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbMovedContent.xml');
159
160 // Test if the placeholder can be found when we ask using recursion (same result)
161 $service = new Tx_Workspaces_Service_Workspaces();
162 $result = $service->selectVersionsInWorkspace(91, 0, -99, 5, 99);
163 $this->assertEquals(1, sizeof($result['pages']), "Wrong amount of page versions found within workspace 91");
164 $this->assertEquals(103, $result['pages'][0]['uid'], "Wrong move-to pointer found for page 3 in workspace 91");
165 $this->assertEquals(5, $result['pages'][0]['wspid'], "Wrong workspace-pointer found for page 3 in workspace 91");
166 $this->assertEquals(2, $result['pages'][0]['livepid'], "Wrong live-pointer found for page 3 in workspace 91");
167 $this->assertEquals(1, sizeof($result['tt_content']), "Wrong amount of tt_content versions found within workspace 91");
168 $this->assertEquals(106, $result['tt_content'][0]['uid'], "Wrong move-to pointer found for page 3 in workspace 91");
169 $this->assertEquals(7, $result['tt_content'][0]['wspid'], "Wrong workspace-pointer found for page 3 in workspace 91");
170 $this->assertEquals(2, $result['tt_content'][0]['livepid'], "Wrong live-pointer found for page 3 in workspace 91");
171 }
172
173 /**
174 * @test
175 **/
176 public function movedElementsCanBeFoundUsingTheirLiveUID() {
177 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
178 $this->importDataSet(dirname(__FILE__) . '/fixtures/dbMovedContent.xml');
179
180 // Test if the placeholder can be found when we ask using recursion (same result)
181 $service = new Tx_Workspaces_Service_Workspaces();
182 $result = $service->selectVersionsInWorkspace(91, 0, -99, 3, 99);
183
184 $this->assertEquals(1, sizeof($result), "Wrong amount of versions found within workspace 91");
185 $this->assertEquals(1, sizeof($result['pages']), "Wrong amount of page versions found within workspace 91");
186 $this->assertEquals(103, $result['pages'][0]['uid'], "Wrong move-to pointer found for page 3 in workspace 91");
187 }
188
189 /**
190 *
191 */
192 public function setUp() {
193 $this->createDatabase();
194 $db = $this->useTestDatabase();
195 $this->importStdDB();
196 $this->importExtensions(array('cms'));
197 }
198
199 /**
200 *
201 */
202 public function tearDown() {
203 $this->cleanDatabase();
204 $this->dropDatabase();
205 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
206 }
207 }
208
209
210 ?>