ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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)
 testRenderSetOnOnDefault More...
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getHelpTextRetriever ()
 
 getUploadLimitResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Additional Inherited Members

- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Detailed Description

Test Toggle Button.

Definition at line 31 of file ToggleButtonTest.php.

Member Function Documentation

◆ getFactory()

◆ testAppendOffAction()

ToggleButtonTest::testAppendOffAction ( )

Definition at line 91 of file ToggleButtonTest.php.

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

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  }
+ Here is the call graph for this function:

◆ testAppendOnAction()

ToggleButtonTest::testAppendOnAction ( )

Definition at line 78 of file ToggleButtonTest.php.

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

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  }
+ Here is the call graph for this function:

◆ testAppendUnavailAction()

ToggleButtonTest::testAppendUnavailAction ( Toggle  $button)

testRenderSetOnOnDefault

Definition at line 168 of file ToggleButtonTest.php.

References $r, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS\UI\Component\Button\Button\withUnavailableAction().

168  : void
169  {
170  $r = $this->getDefaultRenderer();
171  $button = $button->withUnavailableAction();
172 
173  $html = $r->render($button);
174 
175  $expected = ''
176  . '<div class="il-toggle-item">'
177  . ' <button class="il-toggle-button unavailable" aria-pressed="false" disabled="disabled">'
178  . ' <span class="il-toggle-switch"></span>'
179  . ' </button>'
180  . '</div>';
181 
182  $this->assertHTMLEquals(
183  $expected,
184  $html
185  );
186  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:377
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:458
withUnavailableAction(bool $flag=true)
Get a button like this, but action should be unavailable atm.
$r
+ Here is the call graph for this function:

◆ testConstructionActionOffTypeWrong()

ToggleButtonTest::testConstructionActionOffTypeWrong ( )

Definition at line 59 of file ToggleButtonTest.php.

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

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  }
+ Here is the call graph for this function:

◆ testConstructionActionOnTypeWrong()

ToggleButtonTest::testConstructionActionOnTypeWrong ( )

Definition at line 48 of file ToggleButtonTest.php.

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

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  }
+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

ToggleButtonTest::testImplementsFactoryInterface ( )

Definition at line 38 of file ToggleButtonTest.php.

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

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  }
+ Here is the call graph for this function:

◆ testRenderWithLabel()

ToggleButtonTest::testRenderWithLabel ( )

Definition at line 103 of file ToggleButtonTest.php.

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

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>
160 EOT;
161 
162  $this->assertHTMLEquals("<div>" . $expected . "</div>", "<div>" . $r->render($button) . "</div>");
163  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:377
button(string $caption, string $cmd)
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:458
This describes a toggle button.
Definition: Toggle.php:28
$r
+ Here is the call graph for this function:

◆ testSetOnOnDefault()

ToggleButtonTest::testSetOnOnDefault ( )

Definition at line 70 of file ToggleButtonTest.php.

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

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  }
+ Here is the call graph for this function:

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