/**
  * The slot for the signal in DatabaseTreeDataProvider.
  *
  * @param DatabaseTreeDataProvider $dataProvider
  * @param TreeNode $treeData
  * @return void
  */
 public function addUserPermissionsToCategoryTreeData(DatabaseTreeDataProvider $dataProvider, $treeData)
 {
     if (!$this->backendUserAuthentication->isAdmin() && $dataProvider->getTableName() === $this->categoryTableName) {
         // Get User permissions related to category
         $categoryMountPoints = $this->backendUserAuthentication->getCategoryMountPoints();
         // Backup child nodes to be processed.
         $treeNodeCollection = $treeData->getChildNodes();
         if (!empty($categoryMountPoints) && !empty($treeNodeCollection)) {
             // First, remove all child nodes which must be analysed to be considered as "secure".
             // The nodes were backed up in variable $treeNodeCollection beforehand.
             $treeData->removeChildNodes();
             // Create an empty tree node collection to receive the secured nodes.
             /** @var TreeNodeCollection $securedTreeNodeCollection */
             $securedTreeNodeCollection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\TreeNodeCollection');
             foreach ($categoryMountPoints as $categoryMountPoint) {
                 $treeNode = $this->lookUpCategoryMountPointInTreeNodes((int) $categoryMountPoint, $treeNodeCollection);
                 if (!is_null($treeNode)) {
                     $securedTreeNodeCollection->append($treeNode);
                 }
             }
             // Reset child nodes.
             $treeData->setChildNodes($securedTreeNodeCollection);
         }
     }
 }
 /**
  * @test
  */
 public function getChildrenOfLevelMaximumSetToTwoWorks()
 {
     $expectedStorage = new TreeNodeCollection();
     $expectedFirstLevelTreeNode = new TreeNode();
     $expectedFirstLevelTreeNode->setId(1);
     $expectedSecondLevelTreeNode = new TreeNode();
     $expectedSecondLevelTreeNode->setId(2);
     $expectedStorageOfSecondLevelChildren = new TreeNodeCollection();
     $expectedStorageOfSecondLevelChildren->append($expectedSecondLevelTreeNode);
     $expectedFirstLevelTreeNode->setChildNodes($expectedStorageOfSecondLevelChildren);
     $expectedStorage->append($expectedFirstLevelTreeNode);
     $this->initializeSubjectMock(array('getRelatedRecords', 'getRootUid'));
     $this->subject->_set('levelMaximum', 2);
     $this->subject->expects($this->at(0))->method('getRelatedRecords')->will($this->returnValue(array(1)));
     $this->subject->expects($this->at(1))->method('getRelatedRecords')->will($this->returnValue(array(2)));
     $storage = $this->subject->_call('getChildrenOf', $this->treeData, 1);
     $this->assertEquals($expectedStorage, $storage);
 }