ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
StandardFormTest Class Reference

Test on standard form implementation. More...

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

Public Member Functions

 getUIFactory ()
 
 test_getPostURL ()
 
 test_render ()
 
 test_render_no_url ()
 
 testRenderWithErrorOnField ()
 
 testRenderWithErrorOnForm ()
 
 testStandardFormRenderWithRequired ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Member Functions

 buildFactory ()
 
 buildInputFactory ()
 
 buildButtonFactory ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Test on standard form implementation.

Definition at line 49 of file StandardFormTest.php.

Member Function Documentation

◆ buildButtonFactory()

StandardFormTest::buildButtonFactory ( )
protected

◆ buildFactory()

StandardFormTest::buildFactory ( )
protected

Definition at line 51 of file StandardFormTest.php.

◆ buildInputFactory()

StandardFormTest::buildInputFactory ( )
protected

Definition at line 57 of file StandardFormTest.php.

58  {
59  $df = new Data\Factory();
60  $language = $this->createMock(\ilLanguage::class);
62  new SignalGenerator(),
63  $df,
64  new \ILIAS\Refinery\Factory($df, $language),
65  $language
66  );
67  }
Class ChatMainBarProvider .
Builds data types.
Definition: Factory.php:19

◆ getUIFactory()

StandardFormTest::getUIFactory ( )

Definition at line 75 of file StandardFormTest.php.

◆ test_getPostURL()

StandardFormTest::test_getPostURL ( )

Definition at line 81 of file StandardFormTest.php.

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

82  {
83  $f = $this->buildFactory();
84  $if = $this->buildInputFactory();
85  $url = "MY_URL";
86  $form = $f->standard($url, [$if->text("label")]);
87  $this->assertEquals($url, $form->getPostURL());
88  }
$url

◆ test_render()

StandardFormTest::test_render ( )

Definition at line 91 of file StandardFormTest.php.

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

