ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AvatarTest Class Reference

Test on avatar implementation. More...

+ Inheritance diagram for AvatarTest:
+ Collaboration diagram for AvatarTest:

Public Member Functions

 testConstruction ()
 
 testAbbreviation ()
 
 testUsername ()
 
 testPicturePath ()
 
 testColorVariant ()
 
 testCrc32 ()
 
 testAlternativeText ()
 
 testRenderingLetter ()
 
 testRenderingPicture ()
 
 testRenderingPictureWithSomeAlternativeText ()
 
 getRandom26StringsForAllColorVariants (int $color_variants=26, int $length=2)
 
 testHTMLInLabel ()
 
 testHTMLInCustomImage ()
 

Protected Attributes

const ICON_PATH = __DIR__ . "/../../../../../../../assets/images/"
 

Private Member Functions

 getAvatarFactory ()
 

Detailed Description

Test on avatar implementation.

Definition at line 30 of file AvatarTest.php.

Member Function Documentation

◆ getAvatarFactory()

AvatarTest::getAvatarFactory ( )
private

◆ 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().

+ Here is the caller graph for this function:

◆ testAbbreviation()

AvatarTest::testAbbreviation ( )

Definition at line 51 of file AvatarTest.php.

51 : void
52 {
53 $f = $this->getAvatarFactory();
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 }
getAvatarFactory()
Definition: AvatarTest.php:34

References Vendor\Package\$f, and getAvatarFactory().

+ Here is the call graph for this function:

◆ testAlternativeText()

AvatarTest::testAlternativeText ( )

Definition at line 138 of file AvatarTest.php.

138 : void
139 {
140 $f = $this->getAvatarFactory();
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().

+ Here is the call graph for this function:

◆ testColorVariant()

AvatarTest::testColorVariant ( )

Definition at line 83 of file AvatarTest.php.

83 : void
84 {
85 $f = $this->getAvatarFactory();
86
87 // Test all 26 colors
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().

+ Here is the call graph for this function:

◆ testConstruction()

AvatarTest::testConstruction ( )

Definition at line 39 of file AvatarTest.php.

39 : void
40 {
41 $f = $this->getAvatarFactory();
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().

+ Here is the call graph for this function:

◆ testCrc32()

AvatarTest::testCrc32 ( )

Definition at line 121 of file AvatarTest.php.

121 : void
122 {
123 // test mechanism (crc32)
124 $f = $this->getAvatarFactory();
125 $number_of_colors = 26;
126 $abb = 'ru';
127
128 $calculated_color_variant = (crc32($abb) % $number_of_colors) + 1; // plus 1 since colors start with 1
129 $this->assertEquals($calculated_color_variant, $f->letter($abb)->getBackgroundColorVariant());
130
131 // test with random abbreviations (dynamically generated)
132
133 foreach ($this->getRandom26StringsForAllColorVariants() as $color => $variant) {
134 $this->assertEquals($color, $f->letter($variant)->getBackgroundColorVariant());
135 }
136 }
getRandom26StringsForAllColorVariants(int $color_variants=26, int $length=2)
Definition: AvatarTest.php:199

References Vendor\Package\$f, getAvatarFactory(), and getRandom26StringsForAllColorVariants().

+ Here is the call graph for this function:

◆ testHTMLInCustomImage()

AvatarTest::testHTMLInCustomImage ( )

Definition at line 242 of file AvatarTest.php.

242 : void
243 {
244 $f = $this->getAvatarFactory();
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="&lt;h1&gt;path&lt;/h1&gt;" alt="user_avatar"/>
252</span>');
253 $this->assertEquals($expected, $html);
254 }

References Vendor\Package\$f, and getAvatarFactory().

+ Here is the call graph for this function:

◆ testHTMLInLabel()

AvatarTest::testHTMLInLabel ( )

Definition at line 228 of file AvatarTest.php.

228 : void
229 {
230 $f = $this->getAvatarFactory();
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="&lt;h1&gt;label&lt;/h1&gt;" role="img">
237 <span class="abbreviation">us</span>
238</span>');
239 $this->assertEquals($expected, $html);
240 }

References Vendor\Package\$f, and getAvatarFactory().

+ Here is the call graph for this function:

◆ testPicturePath()

AvatarTest::testPicturePath ( )

Definition at line 75 of file AvatarTest.php.

75 : void
76 {
77 $f = $this->getAvatarFactory();
78
79 $str = '/path/to/picture.jpg';
80 $this->assertEquals($str, $f->picture($str, 'ro')->getPicturePath());
81 }

References Vendor\Package\$f, and getAvatarFactory().

+ Here is the call graph for this function:

◆ testRenderingLetter()

AvatarTest::testRenderingLetter ( )

Definition at line 151 of file AvatarTest.php.

151 : void
152 {
153 $f = $this->getAvatarFactory();
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().

+ Here is the call graph for this function:

◆ testRenderingPicture()

AvatarTest::testRenderingPicture ( )

Definition at line 165 of file AvatarTest.php.

165 : void
166 {
167 $f = $this->getAvatarFactory();
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().

+ Here is the call graph for this function:

◆ testRenderingPictureWithSomeAlternativeText()

AvatarTest::testRenderingPictureWithSomeAlternativeText ( )

Definition at line 180 of file AvatarTest.php.

180 : void
181 {
182 $f = $this->getAvatarFactory();
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().

+ Here is the call graph for this function:

◆ testUsername()

AvatarTest::testUsername ( )

Definition at line 61 of file AvatarTest.php.

61 : void
62 {
63 $f = $this->getAvatarFactory();
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().

+ Here is the call graph for this function:

Field Documentation

◆ ICON_PATH

const AvatarTest::ICON_PATH = __DIR__ . "/../../../../../../../assets/images/"
protected

Definition at line 32 of file AvatarTest.php.


The documentation for this class was generated from the following file: