ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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)
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
 
 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.

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

16  : Factory
17  {
18  return new I\Component\Symbol\Avatar\Factory();
19  }
+ Here is the caller graph for this function:

◆ getRandom26StringsForAllColorVariants()

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

Definition at line 181 of file AvatarTest.php.

References $i.

Referenced by testCrc32().

181  : Generator
182  {
183  $sh = static function ($length = 10) {
184  return substr(str_shuffle(str_repeat($x = 'abcdefghijklmnopqrstuvwxyz', (int) ceil($length / strlen($x)))), 1, $length);
185  };
186 
187  $strings = [];
188  $running = true;
189  while ($running) {
190  $str = $sh($length);
191  $probe = crc32($str);
192  $i = ($probe % $color_variants) + 1;
193  if (!in_array($i, $strings, true)) {
194  $strings[$i] = $str;
195  yield $i => $str;
196  }
197  if (count($strings) === $color_variants) {
198  $running = false;
199  }
200  }
201  }
$i
Definition: metadata.php:24
+ Here is the caller graph for this function:

◆ testAbbreviation()

AvatarTest::testAbbreviation ( )

Definition at line 33 of file AvatarTest.php.

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

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
+ Here is the call graph for this function:

◆ testAlternativeText()

AvatarTest::testAlternativeText ( )

Definition at line 120 of file AvatarTest.php.

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

120  : void
121  {
122  $f = $this->getAvatarFactory();
123  $this->assertEquals("", $f->picture('', 'ro')->getAlternativeText());
124  $this->assertEquals("", $f->letter('', 'ro')->getAlternativeText());
125  $this->assertEquals("alternative", $f->picture('', 'ro')
126  ->withAlternativeText("alternative")
127  ->getAlternativeText());
128  $this->assertEquals("alternative", $f->letter('', 'ro')
129  ->withAlternativeText("alternative")
130  ->getAlternativeText());
131  }
getAvatarFactory()
Definition: AvatarTest.php:16
+ Here is the call graph for this function:

◆ testColorVariant()

AvatarTest::testColorVariant ( )

Definition at line 65 of file AvatarTest.php.

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

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  }
getAvatarFactory()
Definition: AvatarTest.php:16
+ Here is the call graph for this function:

◆ testConstruction()

AvatarTest::testConstruction ( )

Definition at line 21 of file AvatarTest.php.

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

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  }
getAvatarFactory()
Definition: AvatarTest.php:16
+ Here is the call graph for this function:

◆ testCrc32()

AvatarTest::testCrc32 ( )

Definition at line 103 of file AvatarTest.php.

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

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  }
getAvatarFactory()
Definition: AvatarTest.php:16
getRandom26StringsForAllColorVariants(int $color_variants=26, int $length=2)
Definition: AvatarTest.php:181
+ Here is the call graph for this function:

◆ testPicturePath()

AvatarTest::testPicturePath ( )

Definition at line 57 of file AvatarTest.php.

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

57  : void
58  {
59  $f = $this->getAvatarFactory();
60 
61  $str = '/path/to/picture.jpg';
62  $this->assertEquals($str, $f->picture($str, 'ro')->getPicturePath());
63  }
getAvatarFactory()
Definition: AvatarTest.php:16
+ Here is the call graph for this function:

◆ testRenderingLetter()

AvatarTest::testRenderingLetter ( )

Definition at line 133 of file AvatarTest.php.

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

134  {
135  $f = $this->getAvatarFactory();
136  $r = $this->getDefaultRenderer();
137 
138  $letter = $f->letter('ro');
139  $html = $this->brutallyTrimHTML($r->render($letter));
140  $expected = $this->brutallyTrimHTML('
141 <span class="il-avatar il-avatar-letter il-avatar-size-large il-avatar-letter-color-1" aria-label="user_avatar" role="img">
142  <span class="abbreviation">ro</span>
143 </span>');
144  $this->assertEquals($expected, $html);
145  }
getAvatarFactory()
Definition: AvatarTest.php:16
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
+ Here is the call graph for this function:

◆ testRenderingPicture()

AvatarTest::testRenderingPicture ( )

Definition at line 147 of file AvatarTest.php.

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

148  {
149  $f = $this->getAvatarFactory();
150  $r = $this->getDefaultRenderer();
151 
152  $str = '/path/to/picture.jpg';
153  $letter = $f->picture($str, 'ro');
154  $html = $this->brutallyTrimHTML($r->render($letter));
155  $expected = $this->brutallyTrimHTML('
156 <span class="il-avatar il-avatar-picture il-avatar-size-large">
157  <img src="/path/to/picture.jpg" alt="user_avatar"/>
158 </span>');
159  $this->assertEquals($expected, $html);
160  }
getAvatarFactory()
Definition: AvatarTest.php:16
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
+ Here is the call graph for this function:

◆ testRenderingPictureWithSomeAlternativeText()

AvatarTest::testRenderingPictureWithSomeAlternativeText ( )

Definition at line 162 of file AvatarTest.php.

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

163  {
164  $f = $this->getAvatarFactory();
165  $r = $this->getDefaultRenderer();
166 
167  $str = '/path/to/picture.jpg';
168  $letter = $f->picture($str, 'ro')->withAlternativeText("alternative");
169  $html = $this->brutallyTrimHTML($r->render($letter));
170  $expected = $this->brutallyTrimHTML('
171 <span class="il-avatar il-avatar-picture il-avatar-size-large">
172  <img src="/path/to/picture.jpg" alt="alternative"/>
173 </span>');
174  $this->assertEquals($expected, $html);
175  }
getAvatarFactory()
Definition: AvatarTest.php:16
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
+ Here is the call graph for this function:

◆ testUsername()

AvatarTest::testUsername ( )

Definition at line 43 of file AvatarTest.php.

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

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  }
getAvatarFactory()
Definition: AvatarTest.php:16
+ 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: