ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ToggleButtonTest Class Reference

Test Toggle Button. More...

+ Inheritance diagram for ToggleButtonTest:
+ Collaboration diagram for ToggleButtonTest:

Public Member Functions

 getFactory ()
 
 test_implements_factory_interface ()
 
 test_construction_action_on_type_wrong ()
 
 test_construction_action_off_type_wrong ()
 
 test_setOn_on_default ()
 
 test_append_OnAction ()
 
 test_append_OffAction ()
 
 test_render_with_label ()
 
 test_render_setOn_on_default ()
 
 test_render_with_signals ()
 
- 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)
 

Detailed Description

Test Toggle Button.

Definition at line 14 of file ToggleButtonTest.php.

Member Function Documentation

◆ getFactory()

ToggleButtonTest::getFactory ( )

◆ test_append_OffAction()

ToggleButtonTest::test_append_OffAction ( )

Definition at line 74 of file ToggleButtonTest.php.

75 {
76 $f = $this->getFactory();
77 $signal_off1 = $this->createMock(Signal::class);
78 $signal_off2 = $this->createMock(Signal::class);
79 //$signal_on = $this->createMock(Signal::class);
80 $button = $f->toggle("label", "action_on", $signal_off1);
81 $this->assertEquals([$signal_off1], $button->getActionOff());
82
83 $button = $button->withAdditionalToggleOffSignal($signal_off2);
84 $this->assertEquals([$signal_off1, $signal_off2], $button->getActionOff());
85 }

References $f, and getFactory().

+ Here is the call graph for this function:

◆ test_append_OnAction()

ToggleButtonTest::test_append_OnAction ( )

Definition at line 61 of file ToggleButtonTest.php.

62 {
63 $f = $this->getFactory();
64 $signal_on1 = $this->createMock(Signal::class);
65 $signal_on2 = $this->createMock(Signal::class);
66 $signal_off = $this->createMock(Signal::class);
67 $button = $f->toggle("label", $signal_on1, $signal_off);
68 $this->assertEquals([$signal_on1], $button->getActionOn());
69
70 $button = $button->withAdditionalToggleOnSignal($signal_on2);
71 $this->assertEquals([$signal_on1, $signal_on2], $button->getActionOn());
72 }

References $f, and getFactory().

+ Here is the call graph for this function:

◆ test_construction_action_off_type_wrong()

ToggleButtonTest::test_construction_action_off_type_wrong ( )

Definition at line 42 of file ToggleButtonTest.php.

43 {
44 $f = $this->getFactory();
45 try {
46 $f->toggle("label", "action_on_string", 2);
47 $this->assertFalse("This should not happen");
48 } catch (\InvalidArgumentException $e) {
49 $this->assertTrue(true);
50 }
51 }

References $f, and getFactory().

+ Here is the call graph for this function:

◆ test_construction_action_on_type_wrong()

ToggleButtonTest::test_construction_action_on_type_wrong ( )

Definition at line 31 of file ToggleButtonTest.php.

32 {
33 $f = $this->getFactory();
34 try {
35 $f->toggle("label", 1, "action_off_string");
36 $this->assertFalse("This should not happen");
37 } catch (\InvalidArgumentException $e) {
38 $this->assertTrue(true);
39 }
40 }

References $f, and getFactory().

+ Here is the call graph for this function:

◆ test_implements_factory_interface()

ToggleButtonTest::test_implements_factory_interface ( )

Definition at line 21 of file ToggleButtonTest.php.

22 {
23 $f = $this->getFactory();
24
25 $this->assertInstanceOf(
26 "ILIAS\\UI\\Component\\Button\\Toggle",
27 $f->toggle("label", "action_on_string", "action_off_string")
28 );
29 }

References $f, and getFactory().

+ Here is the call graph for this function:

◆ test_render_setOn_on_default()

ToggleButtonTest::test_render_setOn_on_default ( )

Definition at line 102 of file ToggleButtonTest.php.

103 {
104 $r = $this->getDefaultRenderer();
105 $button = $this->getFactory()->toggle("", "action_on_string", "action_off_string", true);
106
107 $expected = ''
108 . '<button class="il-toggle-button on" id="id_1" aria-pressed="false">' //aria-pressed is set to "true" by JS
109 . ' <div class="il-toggle-switch"></div>'
110 . '</button>';
111
112 $this->assertHTMLEquals($expected, $r->render($button));
113 }
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

References $r, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\getDefaultRenderer(), and getFactory().

+ Here is the call graph for this function:

◆ test_render_with_label()

ToggleButtonTest::test_render_with_label ( )

Definition at line 87 of file ToggleButtonTest.php.

88 {
89 $r = $this->getDefaultRenderer();
90 $button = $this->getFactory()->toggle("label", "action_on_string", "action_off_string");
91
92 $expected = <<<EOT
93 <label>label</label>
94<button class="il-toggle-button" id="id_1" aria-pressed="false">
95 <div class="il-toggle-switch"></div>
96</button>
97EOT;
98
99 $this->assertHTMLEquals("<div>" . $expected . "</div>", "<div>" . $r->render($button) . "</div>");
100 }

References $r, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\getDefaultRenderer(), and getFactory().

+ Here is the call graph for this function:

◆ test_render_with_signals()

ToggleButtonTest::test_render_with_signals ( )

Definition at line 115 of file ToggleButtonTest.php.

116 {
117 $r = $this->getDefaultRenderer();
118 $signal_on = $this->createMock(Signal::class);
119 $signal_on->method("__toString")
120 ->willReturn("MOCK_SIGNAL");
121 $signal_off = $this->createMock(Signal::class);
122 $signal_off->method("__toString")
123 ->willReturn("MOCK_SIGNAL");
124 $button = $this->getFactory()->toggle("label", $signal_on, $signal_off);
125
126 $expected = <<<EOT
127 <label>label</label>
128<button class="il-toggle-button" id="id_1" aria-pressed="false">
129 <div class="il-toggle-switch"></div>
130</button>
131EOT;
132
133 $this->assertHTMLEquals("<div>" . $expected . "</div>", "<div>" . $r->render($button) . "</div>");
134 }

References $r, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\getDefaultRenderer(), and getFactory().

+ Here is the call graph for this function:

◆ test_setOn_on_default()

ToggleButtonTest::test_setOn_on_default ( )

Definition at line 53 of file ToggleButtonTest.php.

54 {
55 $f = $this->getFactory();
56 $button = $f->toggle("label", "action_on_string", "action_off_string", true);
57
58 $this->assertTrue($button->isOn());
59 }

References $f, and getFactory().

+ Here is the call graph for this function:

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