ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
TreeTest.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 require_once(__DIR__ . "/../../Base.php");
23 
28 
32 class 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,
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 }
withEnvironment($environment)
Configure the Tree with additional information that will be relayed to TreeRecursion.
Definition: Tree.php:66
testWithData(TestingTree $tree)
Definition: TreeTest.php:96
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
withHighlightOnNodeClick(bool $highlight_nodes_on_click)
Should a clicked node be highlighted?
Definition: Tree.php:110
testWrongConstruction()
Definition: TreeTest.php:41
This describes a Tree Node.
Definition: Node.php:30
testWrongTypeConstruction()
Definition: TreeTest.php:47
getRecursion()
Get the mapping-class.
Definition: Tree.php:102
testWithHighlightOnNodeClick(TestingTree $tree)
Definition: TreeTest.php:103
getHighlightOnNodeClick()
Is the tree configured to highlight a clicked node?
Definition: Tree.php:120
Dummy-implementation for testing.
Definition: TreeTest.php:32
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testConstruction()
Definition: TreeTest.php:53
Tests for the (Base-)Tree.
Definition: TreeTest.php:39
testWithEnvironment(TestingTree $tree)
Definition: TreeTest.php:89
withIsSubTree(bool $is_sub)
Set this tree to be a part of a tree.Needed if parts are loaded async.
Definition: Tree.php:136
Interface for mapping data-structures to the Tree.
testGetRecursion(TestingTree $tree)
Definition: TreeTest.php:83
testWithIsSubTree(TestingTree $tree)
Definition: TreeTest.php:110
testGetLabel(TestingTree $tree)
Definition: TreeTest.php:77