19 declare(strict_types=1);
21 require_once(__DIR__ .
"/../../../../Base.php");
49 public ?Input\InputData $input_data = null;
56 $this->input_factory = $input_factory;
62 return $this->extractRequestData($request);
67 if ($this->input_data !== null) {
68 return $this->input_data;
71 return parent::extractRequestData($request);
77 $this->input_group = $this->input_factory->group($inputs);
95 return new Input\Container\Form\Factory($this->buildInputFactory());
100 $df =
new Data\Factory();
101 $this->
language = $this->createMock(ilLanguage::class);
102 return new Input\Field\Factory(
113 return new I\Button\Factory();
118 $dataFactory =
new Data\Factory();
119 $language = $this->createMock(ilLanguage::class);
122 return $refinery->custom()->transformation($trafo);
132 return new Data\Factory();
137 $this->buildFactory();
138 $if = $this->buildInputFactory();
141 $inputs = [$if->text(
""), $if->text(
"")];
145 $form_inputs = $form->getInputs();
146 $this->assertSameSize($inputs, $form_inputs);
148 foreach ($form_inputs as $input) {
149 $name = $input->getName();
150 $name_source->name =
$name;
153 $this->assertIsString(
$name);
156 $input = array_shift($form_inputs);
157 $this->assertEquals($input->withNameFrom($name_source), $input);
160 $this->assertNotContains(
$name, $seen_names);
161 $seen_names[] =
$name;
168 $request = $this->createMock(ServerRequestInterface::class);
170 ->expects($this->once())
171 ->method(
"getParsedBody")
173 $input_data = $form->_extractRequestData($request);
174 $this->assertInstanceOf(InputData::class, $input_data);
179 $df = $this->buildDataFactory();
180 $request = $this->createMock(ServerRequestInterface::class);
181 $input_data = $this->createMock(InputData::class);
183 $input_1 = $this->inputMock();
185 ->expects($this->once())
186 ->method(
"withInput")
188 ->willReturn($input_1);
190 ->expects($this->once())
191 ->method(
"getContent")
192 ->willReturn($df->ok(0));
194 $input_2 = $this->inputMock();
196 ->expects($this->once())
197 ->method(
"withInput")
199 ->willReturn($input_2);
201 ->expects($this->once())
202 ->method(
"getContent")
203 ->willReturn($df->ok(0));
206 $form->setInputs([$input_1, $input_2]);
207 $form->input_data = $input_data;
209 $form2 = $form->withRequest($request);
211 $this->assertNotSame($form2, $form);
212 $this->assertInstanceOf(Form::class, $form2);
213 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
218 $df = $this->buildDataFactory();
219 $request = $this->createMock(ServerRequestInterface::class);
220 $input_data = $this->createMock(InputData::class);
222 $input_1 = $this->inputMock();
224 ->expects($this->once())
225 ->method(
"withInput")
227 ->willReturn($input_1);
229 ->expects($this->once())
230 ->method(
"getContent")
231 ->willReturn($df->ok(0));
233 $input_2 = $this->inputMock();
235 ->expects($this->once())
236 ->method(
"withInput")
238 ->willReturn($input_2);
240 ->expects($this->once())
241 ->method(
"getContent")
242 ->willReturn($df->ok(0));
245 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
246 $form->input_data = $input_data;
248 $form2 = $form->withRequest($request);
250 $this->assertNotSame($form2, $form);
251 $this->assertInstanceOf(Form::class, $form2);
252 $this->assertEquals([
"foo" => $input_1,
"bar" => $input_2], $form2->getInputs());
257 $df = $this->buildDataFactory();
258 $request = $this->createMock(ServerRequestInterface::class);
260 ->expects($this->once())
261 ->method(
"getParsedBody")
264 $input_1 = $this->inputMock();
266 ->expects($this->once())
267 ->method(
"getContent")
268 ->willReturn($df->ok(1));
270 ->expects($this->once())
271 ->method(
"withInput")
272 ->willReturn($input_1);
274 $input_2 = $this->inputMock();
276 ->expects($this->once())
277 ->method(
"getContent")
278 ->willReturn($df->ok(2));
280 ->expects($this->once())
281 ->method(
"withInput")
282 ->willReturn($input_2);
285 $form->setInputs([$input_1, $input_2]);
286 $form = $form->withRequest($request);
287 $this->assertEquals([1, 2], $form->getData());
292 $df = $this->buildDataFactory();
293 $request = $this->createMock(ServerRequestInterface::class);
295 ->expects($this->once())
296 ->method(
"getParsedBody")
299 $input_1 = $this->inputMock();
301 ->expects($this->once())
302 ->method(
"getContent")
303 ->willReturn($df->ok(1));
305 ->expects($this->once())
306 ->method(
"withInput")
307 ->willReturn($input_1);
309 $input_2 = $this->inputMock();
311 ->expects($this->once())
312 ->method(
"getContent")
313 ->willReturn($df->ok(2));
315 ->expects($this->once())
316 ->method(
"withInput")
317 ->willReturn($input_2);
320 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
321 $form = $form->withRequest($request);
322 $this->assertEquals([
"foo" => 1,
"bar" => 2], $form->getData());
327 $df = $this->buildDataFactory();
328 $request = $this->createMock(ServerRequestInterface::class);
330 ->expects($this->once())
331 ->method(
"getParsedBody")
334 $input_1 = $this->inputMock();
336 ->expects($this->once())
337 ->method(
"getContent")
338 ->willReturn($df->error(
"error"));
340 ->expects($this->once())
341 ->method(
"withInput")
342 ->willReturn($input_1);
344 $input_2 = $this->inputMock();
346 ->expects($this->once())
347 ->method(
"getContent")
348 ->willReturn($df->ok(2));
350 ->expects($this->once())
351 ->method(
"withInput")
352 ->willReturn($input_2);
355 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
357 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
359 ->expects($this->once())
361 ->with(
"ui_error_in_group")
365 $form = $form->withRequest($request);
366 $this->assertEquals(null, null);
371 $df = $this->buildDataFactory();
372 $request = $this->createMock(ServerRequestInterface::class);
374 ->expects($this->once())
375 ->method(
"getParsedBody")
378 $input_1 = $this->inputMock();
380 ->expects($this->once())
381 ->method(
"getContent")
382 ->willReturn($df->ok(1));
384 ->expects($this->once())
385 ->method(
"withInput")
386 ->willReturn($input_1);
388 $input_2 = $this->inputMock();
390 ->expects($this->once())
391 ->method(
"getContent")
392 ->willReturn($df->ok(2));
394 ->expects($this->once())
395 ->method(
"withInput")
396 ->willReturn($input_2);
399 $form->setInputs([$input_1, $input_2]);
401 $form2 = $form->withAdditionalTransformation($this->buildTransformation(
function () {
402 return "transformed";
405 $this->assertNotSame($form2, $form);
406 $form2 = $form2->withRequest($request);
408 $this->assertEquals(
"transformed", $form2->getData());
413 $if = $this->buildInputFactory();
416 "foo" => $if->text(
""),
421 $form->setInputs($inputs);
422 $named_inputs = $form->getInputs();
423 $this->assertEquals(array_keys($inputs), array_keys($named_inputs));
433 ->getMockBuilder(
Input\Field\FormInputInternal::class)
452 "withAdditionalTransformation",
453 "getUpdateOnLoadCode",
456 "withAdditionalOnLoadCode",
460 "withResetTriggeredSignals",
461 "getTriggeredSignals" 463 ->setMockClassName(
"Mock_InputNo" . ($no++))
469 $f = $this->buildFactory();
470 $if = $this->buildInputFactory();
471 $inputs = [$if->text(
""), $if->text(
"")];
474 $this->assertFalse($form->hasRequiredInputs());
479 $f = $this->buildFactory();
480 $if = $this->buildInputFactory();
482 $if->text(
"")->withRequired(
true),
486 $this->assertTrue($form->hasRequiredInputs());
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNewName()
Generates a unique name on every call.
Provides common functionality for UI tests.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Refinery Factory $refinery