TYPO3 API  SVNRelease
WorkspaceTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 
00028 /**
00029  * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
00030  * @package Workspaces
00031  * @subpackage Service
00032  */
00033 class tx_Workspaces_Service_WorkspacesTest extends tx_phpunit_database_testcase {
00034 
00035     /**
00036      * @test
00037      **/
00038     public function emptyWorkspaceReturnsEmptyArray() {
00039         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00040 
00041         $service = new tx_Workspaces_Service_Workspaces();
00042         $result = $service->selectVersionsInWorkspace(90);
00043         $this->assertTrue(empty($result), "The workspace 90 contains no changes and the result was supposed to be empty");
00044         $this->assertTrue(is_array($result), "Even the empty result from workspace 90 is supposed to be an array");
00045     }
00046 
00047     /**
00048      * @test
00049      **/
00050     public function versionsFromSpecificWorkspaceCanBeFound() {
00051         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00052         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
00053 
00054         $service = new tx_Workspaces_Service_Workspaces();
00055         $result = $service->selectVersionsInWorkspace(91, 0, -99, 2);
00056         $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
00057         $this->assertEquals(1, sizeof($result['pages']), "The result is supposed to contain one version for this page in workspace 91");
00058         $this->assertEquals(102, $result['pages'][0]['uid'], "Wrong workspace overlay record picked");
00059         $this->assertEquals(1, $result['pages'][0]['livepid'], "Real pid wasn't resolved correctly");
00060     }
00061 
00062     /**
00063      * @test
00064      **/
00065     public function versionsFromAllWorkspaceCanBeFound() {
00066         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00067         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
00068 
00069         $service = new tx_Workspaces_Service_Workspaces();
00070         $result = $service->selectVersionsInWorkspace(tx_Workspaces_Service_Workspaces::SELECT_ALL_WORKSPACES, 0, -99, 2);
00071         $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
00072         $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain one version for this page in workspace 91");
00073     }
00074 
00075     /**
00076      * @test
00077      **/
00078     public function versionsCanBeFoundRecursive() {
00079         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00080         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
00081 
00082         $service = new tx_Workspaces_Service_Workspaces();
00083         $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
00084         $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
00085         $this->assertEquals(4, sizeof($result['pages']), "The result is supposed to contain four versions for this page in workspace 91");
00086     }
00087 
00088     /**
00089      * @test
00090      **/
00091     public function versionsCanBeFilteredToSpecificStage() {
00092         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00093         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
00094 
00095         $service = new tx_Workspaces_Service_Workspaces();
00096 
00097             // testing stage 1
00098         $result = $service->selectVersionsInWorkspace(91, 0, 1, 1, 99);
00099         $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
00100         $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
00101         $this->assertEquals(102, $result['pages'][0]['uid'], "First records is supposed to have the uid 102");
00102         $this->assertEquals(105, $result['pages'][1]['uid'], "First records is supposed to have the uid 105");
00103 
00104             // testing stage 2
00105         $result = $service->selectVersionsInWorkspace(91, 0, 2, 1, 99);
00106         $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
00107         $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
00108         $this->assertEquals(104, $result['pages'][0]['uid'], "First records is supposed to have the uid 106");
00109         $this->assertEquals(106, $result['pages'][1]['uid'], "First records is supposed to have the uid 106");
00110     }
00111 
00112     /**
00113      * @test
00114      **/
00115     public function versionsCanBeFilteredToSpecificLifecycleStep() {
00116         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00117         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultPages.xml');
00118 
00119         $service = new tx_Workspaces_Service_Workspaces();
00120 
00121             // testing all "draft" records
00122         $result = $service->selectVersionsInWorkspace(91, 1, -99, 1, 99);
00123         $this->assertTrue(is_array($result), "The result from workspace 91 is supposed to be an array");
00124         $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain three versions for this page in workspace 91");
00125 
00126             // testing all "archive" records
00127         $result = $service->selectVersionsInWorkspace(91, 2, -99, 1, 99);
00128         $this->assertEquals(2, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
00129 
00130             // testing both types records
00131         $result = $service->selectVersionsInWorkspace(91, 0, -99, 1, 99);
00132         $this->assertEquals(4, sizeof($result['pages']), "The result is supposed to contain two versions for this page in workspace 91");
00133     }
00134 
00135     /**
00136      * The only change which we could find here actually moved away from this
00137      * branch of the tree - therefore we're not supposed to find anything here
00138      *
00139      * @test
00140      **/
00141     public function movedElementsCanNotBeFoundAtTheirOrigin() {
00142         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00143         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbMovedContent.xml');
00144 
00145             // Test if the placeholder can be found when we ask using recursion (same result)
00146         $service = new tx_Workspaces_Service_Workspaces();
00147         $result = $service->selectVersionsInWorkspace(91, 0, -99, 2, 99);
00148 
00149         $this->assertEquals(0, sizeof($result['pages']), "Changes should not show up in this branch of the tree within workspace 91");
00150         $this->assertEquals(0, sizeof($result['tt_content']), "Changes should not show up in this branch of the tree within workspace 91");
00151     }
00152 
00153     /**
00154      * @test
00155      **/
00156     public function movedElementsCanBeFoundAtTheirDestination() {
00157         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00158         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbMovedContent.xml');
00159 
00160             // Test if the placeholder can be found when we ask using recursion (same result)
00161         $service = new tx_Workspaces_Service_Workspaces();
00162         $result = $service->selectVersionsInWorkspace(91, 0, -99, 5, 99);
00163         $this->assertEquals(1, sizeof($result['pages']), "Wrong amount of page versions found within workspace 91");
00164         $this->assertEquals(103, $result['pages'][0]['uid'], "Wrong move-to pointer found for page 3 in workspace 91");
00165         $this->assertEquals(5, $result['pages'][0]['wspid'], "Wrong workspace-pointer found for page 3 in workspace 91");
00166         $this->assertEquals(2, $result['pages'][0]['livepid'], "Wrong live-pointer found for page 3 in workspace 91");
00167         $this->assertEquals(1, sizeof($result['tt_content']), "Wrong amount of tt_content versions found within workspace 91");
00168         $this->assertEquals(106, $result['tt_content'][0]['uid'], "Wrong move-to pointer found for page 3 in workspace 91");
00169         $this->assertEquals(7, $result['tt_content'][0]['wspid'], "Wrong workspace-pointer found for page 3 in workspace 91");
00170         $this->assertEquals(2, $result['tt_content'][0]['livepid'], "Wrong live-pointer found for page 3 in workspace 91");
00171     }
00172 
00173     /**
00174      * @test
00175      **/
00176     public function movedElementsCanBeFoundUsingTheirLiveUID() {
00177         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbDefaultWorkspaces.xml');
00178         $this->importDataSet(dirname(__FILE__) . '/fixtures/dbMovedContent.xml');
00179 
00180             // Test if the placeholder can be found when we ask using recursion (same result)
00181         $service = new tx_Workspaces_Service_Workspaces();
00182         $result = $service->selectVersionsInWorkspace(91, 0, -99, 3, 99);
00183 
00184         $this->assertEquals(1, sizeof($result), "Wrong amount of versions found within workspace 91");
00185         $this->assertEquals(1, sizeof($result['pages']), "Wrong amount of page versions found within workspace 91");
00186         $this->assertEquals(103, $result['pages'][0]['uid'], "Wrong move-to pointer found for page 3 in workspace 91");
00187     }
00188 
00189     /**
00190      *
00191      */
00192     public function setUp() {
00193         $this->createDatabase();
00194         $db = $this->useTestDatabase();
00195         $this->importStdDB();
00196         $this->importExtensions(array('cms'));
00197     }
00198 
00199     /**
00200      *
00201      */
00202     public function tearDown() {
00203         $this->cleanDatabase();
00204         $this->dropDatabase();
00205         $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);
00206     }
00207 }
00208 
00209 
00210 ?>