‪TYPO3CMS  11.5
SortedTreeNodeCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪SortedTreeNodeCollectionTest extends UnitTestCase
28 {
30  {
31  $nodeCollection = new ‪SortedTreeNodeCollection();
32  $node = new ‪TreeNode(['id' => 5]);
33  $nodeCollection->append($node);
34  $node = new ‪TreeNode(['id' => 15]);
35  $nodeCollection->append($node);
36  $node = new ‪TreeNode(['id' => 3]);
37  $nodeCollection->append($node);
38  return $nodeCollection;
39  }
40 
42  {
43  $nodeCollection = new ‪SortedTreeNodeCollection();
44  $node = new ‪TreeNode(['id' => 5]);
45  $nodeCollection->append($node);
46  $node = new ‪TreeNode(['id' => 3]);
47  $nodeCollection->append($node);
48  return $nodeCollection;
49  }
50 
54  public function ‪appendsSorted(): void
55  {
56  $nodeCollection = $this->‪createTestCollection();
57  $expected = [3, 5, 15];
58  $ids = [];
59  foreach ($nodeCollection as $node) {
60  $ids[] = $node->getId();
61  }
62  self::assertSame($expected, $ids);
63  }
64 
68  public function ‪collectionContainsNode(): void
69  {
70  $nodeCollection = $this->‪createTestCollection();
71  $node = new ‪TreeNode(['id' => 5]);
72  self::assertTrue($nodeCollection->contains($node));
73  }
74 
78  public function ‪searchDataWithBinarySearch(): void
79  {
80  $nodeCollection = $this->‪createTestCollection();
81  $node = new ‪TreeNode(['id' => 15]);
82  self::assertTrue($nodeCollection->contains($node));
83  $node = new ‪TreeNode(['id' => 99]);
84  self::assertFalse($nodeCollection->contains($node));
85  $nodeCollection = $this->‪createTestCollectionWithTwoNodes();
86  $node = new ‪TreeNode(['id' => 3]);
87  self::assertTrue($nodeCollection->contains($node));
88  $node = new ‪TreeNode(['id' => 99]);
89  self::assertFalse($nodeCollection->contains($node));
90  }
91 }
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest
Definition: SortedTreeNodeCollectionTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\searchDataWithBinarySearch
‪searchDataWithBinarySearch()
Definition: SortedTreeNodeCollectionTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\appendsSorted
‪appendsSorted()
Definition: SortedTreeNodeCollectionTest.php:54
‪TYPO3\CMS\Backend\Tree\TreeNode
Definition: TreeNode.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Tree
Definition: SortedTreeNodeCollectionTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\createTestCollection
‪createTestCollection()
Definition: SortedTreeNodeCollectionTest.php:29
‪TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection
Definition: SortedTreeNodeCollection.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\createTestCollectionWithTwoNodes
‪createTestCollectionWithTwoNodes()
Definition: SortedTreeNodeCollectionTest.php:41
‪TYPO3\CMS\Backend\Tests\Unit\Tree\SortedTreeNodeCollectionTest\collectionContainsNode
‪collectionContainsNode()
Definition: SortedTreeNodeCollectionTest.php:68