ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ()
 
 testRenderingLetter ()
 
 testRenderingPicture ()
 
 getRandom26StringsForAllColorVariants (int $color_variants=26, int $length=10)
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Attributes

const ICON_PATH = __DIR__ . "/../../../../../templates/default/images/"
 

Private Member Functions

 getAvatarFactory ()
 

Additional Inherited Members

- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Test on avatar implementation.

Definition at line 12 of file AvatarTest.php.

Member Function Documentation

◆ getAvatarFactory()

AvatarTest::getAvatarFactory ( )
private

Definition at line 16 of file AvatarTest.php.

16 : Factory
17 {
18 return new I\Component\Symbol\Avatar\Factory();
19 }

Referenced by testAbbreviation(), testColorVariant(), testConstruction(), testCrc32(), testPicturePath(), testRenderingLetter(), testRenderingPicture(), and testUsername().

+ Here is the caller graph for this function:

◆ getRandom26StringsForAllColorVariants()

AvatarTest::getRandom26StringsForAllColorVariants ( int  $color_variants = 26,
int  $length = 10 
)
Parameters
int$color_variants
int$length
Returns
Generator|Closure

Definition at line 148 of file AvatarTest.php.

148 : Generator
149 {
150 $sh = static function ($length = 10) {
151 return substr(str_shuffle(str_repeat($x = 'abcdefghijklmnopqrstuvwxyz', (int) ceil($length / strlen($x)))), 1, $length);
152 };
153
154 $strings = [];
155 $running = true;
156 while ($running) {
157 $str = $sh($length);
158 $probe = crc32($str);
159 $i = ($probe % $color_variants) + 1;
160 if (!in_array($i, $strings, true)) {
161 $strings[$i] = $str;
162 yield $i => $str;
163 }
164 if (count($strings) === $color_variants) {
165 $running = false;
166 }
167 }
168 }
$i
Definition: metadata.php:24

References $i.

Referenced by testCrc32().

+ Here is the caller graph for this function:

◆ testAbbreviation()

AvatarTest::testAbbreviation ( )

Definition at line 33 of file AvatarTest.php.

33 : void
34 {
35 $f = $this->getAvatarFactory();
36
37 $this->assertEquals('ro', $f->letter('ro')->getAbbreviation());
38 $this->assertEquals('ro', $f->letter('root')->getAbbreviation());
39 $this->assertEquals('Ro', $f->letter('Root')->getAbbreviation());
40 $this->assertEquals('RO', $f->letter('ROOT')->getAbbreviation());
41 }
getAvatarFactory()
Definition: AvatarTest.php:16

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

+ Here is the call graph for this function:

◆ testColorVariant()

AvatarTest::testColorVariant ( )

Definition at line 65 of file AvatarTest.php.

65 : void
66 {
67 $f = $this->getAvatarFactory();
68
69 // Test all 26 colors
70 $variants = array(
71 1 => 'om',
72 2 => 'gk',
73 3 => 'bj',
74 4 => 'ea',
75 5 => 'mf',
76 6 => 'ob',
77 7 => 'bi',
78 8 => 'hu',
79 9 => 'fa',
80 10 => 'so',
81 11 => 'il',
82 12 => 'ut',
83 13 => 'ur',
84 14 => 'lt',
85 15 => 'kg',
86 16 => 'jl',
87 17 => 'qb',
88 18 => 'rq',
89 19 => 'ot',
90 20 => 'cq',
91 21 => 'rm',
92 22 => 'aj',
93 23 => 'li',
94 24 => 'er',
95 25 => 'ui',
96 26 => 'mi',
97 );
98 foreach ($variants as $color => $variant) {
99 $this->assertEquals($color, $f->letter($variant)->getBackgroundColorVariant());
100 }
101 }

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

+ Here is the call graph for this function:

◆ testConstruction()

AvatarTest::testConstruction ( )

Definition at line 21 of file AvatarTest.php.

