ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TreeTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
28
32class TestingTree extends Tree
33{
34}
35
40{
41 public function testWrongConstruction(): void
42 {
43 $this->expectException(ArgumentCountError::class);
44 $tree = new TestingTree();
45 }
46
47 public function testWrongTypeConstruction(): void
48 {
49 $this->expectException(TypeError::class);
50 $tree = new TestingTree('something');
51 }
52
53 public function testConstruction(): TestingTree
54 {
55 $label = "label";
56 $recursion = new class () implements TreeRecursion {
57 public function getChildren($record, $environment = null): array
58 {
59 return [];
60 }
61
62 public function build(
63 Factory $factory,
64 $record,
65 $environment = null
66 ): Node {
67 }
68 };
69
70 $tree = new TestingTree($label, $recursion);
71 $this->assertInstanceOf("ILIAS\\UI\\Component\\Tree\\Tree", $tree);
72
73 return $tree;
74 }
75
76 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
77 public function testGetLabel(TestingTree $tree): void
78 {
79 $this->assertEquals("label", $tree->getLabel());
80 }
81
82 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
83 public function testGetRecursion(TestingTree $tree): void
84 {
85 $this->assertInstanceOf("ILIAS\\UI\\Component\\Tree\\TreeRecursion", $tree->getRecursion());
86 }
87
88 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
89 public function testWithEnvironment(TestingTree $tree): void
90 {
91 $env = ['key1' => 'val1', 'key2' => 2];
92 $this->assertEquals($env, $tree->withEnvironment($env)->getEnvironment());
93 }
94
95 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
96 public function testWithData(TestingTree $tree): void
97 {
98 $data = ['entry1', 'entry2'];
99 $this->assertEquals($data, $tree->withData($data)->getData());
100 }
101
102 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
103 public function testWithHighlightOnNodeClick(TestingTree $tree): void
104 {
105 $this->assertFalse($tree->getHighlightOnNodeClick());
106 $this->assertTrue($tree->withHighlightOnNodeClick(true)->getHighlightOnNodeClick());
107 }
108
109 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
110 public function testWithIsSubTree(TestingTree $tree): void
111 {
112 $this->assertFalse($tree->isSubTree());
113 $this->assertTrue($tree->withIsSubTree(true)->isSubTree());
114 }
115}
withIsSubTree(bool $is_sub)
Set this tree to be a part of a tree.Needed if parts are loaded async.
Definition: Tree.php:136
withHighlightOnNodeClick(bool $highlight_nodes_on_click)
Should a clicked node be highlighted?
Definition: Tree.php:110
withEnvironment($environment)
Configure the Tree with additional information that will be relayed to TreeRecursion.
Definition: Tree.php:66
getHighlightOnNodeClick()
Is the tree configured to highlight a clicked node?
Definition: Tree.php:120
isSubTree()
Is this only a part of a tree? Needed if parts are loaded async.
Definition: Tree.php:128
withData($data)
Apply data to the Tree.
Definition: Tree.php:76
getRecursion()
Get the mapping-class.
Definition: Tree.php:102
Provides common functionality for UI tests.
Definition: Base.php:337
Dummy-implementation for testing.
Definition: TreeTest.php:33
Tests for the (Base-)Tree.
Definition: TreeTest.php:40
testWithHighlightOnNodeClick(TestingTree $tree)
Definition: TreeTest.php:103
testWithData(TestingTree $tree)
Definition: TreeTest.php:96
testConstruction()
Definition: TreeTest.php:53
testWrongTypeConstruction()
Definition: TreeTest.php:47
testGetLabel(TestingTree $tree)
Definition: TreeTest.php:77
testWrongConstruction()
Definition: TreeTest.php:41
testGetRecursion(TestingTree $tree)
Definition: TreeTest.php:83
testWithEnvironment(TestingTree $tree)
Definition: TreeTest.php:89
testWithIsSubTree(TestingTree $tree)
Definition: TreeTest.php:110
This describes a Tree Node.
Definition: Node.php:31
Interface for mapping data-structures to the Tree.
This describes a Tree Control.
Definition: Tree.php:29