ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 ()
 
 button_type_provider ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getDefaultRenderer ()
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Static Public Attributes

static $canonical_css_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 219 of file ButtonTest.php.

References array.

219  {
220  return array
221  ( array("standard")
222  , array("primary")
223  );
224  }
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 197 of file ButtonTest.php.

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

197  {
198  $f = $this->getButtonFactory();
199  $r = $this->getDefaultRenderer();
200  $ids = array();
201  $b = $f->close()
202  ->withOnLoadCode(function($id) use (&$ids) {
203  $ids[] = $id;
204  return "";
205  });
206 
207  $html = $this->normalizeHTML($r->render($b));
208 
209  $this->assertCount(1, $ids);
210 
211  $id = $ids[0];
212  $expected = "<button type=\"button\" class=\"close\" data-dismiss=\"modal\" id=\"$id\">".
213  " <span aria-hidden=\"true\">&times;</span>".
214  " <span class=\"sr-only\">Close</span>".
215  "</button>";
216  $this->assertEquals($expected, $html);
217  }
normalizeHTML($html)
Definition: Base.php:110
getButtonFactory()
Definition: ButtonTest.php:14
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
getDefaultRenderer()
Definition: Base.php:100
$html
Definition: example_001.php:87
+ Here is the call graph for this function:

◆ test_button_action()

ButtonTest::test_button_action (   $factory_method)

button_type_provider

Definition at line 91 of file ButtonTest.php.

References getButtonFactory().

91  {
92  $f = $this->getButtonFactory();
93  $b = $f->$factory_method("label", "http://www.ilias.de");
94 
95  $this->assertEquals("http://www.ilias.de", $b->getAction());
96  }
getButtonFactory()
Definition: ButtonTest.php:14
+ 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 101 of file ButtonTest.php.

References getButtonFactory().

101  {
102  $f = $this->getButtonFactory();
103  $b = $f->$factory_method("label", "http://www.ilias.de");
104 
105  $this->assertTrue($b->isActive());
106  }
getButtonFactory()
Definition: ButtonTest.php:14
+ Here is the call graph for this function:

◆ test_button_deactivation()

ButtonTest::test_button_deactivation (   $factory_method)

button_type_provider

Definition at line 111 of file ButtonTest.php.

References getButtonFactory().

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

◆ test_button_label()

ButtonTest::test_button_label (   $factory_method)

button_type_provider

Definition at line 68 of file ButtonTest.php.

References getButtonFactory().

68  {
69  $f = $this->getButtonFactory();
70  $b = $f->$factory_method("label", "http://www.ilias.de");
71 
72  $this->assertEquals("label", $b->getLabel());
73  }
getButtonFactory()
Definition: ButtonTest.php:14
+ 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 44 of file ButtonTest.php.

References getButtonFactory().

44  {
45  $f = $this->getButtonFactory();
46  try {
47  $f->$factory_method($this, "http://www.ilias.de");
48  $this->assertFalse("This should not happen");
49  }
50  catch (\InvalidArgumentException $e) {}
51  }
getButtonFactory()
Definition: ButtonTest.php:14
+ 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 56 of file ButtonTest.php.

References getButtonFactory().

56  {
57  $f = $this->getButtonFactory();
58  try {
59  $f->$factory_method("label", $this);
60  $this->assertFalse("This should not happen");
61  }
62  catch (\InvalidArgumentException $e) {}
63  }
getButtonFactory()
Definition: ButtonTest.php:14
+ 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 78 of file ButtonTest.php.

References getButtonFactory().

78  {
79  $f = $this->getButtonFactory();
80  $b = $f->$factory_method("label", "http://www.ilias.de");
81 
82  $b2 = $b->withLabel("label2");
83 
84  $this->assertEquals("label", $b->getLabel());
85  $this->assertEquals("label2", $b2->getLabel());
86  }
getButtonFactory()
Definition: ButtonTest.php:14
+ Here is the call graph for this function:

◆ test_implements_factory_interface()

ButtonTest::test_implements_factory_interface ( )

Definition at line 23 of file ButtonTest.php.

References getButtonFactory().

