|
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_Node. 00027 * 00028 * @author Stefan Galinski <stefan.galinski@gmail.com> 00029 * @package TYPO3 00030 * @subpackage t3lib 00031 */ 00032 class t3lib_tree_NodeTest extends tx_phpunit_testcase { 00033 ////////////////////// 00034 // Utility functions 00035 ////////////////////// 00036 00037 /** 00038 * Returns the absolute fixtures path for this testcase. 00039 * 00040 * @return string the absolute fixtures path for this testcase, will not be empty 00041 */ 00042 private function determineFixturesPath() { 00043 return t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder') 00044 ->getAbsoluteCoreTestsPath() . 't3lib/tree/fixtures/'; 00045 } 00046 00047 protected function setUpNodeTestData() { 00048 $fixture = new t3lib_tree_Node; 00049 $fixture->setId('Root'); 00050 00051 $nodeCollection = new t3lib_tree_NodeCollection; 00052 for ($i = 0; $i < 10; ++$i) { 00053 $node = new t3lib_tree_Node; 00054 $node->setId($i); 00055 $node->setParentNode($fixture); 00056 00057 $subNodeCollection = new t3lib_tree_NodeCollection; 00058 for ($j = 0; $j < 5; ++$j) { 00059 $subNode = new t3lib_tree_RepresentationNode; 00060 $subNode->setId($j); 00061 $subNode->setLabel('SubTest'); 00062 $subNode->setType('Type'); 00063 $subNode->setClass('Class'); 00064 $subNode->setIcon('Icon'); 00065 $subNode->setCallbackAction('Callback Action'); 00066 $subNode->setParentNode($node); 00067 $subNodeCollection->append($subNode); 00068 } 00069 $node->setChildNodes($subNodeCollection); 00070 $nodeCollection->append($node); 00071 } 00072 $fixture->setChildNodes($nodeCollection); 00073 00074 00075 return $fixture; 00076 } 00077 00078 00079 /////////////// 00080 // Test cases 00081 /////////////// 00082 00083 /** 00084 * @test 00085 */ 00086 public function serializeFixture() { 00087 $expected = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt')); 00088 $fixture = $this->setUpNodeTestData(); 00089 $serializedString = trim($fixture->serialize()); 00090 $this->assertSame($expected, $serializedString); 00091 } 00092 00093 /** 00094 * @test 00095 */ 00096 public function deserializeFixture() { 00097 $source = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt')); 00098 $node = new t3lib_tree_Node(); 00099 $node->unserialize($source); 00100 $serializedString = $node->serialize(); 00101 $this->assertSame($source, $serializedString); 00102 } 00103 00104 /** 00105 * @test 00106 */ 00107 public function compareNodes() { 00108 $node = new t3lib_tree_Node(array('id' => '15')); 00109 $otherNode = new t3lib_tree_Node(array('id' => '5')); 00110 $compareResult = $node->compareTo($otherNode); 00111 00112 $otherNode->setId('25'); 00113 $compareResult = $node->compareTo($otherNode); 00114 $this->assertSame(-1, $compareResult); 00115 00116 $otherNode->setId('15'); 00117 $compareResult = $node->compareTo($otherNode); 00118 $this->assertSame(0, $compareResult); 00119 } 00120 } 00121 ?>
1.8.0