3480399da92c718f8d4f191fd3f887c767152f06
[Packages/TYPO3.CMS.git] / tests / t3lib / tree / t3lib_tree_nodeTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 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 public function setUp() {
34 }
35
36 public function tearDown() {
37 }
38
39 protected function setUpNodeTestData() {
40 $fixture = new t3lib_tree_Node;
41 $fixture->setId('Root');
42
43 $nodeCollection = new t3lib_tree_NodeCollection;
44 for ($i = 0; $i < 10; ++$i) {
45 $node = new t3lib_tree_Node;
46 $node->setId($i);
47 $node->setParentNode($fixture);
48
49 $subNodeCollection = new t3lib_tree_NodeCollection;
50 for ($j = 0; $j < 5; ++$j) {
51 $subNode = new t3lib_tree_RepresentationNode;
52 $subNode->setId($j);
53 $subNode->setLabel('SubTest');
54 $subNode->setType('Type');
55 $subNode->setClass('Class');
56 $subNode->setIcon('Icon');
57 $subNode->setCallbackAction('Callback Action');
58 $subNode->setParentNode($node);
59 $subNodeCollection->append($subNode);
60 }
61 $node->setChildNodes($subNodeCollection);
62 $nodeCollection->append($node);
63 }
64 $fixture->setChildNodes($nodeCollection);
65
66
67 return $fixture;
68 }
69
70 /**
71 * @test
72 */
73 public function serializeFixture() {
74 $expected = trim(file_get_contents(PATH_site . 'tests/t3lib/tree/fixtures/serialized.txt'));
75 $fixture = $this->setUpNodeTestData();
76 $serializedString = trim($fixture->serialize());
77 $this->assertSame($expected, $serializedString);
78 }
79
80 /**
81 * @test
82 */
83 public function deserializeFixture() {
84 $source = trim(file_get_contents(PATH_site . 'tests/t3lib/tree/fixtures/serialized.txt'));
85 $node = new t3lib_tree_Node;
86 $node->unserialize($source);
87 $serializedString = $node->serialize();
88 $this->assertSame($source, $serializedString);
89 }
90
91 /**
92 * @test
93 */
94 public function compareNodes() {
95 $node = new t3lib_tree_Node(array('id' => '15'));
96 $otherNode = new t3lib_tree_Node(array('id' => '5'));
97 $compareResult = $node->compareTo($otherNode);
98
99 $otherNode->setId('25');
100 $compareResult = $node->compareTo($otherNode);
101 $this->assertSame(-1, $compareResult);
102
103 $otherNode->setId('15');
104 $compareResult = $node->compareTo($otherNode);
105 $this->assertSame(0, $compareResult);
106 }
107 }
108 ?>