2 /***************************************************************
5 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
33 class Tx_Workspaces_Service_WorkspacesTest
extends tx_phpunit_database_testcase
{
38 public function emptyWorkspaceReturnsEmptyArray() {
39 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
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');
50 public function versionsFromSpecificWorkspaceCanBeFound() {
51 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
52 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultPages.xml');
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');
65 public function versionsFromAllWorkspaceCanBeFound() {
66 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
67 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultPages.xml');
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');
78 public function versionsCanBeFoundRecursive() {
79 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
80 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultPages.xml');
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');
91 public function versionsCanBeFilteredToSpecificStage() {
92 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
93 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultPages.xml');
95 $service = new Tx_Workspaces_Service_Workspaces();
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');
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');
115 public function versionsCanBeFilteredToSpecificLifecycleStep() {
116 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
117 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultPages.xml');
119 $service = new Tx_Workspaces_Service_Workspaces();
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');
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');
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');
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
141 public function movedElementsCanNotBeFoundAtTheirOrigin() {
142 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
143 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbMovedContent.xml');
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);
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');
156 public function movedElementsCanBeFoundAtTheirDestination() {
157 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
158 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbMovedContent.xml');
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');
176 public function movedElementsCanBeFoundUsingTheirLiveUID() {
177 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbDefaultWorkspaces.xml');
178 $this->importDataSet(dirname(__FILE__
) . '/fixtures/dbMovedContent.xml');
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);
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');
192 public function setUp() {
193 $this->createDatabase();
194 $db = $this->useTestDatabase();
195 $this->importStdDB();
196 $this->importExtensions(array('cms'));
202 public function tearDown() {
203 $this->cleanDatabase();
204 $this->dropDatabase();
205 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db
);