ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
KSDocumentationTreeRecursionTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once('vendor/composer/vendor/autoload.php');
22include_once('./components/ILIAS/UI/tests/UITestHelper.php');
23
24use PHPUnit\Framework\TestCase;
28
30{
32 protected $entries_data;
33 protected Entries $entries;
34 protected Entry $entry;
35 protected array $entry_data;
36 protected URI $test_uri;
38
39 protected function setUp(): void
40 {
41 $this->ui_helper = new UITestHelper();
42
43 $this->entries_data = include './components/ILIAS/UI/tests/Crawler/Fixture/EntriesFixture.php';
44 $this->entries = new Entries();
45 $this->entries->addEntriesFromArray($this->entries_data);
46 $this->test_uri = new URI('http://ilias.de');
47 $this->tree_recursion = new KSDocumentationTreeRecursion($this->entries, $this->test_uri, '');
48 }
49
50 public function testConstruct(): void
51 {
52 $this->assertInstanceOf('KSDocumentationTreeRecursion', $this->tree_recursion);
53 }
54
55 public function testGetChildren(): void
56 {
57 $this->assertEquals(
58 [$this->entries->getEntryById('Entry2')],
59 $this->tree_recursion->getChildren($this->entries->getEntryById('Entry1'))
60 );
61 $this->assertEquals([], $this->tree_recursion->getChildren($this->entries->getEntryById('Entry2')));
62 }
63
64 public function testBuild(): void
65 {
66 $tree_factory = $this->ui_helper->factory()->tree()->node();
67 $built_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry1'));
68 $this->assertInstanceOf('ILIAS\UI\Implementation\Component\Tree\Node\Simple', $built_node);
69 }
70
71 public function testIsNodeExpandedByDefault(): void
72 {
73 $tree_factory = $this->ui_helper->factory()->tree()->node();
74 $built_root_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry1'));
75 $built_child_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry2'));
76
77 $this->assertEquals(true, $built_root_node->isExpanded());
78 $this->assertEquals(false, $built_child_node->isExpanded());
79 }
80
81 public function testIsNodeHighlightedByDefault(): void
82 {
83 $this->tree_recursion = new KSDocumentationTreeRecursion($this->entries, $this->test_uri, 'Entry2');
84
85 $tree_factory = $this->ui_helper->factory()->tree()->node();
86 $built_root_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry1'));
87 $built_child_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry2'));
88
89 $this->assertEquals(false, $built_root_node->isHighlighted());
90 $this->assertEquals(true, $built_child_node->isHighlighted());
91 }
92
94 {
95 $this->tree_recursion = new KSDocumentationTreeRecursion($this->entries, $this->test_uri, 'Entry2');
96
97 $tree_factory = $this->ui_helper->factory()->tree()->node();
98 $built_root_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry1'));
99 $built_child_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry2'));
100
101 $this->assertEquals(true, $built_root_node->isExpanded());
102 $this->assertEquals(false, $built_child_node->isExpanded());
103 }
104
106 {
107 $this->tree_recursion = new KSDocumentationTreeRecursion($this->entries, $this->test_uri, 'Entry2');
108
109 $tree_factory = $this->ui_helper->factory()->tree()->node();
110 $built_root_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry1'));
111 $built_child_node = $this->tree_recursion->build($tree_factory, $this->entries->getEntryById('Entry2'));
112
113 $this->assertEquals(false, $built_root_node->isHighlighted());
114 $this->assertEquals(true, $built_child_node->isHighlighted());
115 }
116}
trait UITestHelper
Class UITestHelper can be helpful for test cases outside the UI Components, to inject a working facto...
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable.
Stores Information of UI Components parsed from YAML, examples and less files.
Tree Recursion, putting Entries into a Tree.