‪TYPO3CMS  9.5
TreeNodeTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪TreeNodeTest extends UnitTestCase
27 {
31  public function ‪serializeFixture()
32  {
33  $expected = trim(file_get_contents(__DIR__ . '/Fixtures/serialized.txt'));
34  $fixture = new ‪TreeNode();
35  $fixture->setId('Root');
36  $nodeCollection = new ‪TreeNodeCollection();
37  for ($i = 0; $i < 10; ++$i) {
38  $node = new ‪TreeNode();
39  $node->setId($i);
40  $node->setParentNode($fixture);
41  $subNodeCollection = new ‪TreeNodeCollection();
42  for ($j = 0; $j < 5; ++$j) {
43  $subNode = new ‪TreeRepresentationNode();
44  $subNode->setId($j);
45  $subNode->setLabel('SubTest');
46  $subNode->setType('Type');
47  $subNode->setClass('Class');
48  $subNode->setIcon('Icon');
49  $subNode->setCallbackAction('Callback Action');
50  $subNode->setParentNode($node);
51  $subNodeCollection->append($subNode);
52  }
53  $node->setChildNodes($subNodeCollection);
54  $nodeCollection->append($node);
55  }
56  $fixture->setChildNodes($nodeCollection);
57  $serializedString = trim($fixture->serialize());
58  $this->assertSame($expected, $serializedString);
59  }
60 
64  public function ‪deserializeFixture()
65  {
66  $source = trim(file_get_contents(__DIR__ . '/Fixtures/serialized.txt'));
67  $node = new ‪TreeNode();
68  $node->unserialize($source);
69  $serializedString = $node->serialize();
70  $this->assertSame($source, $serializedString);
71  }
72 
76  public function ‪compareNodes()
77  {
78  $node = new ‪TreeNode(['id' => '15']);
79  $otherNode = new ‪TreeNode(['id' => '5']);
80  $otherNode->setId('25');
81  $compareResult = $node->compareTo($otherNode);
82  $this->assertSame(-1, $compareResult);
83  $otherNode->setId('15');
84  $compareResult = $node->compareTo($otherNode);
85  $this->assertSame(0, $compareResult);
86  }
87 }
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest\deserializeFixture
‪deserializeFixture()
Definition: TreeNodeTest.php:64
‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode
Definition: TreeRepresentationNode.php:22
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest\compareNodes
‪compareNodes()
Definition: TreeNodeTest.php:76
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:21
‪TYPO3\CMS\Backend\Tree\TreeNode
Definition: TreeNode.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Tree
Definition: SortedTreeNodeCollectionTest.php:2
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest\serializeFixture
‪serializeFixture()
Definition: TreeNodeTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest
Definition: TreeNodeTest.php:27