92  {
93  $f = $this->buildFactory();
94  $if = $this->buildInputFactory();
95 
96  $url = "MY_URL";
97  $form = $f->standard($url, [
98  $if->text("label", "byline"),
99  ]);
100 
101  $r = $this->getDefaultRenderer();
102  $html = $this->brutallyTrimHTML($r->render($form));
103 
104  $expected = $this->brutallyTrimHTML('
105 <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" action="MY_URL" method="post" novalidate="novalidate">
106  <div class="il-standard-form-header clearfix">
107  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
108  </div>
109  <div class="form-group row">
110  <label for="id_1" class="control-label col-sm-3">label</label>
111  <div class="col-sm-9">
112  <input id="id_1" type="text" name="form_input_1" class="form-control form-control-sm"/>
113  <div class="help-block">byline</div>
114  </div>
115  </div>
116  <div class="il-standard-form-footer clearfix">
117  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
118  </div>
119 </form>
120  ');
121  $this->assertHTMLEquals($expected, $html);
122  }
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
$url
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311

◆ test_render_no_url()

StandardFormTest::test_render_no_url ( )

Definition at line 124 of file StandardFormTest.php.

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

125  {
126  $f = $this->buildFactory();
127  $if = $this->buildInputFactory();
128 
129  $url = "";
130  $form = $f->standard($url, [
131  $if->text("label", "byline"),
132  ]);
133 
134  $r = $this->getDefaultRenderer();
135  $html = $this->brutallyTrimHTML($r->render($form));
136 
137  $expected = $this->brutallyTrimHTML('
138 <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" method="post" novalidate="novalidate">
139  <div class="il-standard-form-header clearfix">
140  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
141  </div>
142  <div class="form-group row">
143  <label for="id_1" class="control-label col-sm-3">label</label>
144  <div class="col-sm-9">
145  <input id="id_1" type="text" name="form_input_1" class="form-control form-control-sm"/>
146  <div class="help-block">byline</div>
147  </div>
148  </div>
149  <div class="il-standard-form-footer clearfix">
150  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
151  </div>
152 </form>
153  ');
154  $this->assertHTMLEquals($expected, $html);
155  }
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
$url
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311

◆ testRenderWithErrorOnField()

StandardFormTest::testRenderWithErrorOnField ( )

Definition at line 158 of file StandardFormTest.php.

159  {
160  $r = $this->getDefaultRenderer();
161  $df = new Data\Factory();
162  $language = $this->createMock(\ilLanguage::class);
163  $language
164  ->expects($this->once())
165  ->method("txt")
166  ->willReturn('testing error message');
167 
168  $refinery = new \ILIAS\Refinery\Factory($df, $language);
169 
171  new SignalGenerator(),
172  $df,
173  $refinery,
174  $language
175  );
176 
177  $fail = $refinery->custom()->constraint(function ($v) {
178  return false;
179  }, "This is invalid...");
180  $input = $if->text("label", "byline");
181 
182  $input = $input->withAdditionalTransformation($fail);
183 
184  $form = new Form\Standard($if, '', [$input]);
185 
186  $request = $this->createMock(ServerRequestInterface::class);
187  $request
188  ->expects($this->once())
189  ->method("getParsedBody")
190  ->willReturn([
191  'form_input_1' => ''
192  ]);
193 
194  $form = $form->withRequest($request);
195  $this->assertNull($form->getData());
196 
197  $html = $this->brutallyTrimHTML($r->render($form));
198  $expected = $this->brutallyTrimHTML('
199  <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" method="post" novalidate="novalidate">
200  <div class="il-standard-form-header clearfix">
201  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
202  </div>
203 
204  <div class="help-block alert alert-danger" role="alert">testing error message</div>
205 
206  <div class="form-group row">
207  <label for="id_1" class="control-label col-sm-3">label</label>
208  <div class="col-sm-9">
209  <div class="help-block alert alert-danger" role="alert">This is invalid...</div>
210  <input id="id_1" type="text" name="form_input_1" class="form-control form-control-sm" />
211  <div class="help-block">byline</div>
212  </div>
213  </div>
214  <div class="il-standard-form-footer clearfix">
215  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
216  </div>
217  </form>
218  ');
219  $this->assertHTMLEquals($expected, $html);
220  }
Builds data types.
Definition: Factory.php:19
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311

◆ testRenderWithErrorOnForm()

StandardFormTest::testRenderWithErrorOnForm ( )

Definition at line 223 of file StandardFormTest.php.

224  {
225  $r = $this->getDefaultRenderer();
226  $df = new Data\Factory();
227  $language = $this->createMock(\ilLanguage::class);
228  $refinery = new \ILIAS\Refinery\Factory($df, $language);
229 
231  new SignalGenerator(),
232  $df,
233  $refinery,
234  $language
235  );
236 
237  $fail = $refinery->custom()->constraint(function ($v) {
238  return false;
239  }, "This is a fail on form.");
240  $input = $if->text("label", "byline");
241 
242  $form = new Form\Standard($if, '', [$input]);
243  $form = $form->withAdditionalTransformation($fail);
244 
245  $request = $this->createMock(ServerRequestInterface::class);
246  $request
247  ->expects($this->once())
248  ->method("getParsedBody")
249  ->willReturn([
250  'form_input_1' => ''
251  ]);
252 
253  $form = $form->withRequest($request);
254  $this->assertNull($form->getData());
255 
256  $html = $this->brutallyTrimHTML($r->render($form));
257  $expected = $this->brutallyTrimHTML('
258  <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" method="post" novalidate="novalidate">
259  <div class="il-standard-form-header clearfix">
260  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
261  </div>
262 
263  <div class="help-block alert alert-danger" role="alert">This is a fail on form.</div>
264 
265  <div class="form-group row">
266  <label for="id_1" class="control-label col-sm-3">label</label>
267  <div class="col-sm-9">
268  <input id="id_1" type="text" name="form_input_1" class="form-control form-control-sm" />
269  <div class="help-block">byline</div>
270  </div>
271  </div>
272  <div class="il-standard-form-footer clearfix">
273  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
274  </div>
275  </form>
276  ');
277  $this->assertHTMLEquals($expected, $html);
278  }
Builds data types.
Definition: Factory.php:19
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311

◆ testStandardFormRenderWithRequired()

StandardFormTest::testStandardFormRenderWithRequired ( )

Definition at line 280 of file StandardFormTest.php.

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

280  : void
281  {
282  $f = $this->buildFactory();
283  $if = $this->buildInputFactory();
284 
285  $url = "MY_URL";
286  $form = $f->standard($url, [$if->text("label", "byline")->withRequired(true)]);
287 
288  $r = $this->getDefaultRenderer();
289  $html = $this->brutallyTrimHTML($r->render($form));
290 
291  $expected = $this->brutallyTrimHTML('
292 <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" action="MY_URL" method="post" novalidate="novalidate">
293  <div class="il-standard-form-header clearfix">
294  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
295  </div>
296  <div class="form-group row">
297  <label for="id_1" class="control-label col-sm-3">label<span class="asterisk">*</span></label>
298  <div class="col-sm-9">
299  <input id="id_1" type="text" name="form_input_1" class="form-control form-control-sm"/>
300  <div class="help-block">byline</div>
301  </div>
302  </div>
303  <div class="il-standard-form-footer clearfix">
304  <span class="asterisk">*</span><span class="small"> required_field</span>
305  </div>
306  <div class="il-standard-form-footer clearfix">
307  <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
308  </div>
309 </form>
310  ');
311  $this->assertHTMLEquals($expected, $html);
312  }
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
$url
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311

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