ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ButtonTest Class Reference

Test on button implementation. More...

+ Inheritance diagram for ButtonTest:
+ Collaboration diagram for ButtonTest:

Public Member Functions

 getButtonFactory ()
 
 test_implements_factory_interface ()
 
 test_button_label_or_glyph_only ($factory_method)
 button_type_provider More...
 
 test_button_string_action_only ($factory_method)
 button_type_provider More...
 
 test_button_label ($factory_method)
 button_type_provider More...
 
 test_button_with_label ($factory_method)
 button_type_provider More...
 
 test_button_action ($factory_method)
 button_type_provider More...
 
 test_button_activated_on_default ($factory_method)
 button_type_provider More...
 
 test_button_deactivation ($factory_method)
 button_type_provider More...
 
 test_render_button_label ($factory_method)
 button_type_provider More...
 
 test_render_button_disabled ($factory_method)
 button_type_provider More...
 
 test_render_close_button ()
 
 test_render_button_with_on_load_code ($factory_method)
 button_type_provider More...
 
 test_____render_close_button_with_on_load_code ()
 
 test_btn_tag_relevance ()
 
 test_render_btn_tag_relevance ()
 
 test_render_btn_tag_colors ()
 
 test_render_btn_tag_classes ()
 
 test_button_with_aria_label ($factory_method)
 button_type_provider More...
 
 test_button_with_aria_checked ($factory_method)
 button_type_provider More...
 
 test_render_button_with_aria_label ($factory_method)
 button_type_provider More...
 
 test_render_button_with_aria_checked ($factory_method)
 button_type_provider More...
 
 button_type_provider ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Static Public Attributes

static $canonical_css_classes
 
static $canonical_css_inactivation_classes
 

Detailed Description

Test on button implementation.

Definition at line 13 of file ButtonTest.php.

Member Function Documentation

◆ button_type_provider()

ButtonTest::button_type_provider ( )

Definition at line 398 of file ButtonTest.php.

References array.

399  {
400  return array( array("standard")
401  , array("primary")
402  , array("shy")
403  , array("tag")
404  );
405  }
Create styles array
The data for the language used.

◆ getButtonFactory()

◆ test_____render_close_button_with_on_load_code()

ButtonTest::test_____render_close_button_with_on_load_code ( )

Definition at line 224 of file ButtonTest.php.

References $html, $id, $r, array, getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

225  {
226  $f = $this->getButtonFactory();
227  $r = $this->getDefaultRenderer();
228  $ids = array();
229  $b = $f->close()
230  ->withOnLoadCode(function ($id) use (&$ids) {
231  $ids[] = $id;
232  return "";
233  });
234 
235  $html = $this->normalizeHTML($r->render($b));
236 
237  $this->assertCount(1, $ids);
238 
239  $id = $ids[0];
240  $expected = "<button type=\"button\" class=\"close\" data-dismiss=\"modal\" id=\"$id\">" .
241  " <span aria-hidden=\"true\">&times;</span>" .
242  " <span class=\"sr-only\">Close</span>" .
243  "</button>";
244  $this->assertEquals($expected, $html);
245  }
if(!array_key_exists('StateId', $_REQUEST)) $id
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_btn_tag_relevance()

ButtonTest::test_btn_tag_relevance ( )

Definition at line 247 of file ButtonTest.php.

References getButtonFactory().

