[BUGFIX] Page tree unit test fails if pages don't exist
authorSusanne Moog <typo3@susannemoog.de>
Sat, 30 Jun 2012 14:54:11 +0000 (16:54 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 30 Jun 2012 16:59:16 +0000 (18:59 +0200)
The unit test getNodesSetsIsMountPointField fails if
the pages with uid 1, 2, 3 are not available.

Instead of relying on user dependent data, we should mock
it. The patch introduces a wrapper method for getRecordWSOL
to be able to mock that method and changes the test to do
that.

Change-Id: I36ec23a47bd39821595e787fba1cb8b77e2c3b0c
Fixes: #38503
Releases: 6.0, 4.7
Reviewed-on: http://review.typo3.org/12478
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php
tests/Unit/t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataproviderTest.php

index 016e68c..2cc25d3 100644 (file)
@@ -148,10 +148,12 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
                                        continue;
                                }
 
-                                       // must be calculated above getRecordWSOL, because the information is lost otherwise
+                                       // must be calculated above getRecordWithWorkspaceOverlay,
+                                       // because the information is lost otherwise
                                $isMountPoint = ($subpage['isMountPoint'] === TRUE);
 
-                               $subpage = t3lib_befunc::getRecordWSOL('pages', $subpage['uid'], '*', '', TRUE, TRUE);
+                               $subpage = $this->getRecordWithWorkspaceOverlay($subpage['uid'], TRUE);
+
                                if (!$subpage) {
                                        continue;
                                }
@@ -180,6 +182,18 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
        }
 
        /**
+        * Wrapper method for t3lib_befunc::getRecordWSOL
+        *
+        * @param integer $uid The page id
+        * @param boolean $unsetMovePointers Whether to unset move pointers
+        * @return array
+        */
+       protected function getRecordWithWorkspaceOverlay($uid, $unsetMovePointers = FALSE) {
+               $subpage = t3lib_befunc::getRecordWSOL('pages', $uid, '*', '', TRUE, $unsetMovePointers);
+               return $subpage;
+       }
+
+       /**
         * Returns a node collection of filtered nodes
         *
         * @param t3lib_tree_Node $node
@@ -370,7 +384,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
                                        continue;
                                }
 
-                               $record = t3lib_BEfunc::getRecordWSOL('pages', $mountPoint, '*', '', TRUE);
+                               $record = $this->getRecordWithWorkspaceOverlay($mountPoint);
                                if (!$record) {
                                        continue;
                                }
index 4fb9604..cd26efe 100644 (file)
@@ -71,10 +71,32 @@ class t3lib_tree_pagetree_DataProviderTest extends tx_phpunit_testcase {
                        ),
                );
 
-               $this->fixture = $this->getMock('t3lib_tree_pagetree_DataProvider', array('getSubpages'));
+               $subpagesWithWorkspaceOverlay = array(
+                       array(
+                               'uid' => 1,
+                               'title' => 'Home',
+                       ),
+                       array(
+                               'uid' => 2,
+                               'title' => 'service',
+                       ),
+                       array(
+                               'uid' => 3,
+                               'title' => 'contact',
+                       ),
+               );
+
+               $this->fixture = $this->getMock('t3lib_tree_pagetree_DataProvider', array('getSubpages', 'getRecordWithWorkspaceOverlay'));
                $this->fixture->expects($this->once())->method('getSubpages')
                        ->will($this->returnValue($subpages));
 
+               $this->fixture->expects($this->at(1))->method('getRecordWithWorkspaceOverlay')->with(1)
+                       ->will($this->returnValue($subpagesWithWorkspaceOverlay[0]));
+               $this->fixture->expects($this->at(2))->method('getRecordWithWorkspaceOverlay')->with(2)
+                       ->will($this->returnValue($subpagesWithWorkspaceOverlay[1]));
+               $this->fixture->expects($this->at(3))->method('getRecordWithWorkspaceOverlay')->with(3)
+                       ->will($this->returnValue($subpagesWithWorkspaceOverlay[2]));
+
                $node = new t3lib_tree_Node();
                $node->setId(12);