23  {
24  $f = $this->getButtonFactory();
25 
26  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Factory", $f);
27  $this->assertInstanceOf
28  ( "ILIAS\\UI\\Component\\Button\\Standard"
29  , $f->standard("label", "http://www.ilias.de")
30  );
31  $this->assertInstanceOf
32  ( "ILIAS\\UI\\Component\\Button\\Primary"
33  , $f->primary("label", "http://www.ilias.de")
34  );
35  $this->assertInstanceOf
36  ( "ILIAS\\UI\\Component\\Button\\Close"
37  , $f->close()
38  );
39  }
getButtonFactory()
Definition: ButtonTest.php:14
+ 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 141 of file ButtonTest.php.

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

141  {
142  $ln = "http://www.ilias.de";
143  $f = $this->getButtonFactory();
144  $b = $f->$factory_method("label", $ln)
145  ->withUnavailableAction();
146  $r = $this->getDefaultRenderer();
147 
148  $html = $this->normalizeHTML($r->render($b));
149 
150  $css_classes = self::$canonical_css_classes[$factory_method];
151  $expected = "<a class=\"$css_classes ilSubmitInactive\" data-action=\"$ln\">".
152  "label".
153  "</a>";
154  $this->assertEquals($expected, $html);
155  }
normalizeHTML($html)
Definition: Base.php:110
getButtonFactory()
Definition: ButtonTest.php:14
$r
Definition: example_031.php:79
getDefaultRenderer()
Definition: Base.php:100
$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 123 of file ButtonTest.php.

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

123  {
124  $ln = "http://www.ilias.de";
125  $f = $this->getButtonFactory();
126  $b = $f->$factory_method("label", $ln);
127  $r = $this->getDefaultRenderer();
128 
129  $html = $this->normalizeHTML($r->render($b));
130 
131  $css_classes = self::$canonical_css_classes[$factory_method];
132  $expected = "<a class=\"$css_classes\" href=\"$ln\" data-action=\"$ln\">".
133  "label".
134  "</a>";
135  $this->assertEquals($expected, $html);
136  }
normalizeHTML($html)
Definition: Base.php:110
getButtonFactory()
Definition: ButtonTest.php:14
$r
Definition: example_031.php:79
getDefaultRenderer()
Definition: Base.php:100
$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 174 of file ButtonTest.php.

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

174  {
175  $ln = "http://www.ilias.de";
176  $f = $this->getButtonFactory();
177  $r = $this->getDefaultRenderer();
178  $ids = array();
179  $b = $f->$factory_method("label", $ln)
180  ->withOnLoadCode(function($id) use (&$ids) {
181  $ids[] = $id;
182  return "";
183  });
184 
185  $html = $this->normalizeHTML($r->render($b));
186 
187  $this->assertCount(1, $ids);
188 
189  $id = $ids[0];
190  $css_classes = self::$canonical_css_classes[$factory_method];
191  $expected = "<a class=\"$css_classes\" href=\"$ln\" data-action=\"$ln\" id=\"$id\">".
192  "label".
193  "</a>";
194  $this->assertEquals($expected, $html);
195  }
normalizeHTML($html)
Definition: Base.php:110
getButtonFactory()
Definition: ButtonTest.php:14
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
getDefaultRenderer()
Definition: Base.php:100
$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 157 of file ButtonTest.php.

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

157  {
158  $f = $this->getButtonFactory();
159  $r = $this->getDefaultRenderer();
160  $b = $f->close();
161 
162  $html = $this->normalizeHTML($r->render($b));
163 
164  $expected = "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">".
165  " <span aria-hidden=\"true\">&times;</span>".
166  " <span class=\"sr-only\">Close</span>".
167  "</button>";
168  $this->assertEquals($expected, $html);
169  }
normalizeHTML($html)
Definition: Base.php:110
getButtonFactory()
Definition: ButtonTest.php:14
$r
Definition: example_031.php:79
getDefaultRenderer()
Definition: Base.php:100
$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:
( "standard" => "btn btn-default"
, "primary" => "btn btn-default btn-primary"
)

Definition at line 18 of file ButtonTest.php.


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