ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BulkyButtonTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation as I;
10use \ILIAS\UI\Implementation\Component\Signal;
11
16{
17 public function setUp()
18 {
19 $this->button_factory = new I\Component\Button\Factory();
20 $this->glyph = new I\Component\Glyph\Glyph("briefcase", "briefcase");
21 $this->icon = new I\Component\Icon\Standard("someExample", "Example", "small", false);
22 }
23
25 {
26 $this->assertInstanceOf(
27 "ILIAS\\UI\\Component\\Button\\Bulky",
28 $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
29 );
30 }
31
33 {
34 $f = $this->button_factory;
35 try {
36 $f->bulky(new StdClass(), "", "http://www.ilias.de");
37 $this->assertFalse("This should not happen");
38 } catch (\InvalidArgumentException $e) {
39 $this->assertTrue(true);
40 }
41 }
42
44 {
45 $f = $this->button_factory;
46 $icon = $this->createMock(ILIAS\UI\Component\Icon\Icon::class);
47 try {
48 $f->bulky($icon, 1, "http://www.ilias.de");
49 $this->assertFalse("This should not happen");
50 } catch (\InvalidArgumentException $e) {
51 $this->assertTrue(true);
52 }
53 }
54
56 {
57 $f = $this->button_factory;
58 $icon = $this->createMock(ILIAS\UI\Component\Icon\Icon::class);
59 try {
60 $f->bulky($icon, "", 1);
61 $this->assertFalse("This should not happen");
62 } catch (\InvalidArgumentException $e) {
63 $this->assertTrue(true);
64 }
65 }
66
68 {
69 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
70 $this->assertEquals(
71 $this->glyph,
72 $b->getIconOrGlyph()
73 );
74 }
75
77 {
78 $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
79 $this->assertEquals(
80 $this->icon,
81 $b->getIconOrGlyph()
82 );
83 }
84
85 public function test_engaged()
86 {
87 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
88 $this->assertFalse($b->isEngaged());
89
90 $b = $b->withEngagedState(true);
91 $this->assertInstanceOf(
92 "ILIAS\\UI\\Component\\Button\\Bulky",
93 $b
94 );
95 $this->assertTrue($b->isEngaged());
96 }
97
99 {
100 $r = $this->getDefaultRenderer();
101 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
102
103 $expected = ''
104 . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" aria-pressed="undefined">'
105 . ' <span class="glyph" aria-label="briefcase">'
106 . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
107 . ' </span>'
108 . ' <div><span class="bulky-label">label</span></div>'
109 . '</button>';
110
111 $this->assertHTMLEquals(
112 $expected,
113 $r->render($b)
114 );
115 }
116
118 {
119 $r = $this->getDefaultRenderer();
120 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
121 ->withEngagedState(true);
122 $expected = ''
123 . '<button class="btn btn-bulky engaged" data-action="http://www.ilias.de" id="id_1" aria-pressed="true">'
124 . ' <span class="glyph" aria-label="briefcase">'
125 . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
126 . ' </span>'
127 . ' <div><span class="bulky-label">label</span></div>'
128 . '</button>';
129
130 $this->assertHTMLEquals(
131 $expected,
132 $r->render($b)
133 );
134 }
135
136 public function test_render_with_icon()
137 {
138 $r = $this->getDefaultRenderer();
139 $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
140
141 $expected = ''
142 . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" aria-pressed="undefined">'
143 . ' <div class="icon someExample small" aria-label="Example"></div>'
144 . ' <div><span class="bulky-label">label</span></div>'
145 . '</button>';
146
147 $this->assertHTMLEquals(
148 $expected,
149 $r->render($b)
150 );
151 }
152}
Test on button implementation.
test_construction_label_type_wrong()
test_construction_action_type_wrong()
test_render_with_glyph_in_context_and_engaged()
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:192
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
$r
Definition: example_031.php:79
Class BaseForm.
Class Factory.