[TASK] Update caching framework to latest FLOW3 version
[Packages/TYPO3.CMS.git] / tests / t3lib / tree / class.t3lib_tree_nodeTest.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_Node.
27 *
28 * @author Stefan Galinski <stefan.galinski@gmail.com>
29 * @package TYPO3
30 * @subpackage t3lib
31 */
32 class t3lib_tree_NodeTest extends tx_phpunit_testcase {
33 //////////////////////
34 // Utility functions
35 //////////////////////
36
37 /**
38 * Returns the absolute fixtures path for this testcase.
39 *
40 * @return string the absolute fixtures path for this testcase, will not be empty
41 */
42 private function determineFixturesPath() {
43 return t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder')
44 ->getAbsoluteCoreTestsPath() . 't3lib/tree/fixtures/';
45 }
46
47 protected function setUpNodeTestData() {
48 $fixture = new t3lib_tree_Node;
49 $fixture->setId('Root');
50
51 $nodeCollection = new t3lib_tree_NodeCollection;
52 for ($i = 0; $i < 10; ++$i) {
53 $node = new t3lib_tree_Node;
54 $node->setId($i);
55 $node->setParentNode($fixture);
56
57 $subNodeCollection = new t3lib_tree_NodeCollection;
58 for ($j = 0; $j < 5; ++$j) {
59 $subNode = new t3lib_tree_RepresentationNode;
60 $subNode->setId($j);
61 $subNode->setLabel('SubTest');
62 $subNode->setType('Type');
63 $subNode->setClass('Class');
64 $subNode->setIcon('Icon');
65 $subNode->setCallbackAction('Callback Action');
66 $subNode->setParentNode($node);
67 $subNodeCollection->append($subNode);
68 }
69 $node->setChildNodes($subNodeCollection);
70 $nodeCollection->append($node);
71 }
72 $fixture->setChildNodes($nodeCollection);
73
74
75 return $fixture;
76 }
77
78
79 ///////////////
80 // Test cases
81 ///////////////
82
83 /**
84 * @test
85 */
86 public function serializeFixture() {
87 $expected = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
88 $fixture = $this->setUpNodeTestData();
89 $serializedString = trim($fixture->serialize());
90 $this->assertSame($expected, $serializedString);
91 }
92
93 /**
94 * @test
95 */
96 public function deserializeFixture() {
97 $source = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
98 $node = new t3lib_tree_Node();
99 $node->unserialize($source);
100 $serializedString = $node->serialize();
101 $this->assertSame($source, $serializedString);
102 }
103
104 /**
105 * @test
106 */
107 public function compareNodes() {
108 $node = new t3lib_tree_Node(array('id' => '15'));
109 $otherNode = new t3lib_tree_Node(array('id' => '5'));
110 $compareResult = $node->compareTo($otherNode);
111
112 $otherNode->setId('25');
113 $compareResult = $node->compareTo($otherNode);
114 $this->assertSame(-1, $compareResult);
115
116 $otherNode->setId('15');
117 $compareResult = $node->compareTo($otherNode);
118 $this->assertSame(0, $compareResult);
119 }
120 }
121 ?>