|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Stefan Galinski <stefan.galinski@gmail.com> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Testcase for class t3lib_tree_SortedNodeCollection. 00027 * 00028 * @author Stefan Galinski <stefan.galinski@gmail.com> 00029 * @package TYPO3 00030 * @subpackage t3lib 00031 */ 00032 class t3lib_tree_SortedNodeCollectionTest extends tx_phpunit_testcase { 00033 protected function createTestCollection() { 00034 $nodeCollection = new t3lib_tree_SortedNodeCollection(); 00035 00036 $node = new t3lib_tree_Node(array('id' => 5)); 00037 $nodeCollection->append($node); 00038 00039 $node = new t3lib_tree_Node(array('id' => 15)); 00040 $nodeCollection->append($node); 00041 00042 $node = new t3lib_tree_Node(array('id' => 3)); 00043 $nodeCollection->append($node); 00044 00045 return $nodeCollection; 00046 } 00047 00048 protected function createTestCollectionWithTwoNodes() { 00049 $nodeCollection = new t3lib_tree_SortedNodeCollection(); 00050 00051 $node = new t3lib_tree_Node(array('id' => 5)); 00052 $nodeCollection->append($node); 00053 00054 $node = new t3lib_tree_Node(array('id' => 3)); 00055 $nodeCollection->append($node); 00056 00057 return $nodeCollection; 00058 } 00059 00060 /** 00061 * @test 00062 */ 00063 public function appendsSorted() { 00064 $nodeCollection = $this->createTestCollection(); 00065 00066 $expected = array(3, 5, 15); 00067 $ids = array(); 00068 foreach ($nodeCollection as $node) { 00069 $ids[] = $node->getId(); 00070 } 00071 $this->assertSame($expected, $ids); 00072 } 00073 00074 /** 00075 * @test 00076 */ 00077 public function collectionContainsNode() { 00078 $nodeCollection = $this->createTestCollection(); 00079 $node = new t3lib_tree_Node(array('id' => 5)); 00080 $this->assertTrue($nodeCollection->contains($node)); 00081 } 00082 00083 /** 00084 * @test 00085 */ 00086 public function searchDataWithBinarySearch() { 00087 $nodeCollection = $this->createTestCollection(); 00088 $node = new t3lib_tree_Node(array('id' => 15)); 00089 $this->assertTrue($nodeCollection->contains($node)); 00090 00091 $node = new t3lib_tree_Node(array('id' => 99)); 00092 $this->assertFalse($nodeCollection->contains($node)); 00093 00094 $nodeCollection = $this->createTestCollectionWithTwoNodes(); 00095 $node = new t3lib_tree_Node(array('id' => 3)); 00096 $this->assertTrue($nodeCollection->contains($node)); 00097 00098 $node = new t3lib_tree_Node(array('id' => 99)); 00099 $this->assertFalse($nodeCollection->contains($node)); 00100 } 00101 } 00102 ?>
1.8.0