‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪SortedTreeNodeCollectionTest extends UnitTestCase
23 {
24  protected function ‪createTestCollection()
25  {
26  $nodeCollection = new \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection();
27  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 5]);
28  $nodeCollection->append($node);
29  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 15]);
30  $nodeCollection->append($node);
31  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 3]);
32  $nodeCollection->append($node);
33  return $nodeCollection;
34  }
35 
37  {
38  $nodeCollection = new \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection();
39  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 5]);
40  $nodeCollection->append($node);
41  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 3]);
42  $nodeCollection->append($node);
43  return $nodeCollection;
44  }
45 
49  public function ‪appendsSorted()
50  {
51  $nodeCollection = $this->‪createTestCollection();
52  $expected = [3, 5, 15];
53  $ids = [];
54  foreach ($nodeCollection as $node) {
55  $ids[] = $node->getId();
56  }
57  $this->assertSame($expected, $ids);
58  }
59 
63  public function ‪collectionContainsNode()
64  {
65  $nodeCollection = $this->‪createTestCollection();
66  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 5]);
67  $this->assertTrue($nodeCollection->contains($node));
68  }
69 
74  {
75  $nodeCollection = $this->‪createTestCollection();
76  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 15]);
77  $this->assertTrue($nodeCollection->contains($node));
78  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 99]);
79  $this->assertFalse($nodeCollection->contains($node));
80  $nodeCollection = $this->‪createTestCollectionWithTwoNodes();
81  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 3]);
82  $this->assertTrue($nodeCollection->contains($node));
83  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => 99]);
84  $this->assertFalse($nodeCollection->contains($node));
85  }
86 }
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest
Definition: SortedTreeNodeCollectionTest.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\searchDataWithBinarySearch
‪searchDataWithBinarySearch()
Definition: SortedTreeNodeCollectionTest.php:73
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\appendsSorted
‪appendsSorted()
Definition: SortedTreeNodeCollectionTest.php:49
‪TYPO3\CMS\Backend\Tests\Unit\Tree
Definition: SortedTreeNodeCollectionTest.php:2
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\createTestCollection
‪createTestCollection()
Definition: SortedTreeNodeCollectionTest.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\createTestCollectionWithTwoNodes
‪createTestCollectionWithTwoNodes()
Definition: SortedTreeNodeCollectionTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\collectionContainsNode
‪collectionContainsNode()
Definition: SortedTreeNodeCollectionTest.php:63