248  {
249  $f = $this->getButtonFactory();
250  $b = $f->tag('tag', '#');
251  try {
252  $b->withRelevance(0);
253  $this->assertFalse("This should not happen");
254  } catch (\InvalidArgumentException $e) {
255  $this->assertTrue(true);
256  }
257  try {
258  $b->withRelevance('notsoimportant');
259  $this->assertFalse("This should not happen");
260  } catch (\InvalidArgumentException $e) {
261  $this->assertTrue(true);
262  }
263  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_action()

ButtonTest::test_button_action (   $factory_method)

button_type_provider

Definition at line 110 of file ButtonTest.php.

References getButtonFactory().

111  {
112  $f = $this->getButtonFactory();
113  $b = $f->$factory_method("label", "http://www.ilias.de");
114 
115  $this->assertEquals("http://www.ilias.de", $b->getAction());
116  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_activated_on_default()

ButtonTest::test_button_activated_on_default (   $factory_method)

button_type_provider

Definition at line 121 of file ButtonTest.php.

References getButtonFactory().

122  {
123  $f = $this->getButtonFactory();
124  $b = $f->$factory_method("label", "http://www.ilias.de");
125 
126  $this->assertTrue($b->isActive());
127  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_deactivation()

ButtonTest::test_button_deactivation (   $factory_method)

button_type_provider

Definition at line 132 of file ButtonTest.php.

References getButtonFactory().

133  {
134  $f = $this->getButtonFactory();
135  $b = $f->$factory_method("label", "http://www.ilias.de")
136  ->withUnavailableAction();
137 
138  $this->assertFalse($b->isActive());
139  $this->assertEquals("http://www.ilias.de", $b->getAction());
140  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_label()

ButtonTest::test_button_label (   $factory_method)

button_type_provider

Definition at line 85 of file ButtonTest.php.

References getButtonFactory().

86  {
87  $f = $this->getButtonFactory();
88  $b = $f->$factory_method("label", "http://www.ilias.de");
89 
90  $this->assertEquals("label", $b->getLabel());
91  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_label_or_glyph_only()

ButtonTest::test_button_label_or_glyph_only (   $factory_method)

button_type_provider

Definition at line 59 of file ButtonTest.php.

References getButtonFactory().

60  {
61  $f = $this->getButtonFactory();
62  try {
63  $f->$factory_method($this, "http://www.ilias.de");
64  $this->assertFalse("This should not happen");
65  } catch (\InvalidArgumentException $e) {
66  }
67  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_string_action_only()

ButtonTest::test_button_string_action_only (   $factory_method)

button_type_provider

Definition at line 72 of file ButtonTest.php.

References getButtonFactory().

73  {
74  $f = $this->getButtonFactory();
75  try {
76  $f->$factory_method("label", $this);
77  $this->assertFalse("This should not happen");
78  } catch (\InvalidArgumentException $e) {
79  }
80  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_with_aria_checked()

ButtonTest::test_button_with_aria_checked (   $factory_method)

button_type_provider

Definition at line 343 of file ButtonTest.php.

References getButtonFactory().

344  {
345  $f = $this->getButtonFactory();
346  $b = $f->$factory_method("label", "http://www.ilias.de");
347  $this->assertEquals(false, $b->isAriaChecked());
348  $b2 = $f->$factory_method("label", "http://www.ilias.de")->withAriaChecked();
349  $this->assertEquals(true, $b2->isAriaChecked());
350  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_with_aria_label()

ButtonTest::test_button_with_aria_label (   $factory_method)

button_type_provider

Definition at line 333 of file ButtonTest.php.

References getButtonFactory().

334  {
335  $f = $this->getButtonFactory();
336  $b = $f->$factory_method("label", "http://www.ilias.de")->withAriaLabel("ariatext");
337  $this->assertEquals("ariatext", $b->getAriaLabel());
338  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_button_with_label()

ButtonTest::test_button_with_label (   $factory_method)

button_type_provider

Definition at line 96 of file ButtonTest.php.

References getButtonFactory().

97  {
98  $f = $this->getButtonFactory();
99  $b = $f->$factory_method("label", "http://www.ilias.de");
100 
101  $b2 = $b->withLabel("label2");
102 
103  $this->assertEquals("label", $b->getLabel());
104  $this->assertEquals("label2", $b2->getLabel());
105  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_implements_factory_interface()

ButtonTest::test_implements_factory_interface ( )

Definition at line 33 of file ButtonTest.php.

References getButtonFactory().

34  {
35  $f = $this->getButtonFactory();
36 
37  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Factory", $f);
38  $this->assertInstanceOf(
39  "ILIAS\\UI\\Component\\Button\\Standard",
40  $f->standard("label", "http://www.ilias.de")
41  );
42  $this->assertInstanceOf(
43  "ILIAS\\UI\\Component\\Button\\Primary",
44  $f->primary("label", "http://www.ilias.de")
45  );
46  $this->assertInstanceOf(
47  "ILIAS\\UI\\Component\\Button\\Close",
48  $f->close()
49  );
50  $this->assertInstanceOf(
51  "ILIAS\\UI\\Component\\Button\\Shy",
52  $f->shy("label", "http://www.ilias.de")
53  );
54  }
getButtonFactory()
Definition: ButtonTest.php:15
+ Here is the call graph for this function:

◆ test_render_btn_tag_classes()

ButtonTest::test_render_btn_tag_classes ( )

Definition at line 315 of file ButtonTest.php.

References $html, $r, array, getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

316  {
317  $f = $this->getButtonFactory();
318  $r = $this->getDefaultRenderer();
319  $df = new \ILIAS\Data\Factory;
320 
321  $classes = array('cl1', 'cl2');
322  $b = $f->tag('tag', '#')
323  ->withClasses($classes);
324  $this->assertEquals($classes, $b->getClasses());
325 
326  $html = $this->normalizeHTML($r->render($b));
327  $expected = '<a class="btn btn-tag btn-tag-relevance-veryhigh cl1 cl2" href="#" data-action="#">tag</a>';
328  $this->assertEquals($expected, $html);
329  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_btn_tag_colors()

ButtonTest::test_render_btn_tag_colors ( )

Definition at line 294 of file ButtonTest.php.

References $html, $r, getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

295  {
296  $f = $this->getButtonFactory();
297  $r = $this->getDefaultRenderer();
298  $df = new \ILIAS\Data\Factory;
299 
300  $bgcol = $df->color('#00ff00');
301 
302  $b = $f->tag('tag', '#')
303  ->withBackgroundColor($bgcol);
304  $html = $this->normalizeHTML($r->render($b));
305  $expected = '<a class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #000000;" href="#" data-action="#">tag</a>';
306  $this->assertEquals($expected, $html);
307 
308  $fcol = $df->color('#ddd');
309  $b = $b->withForegroundColor($fcol);
310  $html = $this->normalizeHTML($r->render($b));
311  $expected = '<a class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #dddddd;" href="#" data-action="#">tag</a>';
312  $this->assertEquals($expected, $html);
313  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_btn_tag_relevance()

ButtonTest::test_render_btn_tag_relevance ( )

Definition at line 265 of file ButtonTest.php.

References $html, $r, $t, $w, array, getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

266  {
267  $expectations = array(
268  '<a class="btn btn-tag btn-tag-relevance-verylow" href="#" data-action="#">tag</a>',
269  '<a class="btn btn-tag btn-tag-relevance-low" href="#" data-action="#">tag</a>',
270  '<a class="btn btn-tag btn-tag-relevance-middle" href="#" data-action="#">tag</a>',
271  '<a class="btn btn-tag btn-tag-relevance-high" href="#" data-action="#">tag</a>',
272  '<a class="btn btn-tag btn-tag-relevance-veryhigh" href="#" data-action="#">tag</a>'
273  );
274 
275  $f = $this->getButtonFactory();
276  $r = $this->getDefaultRenderer();
277  $t = $f->tag('tag', '#');
278  $possible_relevances = array(
279  $t::REL_VERYLOW,
280  $t::REL_LOW,
281  $t::REL_MID,
282  $t::REL_HIGH,
283  $t::REL_VERYHIGH
284  );
285  foreach ($possible_relevances as $w) {
286  $html = $this->normalizeHTML(
287  $r->render($t->withRelevance($w))
288  );
289  $expected = $expectations[array_search($w, $possible_relevances)];
290  $this->assertEquals($expected, $html);
291  }
292  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
$w
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_button_disabled()

ButtonTest::test_render_button_disabled (   $factory_method)

button_type_provider

Definition at line 164 of file ButtonTest.php.

References $html, $r, ILIAS_UI_TestBase\assertHTMLEquals(), getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

165  {
166  $ln = "http://www.ilias.de";
167  $f = $this->getButtonFactory();
168  $b = $f->$factory_method("label", $ln)
169  ->withUnavailableAction();
170  $r = $this->getDefaultRenderer();
171 
172  $html = $this->normalizeHTML($r->render($b));
173 
174  $css_classes = self::$canonical_css_classes[$factory_method];
175  $css_class_inactive = self::$canonical_css_inactivation_classes[$factory_method];
176  $expected = "<a class=\"$css_classes $css_class_inactive\" data-action=\"$ln\">" .
177  "label" .
178  "</a>";
179  $this->assertHTMLEquals($expected, $html);
180  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_button_label()

ButtonTest::test_render_button_label (   $factory_method)

button_type_provider

Definition at line 145 of file ButtonTest.php.

References $html, $r, ILIAS_UI_TestBase\assertHTMLEquals(), getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

146  {
147  $ln = "http://www.ilias.de";
148  $f = $this->getButtonFactory();
149  $b = $f->$factory_method("label", $ln);
150  $r = $this->getDefaultRenderer();
151 
152  $html = $this->normalizeHTML($r->render($b));
153 
154  $css_classes = self::$canonical_css_classes[$factory_method];
155  $expected = "<a class=\"$css_classes\" href=\"$ln\" data-action=\"$ln\">" .
156  "label" .
157  "</a>";
158  $this->assertHTMLEquals($expected, $html);
159  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_button_with_aria_checked()

ButtonTest::test_render_button_with_aria_checked (   $factory_method)

button_type_provider

Definition at line 378 of file ButtonTest.php.

References $html, $r, ILIAS_UI_TestBase\assertHTMLEquals(), getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

379  {
380  //only standard buttons have aria labels in the template. Should the others accept aria stuff?
381  //if yes, remove this conditional
382  if ($factory_method == "standard") {
383  $ln = "http://www.ilias.de";
384  $f = $this->getButtonFactory();
385  $r = $this->getDefaultRenderer();
386  $b = $f->$factory_method("label", $ln)->withAriaChecked();
387 
388  $html = $this->normalizeHTML($r->render($b));
389  $css_classes = self::$canonical_css_classes[$factory_method];
390  $expected = "<a class=\"$css_classes\" href=\"$ln\" aria-checked=\"true\" data-action=\"$ln\">" .
391  "label" .
392  "</a>";
393  $this->assertHTMLEquals($expected, $html);
394  }
395  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_button_with_aria_label()

ButtonTest::test_render_button_with_aria_label (   $factory_method)

button_type_provider

Definition at line 355 of file ButtonTest.php.

References $html, $r, ILIAS_UI_TestBase\assertHTMLEquals(), getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

356  {
357  //only standard buttons have aria labels in the template. Should the others accept aria stuff?
358  //if yes, remove this conditional
359  if ($factory_method == "standard") {
360  $ln = "http://www.ilias.de";
361  $f = $this->getButtonFactory();
362  $r = $this->getDefaultRenderer();
363  $b = $f->$factory_method("label", $ln)->withAriaLabel("aria label text");
364  $aria_label = $b->getAriaLabel();
365 
366  $html = $this->normalizeHTML($r->render($b));
367  $css_classes = self::$canonical_css_classes[$factory_method];
368  $expected = "<a class=\"$css_classes\" href=\"$ln\" aria-label=\"$aria_label\" data-action=\"$ln\">" .
369  "label" .
370  "</a>";
371  $this->assertHTMLEquals($expected, $html);
372  }
373  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_button_with_on_load_code()

ButtonTest::test_render_button_with_on_load_code (   $factory_method)

button_type_provider

Definition at line 200 of file ButtonTest.php.

References $html, $id, $r, array, ILIAS_UI_TestBase\assertHTMLEquals(), getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

201  {
202  $ln = "http://www.ilias.de";
203  $f = $this->getButtonFactory();
204  $r = $this->getDefaultRenderer();
205  $ids = array();
206  $b = $f->$factory_method("label", $ln)
207  ->withOnLoadCode(function ($id) use (&$ids) {
208  $ids[] = $id;
209  return "";
210  });
211 
212  $html = $this->normalizeHTML($r->render($b));
213 
214  $this->assertCount(1, $ids);
215 
216  $id = $ids[0];
217  $css_classes = self::$canonical_css_classes[$factory_method];
218  $expected = "<a class=\"$css_classes\" href=\"$ln\" data-action=\"$ln\" id=\"$id\">" .
219  "label" .
220  "</a>";
221  $this->assertHTMLEquals($expected, $html);
222  }
if(!array_key_exists('StateId', $_REQUEST)) $id
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
Create styles array
The data for the language used.
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_render_close_button()

ButtonTest::test_render_close_button ( )

Definition at line 182 of file ButtonTest.php.

References $html, $r, getButtonFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

183  {
184  $f = $this->getButtonFactory();
185  $r = $this->getDefaultRenderer();
186  $b = $f->close();
187 
188  $html = $this->normalizeHTML($r->render($b));
189 
190  $expected = "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">" .
191  " <span aria-hidden=\"true\">&times;</span>" .
192  " <span class=\"sr-only\">Close</span>" .
193  "</button>";
194  $this->assertEquals($expected, $html);
195  }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
getButtonFactory()
Definition: ButtonTest.php:15
$r
Definition: example_031.php:79
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

Field Documentation

◆ $canonical_css_classes

ButtonTest::$canonical_css_classes
static
Initial value:
= array( "standard" => "btn btn-default"
, "primary" => "btn btn-default btn-primary"
, "shy" => "btn btn-link"
, "tag" => "btn btn-tag btn-tag-relevance-veryhigh"
)

Definition at line 20 of file ButtonTest.php.

◆ $canonical_css_inactivation_classes

ButtonTest::$canonical_css_inactivation_classes
static
Initial value:
= array( "standard" => "ilSubmitInactive disabled"
, "primary" => "ilSubmitInactive disabled"
, "shy" => "ilSubmitInactive disabled"
, "tag" => "btn-tag-inactive"
)

Definition at line 26 of file ButtonTest.php.


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