Test on avatar implementation.
More...
|
const | ICON_PATH = __DIR__ . "/../../../../../../../assets/images/" |
|
Test on avatar implementation.
Definition at line 30 of file AvatarTest.php.
◆ getAvatarFactory()
AvatarTest::getAvatarFactory |
( |
| ) |
|
|
private |
Definition at line 34 of file AvatarTest.php.
35 {
36 return new I\Component\Symbol\Avatar\Factory();
37 }
Referenced by testAbbreviation(), testAlternativeText(), testColorVariant(), testConstruction(), testCrc32(), testHTMLInCustomImage(), testHTMLInLabel(), testPicturePath(), testRenderingLetter(), testRenderingPicture(), testRenderingPictureWithSomeAlternativeText(), and testUsername().
◆ getRandom26StringsForAllColorVariants()
AvatarTest::getRandom26StringsForAllColorVariants |
( |
int |
$color_variants = 26 , |
|
|
int |
$length = 2 |
|
) |
| |
- Parameters
-
int | $color_variants | |
int | $length | |
- Returns
- Generator|Closure
Definition at line 199 of file AvatarTest.php.
199 : Generator
200 {
201 $sh = static function ($length = 10) {
202 return substr(
203 str_shuffle(str_repeat(
204 $x = 'abcdefghijklmnopqrstuvwxyz',
205 (int) ceil($length / strlen($x))
206 )),
207 1,
208 $length
209 );
210 };
211
212 $strings = [];
213 $running = true;
214 while ($running) {
215 $str = $sh($length);
216 $probe = crc32($str);
217 $i = ($probe % $color_variants) + 1;
218 if (!in_array($i, $strings, true)) {
219 $strings[$i] = $str;
220 yield $i => $str;
221 }
222 if (count($strings) === $color_variants) {
223 $running = false;
224 }
225 }
226 }
Referenced by testCrc32().
◆ testAbbreviation()
AvatarTest::testAbbreviation |
( |
| ) |
|
Definition at line 51 of file AvatarTest.php.
51 : void
52 {
54
55 $this->assertEquals(
'ro',
$f->letter(
'ro')->getAbbreviation());
56 $this->assertEquals(
'ro',
$f->letter(
'root')->getAbbreviation());
57 $this->assertEquals(
'Ro',
$f->letter(
'Root')->getAbbreviation());
58 $this->assertEquals(
'RO',
$f->letter(
'ROOT')->getAbbreviation());
59 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testAlternativeText()
AvatarTest::testAlternativeText |
( |
| ) |
|
Definition at line 138 of file AvatarTest.php.
138 : void
139 {
141 $this->assertEquals(
"",
$f->picture(
'',
'ro')->getLabel());
142 $this->assertEquals(
"",
$f->letter(
'',
'ro')->getLabel());
143 $this->assertEquals(
"alternative",
$f->picture(
'',
'ro')
144 ->withLabel("alternative")
145 ->getLabel());
146 $this->assertEquals(
"alternative",
$f->letter(
'',
'ro')
147 ->withLabel("alternative")
148 ->getLabel());
149 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testColorVariant()
AvatarTest::testColorVariant |
( |
| ) |
|
Definition at line 83 of file AvatarTest.php.
83 : void
84 {
86
87
88 $variants = array(
89 1 => 'om',
90 2 => 'gk',
91 3 => 'bj',
92 4 => 'ea',
93 5 => 'mf',
94 6 => 'ob',
95 7 => 'bi',
96 8 => 'hu',
97 9 => 'fa',
98 10 => 'so',
99 11 => 'il',
100 12 => 'ut',
101 13 => 'ur',
102 14 => 'lt',
103 15 => 'kg',
104 16 => 'jl',
105 17 => 'qb',
106 18 => 'rq',
107 19 => 'ot',
108 20 => 'cq',
109 21 => 'rm',
110 22 => 'aj',
111 23 => 'li',
112 24 => 'er',
113 25 => 'ui',
114 26 => 'mi',
115 );
116 foreach ($variants as $color => $variant) {
117 $this->assertEquals($color,
$f->letter($variant)->getBackgroundColorVariant());
118 }
119 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testConstruction()
AvatarTest::testConstruction |
( |
| ) |
|
Definition at line 39 of file AvatarTest.php.
39 : void
40 {
42 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Symbol\\Avatar\\Factory",
$f);
43
44 $le =
$f->letter(
'ru');
45 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Avatar\\Letter", $le);
46
47 $ci =
$f->picture(self::ICON_PATH .
'placeholder/no_photo_xsmall.jpg',
'ru');
48 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Avatar\\Picture", $ci);
49 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testCrc32()
AvatarTest::testCrc32 |
( |
| ) |
|
Definition at line 121 of file AvatarTest.php.
121 : void
122 {
123
125 $number_of_colors = 26;
126 $abb = 'ru';
127
128 $calculated_color_variant = (crc32($abb) % $number_of_colors) + 1;
129 $this->assertEquals($calculated_color_variant,
$f->letter($abb)->getBackgroundColorVariant());
130
131
132
134 $this->assertEquals($color,
$f->letter($variant)->getBackgroundColorVariant());
135 }
136 }
getRandom26StringsForAllColorVariants(int $color_variants=26, int $length=2)
References Vendor\Package\$f, getAvatarFactory(), and getRandom26StringsForAllColorVariants().
◆ testHTMLInCustomImage()
AvatarTest::testHTMLInCustomImage |
( |
| ) |
|
Definition at line 242 of file AvatarTest.php.
242 : void
243 {
245 $r = $this->getDefaultRenderer();
246
247 $avatar =
$f->picture(
'<h1>path</h1>',
'user');
248 $html = $this->brutallyTrimHTML($r->render($avatar));
249 $expected = $this->brutallyTrimHTML('
250<span class="il-avatar il-avatar-picture il-avatar-size-large">
251 <img src="<h1>path</h1>" alt="user_avatar"/>
252</span>');
253 $this->assertEquals($expected, $html);
254 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testHTMLInLabel()
AvatarTest::testHTMLInLabel |
( |
| ) |
|
Definition at line 228 of file AvatarTest.php.
228 : void
229 {
231 $r = $this->getDefaultRenderer();
232
233 $avatar =
$f->letter(
'user')->withLabel(
'<h1>label</h1>');
234 $html = $this->brutallyTrimHTML($r->render($avatar));
235 $expected = $this->brutallyTrimHTML('
236<span class="il-avatar il-avatar-letter il-avatar-size-large il-avatar-letter-color-11" aria-label="<h1>label</h1>" role="img">
237 <span class="abbreviation">us</span>
238</span>');
239 $this->assertEquals($expected, $html);
240 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testPicturePath()
AvatarTest::testPicturePath |
( |
| ) |
|
◆ testRenderingLetter()
AvatarTest::testRenderingLetter |
( |
| ) |
|
Definition at line 151 of file AvatarTest.php.
151 : void
152 {
154 $r = $this->getDefaultRenderer();
155
156 $letter =
$f->letter(
'ro');
157 $html = $this->brutallyTrimHTML($r->render($letter));
158 $expected = $this->brutallyTrimHTML('
159<span class="il-avatar il-avatar-letter il-avatar-size-large il-avatar-letter-color-1" aria-label="user_avatar" role="img">
160 <span class="abbreviation">ro</span>
161</span>');
162 $this->assertEquals($expected, $html);
163 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testRenderingPicture()
AvatarTest::testRenderingPicture |
( |
| ) |
|
Definition at line 165 of file AvatarTest.php.
165 : void
166 {
168 $r = $this->getDefaultRenderer();
169
170 $str = '/path/to/picture.jpg';
171 $letter =
$f->picture($str,
'ro');
172 $html = $this->brutallyTrimHTML($r->render($letter));
173 $expected = $this->brutallyTrimHTML('
174<span class="il-avatar il-avatar-picture il-avatar-size-large">
175 <img src="/path/to/picture.jpg" alt="user_avatar"/>
176</span>');
177 $this->assertEquals($expected, $html);
178 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testRenderingPictureWithSomeAlternativeText()
AvatarTest::testRenderingPictureWithSomeAlternativeText |
( |
| ) |
|
Definition at line 180 of file AvatarTest.php.
180 : void
181 {
183 $r = $this->getDefaultRenderer();
184
185 $str = '/path/to/picture.jpg';
186 $letter =
$f->picture($str,
'ro')->withLabel(
"alternative");
187 $html = $this->brutallyTrimHTML($r->render($letter));
188 $expected = $this->brutallyTrimHTML('
189<span class="il-avatar il-avatar-picture il-avatar-size-large">
190 <img src="/path/to/picture.jpg" alt="alternative"/>
191</span>');
192 $this->assertEquals($expected, $html);
193 }
References Vendor\Package\$f, and getAvatarFactory().
◆ testUsername()
AvatarTest::testUsername |
( |
| ) |
|
Definition at line 61 of file AvatarTest.php.
61 : void
62 {
64
65 $this->assertEquals(
'ro',
$f->letter(
'ro')->getUsername());
66 $this->assertEquals(
'ro',
$f->picture(
'',
'ro')->getUsername());
67 $this->assertEquals(
'root',
$f->letter(
'root')->getUsername());
68 $this->assertEquals(
'root',
$f->picture(
'',
'root')->getUsername());
69 $this->assertEquals(
'Root',
$f->letter(
'Root')->getUsername());
70 $this->assertEquals(
'Root',
$f->picture(
'',
'Root')->getUsername());
71 $this->assertEquals(
'ROOT',
$f->letter(
'ROOT')->getUsername());
72 $this->assertEquals(
'ROOT',
$f->picture(
'',
'ROOT')->getUsername());
73 }
References Vendor\Package\$f, and getAvatarFactory().
◆ ICON_PATH
const AvatarTest::ICON_PATH = __DIR__ . "/../../../../../../../assets/images/" |
|
protected |
The documentation for this class was generated from the following file: