ILIAS  release_7 Revision v7.30-3-g800a261c036
FormTest Class Reference

Test on form implementation. More...

+ Inheritance diagram for FormTest:
+ Collaboration diagram for FormTest:

Public Member Functions

 getUIFactory ()
 
 buildDataFactory ()
 
 test_getInputs ()
 
 test_extractPostData ()
 
 test_withRequest ()
 
 test_withRequest_respects_keys ()
 
 test_getData ()
 
 test_getData_respects_keys ()
 
 test_getData_faulty ()
 
 test_withAdditionalTransformation ()
 
 test_nameInputs_respects_keys ()
 
 testFormWithoutRequiredField ()
 
 testFormWithRequiredField ()
 
- 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 ()
 
 buildTransformation (\Closure $trafo)
 
 inputMock ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Test on form implementation.

Definition at line 86 of file FormTest.php.

Member Function Documentation

◆ buildButtonFactory()

FormTest::buildButtonFactory ( )
protected

Definition at line 107 of file FormTest.php.

108 {
110 }
Builds a Color from either hex- or rgb values.
Definition: Factory.php:14

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ buildDataFactory()

FormTest::buildDataFactory ( )

Definition at line 129 of file FormTest.php.

130 {
131 return new \ILIAS\Data\Factory;
132 }

Referenced by test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), and test_withRequest_respects_keys().

+ Here is the caller graph for this function:

◆ buildFactory()

FormTest::buildFactory ( )
protected

Definition at line 88 of file FormTest.php.

References buildInputFactory().

Referenced by test_getInputs(), testFormWithoutRequiredField(), and testFormWithRequiredField().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildInputFactory()

FormTest::buildInputFactory ( )
protected

Definition at line 94 of file FormTest.php.

95 {
96 $df = new Data\Factory();
97 $this->language = $this->createMock(\ilLanguage::class);
99 new SignalGenerator(),
100 $df,
101 new \ILIAS\Refinery\Factory($df, $this->language),
102 $this->language
103 );
104 }
language()
Definition: language.php:2
Class ChatMainBarProvider \MainMenu\Provider.

References language().

Referenced by buildFactory(), test_extractPostData(), test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_getInputs(), test_nameInputs_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), test_withRequest_respects_keys(), testFormWithoutRequiredField(), and testFormWithRequiredField().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildTransformation()

FormTest::buildTransformation ( \Closure  $trafo)
protected

Definition at line 113 of file FormTest.php.

114 {
115 $dataFactory = new Data\Factory();
116 $language = $this->createMock(\ilLanguage::class);
117 $refinery = new \ILIAS\Refinery\Factory($dataFactory, $language);
118
119 return $refinery->custom()->transformation($trafo);
120 }

Referenced by test_withAdditionalTransformation().

+ Here is the caller graph for this function:

◆ getUIFactory()

FormTest::getUIFactory ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 123 of file FormTest.php.

124 {
125 return new WithButtonNoUIFactory($this->buildButtonFactory());
126 }
buildButtonFactory()
Definition: FormTest.php:107

References buildButtonFactory().

+ Here is the call graph for this function:

◆ inputMock()

FormTest::inputMock ( )
protected

Definition at line 434 of file FormTest.php.

435 {
436 static $no = 1000;
437 $config = $this
438 ->getMockBuilder(FormInputInternal::class)
439 ->setMethods(["getName", "withNameFrom", "withInput", "getContent", "getLabel", "withLabel", "getByline", "withByline", "isRequired", "withRequired", "isDisabled", "withDisabled", "getValue", "withValue", "getError", "withError", "withAdditionalTransformation", "withAdditionalConstraint", "getUpdateOnLoadCode", "getCanonicalName", "withOnLoadCode", "withAdditionalOnLoadCode", "getOnLoadCode", "withOnUpdate", "appendOnUpdate", "withResetTriggeredSignals", "getTriggeredSignals"])
440 ->setMockClassName("Mock_InputNo" . ($no++))
441 ->getMock();
442 return $config;
443 }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68

References $config.

Referenced by test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), and test_withRequest_respects_keys().

+ Here is the caller graph for this function:

◆ test_extractPostData()

FormTest::test_extractPostData ( )

Definition at line 166 of file FormTest.php.

167 {
168 $form = new ConcreteForm($this->buildInputFactory(), []);
169 $request = $this->createMock(ServerRequestInterface::class);
170 $request
171 ->expects($this->once())
172 ->method("getParsedBody")
173 ->willReturn([]);
174 $input_data = $form->_extractPostData($request);
175 $this->assertInstanceOf(InputData::class, $input_data);
176 }

References buildInputFactory().

+ Here is the call graph for this function:

◆ test_getData()

FormTest::test_getData ( )

Definition at line 259 of file FormTest.php.

