ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LauncherInlineTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27use ILIAS\Refinery\Factory as Refinery;
28
30{
33
34 public function setUp(): void
35 {
36 $this->df = new \ILIAS\Data\Factory();
37 }
38
39 protected function getInputFactory(): I\Input\Field\Factory
40 {
41 $this->language = $this->createMock(ILIAS\Language\Language::class);
42 return new I\Input\Field\Factory(
43 $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
44 $this->createMock(I\Input\UploadLimitResolver::class),
45 new I\SignalGenerator(),
46 $this->df,
47 new Refinery($this->df, $this->language),
48 $this->language
49 );
50 }
51
52 protected function getModalFactory(): I\Modal\Factory
53 {
54 return new I\Modal\Factory(
55 new I\SignalGenerator(),
56 new I\Modal\InterruptiveItem\Factory(),
57 $this->getInputFactory()
58 );
59 }
60
61 protected function getIconFactory(): I\Symbol\Icon\Factory
62 {
63 return new I\Symbol\Icon\Factory();
64 }
65
66 public function getUIFactory(): NoUIFactory
67 {
68 $factory = new class () extends NoUIFactory {
69 public I\SignalGenerator $sig_gen;
70 public I\Input\Field\Factory $input_factory;
71
72 public function button(): I\Button\Factory
73 {
74 return new I\Button\Factory();
75 }
76 public function symbol(): I\Symbol\Factory
77 {
78 return new I\Symbol\Factory(
79 new I\Symbol\Icon\Factory(),
80 new I\Symbol\Glyph\Factory(),
81 new I\Symbol\Avatar\Factory()
82 );
83 }
84 public function modal(): I\Modal\Factory
85 {
86 return new I\Modal\Factory(
87 $this->sig_gen,
88 new I\Modal\InterruptiveItem\Factory(),
89 $this->input_factory
90 );
91 }
92 };
93 $factory->sig_gen = new I\SignalGenerator();
94 $factory->input_factory = $this->getInputFactory();
95 return $factory;
96 }
97
98 protected function getURI(): URI
99 {
100 return $this->df->uri('http://localhost/ilias.php');
101 }
102
103 protected function getLauncher(): I\Launcher\Inline
104 {
105 $target = $this->df->link('LaunchSomething', $this->getURI());
106 return new I\Launcher\Inline(
107 $this->getModalFactory(),
108 $target
109 );
110 }
111
115 protected function getMessageBox(): array
116 {
117 $html = sha1(C\MessageBox\MessageBox::class);
118 $stub = $this->createMock(C\MessageBox\MessageBox::class);
119 $stub->method('getCanonicalName')->willReturn($html);
120
121 return [$stub, $html];
122 }
123
124 public function testLauncherInlineConstruction(): void
125 {
126 $l = $this->getLauncher();
127 $this->assertInstanceOf(C\Launcher\Inline::class, $l);
128 $this->assertEquals($this->df->link('LaunchSomething', $this->getURI()), $l->getTarget());
129 $this->assertEquals('LaunchSomething', $l->getButtonLabel());
130 $this->assertTrue($l->isLaunchable());
131 $this->assertNull($l->getStatusIcon());
132 $this->assertNull($l->getStatusMessageBox());
133 $this->assertNull($l->getModal());
134 $this->assertNull($l->getModalSubmitLabel());
135 $this->assertNull($l->getModalCancelLabel());
136 }
137
138 public function testLauncherInlineBasicModifier(): void
139 {
140 [$msg] = $this->getMessageBox();
141 $icon = $this->getIconFactory()->standard('course', 'some icon');
142 $some_submit_label = 'some submit label';
143 $some_cancel_label = 'some cancel label';
144 $l = $this->getLauncher()
145 ->withDescription('some description')
146 ->withButtonLabel('different label', false)
147 ->withStatusMessageBox($msg)
148 ->withStatusIcon($icon)
149 ->withModalSubmitLabel($some_submit_label)
150 ->withModalCancelLabel($some_cancel_label)
151 ;
152
153 $this->assertEquals($this->df->link('LaunchSomething', $this->getURI()), $l->getTarget());
154 $this->assertEquals('different label', $l->getButtonLabel());
155 $this->assertfalse($l->isLaunchable());
156 $this->assertEquals($msg, $l->getStatusMessageBox());
157 $this->assertEquals($icon, $l->getStatusIcon());
158 $this->assertNull($l->getModal());
159 $this->assertEquals($l->getModalSubmitLabel(), $some_submit_label);
160 $this->assertEquals($l->getModalCancelLabel(), $some_cancel_label);
161 }
162
163 public function testLauncherInlineWithFields(): void
164 {
165 $ff = $this->getInputFactory();
166 $field = $ff->checkbox('Understood', 'ok');
167 $group = $ff->group([$field]);
168 $evaluation = fn(Result $result, Launcher & $launcher) => true;
169 [$instruction] = $this->getMessageBox();
170 $l = $this->getLauncher()
171 ->withInputs($group, $evaluation, $instruction);
172
173 $this->assertEquals($evaluation, $l->getEvaluation());
174 $this->assertInstanceOf(C\Modal\Roundtrip::class, $l->getModal());
175
176 $this->assertEquals(
177 $instruction,
178 $l->getModal()->getContent()[0]
179 );
180
181 $ns = new class () extends I\Input\FormInputNameSource {
182 public function getNewName(): string
183 {
184 return 'form/input_0';
185 }
186 };
187 $this->assertEquals(
188 [$field->withNameFrom($ns)],
189 $l->getModal()->getInputs()
190 );
191 }
192
193 public function testLauncherInlineRendering(): void
194 {
195 $ff = $this->getInputFactory();
196 $group = $ff->group([$ff->checkbox('Understood', 'ok')]);
197 $evaluation = fn(Result $result, Launcher & $launcher) => true;
198 [$msg, $msg_html] = $this->getMessageBox();
199 $icon = $this->getIconFactory()->standard('course', 'some icon');
200
201 $l = $this->getLauncher()
202 ->withDescription('some description')
203 ->withButtonLabel('different label', false)
204 ->withStatusMessageBox($msg)
205 ->withStatusIcon($icon)
206 ->withInputs($group, $evaluation, $msg)
207 ->withModalSubmitLabel('some submit label')
208 ->withModalCancelLabel('some cancel label')
209 ;
210
211 $expected = <<<EXP
212<div class="c-launcher c-launcher--inline">
213 <div class="c-launcher__status">
214 <div class="c-launcher__status__message">$msg_html
215 </div>
216 <div class="c-launcher__status__icon"><img class="icon course small" src="./assets/images/standard/icon_default.svg" alt="some icon"/></div>
217 </div>
218 <div class="c-launcher__description">
219 some description
220 </div>
221 <button class="btn btn-bulky" id="id_5" disabled="disabled"><span class="glyph" role="img"><span class="glyphicon glyphicon-launch" aria-hidden="true"></span></span><span class="bulky-label">different label</span></button>
222 <div class="c-launcher__form">
223 <dialog class="c-modal il-modal-roundtrip" tabindex="-1" id="id_1">
224 <div class="modal-dialog" role="document" data-replace-marker="component">
225 <div class="modal-content">
226 <div class="modal-header">
227 <form><button formmethod="dialog" class="close" aria-label="close"><span aria-hidden="true">&times;</span></button></form>
228 <h1 class="modal-title">different label</h1>
229 </div>
230 <div class="modal-body">$msg_html
231 <form id="id_3" class="c-form c-form--horizontal" enctype="multipart/form-data" action="http://localhost/ilias.php" method="post">
232 <fieldset class="c-input" data-il-ui-component="checkbox-field-input" data-il-ui-input-name="form/input_0">
233 <label for="id_2">Understood</label>
234 <div class="c-input__field">
235 <input type="checkbox" id="id_2" value="checked" name="form/input_0" class="c-field-checkbox" />
236 </div>
237 <div class="c-input__help-byline">ok</div>
238 </fieldset>
239 </form>
240 </div>
241 <div class="modal-footer">
242 <form>
243 <button class="btn btn-default" id="id_4">some submit label</button>
244 <button formmethod="dialog" class="btn btn-default" data-dismiss="modal">some cancel label</button>
245 </form>
246 </div>
247 </div>
248 </div>
249 </dialog>
250 </div>
251</div>
252EXP;
253 $r = $this->getDefaultRenderer(null, [$msg]);
254 $actual = $r->render($l);
255 $this->assertEquals(
256 $this->brutallyTrimSignals($this->brutallyTrimHTML($expected)),
257 $this->brutallyTrimSignals($this->brutallyTrimHTML($actual))
258 );
259 }
260}
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Provides common functionality for UI tests.
Definition: Base.php:337
ILIAS Language Language $language
ILIAS Data Factory $df
form( $class_path, string $cmd, string $submit_caption="")
modal(string $title="", string $cancel_label="")
button(string $caption, string $cmd)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.