ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
63  $b = $b->withEngagedState(true);
64  $this->assertInstanceOf(
65  "ILIAS\\UI\\Component\\Button\\Bulky",
66  $b
67  );
68  $this->assertTrue($b->isEngaged());
69  }
70 
71  public function test_with_aria_role()
72  {
73  try {
74  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
75  ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
76  $this->assertEquals("menuitem", $b->getAriaRole());
77  } catch (\InvalidArgumentException $e) {
78  $this->assertFalse("This should not happen");
79  }
80  }
81 
83  {
84  try {
85  $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
86  ->withAriaRole("loremipsum");
87  $this->assertFalse("This should not happen");
88  } catch (\InvalidArgumentException $e) {
89  $this->assertTrue(true);
90  }
91  }
92 
94  {
95  $r = $this->getDefaultRenderer();
96  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
97 
98  $expected = ''
99  . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1">'
100  . ' <span class="glyph" aria-label="briefcase">'
101  . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
102  . ' </span>'
103  . ' <span class="bulky-label">label</span>'
104  . '</button>';
105 
106  $this->assertHTMLEquals(
107  $expected,
108  $r->render($b)
109  );
110  }
111 
113  {
114  $r = $this->getDefaultRenderer();
115  $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
116  ->withEngagedState(true);
117  $expected = ''
118  . '<button class="btn btn-bulky engaged" data-action="http://www.ilias.de" id="id_1" aria-pressed="true">'
119  . ' <span class="glyph" aria-label="briefcase">'
120  . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
121  . ' </span>'
122  . ' <span class="bulky-label">label</span>'
123  . '</button>';
124 
125  $this->assertHTMLEquals(
126  $expected,
127  $r->render($b)
128  );
129  }
130 
131  public function test_render_with_icon()
132  {
133  $r = $this->getDefaultRenderer();
134  $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
135 
136  $expected = ''
137  . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1">'
138  . ' <div class="icon someExample small" aria-label="Example"></div>'
139  . ' <span class="bulky-label">label</span>'
140  . '</button>';
141 
142  $this->assertHTMLEquals(
143  $expected,
144  $r->render($b)
145  );
146  }
147 
149  {
150  $r = $this->getDefaultRenderer();
151  $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de")
152  ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
153 
154  $expected = ''
155  . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem" aria-haspopup="true">'
156  . ' <div class="icon someExample small" aria-label="Example"></div>'
157  . ' <span class="bulky-label">label</span>'
158  . '</button>';
159 
160  $this->assertHTMLEquals(
161  $expected,
162  $r->render($b)
163  );
164  }
165 }
Test on button implementation.
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
test_render_with_glyph_in_context_and_engaged()
Provides common functionality for UI tests.
Definition: Base.php:224
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326