260 {
261 $df = $this->buildDataFactory();
262 $request = $this->createMock(ServerRequestInterface::class);
263 $request
264 ->expects($this->once())
265 ->method("getParsedBody")
266 ->willReturn([]);
267
268 $input_1 = $this->inputMock();
269 $input_1
270 ->expects($this->once())
271 ->method("getContent")
272 ->willReturn($df->ok(1));
273 $input_1
274 ->expects($this->once())
275 ->method("withInput")
276 ->willReturn($input_1);
277
278 $input_2 = $this->inputMock();
279 $input_2
280 ->expects($this->once())
281 ->method("getContent")
282 ->willReturn($df->ok(2));
283 $input_2
284 ->expects($this->once())
285 ->method("withInput")
286 ->willReturn($input_2);
287
288 $form = new ConcreteForm($this->buildInputFactory(), []);
289 $form->setInputs([$input_1, $input_2]);
290 $form = $form->withRequest($request);
291 $this->assertEquals([1, 2], $form->getData());
292 }
buildDataFactory()
Definition: FormTest.php:129
inputMock()
Definition: FormTest.php:434

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ test_getData_faulty()

FormTest::test_getData_faulty ( )

Definition at line 331 of file FormTest.php.

332 {
333 $df = $this->buildDataFactory();
334 $request = $this->createMock(ServerRequestInterface::class);
335 $request
336 ->expects($this->once())
337 ->method("getParsedBody")
338 ->willReturn([]);
339
340 $input_1 = $this->inputMock();
341 $input_1
342 ->expects($this->once())
343 ->method("getContent")
344 ->willReturn($df->error("error"));
345 $input_1
346 ->expects($this->once())
347 ->method("withInput")
348 ->willReturn($input_1);
349
350 $input_2 = $this->inputMock();
351 $input_2
352 ->expects($this->once())
353 ->method("getContent")
354 ->willReturn($df->ok(2));
355 $input_2
356 ->expects($this->once())
357 ->method("withInput")
358 ->willReturn($input_2);
359
360 $form = new ConcreteForm($this->buildInputFactory(), []);
361 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
362
363 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
364 $this->language
365 ->expects($this->once())
366 ->method("txt")
367 ->with("ui_error_in_group")
368 ->willReturn($i18n);
369
370 //Todo: This is not good, this should throw an error or similar.
371 $form = $form->withRequest($request);
372 $this->assertEquals(null, null);
373 }

References buildDataFactory(), buildInputFactory(), inputMock(), and language().

+ Here is the call graph for this function:

◆ test_getData_respects_keys()

FormTest::test_getData_respects_keys ( )

Definition at line 295 of file FormTest.php.

296 {
297 $df = $this->buildDataFactory();
298 $request = $this->createMock(ServerRequestInterface::class);
299 $request
300 ->expects($this->once())
301 ->method("getParsedBody")
302 ->willReturn([]);
303
304 $input_1 = $this->inputMock();
305 $input_1
306 ->expects($this->once())
307 ->method("getContent")
308 ->willReturn($df->ok(1));
309 $input_1
310 ->expects($this->once())
311 ->method("withInput")
312 ->willReturn($input_1);
313
314 $input_2 = $this->inputMock();
315 $input_2
316 ->expects($this->once())
317 ->method("getContent")
318 ->willReturn($df->ok(2));
319 $input_2
320 ->expects($this->once())
321 ->method("withInput")
322 ->willReturn($input_2);
323
324 $form = new ConcreteForm($this->buildInputFactory(), []);
325 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
326 $form = $form->withRequest($request);
327 $this->assertEquals(["foo" => 1, "bar" => 2], $form->getData());
328 }

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ test_getInputs()

FormTest::test_getInputs ( )

Definition at line 135 of file FormTest.php.

136 {
137 $f = $this->buildFactory();
138 $if = $this->buildInputFactory();
139 $name_source = new FixedNameSource();
140
141 $inputs = [$if->text(""), $if->text("")];
142 $form = new ConcreteForm($this->buildInputFactory(), $inputs);
143
144 $seen_names = [];
145 $inputs = $form->getInputs();
146 $this->assertEquals(count($inputs), count($inputs));
147
148 foreach ($inputs as $input) {
149 $name = $input->getName();
150 $name_source->name = $name;
151
152 // name is a string
153 $this->assertIsString($name);
154
155 // only name is attached
156 $input = array_shift($inputs);
157 $this->assertEquals($input->withNameFrom($name_source), $input);
158
159 // every name can only be contained once.
160 $this->assertNotContains($name, $seen_names);
161 $seen_names[] = $name;
162 }
163 }
buildFactory()
Definition: FormTest.php:88
if($format !==null) $name
Definition: metadata.php:230

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

+ Here is the call graph for this function:

◆ test_nameInputs_respects_keys()

FormTest::test_nameInputs_respects_keys ( )

Definition at line 419 of file FormTest.php.

420 {
421 $if = $this->buildInputFactory();
422 $inputs = [
423 2 => $if->text(""),
424 "foo" => $if->text(""),
425 1 => $if->text(""),
426 $if->text(""),
427 ];
428 $form = new ConcreteForm($this->buildInputFactory(), []);
429 $form->setInputs($inputs);
430 $named_inputs = $form->getInputs();
431 $this->assertEquals(array_keys($inputs), array_keys($named_inputs));
432 }

References buildInputFactory().

+ Here is the call graph for this function:

