diff --git a/components/ILIAS/Tracking/classes/status/class.ilLPStatusIcons.php b/components/ILIAS/Tracking/classes/status/class.ilLPStatusIcons.php index 4ceb16a40e9d..8a3b01f2886a 100755 --- a/components/ILIAS/Tracking/classes/status/class.ilLPStatusIcons.php +++ b/components/ILIAS/Tracking/classes/status/class.ilLPStatusIcons.php @@ -16,6 +16,8 @@ * *********************************************************************/ +declare(strict_types=1); + /** * Caches and supplies the paths to the learning progress status images. * @author Tim Schmitz @@ -82,28 +84,28 @@ private function __construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\ switch ($variant) { case ilLPStatusIcons::ICON_VARIANT_SCORM: - $this->image_path_in_progress = ilUtil::getImagePath('scorm/incomplete.svg'); - $this->image_path_completed = ilUtil::getImagePath('scorm/complete.svg'); - $this->image_path_not_attempted = ilUtil::getImagePath('scorm/not_attempted.svg'); - $this->image_path_failed = ilUtil::getImagePath('scorm/failed.svg'); - $this->image_path_asset = ilUtil::getImagePath('scorm/asset.svg'); - $this->image_path_running = ilUtil::getImagePath('scorm/running.svg'); + $this->image_path_in_progress = $this->buildImagePath('scorm/incomplete.svg'); + $this->image_path_completed = $this->buildImagePath('scorm/complete.svg'); + $this->image_path_not_attempted = $this->buildImagePath('scorm/not_attempted.svg'); + $this->image_path_failed = $this->buildImagePath('scorm/failed.svg'); + $this->image_path_asset = $this->buildImagePath('scorm/asset.svg'); + $this->image_path_running = $this->buildImagePath('scorm/running.svg'); break; case ilLPStatusIcons::ICON_VARIANT_SHORT: - $this->image_path_in_progress = ilUtil::getImagePath('learning_progress/short/in_progress.svg'); - $this->image_path_completed = ilUtil::getImagePath('learning_progress/short/completed.svg'); - $this->image_path_not_attempted = ilUtil::getImagePath('learning_progress/short/not_attempted.svg'); - $this->image_path_failed = ilUtil::getImagePath('learning_progress/short/failed.svg'); - $this->image_path_asset = ilUtil::getImagePath('learning_progress/short/asset.svg'); - $this->image_path_running = ilUtil::getImagePath('learning_progress/short/running.svg'); + $this->image_path_in_progress = $this->buildImagePath('learning_progress/short/in_progress.svg'); + $this->image_path_completed = $this->buildImagePath('learning_progress/short/completed.svg'); + $this->image_path_not_attempted = $this->buildImagePath('learning_progress/short/not_attempted.svg'); + $this->image_path_failed = $this->buildImagePath('learning_progress/short/failed.svg'); + $this->image_path_asset = $this->buildImagePath('learning_progress/short/asset.svg'); + $this->image_path_running = $this->buildImagePath('learning_progress/short/running.svg'); break; case ilLPStatusIcons::ICON_VARIANT_LONG: - $this->image_path_in_progress = ilUtil::getImagePath('learning_progress/in_progress.svg'); - $this->image_path_completed = ilUtil::getImagePath('learning_progress/completed.svg'); - $this->image_path_not_attempted = ilUtil::getImagePath('learning_progress/not_attempted.svg'); - $this->image_path_failed = ilUtil::getImagePath('learning_progress/failed.svg'); + $this->image_path_in_progress = $this->buildImagePath('learning_progress/in_progress.svg'); + $this->image_path_completed = $this->buildImagePath('learning_progress/completed.svg'); + $this->image_path_not_attempted = $this->buildImagePath('learning_progress/not_attempted.svg'); + $this->image_path_failed = $this->buildImagePath('learning_progress/failed.svg'); break; default: @@ -111,6 +113,11 @@ private function __construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\ } } + protected function buildImagePath(string $image_name): string + { + return ilUtil::getImagePath($image_name); + } + public function getImagePathInProgress(): string { return $this->image_path_in_progress; diff --git a/components/ILIAS/Tracking/tests/ilLPStatusIconsTest.php b/components/ILIAS/Tracking/tests/ilLPStatusIconsTest.php index 29e114fc47d3..5f68dedf5ab2 100755 --- a/components/ILIAS/Tracking/tests/ilLPStatusIconsTest.php +++ b/components/ILIAS/Tracking/tests/ilLPStatusIconsTest.php @@ -1,7 +1,5 @@ - */ - public function testTripleton(): array + protected function getUIFactory(): UIFactory { - $this->markTestSkipped('Data Provider needs to be revisited.'); - - $utilMock = Mockery::mock('alias:' . ilUtil::class); - $utilMock->shouldReceive('getImagePath') - ->with(Mockery::type('string')) - ->andReturnUsing(function ($arg) { - return 'test/' . $arg; - }); + $custom_icon = $this->createMock(Custom::class); + $custom_icon->method('getIconPath') + ->willReturn($this->path); + $custom_icon->method('getSize') + ->willReturn($this->size); + $custom_icon->method('getLabel') + ->willReturn($this->alt); + + $icon_factory = $this->createMock(IconFactory::class); + $icon_factory->method('custom') + ->willReturn($custom_icon); + + $symbol_factory = $this->createMock(SymbolFactory::class); + $symbol_factory->method('icon') + ->willReturn($icon_factory); + + $factory = $this->createMock(UIFactory::class); + $factory->method('symbol') + ->willReturn($symbol_factory); + + return $factory; + } - $renderer = Mockery::mock(Renderer::class); - $renderer->shouldReceive('render') - ->andReturnUsing(function ($arg1) { - return 'rendered: path(' . $arg1->getIconPath() . - '), alt(' . $arg1->getLabel() . - '), size(' . $arg1->getSize() . ')'; + protected function getUIRenderer(): UIRenderer + { + $renderer = $this->createMock(UIRenderer::class); + $renderer->method('render') + ->willReturnCallback(function ($arg) { + return 'rendered: path(' . $arg->getIconPath() . + '), alt(' . $arg->getLabel() . + '), size(' . $arg->getSize() . ')'; }); - $custom_icon = Mockery::mock(Custom::class); - $custom_icon->shouldReceive('getIconPath') - ->andReturn($this->path); - $custom_icon->shouldReceive('getSize') - ->andReturn($this->size); - $custom_icon->shouldReceive('getLabel') - ->andReturn($this->alt); + return $renderer; + } - $factory = Mockery::mock(Factory::class); - $factory->shouldReceive('symbol->icon->custom') - ->andReturn($custom_icon); + /** + * @return array + */ + public function testTripleton(): array + { + $factory = $this->getUIFactory(); + $renderer = $this->getUIRenderer(); - $long1 = ilLPStatusIcons::getInstance(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory); - $long2 = ilLPStatusIcons::getInstance(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory); + $long1 = ilLPStatusIconsMock::getInstance(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory); + $long2 = ilLPStatusIconsMock::getInstance(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory); - $short1 = ilLPStatusIcons::getInstance(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory); - $short2 = ilLPStatusIcons::getInstance(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory); + $short1 = ilLPStatusIconsMock::getInstance(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory); + $short2 = ilLPStatusIconsMock::getInstance(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory); - $scorm1 = ilLPStatusIcons::getInstance(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory); - $scorm2 = ilLPStatusIcons::getInstance(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory); + $scorm1 = ilLPStatusIconsMock::getInstance(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory); + $scorm2 = ilLPStatusIconsMock::getInstance(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory); $this->assertSame($short1, $short2); $this->assertSame($long1, $long2); @@ -91,11 +104,11 @@ public function testTripleton(): array public function testGetInstanceForInvalidVariant(): void { - $renderer = $this->getMockBuilder(Renderer::class) + $renderer = $this->getMockBuilder(UIRenderer::class) ->disableOriginalConstructor() ->getMock(); - $factory = $this->getMockBuilder(Factory::class) + $factory = $this->getMockBuilder(UIFactory::class) ->disableOriginalConstructor() ->getMock(); @@ -174,3 +187,14 @@ public function testRenderScormIcons(array $instances): void $instances['scorm']->renderIcon('path', 'alt'); } } + +/** + * Mocks out calls to ilUtil::getImagePath + */ +class ilLPStatusIconsMock extends ilLPStatusIcons +{ + protected function buildImagePath(string $image_name): string + { + return 'test/' . $image_name; + } +}