TYPO3 CMS  TYPO3_7-6
SortedTreeNodeCollectionTest.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 
21 {
22  protected function createTestCollection()
23  {
24  $nodeCollection = new \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection();
25  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 5]);
26  $nodeCollection->append($node);
27  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 15]);
28  $nodeCollection->append($node);
29  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 3]);
30  $nodeCollection->append($node);
31  return $nodeCollection;
32  }
33 
34  protected function createTestCollectionWithTwoNodes()
35  {
36  $nodeCollection = new \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection();
37  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 5]);
38  $nodeCollection->append($node);
39  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 3]);
40  $nodeCollection->append($node);
41  return $nodeCollection;
42  }
43 
47  public function appendsSorted()
48  {
49  $nodeCollection = $this->createTestCollection();
50  $expected = [3, 5, 15];
51  $ids = [];
52  foreach ($nodeCollection as $node) {
53  $ids[] = $node->getId();
54  }
55  $this->assertSame($expected, $ids);
56  }
57 
61  public function collectionContainsNode()
62  {
63  $nodeCollection = $this->createTestCollection();
64  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 5]);
65  $this->assertTrue($nodeCollection->contains($node));
66  }
67 
71  public function searchDataWithBinarySearch()
72  {
73  $nodeCollection = $this->createTestCollection();
74  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 15]);
75  $this->assertTrue($nodeCollection->contains($node));
76  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 99]);
77  $this->assertFalse($nodeCollection->contains($node));
78  $nodeCollection = $this->createTestCollectionWithTwoNodes();
79  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 3]);
80  $this->assertTrue($nodeCollection->contains($node));
81  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 99]);
82  $this->assertFalse($nodeCollection->contains($node));
83  }
84 }