ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilLPStatusIconsTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 
32 class ilLPStatusIconsTest extends TestCase
33 {
34  protected $path = 'sample/path';
35  protected $alt = 'alt';
36  protected $size = Icon::SMALL;
37 
41  public function testTripleton(): array
42  {
43  $utilMock = Mockery::mock('alias:' . ilUtil::class);
44  $utilMock->shouldReceive('getImagePath')
45  ->with(Mockery::type('string'))
46  ->andReturnUsing(function ($arg) {
47  return 'test/' . $arg;
48  });
49 
50  $renderer = Mockery::mock(Renderer::class);
51  $renderer->shouldReceive('render')
52  ->andReturnUsing(function ($arg1) {
53  return 'rendered: path(' . $arg1->getIconPath() .
54  '), alt(' . $arg1->getLabel() .
55  '), size(' . $arg1->getSize() . ')';
56  });
57 
58  $custom_icon = Mockery::mock(Custom::class);
59  $custom_icon->shouldReceive('getIconPath')
60  ->andReturn($this->path);
61  $custom_icon->shouldReceive('getSize')
62  ->andReturn($this->size);
63  $custom_icon->shouldReceive('getLabel')
64  ->andReturn($this->alt);
65 
66  $factory = Mockery::mock(Factory::class);
67  $factory->shouldReceive('symbol->icon->custom')
68  ->andReturn($custom_icon);
69 
72 
75 
78 
79  $this->assertSame($short1, $short2);
80  $this->assertSame($long1, $long2);
81  $this->assertSame($scorm1, $scorm2);
82 
83  $this->assertNotSame($long1, $short1);
84  $this->assertNotSame($long1, $scorm1);
85  $this->assertNotSame($short1, $scorm1);
86 
87  return ['long' => $long1, 'short' => $short1, 'scorm' => $scorm1];
88  }
89 
90  public function testGetInstanceForInvalidVariant(): void
91  {
92  $renderer = $this->getMockBuilder(Renderer::class)
93  ->disableOriginalConstructor()
94  ->getMock();
95 
96  $factory = $this->getMockBuilder(Factory::class)
97  ->disableOriginalConstructor()
98  ->getMock();
99 
100  $this->expectException(ilLPException::class);
101  ilLPStatusIcons::getInstance(793, $renderer, $factory);
102  }
103 
108  public function testSomeExamplesForImagePathsByStatus(array $instances): void
109  {
110  $path1 = $instances['long']->getImagePathInProgress();
111  $path2 = $instances['long']->getImagePathForStatus(ilLPStatus::LP_STATUS_IN_PROGRESS_NUM);
112  $this->assertSame($path1, $path2);
113 
114  $path1 = $instances['short']->getImagePathCompleted();
115  $path2 = $instances['short']->getImagePathForStatus(ilLPStatus::LP_STATUS_COMPLETED_NUM);
116  $this->assertSame($path1, $path2);
117 
118  $path1 = $instances['scorm']->getImagePathFailed();
119  $path2 = $instances['scorm']->getImagePathForStatus(ilLPStatus::LP_STATUS_FAILED_NUM);
120  $this->assertSame($path1, $path2);
121  }
122 
127  public function testImagePathRunningForLongVariant(array $instances): void
128  {
129  $this->expectException(ilLPException::class);
130  $instances['long']->getImagePathRunning();
131  }
132 
137  public function testImagePathAssetForLongVariant(array $instances): void
138  {
139  $this->expectException(ilLPException::class);
140  $instances['long']->getImagePathAsset();
141  }
142 
147  public function testSomeExamplesForRenderedIcons(array $instances): void
148  {
149  //try rendering some icons
150  $this->assertSame(
151  'rendered: path(' . $this->path .
152  '), alt(' . $this->alt .
153  '), size(' . $this->size . ')',
154  $instances['long']->renderIcon($this->path, $this->alt)
155  );
156 
157  $this->assertSame(
158  'rendered: path(' . $this->path .
159  '), alt(' . $this->alt .
160  '), size(' . $this->size . ')',
161  $instances['short']->renderIcon($this->path, $this->alt)
162  );
163  }
164 
169  public function testRenderScormIcons(array $instances): void
170  {
171  $this->expectException(ilLPException::class);
172  $instances['scorm']->renderIcon('path', 'alt');
173  }
174 }
const LP_STATUS_COMPLETED_NUM
testRenderScormIcons(array $instances)
testTripleton
testImagePathRunningForLongVariant(array $instances)
testTripleton
testImagePathAssetForLongVariant(array $instances)
testTripleton
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
Unit tests for class ilLPStatusIcons.
testSomeExamplesForRenderedIcons(array $instances)
testTripleton
$factory
Definition: metadata.php:75
const LP_STATUS_FAILED_NUM