ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLPStatusIconsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 
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);
116  ilLPStatusIcons::getInstance(793, $renderer, $factory);
117  }
118 
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 
142  public function testImagePathRunningForLongVariant(array $instances): void
143  {
144  $this->expectException(ilLPException::class);
145  $instances['long']->getImagePathRunning();
146  }
147 
152  public function testImagePathAssetForLongVariant(array $instances): void
153  {
154  $this->expectException(ilLPException::class);
155  $instances['long']->getImagePathAsset();
156  }
157 
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 
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 }
const LP_STATUS_COMPLETED_NUM
testRenderScormIcons(array $instances)
testTripleton
$renderer
testImagePathRunningForLongVariant(array $instances)
testTripleton
buildImagePath(string $image_name)
testImagePathAssetForLongVariant(array $instances)
testTripleton
Mocks out calls to ilUtil::getImagePath.
const LP_STATUS_IN_PROGRESS_NUM
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
testSomeExamplesForImagePathsByStatus(array $instances)
testTripleton
This is how a factory for icons looks like.
Definition: Factory.php:26
Unit tests for class ilLPStatusIcons.
testSomeExamplesForRenderedIcons(array $instances)
testTripleton
const LP_STATUS_FAILED_NUM