ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCtrlStructureTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2020 Richard Klees <richard.klees@concepts-and-training.de>, Extended GPL, see docs/LICENSE */
3
4use PHPUnit\Framework\TestCase;
5
6class ilCtrlStructureTest extends TestCase
7{
8 protected function setUp() : void
9 {
10 $this->ctrl_structure = new \ilCtrlStructure();
11 }
12
13 public function testAddClassScript()
14 {
15 $this->ctrl_structure = $this->ctrl_structure
16 ->withClassScript("class1", "file1")
17 ->withClassScript("class2", "file2")
18 ->withClassScript("class3", "file3")
19 ->withClassScript("class2", "file2");
20
21 $expected = [
22 "class1" => "file1",
23 "class2" => "file2",
24 "class3" => "file3",
25 ];
26
27 $this->assertEquals(
28 $expected,
29 iterator_to_array($this->ctrl_structure->getClassScripts())
30 );
31 }
32
34 {
35 $this->expectException(\RuntimeException::class);
36
37 $this->ctrl_structure
38 ->withClassScript("class1", "file1")
39 ->withClassScript("class1", "file2");
40 }
41
42 public function testAddClassChild()
43 {
44 $this->ctrl_structure = $this->ctrl_structure
45 ->withClassChild("parent1", "child1")
46 ->withClassChild("parent2", "child2")
47 ->withClassChild("parent1", "child3");
48
49 $expected = [
50 "parent1" => ["child1", "child3"],
51 "parent2" => ["child2"]
52 ];
53
54 $this->assertEquals(
55 $expected,
56 iterator_to_array($this->ctrl_structure->getClassChildren())
57 );
58 }
59
60 public function testConstructor()
61 {
62 $scripts = [
63 "class1" => "file1",
64 "class2" => "file2",
65 "class3" => "file3",
66 ];
67
68 $children = [
69 "parent1" => ["child1", "child3"],
70 "parent2" => ["child2"]
71 ];
72
73 $ctrl_structure = new \ilCtrlStructure($scripts, $children);
74
75 $this->assertEquals(
76 $scripts,
77 iterator_to_array($ctrl_structure->getClassScripts())
78 );
79
80 $this->assertEquals(
81 $children,
82 iterator_to_array($ctrl_structure->getClassChildren())
83 );
84 }
85
86 public function testGetClassScriptOf()
87 {
88 $scripts = [
89 "class1" => "file1",
90 "class2" => "file2",
91 "class3" => "file3",
92 ];
93
94 $ctrl_structure = new \ilCtrlStructure($scripts, []);
95
96 $this->assertEquals("file1", $ctrl_structure->getClassScriptOf("class1"));
97 $this->assertEquals("file2", $ctrl_structure->getClassScriptOf("class2"));
98 $this->assertEquals("file3", $ctrl_structure->getClassScriptOf("class3"));
99 $this->assertSame(null, $ctrl_structure->getClassScriptOf("class4"));
100 }
101}
An exception for terminatinating execution or to throw for unit testing.