ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
StandardFormTest Class Reference

Test on standard form implementation. More...

+ Inheritance diagram for StandardFormTest:
+ Collaboration diagram for StandardFormTest:

Public Member Functions

 getUIFactory ()
 
 testGetPostURL ()
 
 testRender ()
 
 testSubmitCaption ()
 
 testSubmitCaptionRender ()
 
 testRenderNoUrl ()
 
 testRenderWithErrorOnField ()
 
 testRenderWithErrorOnForm ()
 
 testStandardFormRenderWithRequired ()
 

Protected Member Functions

 buildFactory ()
 
 buildButtonFactory ()
 
 getTextFieldHtml ()
 

Detailed Description

Test on standard form implementation.

Definition at line 73 of file StandardFormTest.php.

Member Function Documentation

◆ buildButtonFactory()

StandardFormTest::buildButtonFactory ( )
protected

Definition at line 86 of file StandardFormTest.php.

86 : I\Button\Factory
87 {
88 return new I\Button\Factory();
89 }

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ buildFactory()

StandardFormTest::buildFactory ( )
protected

Definition at line 77 of file StandardFormTest.php.

77 : I\Input\Container\Form\Factory
78 {
79
80 return new I\Input\Container\Form\Factory(
81 $this->getFieldFactory(),
82 new SignalGenerator()
83 );
84 }

Referenced by testGetPostURL(), testRender(), testRenderNoUrl(), testStandardFormRenderWithRequired(), testSubmitCaption(), and testSubmitCaptionRender().

+ Here is the caller graph for this function:

◆ getTextFieldHtml()

StandardFormTest::getTextFieldHtml ( )
protected

Definition at line 105 of file StandardFormTest.php.

105 : string
106 {
107 return $this->getFormWrappedHtml(
108 'text-field-input',
109 'label',
110 '<input id="id_1" type="text" name="form/input_0" class="c-field-text" />',
111 'byline',
112 'id_1',
113 null,
114 'form/input_0'
115 );
116 }

Referenced by testRender(), testRenderNoUrl(), and testSubmitCaptionRender().

+ Here is the caller graph for this function:

◆ getUIFactory()

StandardFormTest::getUIFactory ( )

Definition at line 91 of file StandardFormTest.php.

References buildButtonFactory().

+ Here is the call graph for this function:

◆ testGetPostURL()

StandardFormTest::testGetPostURL ( )

Definition at line 96 of file StandardFormTest.php.

96 : void
97 {
98 $f = $this->buildFactory();
99 $if = $this->getFieldFactory();
100 $url = "MY_URL";
101 $form = $f->standard($url, [$if->text("label")]);
102 $this->assertEquals($url, $form->getPostURL());
103 }
$url
Definition: shib_logout.php:70

References Vendor\Package\$f, $url, and buildFactory().

+ Here is the call graph for this function:

◆ testRender()

StandardFormTest::testRender ( )

Definition at line 118 of file StandardFormTest.php.

118 : void
119 {
120 $f = $this->buildFactory();
121 $if = $this->getFieldFactory();
122
123 $url = "MY_URL";
124 $form = $f->standard($url, [
125 $if->text("label", "byline"),
126 ]);
127
128 $r = $this->getDefaultRenderer();
129 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($form));
130
131 $expected = $this->brutallyTrimHTML('
132 <form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
133 <div class="c-form__header">
134 </div>'
135 . $this->getTextFieldHtml() .
136 '<div class="c-form__footer">
137 <div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
138 </div>
139 </form>
140 ');
141 $this->assertHTMLEquals($expected, $html);
142 }

References Vendor\Package\$f, $url, buildFactory(), and getTextFieldHtml().

+ Here is the call graph for this function:

◆ testRenderNoUrl()

StandardFormTest::testRenderNoUrl ( )

Definition at line 188 of file StandardFormTest.php.

