ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLPStatusIconsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23use ILIAS\UI\Renderer as UIRenderer;
24use ILIAS\UI\Factory as UIFactory;
25use ILIAS\UI\Component\Symbol\Factory as SymbolFactory;
28
33class ilLPStatusIconsTest extends TestCase
34{
35 protected $path = 'sample/path';
36 protected $alt = 'alt';
37 protected $size = Icon::SMALL;
38
39 protected function getUIFactory(): UIFactory
40 {
41 $custom_icon = $this->createMock(Custom::class);
42 $custom_icon->method('getIconPath')
43 ->willReturn($this->path);
44 $custom_icon->method('getSize')
45 ->willReturn($this->size);
46 $custom_icon->method('getLabel')
47 ->willReturn($this->alt);
48
49 $icon_factory = $this->createMock(IconFactory::class);
50 $icon_factory->method('custom')
51 ->willReturn($custom_icon);
52
53 $symbol_factory = $this->createMock(SymbolFactory::class);
54 $symbol_factory->method('icon')
55 ->willReturn($icon_factory);
56
57 $factory = $this->createMock(UIFactory::class);
58 $factory->method('symbol')
59 ->willReturn($symbol_factory);
60
61 return $factory;
62 }
63
64 protected function getUIRenderer(): UIRenderer
65 {
66 $renderer = $this->createMock(UIRenderer::class);
67 $renderer->method('render')
68 ->willReturnCallback(function ($arg) {
69 return 'rendered: path(' . $arg->getIconPath() .
70 '), alt(' . $arg->getLabel() .
71 '), size(' . $arg->getSize() . ')';
72 });
73
74 return $renderer;
75 }
76
80 public function testTripleton(): array
81 {
82 $factory = $this->getUIFactory();
83 $renderer = $this->getUIRenderer();
84
87
90
93
94 $this->assertSame($short1, $short2);
95 $this->assertSame($long1, $long2);
96 $this->assertSame($scorm1, $scorm2);
97
98 $this->assertNotSame($long1, $short1);
99 $this->assertNotSame($long1, $scorm1);
100 $this->assertNotSame($short1, $scorm1);
101
102 return ['long' => $long1, 'short' => $short1, 'scorm' => $scorm1];
103 }
104
105 public function testGetInstanceForInvalidVariant(): void
106 {
107 $renderer = $this->getMockBuilder(UIRenderer::class)
108 ->disableOriginalConstructor()
109 ->getMock();
110
111 $factory = $this->getMockBuilder(UIFactory::class)
112 ->disableOriginalConstructor()
113 ->getMock();
114
115 $this->expectException(ilLPException::class);
117 }
118
122 #[\PHPUnit\Framework\Attributes\Depends('testTripleton')]
123 public function testSomeExamplesForImagePathsByStatus(array $instances): void
124 {
125 $path1 = $instances['long']->getImagePathInProgress();
126 $path2 = $instances['long']->getImagePathForStatus(ilLPStatus::LP_STATUS_IN_PROGRESS_NUM);
127 $this->assertSame($path1, $path2);
128
129 $path1 = $instances['short']->getImagePathCompleted();
130 $path2 = $instances['short']->getImagePathForStatus(ilLPStatus::LP_STATUS_COMPLETED_NUM);
131 $this->assertSame($path1, $path2);
132
133 $path1 = $instances['scorm']->getImagePathFailed();
134 $path2 = $instances['scorm']->getImagePathForStatus(ilLPStatus::LP_STATUS_FAILED_NUM);
135 $this->assertSame($path1, $path2);
136 }
137
141 #[\PHPUnit\Framework\Attributes\Depends('testTripleton')]
142 public function testImagePathRunningForLongVariant(array $instances): void
143 {
144 $this->expectException(ilLPException::class);
145 $instances['long']->getImagePathRunning();
146 }
147
151 #[\PHPUnit\Framework\Attributes\Depends('testTripleton')]
152 public function testImagePathAssetForLongVariant(array $instances): void
153 {
154 $this->expectException(ilLPException::class);
155 $instances['long']->getImagePathAsset();
156 }
157
161 #[\PHPUnit\Framework\Attributes\Depends('testTripleton')]
162 public function testSomeExamplesForRenderedIcons(array $instances): void
163 {
164 //try rendering some icons
165 $this->assertSame(
166 'rendered: path(' . $this->path .
167 '), alt(' . $this->alt .
168 '), size(' . $this->size . ')',
169 $instances['long']->renderIcon($this->path, $this->alt)
170 );
171
172 $this->assertSame(
173 'rendered: path(' . $this->path .
174 '), alt(' . $this->alt .
175 '), size(' . $this->size . ')',
176 $instances['short']->renderIcon($this->path, $this->alt)
177 );
178 }
179
183 #[\PHPUnit\Framework\Attributes\Depends('testTripleton')]
184 public function testRenderScormIcons(array $instances): void
185 {
186 $this->expectException(ilLPException::class);
187 $instances['scorm']->renderIcon('path', 'alt');
188 }
189}
190
195{
196 protected function buildImagePath(string $image_name): string
197 {
198 return 'test/' . $image_name;
199 }
200}
$renderer
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Mocks out calls to ilUtil::getImagePath.
buildImagePath(string $image_name)
Unit tests for class ilLPStatusIcons.
testImagePathRunningForLongVariant(array $instances)
testRenderScormIcons(array $instances)
testImagePathAssetForLongVariant(array $instances)
testSomeExamplesForRenderedIcons(array $instances)
testSomeExamplesForImagePathsByStatus(array $instances)
Caches and supplies the paths to the learning progress status images.
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_FAILED_NUM
This describes the behavior of an custom icon.
Definition: Custom.php:27
This is how a factory for icons looks like.
Definition: Factory.php:27
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31