ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilPluginInfoTest.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\Data;
21 
23 {
24  protected ?Data\Factory $data_factory = 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"),
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"),
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 
124  public function testUpdateIsNotRequiredNotInstalled(): void
125  {
126  $this->plugin = new ilPluginInfo(
127  $this->data_factory->version("6.5"),
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"),
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"),
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"),
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  ilComponentRepository::PLUGIN_BASE_PATH . "/Type1/Module1/Slot1/Plugin1",
255  $this->plugin->getPath()
256  );
257  }
258 
259  public function testGetClassName(): void
260  {
261  $this->assertEquals(
262  "ilPlugin1Plugin",
263  $this->plugin->getClassName()
264  );
265  }
266 
267  public function testGetConfigureClassName(): void
268  {
269  $this->assertEquals(
270  "ilPlugin1ConfigGUI",
271  $this->plugin->getConfigGUIClassName()
272  );
273  }
274 
275  #[\PHPUnit\Framework\Attributes\DataProvider('isActivationPossibleTruthTable')]
276  public function testIsActivationPossible(
277  bool $is_installed,
278  bool $supports_current_ilias,
279  bool $needs_update,
280  bool $is_version_to_old,
281  bool $is_activation_possible
282  ): void {
283  $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_version_to_old) extends ilPluginInfo {
284  protected bool $is_installed;
285  protected bool $supports_current_ilias;
286  protected bool $needs_update;
287  protected bool $is_version_to_old;
288 
289  public function __construct(
290  bool $is_installed,
291  bool $supports_current_ilias,
292  bool $needs_update,
293  bool $is_version_to_old
294  ) {
295  $this->is_installed = $is_installed;
296  $this->supports_current_ilias = $supports_current_ilias;
297  $this->needs_update = $needs_update;
298  $this->is_version_to_old = $is_version_to_old;
299  }
300 
301  public function isInstalled(): bool
302  {
303  return $this->is_installed;
304  }
305 
306  public function isUpdateRequired(): bool
307  {
308  return $this->needs_update;
309  }
310 
311  public function isCompliantToILIAS(): bool
312  {
313  return $this->supports_current_ilias;
314  }
315 
316  public function isVersionToOld(): bool
317  {
318  return $this->is_version_to_old;
319  }
320  };
321 
322  $this->assertEquals($is_activation_possible, $plugin->isActivationPossible());
323  }
324 
325  public static function isActivationPossibleTruthTable(): array
326  {
327  // is_installed, supports_current_ilias, needs_update, is_version_to_old => is_activation_possible
328  return [
329  [false, false, false, false, false],
330  [false, false, true, false, false],
331  [false, true, false, false, false],
332  [false, true, true, false, false],
333  [true, false, false, false, false],
334  [true, false, true, false, false],
335  [true, true, false, false, true],
336  [true, true, true, true, false],
337  [false, false, false, true, false],
338  [false, false, true, true, false],
339  [false, true, false, true, false],
340  [false, true, true, true, false],
341  [true, false, false, true, false],
342  [true, false, true, true, false],
343  [true, true, false, true, false],
344  [true, true, true, true, false]
345  ];
346  }
347 
348  #[\PHPUnit\Framework\Attributes\DataProvider('isActiveTruthTable')]
349  public function testIsActive(
350  bool $is_installed,
351  bool $supports_current_ilias,
352  bool $needs_update,
353  bool $is_activated,
354  bool $is_version_to_old,
355  bool $is_activation_possible
356  ): void {
357  $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_activated, $is_version_to_old) extends ilPluginInfo {
358  protected bool $is_installed;
359  protected bool $supports_current_ilias;
360  protected bool $needs_update;
361  protected bool $is_activated;
362  protected bool $is_version_to_old;
363 
364  public function __construct(
365  bool $is_installed,
366  bool $supports_current_ilias,
367  bool $needs_update,
368  bool $is_activated,
369  bool $is_version_to_old
370  ) {
371  $this->is_installed = $is_installed;
372  $this->supports_current_ilias = $supports_current_ilias;
373  $this->needs_update = $needs_update;
374  $this->is_activated = $is_activated;
375  $this->is_version_to_old = $is_version_to_old;
376  }
377 
378  public function isActivated(): bool
379  {
380  return $this->is_activated;
381  }
382 
383  public function isInstalled(): bool
384  {
385  return $this->is_installed;
386  }
387 
388  public function isUpdateRequired(): bool
389  {
390  return $this->needs_update;
391  }
392 
393  public function isCompliantToILIAS(): bool
394  {
395  return $this->supports_current_ilias;
396  }
397 
398  public function isVersionToOld(): bool
399  {
400  return $this->is_version_to_old;
401  }
402  };
403 
404  $this->assertEquals($is_activation_possible, $plugin->isActive());
405  }
406 
407  public static function isActiveTruthTable(): array
408  {
409  // is_installed, supports_current_ilias, needs_update, is_activated, is_version_to_old => is_active
410  return [
411  [false, false, false, false, false, false],
412  [false, false, false, true, false, false],
413  [false, false, true , false, false, false],
414  [false, false, true , true, false, false],
415  [false, true, false, false, false, false],
416  [false, true, false, true, false, false],
417  [false, true, true , false, false, false],
418  [false, true, true , true, false, false],
419  [true, false, false, false, false, false],
420  [true, false, false, true, false, false],
421  [true, false, true , false, false, false],
422  [true, false, true , true, false, false],
423  [true, true, false, false, false, false],
424  [true, true, false, true, false, true],
425  [true, true, true , false, false, false],
426  [true, true, true , true, false, false],
427 
428  [false, false, false, false, true, false],
429  [false, false, false, true, true, false],
430  [false, false, true , false, true, false],
431  [false, false, true , true, true, false],
432  [false, true, false, false, true, false],
433  [false, true, false, true, true, false],
434  [false, true, true , false, true, false],
435  [false, true, true , true, true, false],
436  [true, false, false, false, true, false],
437  [true, false, false, true, true, false],
438  [true, false, true , false, true, false],
439  [true, false, true , true, true, false],
440  [true, true, false, false, true, false],
441  [true, true, false, true, true, false],
442  [true, true, true , false, true, false],
443  [true, true, true , true, true, false],
444  ];
445  }
446 
447 
448  #[\PHPUnit\Framework\Attributes\DataProvider('inactivityReasonTable')]
449  public function testGetReasonForInactivity(
450  bool $is_installed,
451  bool $supports_current_ilias,
452  bool $needs_update,
453  bool $is_activated,
454  bool $is_version_to_old,
455  string $inactivity_reason
456  ): void {
457  $plugin = new class ($is_installed, $supports_current_ilias, $needs_update, $is_activated, $is_version_to_old) extends ilPluginInfo {
458  protected bool $is_installed;
459  protected bool $supports_current_ilias;
460  protected bool $needs_update;
461  protected bool $is_activated;
462  protected bool $is_version_to_old;
463 
464  public function __construct(
465  bool $is_installed,
466  bool $supports_current_ilias,
467  bool $needs_update,
468  bool $is_activated,
469  bool $is_version_to_old
470  ) {
471  $this->is_installed = $is_installed;
472  $this->supports_current_ilias = $supports_current_ilias;
473  $this->needs_update = $needs_update;
474  $this->is_activated = $is_activated;
475  $this->is_version_to_old = $is_version_to_old;
476  }
477 
478  public function isActivated(): bool
479  {
480  return $this->is_activated;
481  }
482 
483  public function isInstalled(): bool
484  {
485  return $this->is_installed;
486  }
487 
488  public function isUpdateRequired(): bool
489  {
490  return $this->needs_update;
491  }
492 
493  public function isCompliantToILIAS(): bool
494  {
495  return $this->supports_current_ilias;
496  }
497 
498  public function getCurrentVersion(): ?Data\Version
499  {
500  return $this->current_version;
501  }
502 
503  public function isVersionToOld(): bool
504  {
505  return $this->is_version_to_old;
506  }
507  };
508 
509  $this->assertEquals($inactivity_reason, $plugin->getReasonForInactivity());
510  }
511 
513  {
514  $this->expectException(LogicException::class);
515 
516  $plugin = new class () extends ilPluginInfo {
517  public function __construct()
518  {
519  }
520 
521  public function isActive(): bool
522  {
523  return true;
524  }
525  };
526 
527  $plugin->getReasonForInactivity();
528  }
529 
530  public static function inactivityReasonTable(): array
531  {
532  // is_installed, supports_current_ilias, needs_update, is_activated, is_version_to_old => inactivity_reason
533  return [
534  [false, false, false, false, false, "cmps_needs_matching_ilias_version"],
535  [false, false, false, true, false, "cmps_needs_matching_ilias_version"],
536  [false, false, true , false, false, "cmps_needs_matching_ilias_version"],
537  [false, false, true , true, false, "cmps_needs_matching_ilias_version"],
538  [false, true, false, false, false, "cmps_must_installed"],
539  [false, true, false, true, false, "cmps_must_installed"],
540  [false, true, true , false, false, "cmps_must_installed"],
541  [false, true, true , true, false, "cmps_must_installed"],
542  [true, false, false, false, false, "cmps_needs_matching_ilias_version"],
543  [true, false, false, true, false, "cmps_needs_matching_ilias_version"],
544  [true, false, true , false, false, "cmps_needs_matching_ilias_version"],
545  [true, false, true , true, false, "cmps_needs_matching_ilias_version"],
546  [true, true, false, false, false, "cmps_not_activated"],
547  [true, true, true , false, false, "cmps_needs_update"],
548  [true, true, true , true, false, "cmps_needs_update"],
549  [false, false, false, false, true, "cmps_needs_matching_ilias_version"],
550  [false, false, false, true, true, "cmps_needs_matching_ilias_version"],
551  [false, false, true , false, true, "cmps_needs_matching_ilias_version"],
552  [false, false, true , true, true, "cmps_needs_matching_ilias_version"],
553  [false, true, false, false, true, "cmps_must_installed"],
554  [false, true, false, true, true, "cmps_must_installed"],
555  [false, true, true , false, true, "cmps_must_installed"],
556  [false, true, true , true, true, "cmps_must_installed"],
557  [true, false, false, false, true, "cmps_needs_matching_ilias_version"],
558  [true, false, false, true, true, "cmps_needs_matching_ilias_version"],
559  [true, false, true , false, true, "cmps_needs_matching_ilias_version"],
560  [true, false, true , true, true, "cmps_needs_matching_ilias_version"],
561  [true, true, false, false, true, "cmps_needs_upgrade"],
562  [true, true, true , false, true, "cmps_needs_upgrade"],
563  [true, true, true , true, true, "cmps_needs_upgrade"],
564  ];
565  }
566 }
testIsCompliantToILIAS(Data\Version $version, bool $is_compliant)
testGetReasonForInactivityThrowsOnActivePlugin()
$version
Definition: plugin.php:24
testIsActivationPossible(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_version_to_old, bool $is_activation_possible)
testIsActive(bool $is_installed, bool $supports_current_ilias, bool $needs_update, bool $is_activated, bool $is_version_to_old, bool $is_activation_possible)
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)