ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilPluginInfoTest.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Data;
20use PHPUnit\Framework\TestCase;
21
22class ilPluginInfoTest extends TestCase
23{
24 protected ?Data\Factory $data_factory = null;
25 protected ?ilComponentInfo $component = null;
26 protected ?ilPluginSlotInfo $pluginslot = null;
27 protected ?ilPluginInfo $plugin = null;
28
29 protected function setUp(): void
30 {
31 $this->data_factory = new Data\Factory();
32
33 $slots = [];
34 $this->component = new ilComponentInfo(
35 "mod1",
36 "components/ILIAS",
37 "Module1",
38 $slots
39 );
40
41 $plugins = [];
42 $this->pluginslot = new ilPluginSlotInfo(
43 $this->component,
44 "slt1",
45 "Slot1",
46 $plugins
47 );
48 $slots[] = $this->pluginslot;
49
50 $this->plugin = new ilPluginInfo(
51 $this->data_factory->version("6.5"),
52 $this->pluginslot,
53 "plg1",
54 "Plugin1",
55 "Type1",
56 true,
57 $this->data_factory->version("1.0.0"),
58 12,
59 $this->data_factory->version("1.0.0"),
60 $this->data_factory->version("6.0"),
61 $this->data_factory->version("6.99"),
62 "Richard Klees",
63 "richard.klees@concepts-and-training.de",
64 true,
65 false,
66 true
67 );
68 }
69
70 public function testGetter(): void
71 {
72 $this->assertEquals($this->pluginslot, $this->plugin->getPluginSlot());
73 $this->assertEquals($this->component, $this->plugin->getComponent());
74 $this->assertEquals("plg1", $this->plugin->getId());
75 $this->assertEquals("Plugin1", $this->plugin->getName());
76 $this->assertEquals("Type1", $this->plugin->getType());
77 $this->assertTrue($this->plugin->isActivated());
78 $this->assertEquals($this->data_factory->version("1.0.0"), $this->plugin->getCurrentVersion());
79 $this->assertEquals(12, $this->plugin->getCurrentDBVersion());
80 $this->assertEquals($this->data_factory->version("1.0.0"), $this->plugin->getAvailableVersion());
81 $this->assertEquals($this->data_factory->version("6.0"), $this->plugin->getMinimumILIASVersion());
82 $this->assertEquals($this->data_factory->version("6.99"), $this->plugin->getMaximumILIASVersion());
83 $this->assertEquals("Richard Klees", $this->plugin->getResponsible());
84 $this->assertEquals("richard.klees@concepts-and-training.de", $this->plugin->getResponsibleMail());
85 $this->assertTrue($this->plugin->supportsLearningProgress());
86 $this->assertFalse($this->plugin->supportsExport());
87 $this->assertTrue($this->plugin->supportsCLISetup());
88 }
89
90 public function testIsInstalled(): void
91 {
92 $this->assertTrue($this->plugin->isInstalled());
93 }
94
95 public function testIsNotInstalled(): void
96 {
97 $this->plugin = new ilPluginInfo(
98 $this->data_factory->version("6.5"),
99 $this->pluginslot,
100 "plg1",
101 "Plugin1",
102 "Type1",
103 true,
104 null,
105 null,
106 $this->data_factory->version("1.0.0"),
107 $this->data_factory->version("6.0"),
108 $this->data_factory->version("6.99"),
109 "Richard Klees",
110 "richard.klees@concepts-and-training.de",
111 true,
112 false,
113 true
114 );
115
116 $this->assertFalse($this->plugin->isInstalled());
117 }
118
119 public function testUpdateIsNotRequired(): void
120 {
121 $this->assertFalse($this->plugin->isUpdateRequired());
122 }
123
125 {
126 $this->plugin = new ilPluginInfo(
127 $this->data_factory->version("6.5"),
128 $this->pluginslot,
129 "plg1",
130 "Plugin1",
131 "Type1",
132 true,
133 null,
134 null,
135 $this->data_factory->version("1.0.0"),
136 $this->data_factory->version("6.0"),
137 $this->data_factory->version("6.99"),
138 "Richard Klees",
139 "richard.klees@concepts-and-training.de",
140 true,
141 false,
142 true
143 );
144
145 $this->assertFalse($this->plugin->isUpdateRequired());
146 }
147
148 public function testUpdateIsRequired(): void
149 {
150 $this->plugin = new ilPluginInfo(
151 $this->data_factory->version("6.5"),
152 $this->pluginslot,
153 "plg1",
154 "Plugin1",
155 "Type1",
156 true,
157 $this->data_factory->version("2.0.0"),
158 11,
159 $this->data_factory->version("1.0.0"),
160 $this->data_factory->version("6.0"),
161 $this->data_factory->version("6.99"),
162 "Richard Klees",
163 "richard.klees@concepts-and-training.de",
164 true,
165 false,
166 true
167 );
168
169 $this->assertTrue($this->plugin->isUpdateRequired());
170 }
171
172 public function testIsVersionOld(): void
173 {
174 $this->assertFalse($this->plugin->isVersionToOld());
175
176 $plugin = new ilPluginInfo(
177 $this->data_factory->version("6.5"),
178 $this->pluginslot,
179 "plg1",
180 "Plugin1",
181 "Type1",
182 true,
183 $this->data_factory->version("1.0.0"),
184 12,
185 $this->data_factory->version("2.0.0"),
186 $this->data_factory->version("6.0"),
187 $this->data_factory->version("6.99"),
188 "Richard Klees",
189 "richard.klees@concepts-and-training.de",
190 true,
191 false,
192 true
193 );
194 $this->assertFalse($plugin->isVersionToOld());
195
196 $plugin = new ilPluginInfo(
197 $this->data_factory->version("6.5"),
198 $this->pluginslot,
199 "plg1",
200 "Plugin1",
201 "Type1",
202 true,
203 $this->data_factory->version("1.2.2"),
204 12,
205 $this->data_factory->version("1.0.0"),
206 $this->data_factory->version("6.0"),
207 $this->data_factory->version("6.99"),
208 "Richard Klees",
209 "richard.klees@concepts-and-training.de",
210 true,
211 false,
212 true
213 );
214 $this->assertTrue($plugin->isVersionToOld());
215 }
216
217 #[\PHPUnit\Framework\Attributes\DataProvider('versionCompliance')]
218 public function testIsCompliantToILIAS(Data\Version $version, bool $is_compliant): void
219 {
220 $plugin = new ilPluginInfo(
221 $version,
222 $this->pluginslot,
223 "plg1",
224 "Plugin1",
225 "Type1",
226 true,
227 $this->data_factory->version("1.2.2"),
228 12,
229 $this->data_factory->version("1.0.0"),
230 $this->data_factory->version("6.0"),
231 $this->data_factory->version("6.99"),
232 "Richard Klees",
233 "richard.klees@concepts-and-training.de",
234 true,
235 false,
236 true
237 );
238 $this->assertSame($is_compliant, $plugin->isCompliantToILIAS());
239 }
240
241 public static function versionCompliance(): array
242 {
243 $data_factory = new Data\Factory();
244 return [
245 [$data_factory->version("5.4"), false],
246 [$data_factory->version("6.5"), true],
247 [$data_factory->version("7.1"), false]
248 ];
249 }
250
251 public function testGetPath(): void
252 {
253 $this->assertEquals(
254 dirname(__DIR__, 4) . "/public/Customizing/global/plugins/Type1/Module1/Slot1/Plugin1",
255 $this->plugin->getPath()
256 );
257 }
258
263 public function testGetPathIsNormalized(): void
264 {
265 $this->assertStringNotContainsString('..', $this->plugin->getPath());
266 }
267
268 public function testGetClassName(): void
269 {
270 $this->assertEquals(
271 "ilPlugin1Plugin",
272 $this->plugin->getClassName()
273 );
274 }
275
276 public function testGetConfigureClassName(): void
277 {
278 $this->assertEquals(
279 "ilPlugin1ConfigGUI",
280 $this->plugin->getConfigGUIClassName()
281 );
282 }
283
284 #[\PHPUnit\Framework\Attributes\DataProvider('isActivationPossibleTruthTable')]
286 bool $is_installed,
287 bool $supports_current_ilias,
288 bool $needs_update,
289 bool $is_version_to_old,
290 bool $is_activation_possible
291 ): void {
292 $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_version_to_old) extends ilPluginInfo {
293 protected bool $is_installed;
294 protected bool $supports_current_ilias;
295 protected bool $needs_update;
296 protected bool $is_version_to_old;
297
298 public function __construct(
299 bool $is_installed,
300 bool $supports_current_ilias,
301 bool $needs_update,
302 bool $is_version_to_old
303 ) {
304 $this->is_installed = $is_installed;
305 $this->supports_current_ilias = $supports_current_ilias;
306 $this->needs_update = $needs_update;
307 $this->is_version_to_old = $is_version_to_old;
308 }
309
310 public function isInstalled(): bool
311 {
312 return $this->is_installed;
313 }
314
315 public function isUpdateRequired(): bool
316 {
317 return $this->needs_update;
318 }
319
320 public function isCompliantToILIAS(): bool
321 {
322 return $this->supports_current_ilias;
323 }
324
325 public function isVersionToOld(): bool
326 {
327 return $this->is_version_to_old;
328 }
329 };
330
331 $this->assertEquals($is_activation_possible, $plugin->isActivationPossible());
332 }
333
334 public static function isActivationPossibleTruthTable(): array
335 {
336 // is_installed, supports_current_ilias, needs_update, is_version_to_old => is_activation_possible
337 return [
338 [false, false, false, false, false],
339 [false, false, true, false, false],
340 [false, true, false, false, false],
341 [false, true, true, false, false],
342 [true, false, false, false, false],
343 [true, false, true, false, false],
344 [true, true, false, false, true],
345 [true, true, true, true, false],
346 [false, false, false, true, false],
347 [false, false, true, true, false],
348 [false, true, false, true, false],
349 [false, true, true, true, false],
350 [true, false, false, true, false],
351 [true, false, true, true, false],
352 [true, true, false, true, false],
353 [true, true, true, true, false]
354 ];
355 }
356
357 #[\PHPUnit\Framework\Attributes\DataProvider('isActiveTruthTable')]
358 public function testIsActive(
359 bool $is_installed,
360 bool $supports_current_ilias,
361 bool $needs_update,
362 bool $is_activated,
363 bool $is_version_to_old,
364 bool $is_activation_possible
365 ): void {
366 $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_activated, $is_version_to_old) extends ilPluginInfo {
367 protected bool $is_installed;
368 protected bool $supports_current_ilias;
369 protected bool $needs_update;
370 protected bool $is_activated;
371 protected bool $is_version_to_old;
372
373 public function __construct(
374 bool $is_installed,
375 bool $supports_current_ilias,
376 bool $needs_update,
377 bool $is_activated,
378 bool $is_version_to_old
379 ) {
380 $this->is_installed = $is_installed;
381 $this->supports_current_ilias = $supports_current_ilias;
382 $this->needs_update = $needs_update;
383 $this->is_activated = $is_activated;
384 $this->is_version_to_old = $is_version_to_old;
385 }
386
387 public function isActivated(): bool
388 {
389 return $this->is_activated;
390 }
391
392 public function isInstalled(): bool
393 {
394 return $this->is_installed;
395 }
396
397 public function isUpdateRequired(): bool
398 {
399 return $this->needs_update;
400 }
401
402 public function isCompliantToILIAS(): bool
403 {
404 return $this->supports_current_ilias;
405 }
406
407 public function isVersionToOld(): bool
408 {
409 return $this->is_version_to_old;
410 }
411 };
412
413 $this->assertEquals($is_activation_possible, $plugin->isActive());
414 }
415
416 public static function isActiveTruthTable(): array
417 {
418 // is_installed, supports_current_ilias, needs_update, is_activated, is_version_to_old => is_active
419 return [
420 [false, false, false, false, false, false],
421 [false, false, false, true, false, false],
422 [false, false, true , false, false, false],
423 [false, false, true , true, false, false],
424 [false, true, false, false, false, false],
425 [false, true, false, true, false, false],
426 [false, true, true , false, false, false],
427 [false, true, true , true, false, false],
428 [true, false, false, false, false, false],
429 [true, false, false, true, false, false],
430 [true, false, true , false, false, false],
431 [true, false, true , true, false, false],
432 [true, true, false, false, false, false],
433 [true, true, false, true, false, true],
434 [true, true, true , false, false, false],
435 [true, true, true , true, false, false],
436
437 [false, false, false, false, true, false],
438 [false, false, false, true, true, false],
439 [false, false, true , false, true, false],
440 [false, false, true , true, true, false],
441 [false, true, false, false, true, false],
442 [false, true, false, true, true, false],
443 [false, true, true , false, true, false],
444 [false, true, true , true, true, false],
445 [true, false, false, false, true, false],
446 [true, false, false, true, true, false],
447 [true, false, true , false, true, false],
448 [true, false, true , true, true, false],
449 [true, true, false, false, true, false],
450 [true, true, false, true, true, false],
451 [true, true, true , false, true, false],
452 [true, true, true , true, true, false],
453 ];
454 }
455
456
457 #[\PHPUnit\Framework\Attributes\DataProvider('inactivityReasonTable')]
459 bool $is_installed,
460 bool $supports_current_ilias,
461 bool $needs_update,
462 bool $is_activated,
463 bool $is_version_to_old,
464 string $inactivity_reason
465 ): void {
466 $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_activated, $is_version_to_old) extends ilPluginInfo {
467 protected bool $is_installed;
468 protected bool $supports_current_ilias;
469 protected bool $needs_update;
470 protected bool $is_activated;
471 protected bool $is_version_to_old;
472
473 public function __construct(
474 bool $is_installed,
475 bool $supports_current_ilias,
476 bool $needs_update,
477 bool $is_activated,
478 bool $is_version_to_old
479 ) {
480 $this->is_installed = $is_installed;
481 $this->supports_current_ilias = $supports_current_ilias;
482 $this->needs_update = $needs_update;
483 $this->is_activated = $is_activated;
484 $this->is_version_to_old = $is_version_to_old;
485 }
486
487 public function isActivated(): bool
488 {
489 return $this->is_activated;
490 }
491
492 public function isInstalled(): bool
493 {
494 return $this->is_installed;
495 }
496
497 public function isUpdateRequired(): bool
498 {
499 return $this->needs_update;
500 }
501
502 public function isCompliantToILIAS(): bool
503 {
504 return $this->supports_current_ilias;
505 }
506
507 public function getCurrentVersion(): ?Data\Version
508 {
509 return $this->current_version;
510 }
511
512 public function isVersionToOld(): bool
513 {
514 return $this->is_version_to_old;
515 }
516 };
517
518 $this->assertEquals($inactivity_reason, $plugin->getReasonForInactivity());
519 }
520
522 {
523 $this->expectException(LogicException::class);
524
525 $plugin = new class () extends ilPluginInfo {
526 public function __construct()
527 {
528 }
529
530 public function isActive(): bool
531 {
532 return true;
533 }
534 };
535
536 $plugin->getReasonForInactivity();
537 }
538
539 public static function inactivityReasonTable(): array
540 {
541 // is_installed, supports_current_ilias, needs_update, is_activated, is_version_to_old => inactivity_reason
542 return [
543 [false, false, false, false, false, "cmps_needs_matching_ilias_version"],
544 [false, false, false, true, false, "cmps_needs_matching_ilias_version"],
545 [false, false, true , false, false, "cmps_needs_matching_ilias_version"],
546 [false, false, true , true, false, "cmps_needs_matching_ilias_version"],
547 [false, true, false, false, false, "cmps_must_installed"],
548 [false, true, false, true, false, "cmps_must_installed"],
549 [false, true, true , false, false, "cmps_must_installed"],
550 [false, true, true , true, false, "cmps_must_installed"],
551 [true, false, false, false, false, "cmps_needs_matching_ilias_version"],
552 [true, false, false, true, false, "cmps_needs_matching_ilias_version"],
553 [true, false, true , false, false, "cmps_needs_matching_ilias_version"],
554 [true, false, true , true, false, "cmps_needs_matching_ilias_version"],
555 [true, true, false, false, false, "cmps_not_activated"],
556 [true, true, true , false, false, "cmps_needs_update"],
557 [true, true, true , true, false, "cmps_needs_update"],
558 [false, false, false, false, true, "cmps_needs_matching_ilias_version"],
559 [false, false, false, true, true, "cmps_needs_matching_ilias_version"],
560 [false, false, true , false, true, "cmps_needs_matching_ilias_version"],
561 [false, false, true , true, true, "cmps_needs_matching_ilias_version"],
562 [false, true, false, false, true, "cmps_must_installed"],
563 [false, true, false, true, true, "cmps_must_installed"],
564 [false, true, true , false, true, "cmps_must_installed"],
565 [false, true, true , true, true, "cmps_must_installed"],
566 [true, false, false, false, true, "cmps_needs_matching_ilias_version"],
567 [true, false, false, true, true, "cmps_needs_matching_ilias_version"],
568 [true, false, true , false, true, "cmps_needs_matching_ilias_version"],
569 [true, false, true , true, true, "cmps_needs_matching_ilias_version"],
570 [true, true, false, false, true, "cmps_needs_upgrade"],
571 [true, true, true , false, true, "cmps_needs_upgrade"],
572 [true, true, true , true, true, "cmps_needs_upgrade"],
573 ];
574 }
575}
$version
Definition: plugin.php:24
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:27
Simple value class for basic information about a component.
testGetPathIsNormalized()
ilComponentRepository::PLUGIN_BASE_PATH is built from DIR, the "../../../.." it carries must not show...
testIsCompliantToILIAS(Data\Version $version, bool $is_compliant)
static isActivationPossibleTruthTable()
ilPluginInfo $plugin
testIsActive(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_activated, bool $is_version_to_old, bool $is_activation_possible)
testGetReasonForInactivityThrowsOnActivePlugin()
testGetReasonForInactivity(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_activated, bool $is_version_to_old, string $inactivity_reason)
static inactivityReasonTable()
testIsActivationPossible(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_version_to_old, bool $is_activation_possible)
Data Factory $data_factory
ilPluginSlotInfo $pluginslot
ilComponentInfo $component
Simple value class for information about a plugin.
isCompliantToILIAS()
"ILIAS Version compliance" tells if the plugin can be operated with the given ILIAS version.
isVersionToOld()
"Version to old" tells if the plugin code has a version that is below the version that was updated la...
Simple value class for basic information about a pluginslot.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc