[FEATURE] New option to disable the age display of dates per field by TCA
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Tree / TreeNodeTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Tree;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase for class \TYPO3\CMS\Backend\Tree\TreeNode.
19 */
20 class TreeNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 //////////////////////
23 // Utility functions
24 //////////////////////
25 /**
26 * Returns the absolute fixtures path for this testcase.
27 *
28 * @return string the absolute fixtures path for this testcase, will not be empty
29 */
30 private function determineFixturesPath() {
31 // We have to take the whole relative path as otherwise this test fails on Windows systems
32 return PATH_site . 'typo3/sysext/backend/Tests/Unit/Tree/Fixtures/';
33 }
34
35 protected function setUpNodeTestData() {
36 $fixture = new \TYPO3\CMS\Backend\Tree\TreeNode();
37 $fixture->setId('Root');
38 $nodeCollection = new \TYPO3\CMS\Backend\Tree\TreeNodeCollection();
39 for ($i = 0; $i < 10; ++$i) {
40 $node = new \TYPO3\CMS\Backend\Tree\TreeNode();
41 $node->setId($i);
42 $node->setParentNode($fixture);
43 $subNodeCollection = new \TYPO3\CMS\Backend\Tree\TreeNodeCollection();
44 for ($j = 0; $j < 5; ++$j) {
45 $subNode = new \TYPO3\CMS\Backend\Tree\TreeRepresentationNode();
46 $subNode->setId($j);
47 $subNode->setLabel('SubTest');
48 $subNode->setType('Type');
49 $subNode->setClass('Class');
50 $subNode->setIcon('Icon');
51 $subNode->setCallbackAction('Callback Action');
52 $subNode->setParentNode($node);
53 $subNodeCollection->append($subNode);
54 }
55 $node->setChildNodes($subNodeCollection);
56 $nodeCollection->append($node);
57 }
58 $fixture->setChildNodes($nodeCollection);
59 return $fixture;
60 }
61
62 ///////////////
63 // Test cases
64 ///////////////
65 /**
66 * @test
67 */
68 public function serializeFixture() {
69 $expected = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
70 $fixture = $this->setUpNodeTestData();
71 $serializedString = trim($fixture->serialize());
72 $this->assertSame($expected, $serializedString);
73 }
74
75 /**
76 * @test
77 */
78 public function deserializeFixture() {
79 $source = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
80 $node = new \TYPO3\CMS\Backend\Tree\TreeNode();
81 $node->unserialize($source);
82 $serializedString = $node->serialize();
83 $this->assertSame($source, $serializedString);
84 }
85
86 /**
87 * @test
88 */
89 public function compareNodes() {
90 $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => '15'));
91 $otherNode = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => '5'));
92 $compareResult = $node->compareTo($otherNode);
93 $otherNode->setId('25');
94 $compareResult = $node->compareTo($otherNode);
95 $this->assertSame(-1, $compareResult);
96 $otherNode->setId('15');
97 $compareResult = $node->compareTo($otherNode);
98 $this->assertSame(0, $compareResult);
99 }
100
101 }