ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 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 71 of file FormTest.php.

Member Function Documentation

◆ buildButtonFactory()

FormTest::buildButtonFactory ( )
protected

◆ buildDataFactory()

FormTest::buildDataFactory ( )

Definition at line 114 of file FormTest.php.

115  {
116  return new \ILIAS\Data\Factory;
117  }

◆ buildFactory()

FormTest::buildFactory ( )
protected

Definition at line 73 of file FormTest.php.

74  {
76  }
buildInputFactory()
Definition: FormTest.php:79
Builds data types.
Definition: Factory.php:19

◆ buildInputFactory()

FormTest::buildInputFactory ( )
protected

Definition at line 79 of file FormTest.php.

References language().

80  {
81  $df = new Data\Factory();
82  $this->language = $this->createMock(\ilLanguage::class);
84  new SignalGenerator(),
85  $df,
86  new \ILIAS\Refinery\Factory($df, $this->language),
87  $this->language
88  );
89  }
Class ChatMainBarProvider .
Builds data types.
Definition: Factory.php:19
language()
Definition: language.php:2
+ Here is the call graph for this function:

◆ buildTransformation()

FormTest::buildTransformation ( \Closure  $trafo)
protected

Definition at line 98 of file FormTest.php.

99  {
100  $dataFactory = new Data\Factory();
101  $language = $this->createMock(\ilLanguage::class);
102  $refinery = new \ILIAS\Refinery\Factory($dataFactory, $language);
103 
104  return $refinery->custom()->transformation($trafo);
105  }

◆ getUIFactory()

FormTest::getUIFactory ( )

Definition at line 108 of file FormTest.php.

109  {
110  return new WithButtonNoUIFactory($this->buildButtonFactory());
111  }
buildButtonFactory()
Definition: FormTest.php:92

◆ inputMock()

FormTest::inputMock ( )
protected

Definition at line 419 of file FormTest.php.

References $config.

420  {
421  static $no = 1000;
422  $config = $this
423  ->getMockBuilder(InputInternal::class)
424  ->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"])
425  ->setMockClassName("Mock_InputNo" . ($no++))
426  ->getMock();
427  return $config;
428  }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68

◆ test_extractPostData()

FormTest::test_extractPostData ( )

Definition at line 151 of file FormTest.php.

152  {
153  $form = new ConcreteForm($this->buildInputFactory(), []);
154  $request = $this->createMock(ServerRequestInterface::class);
155  $request
156  ->expects($this->once())
157  ->method("getParsedBody")
158  ->willReturn([]);
159  $input_data = $form->_extractPostData($request);
160  $this->assertInstanceOf(InputData::class, $input_data);
161  }
buildInputFactory()
Definition: FormTest.php:79

◆ test_getData()

FormTest::test_getData ( )

Definition at line 244 of file FormTest.php.

245  {
246  $df = $this->buildDataFactory();
247  $request = $this->createMock(ServerRequestInterface::class);
248  $request
249  ->expects($this->once())
250  ->method("getParsedBody")
251  ->willReturn([]);
252 
253  $input_1 = $this->inputMock();
254  $input_1
255  ->expects($this->once())
256  ->method("getContent")
257  ->willReturn($df->ok(1));
258  $input_1
259  ->expects($this->once())
260  ->method("withInput")
261  ->willReturn($input_1);
262 
263  $input_2 = $this->inputMock();
264  $input_2
265  ->expects($this->once())
266  ->method("getContent")
267  ->willReturn($df->ok(2));
268  $input_2
269  ->expects($this->once())
270  ->method("withInput")
271  ->willReturn($input_2);
272 
273  $form = new ConcreteForm($this->buildInputFactory(), []);
274  $form->setInputs([$input_1, $input_2]);
275  $form = $form->withRequest($request);
276  $this->assertEquals([1, 2], $form->getData());
277  }
buildInputFactory()
Definition: FormTest.php:79
inputMock()
Definition: FormTest.php:419
buildDataFactory()
Definition: FormTest.php:114

◆ test_getData_faulty()

FormTest::test_getData_faulty ( )

Definition at line 316 of file FormTest.php.

References language().

