TYPO3 CMS  TYPO3_7-6
DatabaseTreeDataProviderTest.php
Go to the documentation of this file.
1 <?php
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 
22 
27 {
31  protected $subject;
32 
36  protected $treeData;
37 
41  protected $database;
42 
48  protected function setUp()
49  {
50  $this->database = $this->getMock(DatabaseConnection::class, ['exec_SELECTgetSingleRow']);
51  $this->database->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue(['uid' => 0, 'parent' => '']));
52  $this->treeData = new TreeNode();
53  $GLOBALS['TYPO3_DB'] = $this->database;
54  }
55 
59  protected function initializeSubjectMock(array $mockMethods)
60  {
61  $this->subject = $this->getAccessibleMock(DatabaseTreeDataProvider::class, $mockMethods, [], '', false);
62  $this->subject->expects($this->any())->method('getRootUid')->will($this->returnValue(0));
63  $this->subject->_set('treeData', $this->treeData);
64  }
65 
70  {
71  $this->initializeSubjectMock(['getRelatedRecords', 'getRootUid', 'getChildrenOf']);
72  $this->subject->_set('levelMaximum', 0);
73  $this->subject->expects($this->never())->method('getChildrenOf');
74  $this->subject->_call('loadTreeData');
75  }
76 
81  {
82  $this->initializeSubjectMock(['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 
92  {
93  $expectedTreeNode = new TreeNode();
94  $expectedTreeNode->setId(1);
95  $expectedStorage = new TreeNodeCollection();
96  $expectedStorage->append($expectedTreeNode);
97 
98  $this->initializeSubjectMock(['getRelatedRecords', 'getRootUid']);
99  $this->subject->_set('levelMaximum', 1);
100  $this->subject->expects($this->once())->method('getRelatedRecords')->will($this->returnValue([1]));
101  $storage = $this->subject->_call('getChildrenOf', $this->treeData, 1);
102 
103  $this->assertEquals($expectedStorage, $storage);
104  }
105 
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(['getRelatedRecords', 'getRootUid']);
126  $this->subject->_set('levelMaximum', 2);
127  $this->subject->expects($this->at(0))->method('getRelatedRecords')->will($this->returnValue([1]));
128  $this->subject->expects($this->at(1))->method('getRelatedRecords')->will($this->returnValue([2]));
129  $storage = $this->subject->_call('getChildrenOf', $this->treeData, 1);
130 
131  $this->assertEquals($expectedStorage, $storage);
132  }
133 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']