[TASK] Update caching framework to latest FLOW3 version
[Packages/TYPO3.CMS.git] / tests / t3lib / tree / class.t3lib_tree_sortednodecollectionTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Stefan Galinski <stefan.galinski@gmail.com>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for class t3lib_tree_SortedNodeCollection.
27 *
28 * @author Stefan Galinski <stefan.galinski@gmail.com>
29 * @package TYPO3
30 * @subpackage t3lib
31 */
32 class t3lib_tree_SortedNodeCollectionTest extends tx_phpunit_testcase {
33 protected function createTestCollection() {
34 $nodeCollection = new t3lib_tree_SortedNodeCollection();
35
36 $node = new t3lib_tree_Node(array('id' => 5));
37 $nodeCollection->append($node);
38
39 $node = new t3lib_tree_Node(array('id' => 15));
40 $nodeCollection->append($node);
41
42 $node = new t3lib_tree_Node(array('id' => 3));
43 $nodeCollection->append($node);
44
45 return $nodeCollection;
46 }
47
48 protected function createTestCollectionWithTwoNodes() {
49 $nodeCollection = new t3lib_tree_SortedNodeCollection();
50
51 $node = new t3lib_tree_Node(array('id' => 5));
52 $nodeCollection->append($node);
53
54 $node = new t3lib_tree_Node(array('id' => 3));
55 $nodeCollection->append($node);
56
57 return $nodeCollection;
58 }
59
60 /**
61 * @test
62 */
63 public function appendsSorted() {
64 $nodeCollection = $this->createTestCollection();
65
66 $expected = array(3, 5, 15);
67 $ids = array();
68 foreach ($nodeCollection as $node) {
69 $ids[] = $node->getId();
70 }
71 $this->assertSame($expected, $ids);
72 }
73
74 /**
75 * @test
76 */
77 public function collectionContainsNode() {
78 $nodeCollection = $this->createTestCollection();
79 $node = new t3lib_tree_Node(array('id' => 5));
80 $this->assertTrue($nodeCollection->contains($node));
81 }
82
83 /**
84 * @test
85 */
86 public function searchDataWithBinarySearch() {
87 $nodeCollection = $this->createTestCollection();
88 $node = new t3lib_tree_Node(array('id' => 15));
89 $this->assertTrue($nodeCollection->contains($node));
90
91 $node = new t3lib_tree_Node(array('id' => 99));
92 $this->assertFalse($nodeCollection->contains($node));
93
94 $nodeCollection = $this->createTestCollectionWithTwoNodes();
95 $node = new t3lib_tree_Node(array('id' => 3));
96 $this->assertTrue($nodeCollection->contains($node));
97
98 $node = new t3lib_tree_Node(array('id' => 99));
99 $this->assertFalse($nodeCollection->contains($node));
100 }
101 }
102 ?>