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