[TASK] Create a first proof-of-concept unit test for t3lib_TCEmain::process_datamap
authorOliver <typo3-coding@oliverklee.de>
Wed, 2 Mar 2011 19:24:08 +0000 (20:24 +0100)
committerTolleiv Nietsch <info@tolleiv.de>
Wed, 2 Mar 2011 19:46:55 +0000 (20:46 +0100)
Resolves: #M17836

Change-Id: I92fa2b9d080e819b81451de3571f101a5d39a235
Reviewed-on: http://review.typo3.org/990
Reviewed-by: Ringer Georg <mail@ringerge.org>
Tested-by: Ringer Georg <mail@ringerge.org>
Reviewed-by: Tolleiv Nietsch <info@tolleiv.de>
Tested-by: Tolleiv Nietsch <info@tolleiv.de>
tests/t3lib/t3lib_tcemainTest.php

index 9c5c7ac..e87b8b9 100644 (file)
@@ -29,6 +29,7 @@
  * @subpackage t3lib
  *
  * @author Oliver Klee <typo3-coding@oliverklee.de>
+ * @author Tolleiv Nietsch <info@tolleiv.de>
  */
 class t3lib_tcemainTest extends tx_phpunit_testcase {
 
@@ -48,6 +49,13 @@ class t3lib_tcemainTest extends tx_phpunit_testcase {
        protected $backupGlobalsBlacklist = array('TYPO3_DB');
 
        /**
+        * a backup of the global database
+        *
+        * @var t3lib_DB
+        */
+       protected $databaseBackup = NULL;
+
+       /**
         * @var t3lib_TCEmain
         */
        private $fixture;
@@ -58,6 +66,8 @@ class t3lib_tcemainTest extends tx_phpunit_testcase {
        private $backEndUser;
 
        public function setUp() {
+               $this->databaseBackup = $GLOBALS['TYPO3_DB'];
+
                $this->backEndUser = $this->getMock('t3lib_beUserAuth');
 
                $this->fixture = new t3lib_TCEmain();
@@ -65,8 +75,12 @@ class t3lib_tcemainTest extends tx_phpunit_testcase {
        }
 
        public function tearDown() {
+               t3lib_div::purgeInstances();
+
+               $GLOBALS['TYPO3_DB'] = $this->databaseBackup;
+
                unset(
-                       $this->fixture->BE_USER, $this->fixture, $this->backEndUser
+                       $this->fixture->BE_USER, $this->fixture, $this->backEndUser, $this->databaseBackup
                );
        }
 
@@ -236,5 +250,78 @@ class t3lib_tcemainTest extends tx_phpunit_testcase {
 
                $this->assertTrue($this->fixture->checkModifyAccessList('tt_content'));
        }
+
+
+       /////////////////////////////////////
+       // Tests concerning process_datamap
+       /////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function processDatamapForFrozenNonZeroWorkspaceReturnsFalse() {
+               $fixture = $this->getMock('t3lib_TCEmain', array('newlog'));
+
+               $this->backEndUser->workspace = 1;
+               $this->backEndUser->workspaceRec = array('freeze' => TRUE);
+
+               $fixture->BE_USER = $this->backEndUser;
+
+               $this->assertFalse(
+                       $fixture->process_datamap()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function processDatamapWhenEditingRecordInWorkspaceCreatesNewRecordInWorkspace() {
+               $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB');
+
+               $fixture = $this->getMock(
+                       't3lib_TCEmain',
+                       array('newlog', 'checkModifyAccessList', 'tableReadOnly', 'checkRecordUpdateAccess')
+               );
+               $fixture->bypassWorkspaceRestrictions = FALSE;
+               $fixture->datamap = array(
+                       'pages' => array(
+                               '1' => array(
+                                       'header' => 'demo',
+                               ),
+                       ),
+               );
+
+               $fixture->expects($this->once())->method('checkModifyAccessList')->with('pages')->will($this->returnValue(TRUE));
+               $fixture->expects($this->once())->method('tableReadOnly')->with('pages')->will($this->returnValue(FALSE));
+               $fixture->expects($this->once())->method('checkRecordUpdateAccess')->will($this->returnValue(TRUE));
+
+               $backEndUser = $this->getMock('t3lib_beUserAuth');
+               $backEndUser->workspace = 1;
+               $backEndUser->workspaceRec = array('freeze' => FALSE);
+               $backEndUser->expects($this->once())->method('workspaceAllowAutoCreation')->will($this->returnValue(TRUE));
+               $backEndUser->expects($this->once())->method('workspaceCannotEditRecord')->will($this->returnValue(TRUE));
+               $backEndUser->expects($this->once())->method('recordEditAccessInternals')->with('pages', 1)->will($this->returnValue(TRUE));
+
+               $fixture->BE_USER = $backEndUser;
+
+               $createdTceMain = $this->getMock('t3lib_TCEmain', array());
+               $createdTceMain->expects($this->once())->method('start')->with(
+                       array(),
+                       array('pages' => array(
+                               1 => array(
+                                       'version' => array(
+                                               'action' => 'new',
+                                               'treeLevels' => -1,
+                                               'label' => 'Auto-created for WS #1',
+                                       )
+                               )
+                       ))
+               );
+               $createdTceMain->expects($this->never())->method('process_datamap');
+               $createdTceMain->expects($this->once())->method('process_cmdmap');
+               t3lib_div::addInstance('t3lib_TCEmain', $createdTceMain);
+
+               $fixture->process_datamap();
+       }
 }
 ?>
\ No newline at end of file