ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ToggleButtonTest Class Reference

Test Toggle Button. More...

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

Public Member Functions

 getFactory ()
 
 testImplementsFactoryInterface ()
 
 testConstructionActionOnTypeWrong ()
 
 testConstructionActionOffTypeWrong ()
 
 testSetOnOnDefault ()
 
 testAppendOnAction ()
 
 testAppendOffAction ()
 
 testRenderWithLabel ()
 
 testAppendUnavailAction (Toggle $button)
 

Detailed Description

Test Toggle Button.

Definition at line 31 of file ToggleButtonTest.php.

Member Function Documentation

◆ getFactory()

ToggleButtonTest::getFactory ( )

◆ testAppendOffAction()

ToggleButtonTest::testAppendOffAction ( )

Definition at line 91 of file ToggleButtonTest.php.

91 : void
92 {
93 $f = $this->getFactory();
94 $signal_off1 = $this->createMock(Signal::class);
95 $signal_off2 = $this->createMock(Signal::class);
96 $button = $f->toggle("label", "action_on", $signal_off1);
97 $this->assertEquals([$signal_off1], $button->getActionOff());
98
99 $button = $button->withAdditionalToggleOffSignal($signal_off2);
100 $this->assertEquals([$signal_off1, $signal_off2], $button->getActionOff());
101 }

References Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

◆ testAppendOnAction()

ToggleButtonTest::testAppendOnAction ( )

Definition at line 78 of file ToggleButtonTest.php.

78 : void
79 {
80 $f = $this->getFactory();
81 $signal_on1 = $this->createMock(Signal::class);
82 $signal_on2 = $this->createMock(Signal::class);
83 $signal_off = $this->createMock(Signal::class);
84 $button = $f->toggle("label", $signal_on1, $signal_off);
85 $this->assertEquals([$signal_on1], $button->getActionOn());
86
87 $button = $button->withAdditionalToggleOnSignal($signal_on2);
88 $this->assertEquals([$signal_on1, $signal_on2], $button->getActionOn());
89 }

References Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

◆ testAppendUnavailAction()

ToggleButtonTest::testAppendUnavailAction ( Toggle  $button)

Definition at line 166 of file ToggleButtonTest.php.

166 : void
167 {
168 $r = $this->getDefaultRenderer();
169 $button = $button->withUnavailableAction();
170
171 $html = $r->render($button);
172
173 $expected = ''
174 . '<div class="il-toggle-item">'
175 . ' <button class="il-toggle-button unavailable" aria-pressed="false" disabled="disabled">'
176 . ' <span class="il-toggle-switch"></span>'
177 . ' </button>'
178 . '</div>';
179
180 $this->assertHTMLEquals(
181 $expected,
182 $html
183 );
184 }
withUnavailableAction(bool $flag=true)
Get a button like this, but action should be unavailable atm.

References ILIAS\UI\Component\Button\Button\withUnavailableAction().

+ Here is the call graph for this function:

◆ testConstructionActionOffTypeWrong()

ToggleButtonTest::testConstructionActionOffTypeWrong ( )

Definition at line 59 of file ToggleButtonTest.php.

59 : void
60 {
61 $f = $this->getFactory();
62 try {
63 $f->toggle("label", "action_on_string", 2);
64 $this->assertFalse("This should not happen");
65 } catch (\InvalidArgumentException $e) {
66 $this->assertTrue(true);
67 }
68 }

References Vendor\Package\$e, Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

◆ testConstructionActionOnTypeWrong()

ToggleButtonTest::testConstructionActionOnTypeWrong ( )

Definition at line 48 of file ToggleButtonTest.php.

48 : void
49 {
50 $f = $this->getFactory();
51 try {
52 $f->toggle("label", 1, "action_off_string");
53 $this->assertFalse("This should not happen");
54 } catch (\InvalidArgumentException $e) {
55 $this->assertTrue(true);
56 }
57 }

References Vendor\Package\$e, Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

ToggleButtonTest::testImplementsFactoryInterface ( )

Definition at line 38 of file ToggleButtonTest.php.

38 : void
39 {
40 $f = $this->getFactory();
41
42 $this->assertInstanceOf(
43 "ILIAS\\UI\\Component\\Button\\Toggle",
44 $f->toggle("label", "action_on_string", "action_off_string")
45 );
46 }

References Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

◆ testRenderWithLabel()

ToggleButtonTest::testRenderWithLabel ( )

Definition at line 103 of file ToggleButtonTest.php.

103 : void
104 {
105 $r = $this->getDefaultRenderer();
106 $button = $this->getFactory()->toggle("label", "action_on_string", "action_off_string");
107
108 $expected = <<<EOT
109 <div class="il-toggle-item">
110 <label>label</label>
111 <button class="il-toggle-button off" id="id_1" aria-pressed="false">
112 <span class="il-toggle-label-on">toggle_on</span>
113 <span class="il-toggle-label-off">toggle_off</span>
114 <span class="il-toggle-switch"></span>
115 </button>
116 </div>
117 EOT;
118
119 $this->assertHTMLEquals("<div>" . $expected . "</div>", "<div>" . $r->render($button) . "</div>");
120 }
121
122 public function testRenderSetOnOnDefault(): Toggle
123 {
124 $r = $this->getDefaultRenderer();
125 $button = $this->getFactory()->toggle("", "action_on_string", "action_off_string", true);
126
127 $expected = ''
128 . '<div class="il-toggle-item">'
129 . ' <button class="il-toggle-button on" id="id_1" aria-pressed="false">' //aria-pressed is set to "true" by JS
130 . ' <span class="il-toggle-label-on">toggle_on</span>'
131 . ' <span class="il-toggle-label-off">toggle_off</span>'
132 . ' <span class="il-toggle-switch"></span>'
133 . ' </button>'
134 . '</div>';
135
136 $this->assertHTMLEquals($expected, $r->render($button));
137 return $button;
138 }
139
140 public function testRenderWithSignals(): void
141 {
142 $r = $this->getDefaultRenderer();
143 $signal_on = $this->createMock(Signal::class);
144 $signal_on->method("__toString")
145 ->willReturn("MOCK_SIGNAL");
146 $signal_off = $this->createMock(Signal::class);
147 $signal_off->method("__toString")
148 ->willReturn("MOCK_SIGNAL");
149 $button = $this->getFactory()->toggle("label", $signal_on, $signal_off);
150
151 $expected = <<<EOT
152 <div class="il-toggle-item">
153 <label>label</label>
154 <button class="il-toggle-button off" id="id_1" aria-pressed="false">
155 <span class="il-toggle-label-on">toggle_on</span>
156 <span class="il-toggle-label-off">toggle_off</span>
157 <span class="il-toggle-switch"></span>
158 </button>
159 </div>
160EOT;
161
162 $this->assertHTMLEquals("<div>" . $expected . "</div>", "<div>" . $r->render($button) . "</div>");
163 }
This describes a toggle button.
Definition: Toggle.php:29
button(string $caption, string $cmd)

References ILIAS\Repository\button(), and getFactory().

+ Here is the call graph for this function:

◆ testSetOnOnDefault()

ToggleButtonTest::testSetOnOnDefault ( )

Definition at line 70 of file ToggleButtonTest.php.

70 : void
71 {
72 $f = $this->getFactory();
73 $button = $f->toggle("label", "action_on_string", "action_off_string", true);
74
75 $this->assertTrue($button->isEngaged());
76 }

References Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

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