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