[FEATURE] New option to disable the age display of dates per field by TCA
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Tree / SortedTreeNodeCollectionTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Tree;
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 /**
18 * Testcase for class \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection.
19 */
20 class SortedTreeNodeCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 protected function createTestCollection() {
23 $nodeCollection = new \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection();
24 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 5));
25 $nodeCollection->append($node);
26 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 15));
27 $nodeCollection->append($node);
28 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 3));
29 $nodeCollection->append($node);
30 return $nodeCollection;
31 }
32
33 protected function createTestCollectionWithTwoNodes() {
34 $nodeCollection = new \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection();
35 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 5));
36 $nodeCollection->append($node);
37 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 3));
38 $nodeCollection->append($node);
39 return $nodeCollection;
40 }
41
42 /**
43 * @test
44 */
45 public function appendsSorted() {
46 $nodeCollection = $this->createTestCollection();
47 $expected = array(3, 5, 15);
48 $ids = array();
49 foreach ($nodeCollection as $node) {
50 $ids[] = $node->getId();
51 }
52 $this->assertSame($expected, $ids);
53 }
54
55 /**
56 * @test
57 */
58 public function collectionContainsNode() {
59 $nodeCollection = $this->createTestCollection();
60 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 5));
61 $this->assertTrue($nodeCollection->contains($node));
62 }
63
64 /**
65 * @test
66 */
67 public function searchDataWithBinarySearch() {
68 $nodeCollection = $this->createTestCollection();
69 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 15));
70 $this->assertTrue($nodeCollection->contains($node));
71 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 99));
72 $this->assertFalse($nodeCollection->contains($node));
73 $nodeCollection = $this->createTestCollectionWithTwoNodes();
74 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 3));
75 $this->assertTrue($nodeCollection->contains($node));
76 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => 99));
77 $this->assertFalse($nodeCollection->contains($node));
78 }
79
80 }