ILIAS  release_7 Revision v7.30-3-g800a261c036
ilLPStatusIconsTest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
19use PHPUnit\Framework\TestCase;
20use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
25
30class ilLPStatusIconsTest extends TestCase
31{
32 protected $path = 'sample/path';
33 protected $alt = 'alt';
34 protected $size = Icon::SMALL;
35
39 public function testTripleton() : array
40 {
41 $utilMock = Mockery::mock('alias:' . ilUtil::class);
42 $utilMock->shouldReceive('getImagePath')
43 ->with(Mockery::type('string'))
44 ->andReturnUsing(function ($arg) {
45 return 'test/' . $arg;
46 });
47
48 $renderer = Mockery::mock(Renderer::class);
49 $renderer->shouldReceive('render')
50 ->andReturnUsing(function ($arg1) {
51 return 'rendered: path(' . $arg1->getIconPath() .
52 '), alt(' . $arg1->getLabel() .
53 '), size(' . $arg1->getSize() . ')';
54 });
55
56 $custom_icon = Mockery::mock(Custom::class);
57 $custom_icon->shouldReceive('getIconPath')
58 ->andReturn($this->path);
59 $custom_icon->shouldReceive('getSize')
60 ->andReturn($this->size);
61 $custom_icon->shouldReceive('getLabel')
62 ->andReturn($this->alt);
63
64 $factory = Mockery::mock(Factory::class);
65 $factory->shouldReceive('symbol->icon->custom')
66 ->andReturn($custom_icon);
67
70
73
76
77 $this->assertSame($short1, $short2);
78 $this->assertSame($long1, $long2);
79 $this->assertSame($scorm1, $scorm2);
80
81 $this->assertNotSame($long1, $short1);
82 $this->assertNotSame($long1, $scorm1);
83 $this->assertNotSame($short1, $scorm1);
84
85 return ['long' => $long1, 'short' => $short1, 'scorm' => $scorm1];
86 }
87
88 public function testGetInstanceForInvalidVariant() : void
89 {
90 $renderer = $this->getMockBuilder(Renderer::class)
91 ->disableOriginalConstructor()
92 ->getMock();
93
94 $factory = $this->getMockBuilder(Factory::class)
95 ->disableOriginalConstructor()
96 ->getMock();
97
98 $this->expectException(ilLPException::class);
100 }
101
106 public function testSomeExamplesForImagePathsByStatus(array $instances) : void
107 {
108 $path1 = $instances['long']->getImagePathInProgress();
109 $path2 = $instances['long']->getImagePathForStatus(ilLPStatus::LP_STATUS_IN_PROGRESS_NUM);
110 $this->assertSame($path1, $path2);
111
112 $path1 = $instances['short']->getImagePathCompleted();
113 $path2 = $instances['short']->getImagePathForStatus(ilLPStatus::LP_STATUS_COMPLETED_NUM);
114 $this->assertSame($path1, $path2);
115
116 $path1 = $instances['scorm']->getImagePathFailed();
117 $path2 = $instances['scorm']->getImagePathForStatus(ilLPStatus::LP_STATUS_FAILED_NUM);
118 $this->assertSame($path1, $path2);
119 }
120
125 public function testImagePathRunningForLongVariant(array $instances) : void
126 {
127 $this->expectException(ilLPException::class);
128 $instances['long']->getImagePathRunning();
129 }
130
135 public function testImagePathAssetForLongVariant(array $instances) : void
136 {
137 $this->expectException(ilLPException::class);
138 $instances['long']->getImagePathAsset();
139 }
140
145 public function testSomeExamplesForRenderedIcons(array $instances) : void
146 {
147 //try rendering some icons
148 $this->assertSame(
149 'rendered: path(' . $this->path .
150 '), alt(' . $this->alt .
151 '), size(' . $this->size . ')',
152 $instances['long']->renderIcon($this->path, $this->alt)
153 );
154
155 $this->assertSame(
156 'rendered: path(' . $this->path .
157 '), alt(' . $this->alt .
158 '), size(' . $this->size . ')',
159 $instances['short']->renderIcon($this->path, $this->alt)
160 );
161 }
162
167 public function testRenderScormIcons(array $instances) : void
168 {
169 $this->expectException(ilLPException::class);
170 $instances['scorm']->renderIcon('path', 'alt');
171 }
172}
An exception for terminatinating execution or to throw for unit testing.
Unit tests for class ilLPStatusIcons.
testImagePathRunningForLongVariant(array $instances)
@depends testTripleton
testRenderScormIcons(array $instances)
@depends testTripleton
testImagePathAssetForLongVariant(array $instances)
@depends testTripleton
testSomeExamplesForRenderedIcons(array $instances)
@depends testTripleton
testSomeExamplesForImagePathsByStatus(array $instances)
@depends testTripleton
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:10
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:10
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
$factory
Definition: metadata.php:58