ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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:66

◆ 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:66
$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:66
$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\UploadLimitResolver::class),
236  new SignalGenerator(),
237  $df,
238  $refinery,
239  $language
240  );
241 
242  $fail = $refinery->custom()->constraint(function ($v) {
243  return false;
244  }, "This is invalid...");
245  $input = $if->text("label", "byline");
246 
247  $input = $input->withAdditionalTransformation($fail);
248 
249  $form = new Form\Standard(new SignalGenerator(), $if, new InputNameSource(), '', [$input]);
250 
251  $request = $this->createMock(ServerRequestInterface::class);
252  $request
253  ->expects($this->once())
254  ->method("getParsedBody")
255  ->willReturn([
256  'form_0/input_1' => ''
257  ]);
258 
259  $form = $form->withRequest($request);
260  $this->assertNull($form->getData());
261 
262  $html = $this->brutallyTrimHTML($r->render($form));
263  $expected = $this->brutallyTrimHTML('
264 <form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
265  <div class="c-form__header">
266  <div class="c-form__actions">
267  <button class="btn btn-default" data-action="">save</button>
268  </div>
269  </div>
270  <div class="c-form__error-msg alert alert-danger"><span class="sr-only">ui_error:</span>testing error
271  message
272  </div>
273  <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="form_0/input_1"
274  aria-describedby="id_2"><label for="id_1">label</label>
275  <div class="c-input__field"><input id="id_1" type="text" name="form_0/input_1" class="c-field-text" /></div>
276  <div class="c-input__error-msg alert alert-danger" id="id_2"><span class="sr-only">ui_error:</span>This is
277  invalid...
278  </div>
279  <div class="c-input__help-byline">byline</div>
280  </fieldset>
281  <div class="c-form__footer">
282  <div class="c-form__actions">
283  <button class="btn btn-default" data-action="">save</button>
284  </div>
285  </div>
286 </form>
287 ');
288  $this->assertEquals($expected, $html);
289  $this->assertHTMLEquals($expected, $html);
290  }
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 293 of file StandardFormTest.php.

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

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

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

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

◆ 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:66
$r

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