317  {
318  $df = $this->buildDataFactory();
319  $request = $this->createMock(ServerRequestInterface::class);
320  $request
321  ->expects($this->once())
322  ->method("getParsedBody")
323  ->willReturn([]);
324 
325  $input_1 = $this->inputMock();
326  $input_1
327  ->expects($this->once())
328  ->method("getContent")
329  ->willReturn($df->error("error"));
330  $input_1
331  ->expects($this->once())
332  ->method("withInput")
333  ->willReturn($input_1);
334 
335  $input_2 = $this->inputMock();
336  $input_2
337  ->expects($this->once())
338  ->method("getContent")
339  ->willReturn($df->ok(2));
340  $input_2
341  ->expects($this->once())
342  ->method("withInput")
343  ->willReturn($input_2);
344 
345  $form = new ConcreteForm($this->buildInputFactory(), []);
346  $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
347 
348  $i18n = "THERE IS SOME ERROR IN THIS GROUP";
349  $this->language
350  ->expects($this->once())
351  ->method("txt")
352  ->with("ui_error_in_group")
353  ->willReturn($i18n);
354 
355  //Todo: This is not good, this should throw an error or similar.
356  $form = $form->withRequest($request);
357  $this->assertEquals(null, null);
358  }
buildInputFactory()
Definition: FormTest.php:79
inputMock()
Definition: FormTest.php:419
buildDataFactory()
Definition: FormTest.php:114
language()
Definition: language.php:2
+ Here is the call graph for this function:

◆ test_getData_respects_keys()

FormTest::test_getData_respects_keys ( )

Definition at line 280 of file FormTest.php.

281  {
282  $df = $this->buildDataFactory();
283  $request = $this->createMock(ServerRequestInterface::class);
284  $request
285  ->expects($this->once())
286  ->method("getParsedBody")
287  ->willReturn([]);
288 
289  $input_1 = $this->inputMock();
290  $input_1
291  ->expects($this->once())
292  ->method("getContent")
293  ->willReturn($df->ok(1));
294  $input_1
295  ->expects($this->once())
296  ->method("withInput")
297  ->willReturn($input_1);
298 
299  $input_2 = $this->inputMock();
300  $input_2
301  ->expects($this->once())
302  ->method("getContent")
303  ->willReturn($df->ok(2));
304  $input_2
305  ->expects($this->once())
306  ->method("withInput")
307  ->willReturn($input_2);
308 
309  $form = new ConcreteForm($this->buildInputFactory(), []);
310  $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
311  $form = $form->withRequest($request);
312  $this->assertEquals(["foo" => 1, "bar" => 2], $form->getData());
313  }
buildInputFactory()
Definition: FormTest.php:79
inputMock()
Definition: FormTest.php:419
buildDataFactory()
Definition: FormTest.php:114

◆ test_getInputs()

FormTest::test_getInputs ( )

Definition at line 120 of file FormTest.php.

References Vendor\Package\$f, ILIAS\GlobalScreen\Provider\$if, and FixedNameSource\$name.

121  {
122  $f = $this->buildFactory();
123  $if = $this->buildInputFactory();
124  $name_source = new FixedNameSource();
125 
126  $inputs = [$if->text(""), $if->text("")];
127  $form = new ConcreteForm($this->buildInputFactory(), $inputs);
128 
129  $seen_names = [];
130  $inputs = $form->getInputs();
131  $this->assertEquals(count($inputs), count($inputs));
132 
133  foreach ($inputs as $input) {
134  $name = $input->getName();
135  $name_source->name = $name;
136 
137  // name is a string
138  $this->assertIsString($name);
139 
140  // only name is attached
141  $input = array_shift($inputs);
142  $this->assertEquals($input->withNameFrom($name_source), $input);
143 
144  // every name can only be contained once.
145  $this->assertNotContains($name, $seen_names);
146  $seen_names[] = $name;
147  }
148  }
buildInputFactory()
Definition: FormTest.php:79
if($format !==null) $name
Definition: metadata.php:230
buildFactory()
Definition: FormTest.php:73

◆ test_nameInputs_respects_keys()

FormTest::test_nameInputs_respects_keys ( )

Definition at line 404 of file FormTest.php.

References ILIAS\GlobalScreen\Provider\$if.

405  {
406  $if = $this->buildInputFactory();
407  $inputs = [
408  2 => $if->text(""),
409  "foo" => $if->text(""),
410  1 => $if->text(""),
411  $if->text(""),
412  ];
413  $form = new ConcreteForm($this->buildInputFactory(), []);
414  $form->setInputs($inputs);
415  $named_inputs = $form->getInputs();
416  $this->assertEquals(array_keys($inputs), array_keys($named_inputs));
417  }
buildInputFactory()
Definition: FormTest.php:79

◆ test_withAdditionalTransformation()

FormTest::test_withAdditionalTransformation ( )

