[TASK] Removes extra empty lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Tree / TableConfiguration / DatabaseTreeDataProviderTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Tree\TreeNode;
18 use TYPO3\CMS\Backend\Tree\TreeNodeCollection;
19 use TYPO3\CMS\Core\Database\DatabaseConnection;
20 use TYPO3\CMS\Core\Tests\UnitTestCase;
21 use TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider;
22
23 /**
24 * Testcase for \TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider
25 */
26 class DatabaseTreeDataProviderTest extends UnitTestCase
27 {
28 /**
29 * @var \PHPUnit_Framework_MockObject_MockObject|DatabaseTreeDataProvider|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
30 */
31 protected $subject;
32
33 /**
34 * @var TreeNode
35 */
36 protected $treeData;
37
38 /**
39 * @var \PHPUnit_Framework_MockObject_MockObject|DatabaseConnection|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
40 */
41 protected $database;
42
43 /**
44 * Set up
45 *
46 * @return void
47 */
48 protected function setUp()
49 {
50 $this->database = $this->getMock(DatabaseConnection::class, array('exec_SELECTgetSingleRow'));
51 $this->database->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue(array('uid' => 0, 'parent' => '')));
52 $this->treeData = new TreeNode();
53 $GLOBALS['TYPO3_DB'] = $this->database;
54 }
55
56 /**
57 * @param array $mockMethods
58 */
59 protected function initializeSubjectMock(array $mockMethods)
60 {
61 $this->subject = $this->getAccessibleMock(DatabaseTreeDataProvider::class, $mockMethods, array(), '', false);
62 $this->subject->expects($this->any())->method('getRootUid')->will($this->returnValue(0));
63 $this->subject->_set('treeData', $this->treeData);
64 }
65
66 /**
67 * @test
68 */
69 public function loadTreeDataLevelMaximumSetToZeroWorks()
70 {
71 $this->initializeSubjectMock(array('getRelatedRecords', 'getRootUid', 'getChildrenOf'));
72 $this->subject->_set('levelMaximum', 0);
73 $this->subject->expects($this->never())->method('getChildrenOf');
74 $this->subject->_call('loadTreeData');
75 }
76
77 /**
78 * @test
79 */
80 public function loadTreeDataLevelMaximumSetToOneWorks()
81 {
82 $this->initializeSubjectMock(array('getRelatedRecords', 'getRootUid', 'getChildrenOf'));
83 $this->subject->_set('levelMaximum', 1);
84 $this->subject->expects($this->once())->method('getChildrenOf')->with($this->treeData, 1);
85 $this->subject->_call('loadTreeData');
86 }
87
88 /**
89 * @test
90 */
91 public function getChildrenOfLevelMaximumSetToOneWorks()
92 {
93 $expectedTreeNode = new TreeNode();
94 $expectedTreeNode->setId(1);
95 $expectedStorage = new TreeNodeCollection();
96 $expectedStorage->append($expectedTreeNode);
97
98 $this->initializeSubjectMock(array('getRelatedRecords', 'getRootUid'));
99 $this->subject->_set('levelMaximum', 1);
100 $this->subject->expects($this->once())->method('getRelatedRecords')->will($this->returnValue(array(1)));
101 $storage = $this->subject->_call('getChildrenOf', $this->treeData, 1);
102
103 $this->assertEquals($expectedStorage, $storage);
104 }
105
106 /**
107 * @test
108 */
109 public function getChildrenOfLevelMaximumSetToTwoWorks()
110 {
111 $expectedStorage = new TreeNodeCollection();
112
113 $expectedFirstLevelTreeNode = new TreeNode();
114 $expectedFirstLevelTreeNode->setId(1);
115
116 $expectedSecondLevelTreeNode = new TreeNode();
117 $expectedSecondLevelTreeNode->setId(2);
118
119 $expectedStorageOfSecondLevelChildren = new TreeNodeCollection();
120 $expectedStorageOfSecondLevelChildren->append($expectedSecondLevelTreeNode);
121
122 $expectedFirstLevelTreeNode->setChildNodes($expectedStorageOfSecondLevelChildren);
123 $expectedStorage->append($expectedFirstLevelTreeNode);
124
125 $this->initializeSubjectMock(array('getRelatedRecords', 'getRootUid'));
126 $this->subject->_set('levelMaximum', 2);
127 $this->subject->expects($this->at(0))->method('getRelatedRecords')->will($this->returnValue(array(1)));
128 $this->subject->expects($this->at(1))->method('getRelatedRecords')->will($this->returnValue(array(2)));
129 $storage = $this->subject->_call('getChildrenOf', $this->treeData, 1);
130
131 $this->assertEquals($expectedStorage, $storage);
132 }
133 }