19use PHPUnit\Framework\TestCase;
25 "mod1" => [
"components/ILIAS",
"Module1", [
29 "mod2" => [
"components/ILIAS",
"Module2", [
31 "ser1" => [
"components/ILIAS",
"Service1", [
34 "ser2" => [
"components/ILIAS",
"Service2", [
49 "richard.klees@concepts-and-training.de",
63 "richard.klees@concepts-and-training.de",
77 "richard.klees@concepts-and-training.de",
105 $this->data_factory =
new Data\Factory();
106 $this->ilias_version = $this->createStub(
Data\Version::class);
108 public function isPluginActivated(
string $id):
bool
116 public function setActivation(
string $id,
bool $activated):
void
123 public function getCurrentPluginDBVersion(
string $id): ?
int
130 public function remove(
string $id):
void
136 protected function readComponentData(): array
140 protected function readPluginData(): array
144 public function _buildDatabase():
void
146 $this->buildDatabase();
165 $this->ilias_version,
171 $this->data_factory->version(
"0.9.1"),
173 $this->data_factory->version(
"1.9.1"),
174 $this->data_factory->version(
"8.0"),
175 $this->data_factory->version(
"8.999"),
177 "richard.klees@concepts-and-training.de",
234 $this->ilias_version,
240 $this->data_factory->version(
"0.9.1"),
242 $this->data_factory->version(
"2.9.1"),
243 $this->data_factory->version(
"8.1"),
244 $this->data_factory->version(
"8.999"),
246 "richard.klees@concepts-and-training.de",
254 $this->ilias_version,
260 $this->data_factory->version(
"0.9.1"),
262 $this->data_factory->version(
"2.9.2"),
263 $this->data_factory->version(
"8.1"),
264 $this->data_factory->version(
"8.999"),
266 "richard.klees@concepts-and-training.de",
276 $this->assertTrue($this->db->hasComponent(
"components/ILIAS",
"Module1"));
277 $this->assertTrue($this->db->hasComponent(
"components/ILIAS",
"Module2"));
278 $this->assertTrue($this->db->hasComponent(
"components/ILIAS",
"Service1"));
279 $this->assertTrue($this->db->hasComponent(
"components/ILIAS",
"Service2"));
280 $this->assertFalse($this->db->hasComponent(
"components/ILIAS",
"Module3"));
281 $this->assertFalse($this->db->hasComponent(
"components/ILIAS",
"Module4"));
282 $this->assertFalse($this->db->hasComponent(
"components/ILIAS",
"Service3"));
283 $this->assertFalse($this->db->hasComponent(
"components/ILIAS",
"Service4"));
288 $this->expectException(\InvalidArgumentException::class);
289 $this->db->hasComponent(
"OtherComponent",
"Module1");
294 $this->assertTrue($this->db->hasComponentId(
"mod1"));
295 $this->assertTrue($this->db->hasComponentId(
"mod2"));
296 $this->assertTrue($this->db->hasComponentId(
"ser1"));
297 $this->assertTrue($this->db->hasComponentId(
"ser2"));
298 $this->assertFalse($this->db->hasComponentId(
"mod3"));
299 $this->assertFalse($this->db->hasComponentId(
"mod4"));
300 $this->assertFalse($this->db->hasComponentId(
"ser3"));
301 $this->assertFalse($this->db->hasComponentId(
"ser4"));
306 $result = iterator_to_array($this->db->getComponents());
308 $ids = array_keys($result);
309 $expected_ids = [
"mod1",
"mod2",
"ser1",
"ser2"];
313 $this->assertEquals($expected_ids, $ids);
315 $this->assertEquals($this->mod1, $result[
"mod1"]);
316 $this->assertEquals($this->mod2, $result[
"mod2"]);
317 $this->assertEquals($this->ser1, $result[
"ser1"]);
318 $this->assertEquals($this->ser2, $result[
"ser2"]);
323 $this->assertEquals($this->mod1, $this->db->getComponentById(
"mod1"));
324 $this->assertEquals($this->mod2, $this->db->getComponentById(
"mod2"));
325 $this->assertEquals($this->ser1, $this->db->getComponentById(
"ser1"));
326 $this->assertEquals($this->ser2, $this->db->getComponentById(
"ser2"));
331 $this->assertEquals($this->mod1, $this->db->getComponentByTypeAndName(
"components/ILIAS",
"Module1"));
332 $this->assertEquals($this->mod2, $this->db->getComponentByTypeAndName(
"components/ILIAS",
"Module2"));
333 $this->assertEquals($this->ser1, $this->db->getComponentByTypeAndName(
"components/ILIAS",
"Service1"));
334 $this->assertEquals($this->ser2, $this->db->getComponentByTypeAndName(
"components/ILIAS",
"Service2"));
339 $this->expectException(\InvalidArgumentException::class);
340 $this->db->getComponentByTypeAndName(
"components/ILIAS",
"Module3");
345 $this->expectException(\InvalidArgumentException::class);
346 $this->db->getComponentByTypeAndName(
"OtherComponent",
"Service1");
351 $this->expectException(\InvalidArgumentException::class);
352 $this->db->getComponentById(
"some_id");
357 $slots = iterator_to_array($this->db->getPluginSlots());
359 $ids = array_keys($slots);
360 $expected_ids = [
"slt1",
"slt2",
"slt3",
"slt4"];
364 $this->assertEquals($expected_ids, $ids);
366 $this->assertEquals($this->slt1, $slots[
"slt1"]);
367 $this->assertEquals($this->slt2, $slots[
"slt2"]);
368 $this->assertEquals($this->slt3, $slots[
"slt3"]);
369 $this->assertEquals($this->slt4, $slots[
"slt4"]);
374 $this->assertEquals($this->slt1, $this->db->getPluginSlotById(
"slt1"));
375 $this->assertEquals($this->slt2, $this->db->getPluginSlotById(
"slt2"));
376 $this->assertEquals($this->slt3, $this->db->getPluginSlotById(
"slt3"));
377 $this->assertEquals($this->slt4, $this->db->getPluginSlotById(
"slt4"));
383 protected function readComponentData(): array
385 return [
"mod2" => [
"components/ILIAS",
"Module2", []]];
387 protected function readPluginData(): array
394 $this->assertEquals([], $slots);
399 $plugins = iterator_to_array($this->db->getPlugins());
401 $ids = array_keys($plugins);
402 $expected_ids = [
"plg1",
"plg2",
"plg3"];
406 $this->assertEquals($expected_ids, $ids);
408 $this->assertEquals($this->plg1, $plugins[
"plg1"]);
409 $this->assertEquals($this->plg2, $plugins[
"plg2"]);
414 $this->assertEquals($this->plg1, $this->db->getPluginById(
"plg1"));
415 $this->assertEquals($this->plg2, $this->db->getPluginById(
"plg2"));
420 $this->assertEquals($this->plg1, $this->db->getPluginByName(
"Plugin1"));
421 $this->assertEquals($this->plg2, $this->db->getPluginByName(
"Plugin2"));
426 $this->expectException(\InvalidArgumentException::class);
427 $this->db->getPluginById(
"some_id");
434 ->method(
"isPluginActivated")
438 ->method(
"getCurrentPluginVersion")
440 ->willReturn($this->data_factory->version(
"1.8.0"));
442 ->method(
"getCurrentPluginDBVersion")
447 protected function readComponentData(): array
449 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
451 protected function readPluginData(): array
463 "richard.klees@concepts-and-training.de",
473 $this->assertTrue(
$plugin->isActivated());
475 $this->data_factory->version(
"1.8.0"),
478 $this->assertEquals(42,
$plugin->getCurrentDBVersion());
484 ->getComponentByTypeAndName(
"components/ILIAS",
"Module1")
485 ->getPluginSlotById(
"slt1")
486 ->getPluginById(
"plg1");
488 $this->assertEquals($this->plg1,
$plg1);
493 $VERSION = $this->data_factory->version(
"1000.0.0");
498 ->method(
"isPluginActivated")
502 ->method(
"getCurrentPluginVersion")
504 ->willReturn($this->data_factory->version(
"1.8.0"));
506 ->method(
"getCurrentPluginDBVersion")
510 ->method(
"setCurrentPluginVersion")
511 ->with(
"plg1", $VERSION, $DB_VERSION);
514 protected function readComponentData(): array
516 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
518 protected function readPluginData(): array
530 "richard.klees@concepts-and-training.de",
544 $VERSION = $this->data_factory->version(
"1000.0.0");
549 public int $build_called = 0;
550 protected function buildDatabase():
void
552 $this->build_called++;
553 parent::buildDatabase();
555 protected function readComponentData(): array
557 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
559 protected function readPluginData(): array
571 "richard.klees@concepts-and-training.de",
580 $this->assertEquals(1,
$db->build_called);
584 $this->assertEquals(2,
$db->build_called);
589 $this->db->_buildDatabase();
591 $this->assertEquals($this->mod1, $this->db->getComponentById(
"mod1"));
592 $this->assertEquals($this->mod1, $this->db->getComponentByTypeAndName(
"components/ILIAS",
"Module1"));
593 $this->assertEquals($this->slt1, $this->db->getPluginSlotById(
"slt1"));
594 $this->assertEquals($this->plg1, $this->db->getPluginById(
"plg1"));
595 $this->assertEquals($this->plg2, $this->db->getPluginByName(
"Plugin2"));
603 protected function readComponentData(): array
605 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
607 protected function readPluginData(): array
619 "richard.klees@concepts-and-training.de",
629 ->method(
"setActivation")
630 ->with(
"plg1",
true);
639 public int $build_called = 0;
640 protected function buildDatabase():
void
642 $this->build_called++;
643 parent::buildDatabase();
645 protected function readComponentData(): array
647 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
649 protected function readPluginData(): array
661 "richard.klees@concepts-and-training.de",
670 $this->assertEquals(1,
$db->build_called);
674 $this->assertEquals(2,
$db->build_called);
682 protected function readComponentData(): array
684 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
686 protected function readPluginData(): array
698 "richard.klees@concepts-and-training.de",
718 public int $build_called = 0;
719 protected function buildDatabase():
void
721 $this->build_called++;
722 parent::buildDatabase();
724 protected function readComponentData(): array
726 return [
"mod1" => [
"components/ILIAS",
"Module1", [[
"slt1",
"Slot1"]]]];
728 protected function readPluginData(): array
740 "richard.klees@concepts-and-training.de",
749 $this->assertEquals(1,
$db->build_called);
753 $this->assertEquals(2,
$db->build_called);
758 $this->assertTrue($this->db->hasPluginId(
"plg1"));
759 $this->assertFalse($this->db->hasPluginId(
"plg666"));
764 $this->assertFalse($this->db->hasActivatedPlugin(
"plg1"));
765 $this->assertFalse($this->db->hasActivatedPlugin(
"plg666"));
766 $this->assertTrue($this->db->hasActivatedPlugin(
"plg3"));
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
A version number that consists of three numbers (major, minor, patch).
ilPluginStateDB $plugin_state_db
ilArtifactComponentRepository $db
testGetComponentByTypeAndNameThrowsOnUnknownComponent1()
testGetComponentByTypeAndNameThrowsOnUnknownComponent2()
testCallBuildDatabaseTwice()
testGetPluginViaComponentAndPluginSlot()
testHasComponentThrowsOnUnknownType()
testRemoveStateInformationOfTriggersRebuild()
testSetCurrentPluginVersionCallsStateDB()
testSetCurrentPluginVersionCallsStateDBTriggersRebuild()
PHPUnit Framework MockObject Stub $ilias_version
testGetComponentByTypeAndName()
Data Factory $data_factory
static array $plugin_data
testGetComponentByIdTypeThrowsOnInvalidId()
testSetActivationCallsStateDB()
static array $component_data
testRemoveStateInformationOfCallsStateDB()
testSetActivationTriggersRebuild()
Repository for component data implemented over artifacts.
getPluginById(string $id)
Get a plugin by id.
setCurrentPluginVersion(string $plugin_id, Data\Version $version, int $db_version)
setActivation(string $plugin_id, bool $activated)
removeStateInformationOf(string $plugin_id)
getPluginSlots()
@inheritdocs
Simple value class for basic information about a component.
Simple value class for information about a plugin.
Simple value class for basic information about a pluginslot.
Repository interface for plugin state data.