Definition at line 361 of file FormTest.php.

362  {
363  $df = $this->buildDataFactory();
364  $request = $this->createMock(ServerRequestInterface::class);
365  $request
366  ->expects($this->once())
367  ->method("getParsedBody")
368  ->willReturn([]);
369 
370  $input_1 = $this->inputMock();
371  $input_1
372  ->expects($this->once())
373  ->method("getContent")
374  ->willReturn($df->ok(1));
375  $input_1
376  ->expects($this->once())
377  ->method("withInput")
378  ->willReturn($input_1);
379 
380  $input_2 = $this->inputMock();
381  $input_2
382  ->expects($this->once())
383  ->method("getContent")
384  ->willReturn($df->ok(2));
385  $input_2
386  ->expects($this->once())
387  ->method("withInput")
388  ->willReturn($input_2);
389 
390  $form = new ConcreteForm($this->buildInputFactory(), []);
391  $form->setInputs([$input_1, $input_2]);
392 
393  $form2 = $form->withAdditionalTransformation($this->buildTransformation(function ($v) {
394  return "transformed";
395  }));
396 
397  $this->assertNotSame($form2, $form);
398  $form2 = $form2->withRequest($request);
399 
400  $this->assertEquals("transformed", $form2->getData());
401  }
buildInputFactory()
Definition: FormTest.php:79
inputMock()
Definition: FormTest.php:419
buildTransformation(\Closure $trafo)
Definition: FormTest.php:98
buildDataFactory()
Definition: FormTest.php:114

◆ test_withRequest()

FormTest::test_withRequest ( )

Definition at line 164 of file FormTest.php.

165  {
166  $df = $this->buildDataFactory();
167  $request = $this->createMock(ServerRequestInterface::class);
168  $input_data = $this->createMock(InputData::class);
169 
170  $input_1 = $this->inputMock();
171  $input_1
172  ->expects($this->once())
173  ->method("withInput")
174  ->with($input_data)
175  ->willReturn($input_1);
176  $input_1
177  ->expects($this->once())
178  ->method("getContent")
179  ->willReturn($df->ok(0));
180 
181  $input_2 = $this->inputMock();
182  $input_2
183  ->expects($this->once())
184  ->method("withInput")
185  ->with($input_data)
186  ->willReturn($input_2);
187  $input_2
188  ->expects($this->once())
189  ->method("getContent")
190  ->willReturn($df->ok(0));
191 
192  $form = new ConcreteForm($this->buildInputFactory(), []);
193  $form->setInputs([$input_1, $input_2]);
194  $form->input_data = $input_data;
195 
196  $form2 = $form->withRequest($request);
197 
198  $this->assertNotSame($form2, $form);
199  $this->assertInstanceOf(Form::class, $form2);
200  $this->assertEquals([$input_1, $input_2], $form2->getInputs());
201  }
buildInputFactory()
Definition: FormTest.php:79
inputMock()
Definition: FormTest.php:419
buildDataFactory()
Definition: FormTest.php:114

◆ test_withRequest_respects_keys()

FormTest::test_withRequest_respects_keys ( )

Definition at line 204 of file FormTest.php.

205  {
206  $df = $this->buildDataFactory();
207  $request = $this->createMock(ServerRequestInterface::class);
208  $input_data = $this->createMock(InputData::class);
209 
210  $input_1 = $this->inputMock();
211  $input_1
212  ->expects($this->once())
213  ->method("withInput")
214  ->with($input_data)
215  ->willReturn($input_1);
216  $input_1
217  ->expects($this->once())
218  ->method("getContent")
219  ->willReturn($df->ok(0));
220 
221  $input_2 = $this->inputMock();
222  $input_2
223  ->expects($this->once())
224  ->method("withInput")
225  ->with($input_data)
226  ->willReturn($input_2);
227  $input_2
228  ->expects($this->once())
229  ->method("getContent")
230  ->willReturn($df->ok(0));
231 
232  $form = new ConcreteForm($this->buildInputFactory(), []);
233  $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
234  $form->input_data = $input_data;
235 
236  $form2 = $form->withRequest($request);
237 
238  $this->assertNotSame($form2, $form);
239  $this->assertInstanceOf(Form::class, $form2);
240  $this->assertEquals(["foo" => $input_1, "bar" => $input_2], $form2->getInputs());
241  }
buildInputFactory()
Definition: FormTest.php:79
inputMock()
Definition: FormTest.php:419
buildDataFactory()
Definition: FormTest.php:114

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