ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilComponentDefinitionReaderTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
20
22{
23}
25{
26}
27
28class ilComponentDefinitionReaderTest extends TestCase
29{
33
34 public static array $components = [
35 ["components/ILIAS", "A_Module", "/path/to/module.xml"],
36 ["components/ILIAS", "A_Service", "/other/path/to/service.xml"]
37 ];
38
39 protected function setUp(): void
40 {
41 $this->processor1 = $this->createMock(ilComponentDefinitionProcessorMock1::class);
42 $this->processor2 = $this->createMock(ilComponentDefinitionProcessorMock2::class);
43
44 $this->reader = new class ($this->processor1, $this->processor2) extends ilComponentDefinitionReader {
45 protected function getComponents(): Iterator
46 {
47 return new ArrayIterator(ilComponentDefinitionReaderTest::$components);
48 }
49 public $read_files = [];
50 protected function readFile(string $path): string
51 {
52 $this->read_files[] = $path;
53 if ($path === "/path/to/module.xml") {
54 return
55'<?xml version = "1.0" encoding = "UTF-8"?>
56<module a1="a1" a2="a2">
57 <tag1>
58 <tag11></tag11>
59 </tag1>
60 <tag2></tag2>
61</module>';
62 }
63 if ($path === "/other/path/to/service.xml") {
64 return
65'<?xml version = "1.0" encoding = "UTF-8"?>
66<service>
67</service>';
68 }
69 return "";
70 }
71 };
72 }
73
74 public function testPurge(): void
75 {
76 $this->processor1
77 ->expects($this->once())
78 ->method("purge")
79 ->with();
80 $this->processor2
81 ->expects($this->once())
82 ->method("purge")
83 ->with();
84
85 $this->reader->purge();
86 }
87
88 public function testGetComponents(): void
89 {
90 $reader = new class () extends ilComponentDefinitionReader {
91 public function __construct()
92 {
93 }
94 public function _getComponents(): array
95 {
96 return iterator_to_array($this->getComponents());
97 }
98 };
99
100 $components = $reader->_getComponents();
101
102 $this->assertIsArray($components);
103 $this->assertContains(["components/ILIAS", "Course", realpath(__DIR__ . "/../../../../components/ILIAS/Course/module.xml")], $components);
104 $this->assertContains(["components/ILIAS", "Component", realpath(__DIR__ . "/../../../../components/ILIAS/Component/service.xml")], $components);
105 }
106
107 public function testReadComponentDefinitions(): void
108 {
109 $processor1_stack = [];
110 $this->processor1
111 ->method("beginComponent")
112 ->willReturnCallback(function ($s1, $s2) use (&$processor1_stack) {
113 $processor1_stack[] = "beginComponent";
114 $processor1_stack[] = $s1;
115 $processor1_stack[] = $s2;
116 });
117 $this->processor1
118 ->method("endComponent")
119 ->willReturnCallback(function ($s1, $s2) use (&$processor1_stack) {
120 $processor1_stack[] = "endComponent";
121 $processor1_stack[] = $s1;
122 $processor1_stack[] = $s2;
123 });
124 $this->processor1
125 ->method("beginTag")
126 ->willReturnCallback(function ($s1, $s2) use (&$processor1_stack) {
127 $processor1_stack[] = "beginTag";
128 $processor1_stack[] = $s1;
129 $processor1_stack[] = $s2;
130 });
131 $this->processor1
132 ->method("endTag")
133 ->willReturnCallback(function ($s1) use (&$processor1_stack) {
134 $processor1_stack[] = "endTag";
135 $processor1_stack[] = $s1;
136 });
137
138 $processor2_stack = [];
139 $this->processor2
140 ->method("beginComponent")
141 ->willReturnCallback(function ($s1, $s2) use (&$processor2_stack) {
142 $processor2_stack[] = "beginComponent";
143 $processor2_stack[] = $s1;
144 $processor2_stack[] = $s2;
145 });
146 $this->processor2
147 ->method("endComponent")
148 ->willReturnCallback(function ($s1, $s2) use (&$processor2_stack) {
149 $processor2_stack[] = "endComponent";
150 $processor2_stack[] = $s1;
151 $processor2_stack[] = $s2;
152 });
153 $this->processor2
154 ->method("beginTag")
155 ->willReturnCallback(function ($s1, $s2) use (&$processor2_stack) {
156 $processor2_stack[] = "beginTag";
157 $processor2_stack[] = $s1;
158 $processor2_stack[] = $s2;
159 });
160 $this->processor2
161 ->method("endTag")
162 ->willReturnCallback(function ($s1) use (&$processor2_stack) {
163 $processor2_stack[] = "endTag";
164 $processor2_stack[] = $s1;
165 });
166
167
168 $this->reader->readComponentDefinitions();
169
170
171 $this->assertEquals([self::$components[0][2], self::$components[1][2]], $this->reader->read_files);
172
173 $expected_processor_stack = [
174 "beginComponent",
175 self::$components[0][1], // A_Module
176 self::$components[0][0], // Modules
177 "beginTag",
178 "module", ["a1" => "a1", "a2" => "a2"],
179 "beginTag",
180 "tag1", [],
181 "beginTag",
182 "tag11", [],
183 "endTag",
184 "tag11",
185 "endTag",
186 "tag1",
187 "beginTag",
188 "tag2", [],
189 "endTag",
190 "tag2",
191 "endTag",
192 "module",
193 "endComponent",
194 self::$components[0][1], // A_Module
195 self::$components[0][0], // Modules
196 "beginComponent",
197 self::$components[1][1], // A_Service
198 self::$components[1][0], // Services
199 "beginTag",
200 "service", [],
201 "endTag",
202 "service",
203 "endComponent",
204 self::$components[1][1], // A_Service
205 self::$components[1][0], // Services
206 ];
207 $this->assertEquals($expected_processor_stack, $processor1_stack);
208 $this->assertEquals($expected_processor_stack, $processor2_stack);
209 }
210}
$components
ilComponentDefinitionProcessor $processor2
ilComponentDefinitionProcessor $processor1
An ilComponentDefinitionProcessor processes some attributes from a component.xml (i....
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc