ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilPluginInfoTest.php
Go to the documentation of this file.
1 <?php
2 
20 use ILIAS\Data;
22 
23 class ilPluginInfoTest extends TestCase
24 {
25  protected ?Data\Factory $data_factory = null;
26  protected ?ilComponentInfo $component = null;
27  protected ?ilPluginSlotInfo $pluginslot = null;
28  protected ?ilPluginInfo $plugin = null;
29 
30  protected function setUp(): void
31  {
32  $this->data_factory = new Data\Factory();
33 
34  $slots = [];
35  $this->component = new ilComponentInfo(
36  "mod1",
37  "components/ILIAS",
38  "Module1",
39  $slots
40  );
41 
42  $plugins = [];
43  $this->pluginslot = new ilPluginSlotInfo(
44  $this->component,
45  "slt1",
46  "Slot1",
47  $plugins
48  );
49  $slots[] = $this->pluginslot;
50 
51  $this->plugin = new ilPluginInfo(
52  $this->data_factory->version("6.5"),
54  "plg1",
55  "Plugin1",
56  "Type1",
57  true,
58  $this->data_factory->version("1.0.0"),
59  12,
60  $this->data_factory->version("1.0.0"),
61  $this->data_factory->version("6.0"),
62  $this->data_factory->version("6.99"),
63  "Richard Klees",
64  "richard.klees@concepts-and-training.de",
65  true,
66  false,
67  true
68  );
69  }
70 
71  public function testGetter(): void
72  {
73  $this->assertEquals($this->pluginslot, $this->plugin->getPluginSlot());
74  $this->assertEquals($this->component, $this->plugin->getComponent());
75  $this->assertEquals("plg1", $this->plugin->getId());
76  $this->assertEquals("Plugin1", $this->plugin->getName());
77  $this->assertEquals("Type1", $this->plugin->getType());
78  $this->assertTrue($this->plugin->isActivated());
79  $this->assertEquals($this->data_factory->version("1.0.0"), $this->plugin->getCurrentVersion());
80  $this->assertEquals(12, $this->plugin->getCurrentDBVersion());
81  $this->assertEquals($this->data_factory->version("1.0.0"), $this->plugin->getAvailableVersion());
82  $this->assertEquals($this->data_factory->version("6.0"), $this->plugin->getMinimumILIASVersion());
83  $this->assertEquals($this->data_factory->version("6.99"), $this->plugin->getMaximumILIASVersion());
84  $this->assertEquals("Richard Klees", $this->plugin->getResponsible());
85  $this->assertEquals("richard.klees@concepts-and-training.de", $this->plugin->getResponsibleMail());
86  $this->assertTrue($this->plugin->supportsLearningProgress());
87  $this->assertFalse($this->plugin->supportsExport());
88  $this->assertTrue($this->plugin->supportsCLISetup());
89  }
90 
91  public function testIsInstalled(): void
92  {
93  $this->assertTrue($this->plugin->isInstalled());
94  }
95 
96  public function testIsNotInstalled(): void
97  {
98  $this->plugin = new ilPluginInfo(
99  $this->data_factory->version("6.5"),
101  "plg1",
102  "Plugin1",
103  "Type1",
104  true,
105  null,
106  null,
107  $this->data_factory->version("1.0.0"),
108  $this->data_factory->version("6.0"),
109  $this->data_factory->version("6.99"),
110  "Richard Klees",
111  "richard.klees@concepts-and-training.de",
112  true,
113  false,
114  true
115  );
116 
117  $this->assertFalse($this->plugin->isInstalled());
118  }
119 
120  public function testUpdateIsNotRequired(): void
121  {
122  $this->assertFalse($this->plugin->isUpdateRequired());
123  }
124 
125  public function testUpdateIsNotRequiredNotInstalled(): void
126  {
127  $this->plugin = new ilPluginInfo(
128  $this->data_factory->version("6.5"),
130  "plg1",
131  "Plugin1",
132  "Type1",
133  true,
134  null,
135  null,
136  $this->data_factory->version("1.0.0"),
137  $this->data_factory->version("6.0"),
138  $this->data_factory->version("6.99"),
139  "Richard Klees",
140  "richard.klees@concepts-and-training.de",
141  true,
142  false,
143  true
144  );
145 
146  $this->assertFalse($this->plugin->isUpdateRequired());
147  }
148 
149  public function testUpdateIsRequired(): void
150  {
151  $this->plugin = new ilPluginInfo(
152  $this->data_factory->version("6.5"),
154  "plg1",
155  "Plugin1",
156  "Type1",
157  true,
158  $this->data_factory->version("2.0.0"),
159  11,
160  $this->data_factory->version("1.0.0"),
161  $this->data_factory->version("6.0"),
162  $this->data_factory->version("6.99"),
163  "Richard Klees",
164  "richard.klees@concepts-and-training.de",
165  true,
166  false,
167  true
168  );
169 
170  $this->assertTrue($this->plugin->isUpdateRequired());
171  }
172 
173  public function testIsVersionOld(): void
174  {
175  $this->assertFalse($this->plugin->isVersionToOld());
176 
177  $plugin = new ilPluginInfo(
178  $this->data_factory->version("6.5"),
180  "plg1",
181  "Plugin1",
182  "Type1",
183  true,
184  $this->data_factory->version("1.0.0"),
185  12,
186  $this->data_factory->version("2.0.0"),
187  $this->data_factory->version("6.0"),
188  $this->data_factory->version("6.99"),
189  "Richard Klees",
190  "richard.klees@concepts-and-training.de",
191  true,
192  false,
193  true
194  );
195  $this->assertFalse($plugin->isVersionToOld());
196 
197  $plugin = new ilPluginInfo(
198  $this->data_factory->version("6.5"),
200  "plg1",
201  "Plugin1",
202  "Type1",
203  true,
204  $this->data_factory->version("1.2.2"),
205  12,
206  $this->data_factory->version("1.0.0"),
207  $this->data_factory->version("6.0"),
208  $this->data_factory->version("6.99"),
209  "Richard Klees",
210  "richard.klees@concepts-and-training.de",
211  true,
212  false,
213  true
214  );
215  $this->assertTrue($plugin->isVersionToOld());
216  }
217 
221  public function testIsCompliantToILIAS(Data\Version $version, bool $is_compliant): void
222  {
223  $plugin = new ilPluginInfo(
224  $version,
225  $this->pluginslot,
226  "plg1",
227  "Plugin1",
228  "Type1",
229  true,
230  $this->data_factory->version("1.2.2"),
231  12,
232  $this->data_factory->version("1.0.0"),
233  $this->data_factory->version("6.0"),
234  $this->data_factory->version("6.99"),
235  "Richard Klees",
236  "richard.klees@concepts-and-training.de",
237  true,
238  false,
239  true
240  );
241  $this->assertSame($is_compliant, $plugin->isCompliantToILIAS());
242  }
243 
244  public static function versionCompliance(): array
245  {
246  $data_factory = new Data\Factory();
247  return [
248  [$data_factory->version("5.4"), false],
249  [$data_factory->version("6.5"), true],
250  [$data_factory->version("7.1"), false]
251  ];
252  }
253 
254  public function testGetPath(): void
255  {
256  $this->assertEquals(
257  ilComponentRepository::PLUGIN_BASE_PATH . "/Type1/Module1/Slot1/Plugin1",
258  $this->plugin->getPath()
259  );
260  }
261 
262  public function testGetClassName(): void
263  {
264  $this->assertEquals(
265  "ilPlugin1Plugin",
266  $this->plugin->getClassName()
267  );
268  }
269 
270  public function testGetConfigureClassName(): void
271  {
272  $this->assertEquals(
273  "ilPlugin1ConfigGUI",
274  $this->plugin->getConfigGUIClassName()
275  );
276  }
277 
281  public function testIsActivationPossible(
282  bool $is_installed,
283  bool $supports_current_ilias,
284  bool $needs_update,
285  bool $is_version_to_old,
286  bool $is_activation_possible
287  ): void {
288  $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_version_to_old) extends ilPluginInfo {
289  protected bool $is_installed;
290  protected bool $supports_current_ilias;
291  protected bool $needs_update;
292  protected bool $is_version_to_old;
293 
294  public function __construct(
295  bool $is_installed,
296  bool $supports_current_ilias,
297  bool $needs_update,
298  bool $is_version_to_old
299  ) {
300  $this->is_installed = $is_installed;
301  $this->supports_current_ilias = $supports_current_ilias;
302  $this->needs_update = $needs_update;
303  $this->is_version_to_old = $is_version_to_old;
304  }
305 
306  public function isInstalled(): bool
307  {
308  return $this->is_installed;
309  }
310 
311  public function isUpdateRequired(): bool
312  {
313  return $this->needs_update;
314  }
315 
316  public function isCompliantToILIAS(): bool
317  {
318  return $this->supports_current_ilias;
319  }
320 
321  public function isVersionToOld(): bool
322  {
323  return $this->is_version_to_old;
324  }
325  };
326 
327  $this->assertEquals($is_activation_possible, $plugin->isActivationPossible());
328  }
329 
330  public static function isActivationPossibleTruthTable(): array
331  {
332  // is_installed, supports_current_ilias, needs_update, is_version_to_old => is_activation_possible
333  return [
334  [false, false, false, false, false],
335  [false, false, true, false, false],
336  [false, true, false, false, false],
337  [false, true, true, false, false],
338  [true, false, false, false, false],
339  [true, false, true, false, false],
340  [true, true, false, false, true],
341  [true, true, true, true, false],
342  [false, false, false, true, false],
343  [false, false, true, true, false],
344  [false, true, false, true, false],
345  [false, true, true, true, false],
346  [true, false, false, true, false],
347  [true, false, true, true, false],
348  [true, true, false, true, false],
349  [true, true, true, true, false]
350  ];
351  }
352 
356  public function testIsActive(
357  bool $is_installed,
358  bool $supports_current_ilias,
359  bool $needs_update,
360  bool $is_activated,
361  bool $is_version_to_old,
362  bool $is_activation_possible
363  ): void {
364  $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_activated, $is_version_to_old) extends ilPluginInfo {
365  protected bool $is_installed;
366  protected bool $supports_current_ilias;
367  protected bool $needs_update;
368  protected bool $is_activated;
369  protected bool $is_version_to_old;
370 
371  public function __construct(
372  bool $is_installed,
373  bool $supports_current_ilias,
374  bool $needs_update,
375  bool $is_activated,
376  bool $is_version_to_old
377  ) {
378  $this->is_installed = $is_installed;
379  $this->supports_current_ilias = $supports_current_ilias;
380  $this->needs_update = $needs_update;
381  $this->is_activated = $is_activated;
382  $this->is_version_to_old = $is_version_to_old;
383  }
384 
385  public function isActivated(): bool
386  {
387  return $this->is_activated;
388  }
389 
390  public function isInstalled(): bool
391  {
392  return $this->is_installed;
393  }
394 
395  public function isUpdateRequired(): bool
396  {
397  return $this->needs_update;
398  }
399 
400  public function isCompliantToILIAS(): bool
401  {
402  return $this->supports_current_ilias;
403  }
404 
405  public function isVersionToOld(): bool
406  {
407  return $this->is_version_to_old;
408  }
409  };
410 
411  $this->assertEquals($is_activation_possible, $plugin->isActive());
412  }
413 
414  public static function isActiveTruthTable(): array
415  {
416  // is_installed, supports_current_ilias, needs_update, is_activated, is_version_to_old => is_active
417  return [
418  [false, false, false, false, false, false],
419  [false, false, false, true, false, false],
420  [false, false, true , false, false, false],
421  [false, false, true , true, false, false],
422  [false, true, false, false, false, false],
423  [false, true, false, true, false, false],
424  [false, true, true , false, false, false],
425  [false, true, true , true, false, false],
426  [true, false, false, false, false, false],
427  [true, false, false, true, false, false],
428  [true, false, true , false, false, false],
429  [true, false, true , true, false, false],
430  [true, true, false, false, false, false],
431  [true, true, false, true, false, true],
432  [true, true, true , false, false, false],
433  [true, true, true , true, false, false],
434 
435  [false, false, false, false, true, false],
436  [false, false, false, true, true, false],
437  [false, false, true , false, true, false],
438  [false, false, true , true, true, false],
439  [false, true, false, false, true, false],
440  [false, true, false, true, true, false],
441  [false, true, true , false, true, false],
442  [false, true, true , true, true, false],
443  [true, false, false, false, true, false],
444  [true, false, false, true, true, false],
445  [true, false, true , false, true, false],
446  [true, false, true , true, true, false],
447  [true, true, false, false, true, false],
448  [true, true, false, true, true, false],
449  [true, true, true , false, true, false],
450  [true, true, true , true, true, false],
451  ];
452  }
453 
454 
458  public function testGetReasonForInactivity(
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 }
testIsCompliantToILIAS(Data\Version $version, bool $is_compliant)
versionCompliance
testGetReasonForInactivityThrowsOnActivePlugin()
$version
Definition: plugin.php:25
testIsActivationPossible(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_version_to_old, bool $is_activation_possible)
isActivationPossibleTruthTable
testIsActive(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_activated, bool $is_version_to_old, bool $is_activation_possible)
isActiveTruthTable
ilComponentInfo $component
Simple value class for basic information about a pluginslot.
isActive()
Is this plugin active right now?
Data Factory $data_factory
static inactivityReasonTable()
static isActivationPossibleTruthTable()
isActivationPossible()
Can this plugin be activated right now.
isCompliantToILIAS()
"ILIAS Version compliance" tells if the plugin can be operated with the given ILIAS version...
ilPluginInfo $plugin
Simple value class for information about a plugin.
getReasonForInactivity()
Which is the reason for the inactivity?
ilPluginSlotInfo $pluginslot
__construct(Container $dic, ilPlugin $plugin)
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:26
Simple value class for basic information about a component.
testGetReasonForInactivity(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_activated, bool $is_version_to_old, string $inactivity_reason)
inactivityReasonTable
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...