17ab21d2e61645b2805c21f698b1626bbf1f3fec
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Tree / Pagetree / DataProviderTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Tree\Pagetree;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Stefan Galinski <stefan.galinski@gmail.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase
29 *
30 * @author Stefan Galinski <stefan.galinski@gmail.com>
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class DataProviderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
34
35 /**
36 * @var \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider|\PHPUnit_Framework_MockObject_MockObject
37 */
38 protected $subject = NULL;
39
40 public function setUp() {
41 $GLOBALS['TYPO3_CONF_VARS']['BE']['pageTree']['preloadLimit'] = 0;
42 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']['postProcessCollections'] = array();
43 $GLOBALS['LOCKED_RECORDS'] = array();
44 /** @var $backendUserMock \TYPO3\CMS\Core\Authentication\BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject */
45 $backendUserMock = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array(), array(),'', FALSE);
46 $GLOBALS['BE_USER'] = $backendUserMock;
47
48 $this->subject = new \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider();
49
50 }
51
52 /**
53 * @test
54 */
55 public function getRootNodeReturnsNodeWithRootId() {
56 $this->assertSame('root', $this->subject->getRoot()->getId());
57 }
58
59 /**
60 * @test
61 */
62 public function getRootNodeReturnsExpandedNode() {
63 $this->assertTrue($this->subject->getRoot()->isExpanded());
64 }
65
66 /**
67 * @test
68 */
69 public function getNodesSetsIsMountPointField() {
70 /** @var $backendUserMock \TYPO3\CMS\Core\Authentication\BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject */
71 $backendUserMock = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array('returnWebmounts'), array(), '', FALSE);
72 $GLOBALS['BE_USER'] = $backendUserMock;
73 $GLOBALS['BE_USER']->expects($this->any())->method('returnWebmounts')->will($this->returnValue(array('false', 'true', 'false')));
74 $subpages = array(
75 array(
76 'uid' => 1,
77 'isMountPoint' => FALSE
78 ),
79 array(
80 'uid' => 2,
81 'isMountPoint' => TRUE
82 ),
83 array(
84 'uid' => 3
85 )
86 );
87 $subpagesWithWorkspaceOverlay = array(
88 array(
89 'uid' => 1,
90 'title' => 'Home'
91 ),
92 array(
93 'uid' => 2,
94 'title' => 'service'
95 ),
96 array(
97 'uid' => 3,
98 'title' => 'contact'
99 )
100 );
101 /** @var \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider $subject */
102 $subject = $this->getMock('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\DataProvider', array('getSubpages', 'getRecordWithWorkspaceOverlay'));
103 $subject->expects($this->once())->method('getSubpages')->will($this->returnValue($subpages));
104 $subject->expects($this->at(1))->method('getRecordWithWorkspaceOverlay')->with(1)->will($this->returnValue($subpagesWithWorkspaceOverlay[0]));
105 $subject->expects($this->at(2))->method('getRecordWithWorkspaceOverlay')->with(2)->will($this->returnValue($subpagesWithWorkspaceOverlay[1]));
106 $subject->expects($this->at(3))->method('getRecordWithWorkspaceOverlay')->with(3)->will($this->returnValue($subpagesWithWorkspaceOverlay[2]));
107 /** @var \TYPO3\CMS\Backend\Tree\TreeNode $node */
108 $node = $this->getMock('TYPO3\\CMS\\Backend\\Tree\\TreeNode');
109 $node->setId(12);
110 $nodeCollection = $subject->getNodes($node);
111 $isMountPointResult = array();
112 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
113 foreach ($nodeCollection as $node) {
114 $isMountPointResult[] = $node->isMountPoint();
115 }
116 $this->assertSame(array(FALSE, TRUE, FALSE), $isMountPointResult);
117 }
118
119 }