[TASK] Add more unit tests for t3lib_tree_pagetree_DataProvider
[Packages/TYPO3.CMS.git] / tests / Unit / t3lib / tree / pagetree / class.t3lib_tree_pagetree_dataproviderTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Stefan Galinski <stefan.galinski@gmail.com>
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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for class t3lib_tree_pagetree_DataProvider.
27 *
28 * @author Stefan Galinski <stefan.galinski@gmail.com>
29 * @author Oliver Klee <typo3-coding@oliverklee.de>
30 *
31 * @package TYPO3
32 * @subpackage t3lib
33 */
34 class t3lib_tree_pagetree_DataProviderTest extends tx_phpunit_testcase {
35 /**
36 * @var boolean
37 */
38 protected $backupGlobals = TRUE;
39
40 /**
41 * Excludes TYPO3_DB from backup/restore of $GLOBALS because resource types cannot be handled during serializing.
42 *
43 * @var array
44 */
45 protected $backupGlobalsBlacklist = array('TYPO3_DB');
46
47 /**
48 * @var t3lib_tree_pagetree_DataProvider|PHPUnit_Framework_MockObject_MockObject
49 */
50 protected $fixture = NULL;
51
52 public function setUp() {
53 $GLOBALS['TYPO3_CONF_VARS']['BE']['pageTree']['preloadLimit'] = 0;
54 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']['postProcessCollections'] = array();
55
56 $this->fixture = new t3lib_tree_pagetree_DataProvider();
57 }
58
59 public function tearDown() {
60 unset($this->fixture);
61 }
62
63 /**
64 * @test
65 */
66 public function getRootNodeReturnsNodeWithRootId() {
67 $this->assertSame(
68 'root',
69 $this->fixture->getRoot()->getId()
70 );
71 }
72
73 /**
74 * @test
75 */
76 public function getRootNodeReturnsExpandedNode() {
77 $this->assertTrue(
78 $this->fixture->getRoot()->isExpanded()
79 );
80 }
81
82 /**
83 * @test
84 */
85 public function getNodesSetsIsMountPointField() {
86 $subpages = array(
87 array(
88 'uid' => 1,
89 'isMountPoint' => FALSE,
90 ),
91 array(
92 'uid' => 2,
93 'isMountPoint' => TRUE,
94 ),
95 array(
96 'uid' => 3,
97 ),
98 );
99
100 $subpagesWithWorkspaceOverlay = array(
101 array(
102 'uid' => 1,
103 'title' => 'Home',
104 ),
105 array(
106 'uid' => 2,
107 'title' => 'service',
108 ),
109 array(
110 'uid' => 3,
111 'title' => 'contact',
112 ),
113 );
114
115 $fixture = $this->getMock('t3lib_tree_pagetree_DataProvider', array('getSubpages', 'getRecordWithWorkspaceOverlay'));
116 $fixture->expects($this->once())->method('getSubpages')->will($this->returnValue($subpages));
117
118 $fixture->expects($this->at(1))->method('getRecordWithWorkspaceOverlay')->with(1)
119 ->will($this->returnValue($subpagesWithWorkspaceOverlay[0]));
120 $fixture->expects($this->at(2))->method('getRecordWithWorkspaceOverlay')->with(2)
121 ->will($this->returnValue($subpagesWithWorkspaceOverlay[1]));
122 $fixture->expects($this->at(3))->method('getRecordWithWorkspaceOverlay')->with(3)
123 ->will($this->returnValue($subpagesWithWorkspaceOverlay[2]));
124
125 $node = new t3lib_tree_Node();
126 $node->setId(12);
127
128 $nodeCollection = $fixture->getNodes($node);
129
130 $isMountPointResult = array();
131 /** @var $node t3lib_tree_pagetree_Node */
132 foreach ($nodeCollection as $node) {
133 $isMountPointResult[] = $node->isMountPoint();
134 }
135 $this->assertSame(array(FALSE, TRUE, FALSE), $isMountPointResult);
136 }
137 }
138
139 ?>