188 : void
189 {
190 $f = $this->buildFactory();
191 $if = $this->getFieldFactory();
192
193 $url = "";
194 $form = $f->standard($url, [
195 $if->text("label", "byline"),
196 ]);
197
198 $r = $this->getDefaultRenderer();
199 $html = $this->brutallyTrimHTML($r->render($form));
200
201 $expected = $this->brutallyTrimHTML('
202 <form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
203 <div class="c-form__header">
204 </div>'
205 . $this->getTextFieldHtml() .
206 '<div class="c-form__footer">
207 <div class="c-form__actions">
208 <button class="btn btn-default" data-action="">save</button>
209 </div>
210 </div>
211 </form>
212 ');
213 $this->assertHTMLEquals($expected, $html);
214 }

References Vendor\Package\$f, $url, buildFactory(), and getTextFieldHtml().

+ Here is the call graph for this function:

◆ testRenderWithErrorOnField()

StandardFormTest::testRenderWithErrorOnField ( )

Definition at line 217 of file StandardFormTest.php.

217 : void
218 {
219 $r = $this->getDefaultRenderer();
220 $df = new Data\Factory();
221 $language = $this->createMock(\ILIAS\Language\Language::class);
222 $language
223 ->expects($this->once())
224 ->method("txt")
225 ->willReturn('testing error message');
226
227 $refinery = new \ILIAS\Refinery\Factory($df, $language);
228
230 $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
231 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
232 new SignalGenerator(),
233 $df,
234 $refinery,
235 $language
236 );
237
238 $fail = $refinery->custom()->constraint(function ($v) {
239 return false;
240 }, "This is invalid...");
241 $input = $if->text("label", "byline");
242
243 $input = $input->withAdditionalTransformation($fail);
244
245 $form = new Form\Standard(new SignalGenerator(), $if, new InputNameSource(), '', [$input]);
246
247 $request = $this->createMock(ServerRequestInterface::class);
248 $request
249 ->expects($this->once())
250 ->method("getParsedBody")
251 ->willReturn([
252 'form_0/input_1' => ''
253 ]);
254
255 $form = $form->withRequest($request);
256 $this->assertNull($form->getData());
257
258 $html = $this->brutallyTrimHTML($r->render($form));
259 $expected = $this->brutallyTrimHTML('
260<form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
261 <div class="c-form__header">
262 </div>
263 <div class="c-form__error-msg alert alert-danger"><span class="sr-only">ui_error:</span>testing error
264 message
265 </div>
266 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="form_0/input_1"
267 aria-describedby="id_2"><label for="id_1">label</label>
268 <div class="c-input__field"><input id="id_1" type="text" name="form_0/input_1" class="c-field-text" /></div>
269 <div class="c-input__error-msg alert alert-danger" id="id_2"><span class="sr-only">ui_error:</span>This is
270 invalid...
271 </div>
272 <div class="c-input__help-byline">byline</div>
273 </fieldset>
274 <div class="c-form__footer">
275 <div class="c-form__actions">
276 <button class="btn btn-default" data-action="">save</button>
277 </div>
278 </div>
279</form>
280');
281 $this->assertEquals($expected, $html);
282 $this->assertHTMLEquals($expected, $html);
283 }
Factory for Date Formats.
Definition: Factory.php:27
This describes commonalities between all inputs.
Definition: Input.php:47
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References ILIAS\UI\examples\Layout\Page\Mail\$refinery.

◆ testRenderWithErrorOnForm()

StandardFormTest::testRenderWithErrorOnForm ( )

Definition at line 286 of file StandardFormTest.php.

286 : void
287 {
288 $r = $this->getDefaultRenderer();
289 $df = new Data\Factory();
290 $language = $this->createMock(\ILIAS\Language\Language::class);
291 $refinery = new \ILIAS\Refinery\Factory($df, $language);
292
294 $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
295 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
296 new SignalGenerator(),
297 $df,
298 $refinery,
299 $language
300 );
301
302 $fail = $refinery->custom()->constraint(function ($v) {
303 return false;
304 }, "This is a fail on form.");
305 $input = $if->text("label", "byline");
306
307 $form = new Form\Standard(new SignalGenerator(), $if, new InputNameSource(), '', [$input]);
308 $form = $form->withAdditionalTransformation($fail);
309
310 $request = $this->createMock(ServerRequestInterface::class);
311 $request
312 ->expects($this->once())
313 ->method("getParsedBody")
314 ->willReturn([
315 'form_0/input_1' => ''
316 ]);
317
318 $form = $form->withRequest($request);
319 $this->assertNull($form->getData());
320
321
322 $field_html = $this->getFormWrappedHtml(
323 'text-field-input',
324 'label',
325 '<input id="id_1" type="text" name="form_0/input_1" class="c-field-text"/>',
326 'byline',
327 'id_1',
328 null,
329 'form_0/input_1'
330 );
331
332 $html = $this->brutallyTrimHTML($r->render($form));
333 $expected = $this->brutallyTrimHTML('
334 <form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
335 <div class="c-form__header">
336 </div>
337 <div class="c-form__error-msg alert alert-danger"><span class="sr-only">ui_error:</span>This is a fail on form.</div>
338 ' . $field_html . '
339 <div class="c-form__footer">
340 <div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
341 </div>
342 </form>
343 ');
344 $this->assertHTMLEquals($expected, $html);
345 }

References ILIAS\UI\examples\Layout\Page\Mail\$refinery.

◆ testStandardFormRenderWithRequired()

StandardFormTest::testStandardFormRenderWithRequired ( )

Definition at line 347 of file StandardFormTest.php.

347 : void
348 {
349 $f = $this->buildFactory();
350 $if = $this->getFieldFactory();
351
352 $url = "MY_URL";
353 $form = $f->standard($url, [$if->text("label", "byline")->withRequired(true)]);
354
355 $r = $this->getDefaultRenderer();
356 $html = $this->brutallyTrimHTML($r->render($form));
357
358 $field_html = $this->getFormWrappedHtml(
359 'text-field-input',
360 'label<span class="sr-only">required_field</span><span class="asterisk" aria-hidden="true">*</span>',
361 '<input id="id_1" type="text" name="form/input_0" class="c-field-text" />',
362 'byline',
363 'id_1',
364 null,
365 'form/input_0'
366 );
367
368 $expected = $this->brutallyTrimHTML('
369<form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
370 <div class="c-form__header">
371 <div class="c-form__required">
372 <span class="asterisk">*</span><span class="small"> required_field</span>
373 </div>
374 </div>
375 ' . $field_html . '
376 <div class="c-form__footer">
377 <div class="c-form__required">
378 <span class="asterisk">*</span><span class="small"> required_field</span>
379 </div>
380 <div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
381 </div>
382</form>
383 ');
384 $this->assertHTMLEquals($expected, $html);
385 }

References Vendor\Package\$f, $url, and buildFactory().

+ Here is the call graph for this function:

◆ testSubmitCaption()

StandardFormTest::testSubmitCaption ( )

Definition at line 144 of file StandardFormTest.php.

144 : void
145 {
146 $f = $this->buildFactory();
147 $if = $this->getFieldFactory();
148
149 $url = "MY_URL";
150 $form = $f->standard($url, [
151 $if->text("label", "byline"),
152 ]);
153
154 $this->assertNull($form->getSubmitLabel());
155
156 $caption = 'Caption';
157 $form = $form->withSubmitLabel($caption);
158
159 $this->assertEquals($caption, $form->getSubmitLabel());
160 }

References Vendor\Package\$f, $url, and buildFactory().

+ Here is the call graph for this function:

◆ testSubmitCaptionRender()

StandardFormTest::testSubmitCaptionRender ( )

Definition at line 162 of file StandardFormTest.php.

162 : void
163 {
164 $f = $this->buildFactory();
165 $if = $this->getFieldFactory();
166
167 $url = "MY_URL";
168 $form = $f->standard($url, [
169 $if->text("label", "byline"),
170 ])->withSubmitLabel('create');
171
172 $r = $this->getDefaultRenderer();
173 $html = $this->brutallyTrimHTML($r->render($form));
174
175 $expected = $this->brutallyTrimHTML('
176 <form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
177 <div class="c-form__header">
178 </div>'
179 . $this->getTextFieldHtml() .
180 '<div class="c-form__footer">
181 <div class="c-form__actions"><button class="btn btn-default" data-action="">create</button></div>
182 </div>
183 </form>
184 ');
185 $this->assertHTMLEquals($expected, $html);
186 }

References Vendor\Package\$f, $url, buildFactory(), and getTextFieldHtml().

+ Here is the call graph for this function:

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