‪TYPO3CMS  10.4
TreeNodeTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪TreeNodeTest extends UnitTestCase
29 {
33  public function ‪serializeFixture()
34  {
35  $expected = trim(file_get_contents(__DIR__ . '/Fixtures/serialized.txt'));
36  $fixture = new ‪TreeNode();
37  $fixture->setId('Root');
38  $nodeCollection = new ‪TreeNodeCollection();
39  for ($i = 0; $i < 10; ++$i) {
40  $node = new ‪TreeNode();
41  $node->setId($i);
42  $node->setParentNode($fixture);
43  $subNodeCollection = new ‪TreeNodeCollection();
44  for ($j = 0; $j < 5; ++$j) {
45  $subNode = new ‪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  $serializedString = trim($fixture->serialize());
60  self::assertSame($expected, $serializedString);
61  }
62 
66  public function ‪deserializeFixture()
67  {
68  $source = trim(file_get_contents(__DIR__ . '/Fixtures/serialized.txt'));
69  $node = new ‪TreeNode();
70  $node->unserialize($source);
71  $serializedString = $node->serialize();
72  self::assertSame($source, $serializedString);
73  }
74 
78  public function ‪compareNodes()
79  {
80  $node = new ‪TreeNode(['id' => '15']);
81  $otherNode = new ‪TreeNode(['id' => '5']);
82  $otherNode->setId('25');
83  $compareResult = $node->compareTo($otherNode);
84  self::assertSame(-1, $compareResult);
85  $otherNode->setId('15');
86  $compareResult = $node->compareTo($otherNode);
87  self::assertSame(0, $compareResult);
88  }
89 }
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest\deserializeFixture
‪deserializeFixture()
Definition: TreeNodeTest.php:66
‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode
Definition: TreeRepresentationNode.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest\compareNodes
‪compareNodes()
Definition: TreeNodeTest.php:78
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:25
‪TYPO3\CMS\Backend\Tree\TreeNode
Definition: TreeNode.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Tree
Definition: SortedTreeNodeCollectionTest.php:16
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest\serializeFixture
‪serializeFixture()
Definition: TreeNodeTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Tree\TreeNodeTest
Definition: TreeNodeTest.php:29