21 : void
22 {
23 $f = $this->getAvatarFactory();
24 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Avatar\\Factory", $f);
25
26 $le = $f->letter('ru');
27 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Avatar\\Letter", $le);
28
29 $ci = $f->picture(self::ICON_PATH . 'no_photo_xsmall.jpg', 'ru');
30 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Avatar\\Picture", $ci);
31 }

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

+ Here is the call graph for this function:

◆ testCrc32()

AvatarTest::testCrc32 ( )

Definition at line 103 of file AvatarTest.php.

104 {
105 // test mechanism (crc32)
106 $f = $this->getAvatarFactory();
107 $number_of_colors = 26;
108 $abb = 'ru';
109
110 $calculated_color_variant = (crc32($abb) % $number_of_colors) + 1; // plus 1 since colors start with 1
111 $this->assertEquals($calculated_color_variant, $f->letter($abb)->getBackgroundColorVariant());
112
113 // test with random abbreviations (dynamically generated)
114
115 foreach ($this->getRandom26StringsForAllColorVariants() as $color => $variant) {
116 $this->assertEquals($color, $f->letter($variant)->getBackgroundColorVariant());
117 }
118 }
getRandom26StringsForAllColorVariants(int $color_variants=26, int $length=10)
Definition: AvatarTest.php:148

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

+ Here is the call graph for this function:

◆ testPicturePath()

AvatarTest::testPicturePath ( )

Definition at line 57 of file AvatarTest.php.

57 : void
58 {
59 $f = $this->getAvatarFactory();
60
61 $str = '/path/to/picture.jpg';
62 $this->assertEquals($str, $f->picture($str, 'ro')->getPicturePath());
63 }

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

+ Here is the call graph for this function:

◆ testRenderingLetter()

AvatarTest::testRenderingLetter ( )

Definition at line 120 of file AvatarTest.php.

121 {
122 $f = $this->getAvatarFactory();
123 $r = $this->getDefaultRenderer();
124
125 $letter = $f->letter('ro');
126 $html = $this->normalizeHTML($r->render($letter));
127 $expected = '<div class="il-avatar il-avatar-letter il-avatar-size-large il-avatar-letter-color-1" aria-label="ro"> <span class="abbreviation">ro</span></div>';
128 $this->assertEquals($expected, $html);
129 }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
normalizeHTML($html)
Definition: Base.php:317

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

+ Here is the call graph for this function:

◆ testRenderingPicture()

AvatarTest::testRenderingPicture ( )

Definition at line 131 of file AvatarTest.php.

132 {
133 $f = $this->getAvatarFactory();
134 $r = $this->getDefaultRenderer();
135
136 $str = '/path/to/picture.jpg';
137 $letter = $f->picture($str, 'ro');
138 $html = $this->normalizeHTML($r->render($letter));
139 $expected = '<div class="il-avatar il-avatar-picture il-avatar-size-large" aria-label="ro"> <img src="/path/to/picture.jpg"/></div>';
140 $this->assertEquals($expected, $html);
141 }

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

+ Here is the call graph for this function:

◆ testUsername()

AvatarTest::testUsername ( )

Definition at line 43 of file AvatarTest.php.

43 : void
44 {
45 $f = $this->getAvatarFactory();
46
47 $this->assertEquals('ro', $f->letter('ro')->getUsername());
48 $this->assertEquals('ro', $f->picture('', 'ro')->getUsername());
49 $this->assertEquals('root', $f->letter('root')->getUsername());
50 $this->assertEquals('root', $f->picture('', 'root')->getUsername());
51 $this->assertEquals('Root', $f->letter('Root')->getUsername());
52 $this->assertEquals('Root', $f->picture('', 'Root')->getUsername());
53 $this->assertEquals('ROOT', $f->letter('ROOT')->getUsername());
54 $this->assertEquals('ROOT', $f->picture('', 'ROOT')->getUsername());
55 }

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

+ Here is the call graph for this function:

Field Documentation

◆ ICON_PATH

const AvatarTest::ICON_PATH = __DIR__ . "/../../../../../templates/default/images/"
protected

Definition at line 14 of file AvatarTest.php.


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