ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation as I;
10 use \ILIAS\UI\Implementation\Component\Signal;
11 
16 {
17  public function setUp() : void
18  {
19  $this->button_factory = new I\Component\Button\Factory();
20  $this->glyph = new I\Component\Symbol\Glyph\Glyph("briefcase", "briefcase");
21  $this->icon = new I\Component\Symbol\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  $this->expectException(\TypeError::class);
35 
36  $f = $this->button_factory;
37  $f->bulky(new StdClass(), "", "http://www.ilias.de");
38  }
39 
40  public function test_glyph_or_icon_for_glyph()
41  {
42  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
43  $this->assertEquals(
44  $this->glyph,
45  $b->getIconOrGlyph()
46  );
47  }
48 
49  public function test_glyph_or_icon_for_icon()
50  {
51  $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
52  $this->assertEquals(
53  $this->icon,
54  $b->getIconOrGlyph()
55  );
56  }
57 
58  public function test_engaged()
59  {
60  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
61  $this->assertFalse($b->isEngaged());
62  $this->assertFalse($b->isEngageable());
63 
64  $b = $b->withEngagedState(true);
65  $this->assertInstanceOf(
66  "ILIAS\\UI\\Component\\Button\\Bulky",
67  $b
68  );
69  $this->assertTrue($b->isEngaged());
70  $this->assertTrue($b->isEngageable());
71  }
72 
73  public function test_engageable_disengaged()
74  {
75  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
76  $this->assertFalse($b->isEngaged());
77  $this->assertFalse($b->isEngageable());
78 
79  $b = $b->withEngagedState(false);
80  $this->assertInstanceOf(
81  "ILIAS\\UI\\Component\\Button\\Bulky",
82  $b
83  );
84  $this->assertFalse($b->isEngaged());
85  $this->assertTrue($b->isEngageable());
86  }
87 
88  public function test_with_aria_role()
89  {
90  try {
91  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
92  ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
93  $this->assertEquals("menuitem", $b->getAriaRole());
94  } catch (\InvalidArgumentException $e) {
95  $this->assertFalse("This should not happen");
96  }
97  }
98 
100  {
101  try {
102  $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
103  ->withAriaRole("loremipsum");
104  $this->assertFalse("This should not happen");
105  } catch (\InvalidArgumentException $e) {
106  $this->assertTrue(true);
107  }
108  }
109 
111  {
112  $r = $this->getDefaultRenderer();
113  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
114 
115  $this->assertHTMLEquals(
116  $this->getHtmlWithGlyph(),
117  $r->render($b)
118  );
119  }
120 
122  {
123  $r = $this->getDefaultRenderer();
124  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
125  ->withEngagedState(true);
126 
127  $this->assertHTMLEquals(
128  $this->getHtmlWithGlyph(true, true),
129  $r->render($b)
130  );
131  }
132 
134  {
135  $r = $this->getDefaultRenderer();
136  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
137  ->withEngagedState(true);
138  $this->assertHTMLEquals(
139  $this->getHtmlWithGlyph(true),
140  $r->render($b)
141  );
142  }
143 
144  protected function getHtmlWithGlyph(bool $engeagable = false, bool $engeaged = false)
145  {
146  $aria_pressed = "";
147  $engaged_class = "";
148  if ($engeagable) {
149  if ($engeagable) {
150  $aria_pressed = " aria-pressed='true'";
151  $engaged_class = " engaged";
152  } else {
153  $aria_pressed = " aria-pressed='false'";
154  $engaged_class = " disengaged";
155  }
156  }
157  return ''
158  . '<button class="btn btn-bulky' . $engaged_class . '" data-action="http://www.ilias.de" id="id_1" ' . $aria_pressed . '>'
159  . ' <span class="glyph" aria-label="briefcase" role="img">'
160  . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
161  . ' </span>'
162  . ' <span class="bulky-label">label</span>'
163  . '</button>';
164  }
165 
166  public function test_render_with_icon()
167  {
168  $r = $this->getDefaultRenderer();
169  $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
170 
171  $expected = ''
172  . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1">'
173  . ' <img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt="Example"/>'
174  . ' <span class="bulky-label">label</span>'
175  . '</button>';
176 
177  $this->assertHTMLEquals(
178  $expected,
179  $r->render($b)
180  );
181  }
182 
184  {
185  $r = $this->getDefaultRenderer();
186  $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de")
187  ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
188 
189  $expected = ''
190  . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem">'
191  . ' <img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt="Example"/>'
192  . ' <span class="bulky-label">label</span>'
193  . '</button>';
194 
195  $this->assertHTMLEquals(
196  $expected,
197  $r->render($b)
198  );
199  }
200 
202  {
203  $r = $this->getDefaultRenderer();
204  $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de")
205  ->withEngagedState(false)
206  ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
207 
208  $expected = ''
209  . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem" aria-haspopup="true">'
210  . ' <img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt="Example"/>'
211  . ' <span class="bulky-label">label</span>'
212  . '</button>';
213 
214  $this->assertHTMLEquals(
215  $expected,
216  $r->render($b)
217  );
218  }
219 }
test_render_button_with_aria_role_menuitem_not_engageable()
test_render_button_with_aria_role_menuitem_is_engageable()
Test on button implementation.
test_render_with_glyph_in_context_and_disengaged()
test_render_with_glyph_in_context_and_engaged()
Provides common functionality for UI tests.
Definition: Base.php:262
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getHtmlWithGlyph(bool $engeagable=false, bool $engeaged=false)
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311