19 declare(strict_types=1);
21 require_once(
"vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ .
"/../../../Base.php");
32 protected const ICON_PATH = __DIR__ .
"/../../../../../../../assets/images/";
36 return new I\Component\Symbol\Avatar\Factory();
42 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Symbol\\Avatar\\Factory",
$f);
44 $le =
$f->letter(
'ru');
45 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Symbol\\Avatar\\Letter", $le);
47 $ci =
$f->picture(self::ICON_PATH .
'placeholder/no_photo_xsmall.jpg',
'ru');
48 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Symbol\\Avatar\\Picture", $ci);
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());
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());
79 $str =
'/path/to/picture.jpg';
80 $this->assertEquals($str,
$f->picture($str,
'ro')->getPicturePath());
116 foreach ($variants as $color => $variant) {
117 $this->assertEquals($color,
$f->letter($variant)->getBackgroundColorVariant());
125 $number_of_colors = 26;
128 $calculated_color_variant = (crc32($abb) % $number_of_colors) + 1;
129 $this->assertEquals($calculated_color_variant,
$f->letter($abb)->getBackgroundColorVariant());
134 $this->assertEquals($color,
$f->letter($variant)->getBackgroundColorVariant());
141 $this->assertEquals(
"",
$f->picture(
'',
'ro')->getLabel());
142 $this->assertEquals(
"",
$f->letter(
'',
'ro')->getLabel());
143 $this->assertEquals(
"alternative",
$f->picture(
'',
'ro')
144 ->withLabel(
"alternative")
146 $this->assertEquals(
"alternative",
$f->letter(
'',
'ro')
147 ->withLabel(
"alternative")
154 $r = $this->getDefaultRenderer();
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> 162 $this->assertEquals($expected, $html);
168 $r = $this->getDefaultRenderer();
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"/> 177 $this->assertEquals($expected, $html);
183 $r = $this->getDefaultRenderer();
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"/> 192 $this->assertEquals($expected, $html);
201 $sh =
static function ($length = 10) {
203 str_shuffle(str_repeat(
204 $x =
'abcdefghijklmnopqrstuvwxyz',
205 (
int) ceil($length / strlen($x))
216 $probe = crc32($str);
217 $i = ($probe % $color_variants) + 1;
218 if (!in_array($i, $strings,
true)) {
222 if (count($strings) === $color_variants) {
231 $r = $this->getDefaultRenderer();
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> 239 $this->assertEquals($expected, $html);
245 $r = $this->getDefaultRenderer();
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"/> 253 $this->assertEquals($expected, $html);
getRandom26StringsForAllColorVariants(int $color_variants=26, int $length=2)
Test on avatar implementation.
testRenderingPictureWithSomeAlternativeText()