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