◆ test_withAdditionalTransformation()

FormTest::test_withAdditionalTransformation ( )

Definition at line 376 of file FormTest.php.

377 {
378 $df = $this->buildDataFactory();
379 $request = $this->createMock(ServerRequestInterface::class);
380 $request
381 ->expects($this->once())
382 ->method("getParsedBody")
383 ->willReturn([]);
384
385 $input_1 = $this->inputMock();
386 $input_1
387 ->expects($this->once())
388 ->method("getContent")
389 ->willReturn($df->ok(1));
390 $input_1
391 ->expects($this->once())
392 ->method("withInput")
393 ->willReturn($input_1);
394
395 $input_2 = $this->inputMock();
396 $input_2
397 ->expects($this->once())
398 ->method("getContent")
399 ->willReturn($df->ok(2));
400 $input_2
401 ->expects($this->once())
402 ->method("withInput")
403 ->willReturn($input_2);
404
405 $form = new ConcreteForm($this->buildInputFactory(), []);
406 $form->setInputs([$input_1, $input_2]);
407
408 $form2 = $form->withAdditionalTransformation($this->buildTransformation(function ($v) {
409 return "transformed";
410 }));
411
412 $this->assertNotSame($form2, $form);
413 $form2 = $form2->withRequest($request);
414
415 $this->assertEquals("transformed", $form2->getData());
416 }
buildTransformation(\Closure $trafo)
Definition: FormTest.php:113

References buildDataFactory(), buildInputFactory(), buildTransformation(), and inputMock().

+ Here is the call graph for this function:

◆ test_withRequest()

FormTest::test_withRequest ( )

Definition at line 179 of file FormTest.php.

180 {
181 $df = $this->buildDataFactory();
182 $request = $this->createMock(ServerRequestInterface::class);
183 $input_data = $this->createMock(InputData::class);
184
185 $input_1 = $this->inputMock();
186 $input_1
187 ->expects($this->once())
188 ->method("withInput")
189 ->with($input_data)
190 ->willReturn($input_1);
191 $input_1
192 ->expects($this->once())
193 ->method("getContent")
194 ->willReturn($df->ok(0));
195
196 $input_2 = $this->inputMock();
197 $input_2
198 ->expects($this->once())
199 ->method("withInput")
200 ->with($input_data)
201 ->willReturn($input_2);
202 $input_2
203 ->expects($this->once())
204 ->method("getContent")
205 ->willReturn($df->ok(0));
206
207 $form = new ConcreteForm($this->buildInputFactory(), []);
208 $form->setInputs([$input_1, $input_2]);
209 $form->input_data = $input_data;
210
211 $form2 = $form->withRequest($request);
212
213 $this->assertNotSame($form2, $form);
214 $this->assertInstanceOf(Form::class, $form2);
215 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
216 }

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ test_withRequest_respects_keys()

FormTest::test_withRequest_respects_keys ( )

Definition at line 219 of file FormTest.php.

220 {
221 $df = $this->buildDataFactory();
222 $request = $this->createMock(ServerRequestInterface::class);
223 $input_data = $this->createMock(InputData::class);
224
225 $input_1 = $this->inputMock();
226 $input_1
227 ->expects($this->once())
228 ->method("withInput")
229 ->with($input_data)
230 ->willReturn($input_1);
231 $input_1
232 ->expects($this->once())
233 ->method("getContent")
234 ->willReturn($df->ok(0));
235
236 $input_2 = $this->inputMock();
237 $input_2
238 ->expects($this->once())
239 ->method("withInput")
240 ->with($input_data)
241 ->willReturn($input_2);
242 $input_2
243 ->expects($this->once())
244 ->method("getContent")
245 ->willReturn($df->ok(0));
246
247 $form = new ConcreteForm($this->buildInputFactory(), []);
248 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
249 $form->input_data = $input_data;
250
251 $form2 = $form->withRequest($request);
252
253 $this->assertNotSame($form2, $form);
254 $this->assertInstanceOf(Form::class, $form2);
255 $this->assertEquals(["foo" => $input_1, "bar" => $input_2], $form2->getInputs());
256 }

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ testFormWithoutRequiredField()

FormTest::testFormWithoutRequiredField ( )

Definition at line 445 of file FormTest.php.

445 : void
446 {
447 $f = $this->buildFactory();
448 $if = $this->buildInputFactory();
449 $inputs = [$if->text(""), $if->text("")];
450 $form = new ConcreteForm($this->buildInputFactory(), $inputs);
451
452 $this->assertFalse($form->hasRequiredInputs());
453 }

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

+ Here is the call graph for this function:

◆ testFormWithRequiredField()

FormTest::testFormWithRequiredField ( )

Definition at line 455 of file FormTest.php.

455 : void
456 {
457 $f = $this->buildFactory();
458 $if = $this->buildInputFactory();
459 $inputs = [
460 $if->text("")->withRequired(true),
461 $if->text("")
462 ];
463 $form = new ConcreteForm($this->buildInputFactory(), $inputs);
464 $this->assertTrue($form->hasRequiredInputs());
465 }

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

+ Here is the call graph for this function:

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