ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
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  }

◆ 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  }

◆ getTextFieldHtml()

StandardFormTest::getTextFieldHtml ( )
protected

Definition at line 105 of file StandardFormTest.php.

References null.

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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getUIFactory()

StandardFormTest::getUIFactory ( )

Definition at line 91 of file StandardFormTest.php.

◆ testGetPostURL()

StandardFormTest::testGetPostURL ( )

Definition at line 96 of file StandardFormTest.php.

References Vendor\Package\$f, and $url.

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:68

◆ testRender()

StandardFormTest::testRender ( )

Definition at line 118 of file StandardFormTest.php.

References Vendor\Package\$f, $r, and $url.

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->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 class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
135  </div>'
136  . $this->getTextFieldHtml() .
137  '<div class="c-form__footer">
138  <div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
139  </div>
140  </form>
141  ');
142  $this->assertHTMLEquals($expected, $html);
143  }
$url
Definition: shib_logout.php:68
$r

◆ testRenderNoUrl()

StandardFormTest::testRenderNoUrl ( )

Definition at line 190 of file StandardFormTest.php.

References Vendor\Package\$f, $r, and $url.

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

◆ testRenderWithErrorOnField()

StandardFormTest::testRenderWithErrorOnField ( )

Definition at line 222 of file StandardFormTest.php.

References $r, and ILIAS\UI\examples\Layout\Page\Standard\$refinery.

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

◆ testRenderWithErrorOnForm()

StandardFormTest::testRenderWithErrorOnForm ( )

Definition at line 294 of file StandardFormTest.php.

References $r, ILIAS\UI\examples\Layout\Page\Standard\$refinery, and null.

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

◆ testStandardFormRenderWithRequired()

StandardFormTest::testStandardFormRenderWithRequired ( )

Definition at line 356 of file StandardFormTest.php.

References Vendor\Package\$f, $r, $url, and null.

356  : void
357  {
358  $f = $this->buildFactory();
359  $if = $this->getFieldFactory();
360 
361  $url = "MY_URL";
362  $form = $f->standard($url, [$if->text("label", "byline")->withRequired(true)]);
363 
364  $r = $this->getDefaultRenderer();
365  $html = $this->brutallyTrimHTML($r->render($form));
366 
367  $field_html = $this->getFormWrappedHtml(
368  'text-field-input',
369  'label<span class="asterisk" aria-label="required_field">*</span>',
370  '<input id="id_1" type="text" name="form/input_0" class="c-field-text" />',
371  'byline',
372  'id_1',
373  null,
374  'form/input_0'
375  );
376 
377  $expected = $this->brutallyTrimHTML('
378 <form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
379  <div class="c-form__header">
380  <div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
381  <div class="c-form__required">
382  <span class="asterisk">*</span><span class="small"> required_field</span>
383  </div>
384  </div>
385  ' . $field_html . '
386  <div class="c-form__footer">
387  <div class="c-form__required">
388  <span class="asterisk">*</span><span class="small"> required_field</span>
389  </div>
390  <div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
391  </div>
392 </form>
393  ');
394  $this->assertHTMLEquals($expected, $html);
395  }
$url
Definition: shib_logout.php:68
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$r

◆ testSubmitCaption()

StandardFormTest::testSubmitCaption ( )

Definition at line 145 of file StandardFormTest.php.

References Vendor\Package\$f, and $url.

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

◆ testSubmitCaptionRender()

StandardFormTest::testSubmitCaptionRender ( )

Definition at line 163 of file StandardFormTest.php.

References Vendor\Package\$f, $r, and $url.

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

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