19declare(strict_types=1);
21require_once(__DIR__ .
"/../../../../Base.php");
31use Psr\Http\Message\ServerRequestInterface;
35use PHPUnit\Framework\MockObject\MockObject;
67 if ($this->input_data !==
null) {
71 return parent::extractRequestData($request);
77 $this->input_group = $this->input_factory->group(
$inputs);
103 $df =
new Data\Factory();
117 return new I\Button\Factory();
122 $dataFactory =
new Data\Factory();
126 return $refinery->custom()->transformation($trafo);
136 return new Data\Factory();
145 $inputs = [$if->text(
""), $if->text(
"")];
149 $form_inputs = $form->getInputs();
150 $this->assertSameSize(
$inputs, $form_inputs);
152 foreach ($form_inputs as $input) {
153 $name = $input->getName();
154 $name_source->name = $name;
157 $this->assertIsString($name);
160 $input = array_shift($form_inputs);
161 $this->assertEquals($input->withNameFrom($name_source), $input);
164 $this->assertNotContains($name, $seen_names);
165 $seen_names[] = $name;
172 $request = $this->createMock(ServerRequestInterface::class);
174 ->expects($this->once())
175 ->method(
"getParsedBody")
177 $input_data = $form->_extractRequestData($request);
178 $this->assertInstanceOf(InputData::class, $input_data);
184 $request = $this->createMock(ServerRequestInterface::class);
185 $input_data = $this->createMock(InputData::class);
189 ->expects($this->once())
190 ->method(
"withInput")
192 ->willReturn($input_1);
194 ->expects($this->once())
195 ->method(
"getContent")
196 ->willReturn($df->ok(0));
200 ->expects($this->once())
201 ->method(
"withInput")
203 ->willReturn($input_2);
205 ->expects($this->once())
206 ->method(
"getContent")
207 ->willReturn($df->ok(0));
210 $form->setInputs([$input_1, $input_2]);
211 $form->input_data = $input_data;
213 $form2 = $form->withRequest($request);
215 $this->assertNotSame($form2, $form);
216 $this->assertInstanceOf(Form::class, $form2);
217 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
223 $request = $this->createMock(ServerRequestInterface::class);
224 $input_data = $this->createMock(InputData::class);
228 ->expects($this->once())
229 ->method(
"withInput")
231 ->willReturn($input_1);
233 ->expects($this->once())
234 ->method(
"getContent")
235 ->willReturn($df->ok(0));
239 ->expects($this->once())
240 ->method(
"withInput")
242 ->willReturn($input_2);
244 ->expects($this->once())
245 ->method(
"getContent")
246 ->willReturn($df->ok(0));
249 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
250 $form->input_data = $input_data;
252 $form2 = $form->withRequest($request);
254 $this->assertNotSame($form2, $form);
255 $this->assertInstanceOf(Form::class, $form2);
256 $this->assertEquals([
"foo" => $input_1,
"bar" => $input_2], $form2->getInputs());
262 $request = $this->createMock(ServerRequestInterface::class);
264 ->expects($this->once())
265 ->method(
"getParsedBody")
270 ->expects($this->once())
271 ->method(
"getContent")
272 ->willReturn($df->ok(1));
274 ->expects($this->once())
275 ->method(
"withInput")
276 ->willReturn($input_1);
280 ->expects($this->once())
281 ->method(
"getContent")
282 ->willReturn($df->ok(2));
284 ->expects($this->once())
285 ->method(
"withInput")
286 ->willReturn($input_2);
289 $form->setInputs([$input_1, $input_2]);
290 $form = $form->withRequest($request);
291 $this->assertEquals([1, 2], $form->getData());
297 $request = $this->createMock(ServerRequestInterface::class);
299 ->expects($this->once())
300 ->method(
"getParsedBody")
305 ->expects($this->once())
306 ->method(
"getContent")
307 ->willReturn($df->ok(1));
309 ->expects($this->once())
310 ->method(
"withInput")
311 ->willReturn($input_1);
315 ->expects($this->once())
316 ->method(
"getContent")
317 ->willReturn($df->ok(2));
319 ->expects($this->once())
320 ->method(
"withInput")
321 ->willReturn($input_2);
324 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
325 $form = $form->withRequest($request);
326 $this->assertEquals([
"foo" => 1,
"bar" => 2], $form->getData());
332 $request = $this->createMock(ServerRequestInterface::class);
334 ->expects($this->once())
335 ->method(
"getParsedBody")
340 ->expects($this->once())
341 ->method(
"getContent")
342 ->willReturn($df->error(
"error"));
344 ->expects($this->once())
345 ->method(
"withInput")
346 ->willReturn($input_1);
350 ->expects($this->once())
351 ->method(
"getContent")
352 ->willReturn($df->ok(2));
354 ->expects($this->once())
355 ->method(
"withInput")
356 ->willReturn($input_2);
359 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
361 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
363 ->expects($this->once())
365 ->with(
"ui_error_in_group")
369 $form = $form->withRequest($request);
370 $this->assertEquals(
null,
null);
376 $request = $this->createMock(ServerRequestInterface::class);
378 ->expects($this->once())
379 ->method(
"getParsedBody")
384 ->expects($this->once())
385 ->method(
"getContent")
386 ->willReturn($df->ok(1));
388 ->expects($this->once())
389 ->method(
"withInput")
390 ->willReturn($input_1);
394 ->expects($this->once())
395 ->method(
"getContent")
396 ->willReturn($df->ok(2));
398 ->expects($this->once())
399 ->method(
"withInput")
400 ->willReturn($input_2);
403 $form->setInputs([$input_1, $input_2]);
406 return "transformed";
409 $this->assertNotSame($form2, $form);
410 $form2 = $form2->withRequest($request);
412 $this->assertEquals(
"transformed", $form2->getData());
420 "foo" => $if->text(
""),
426 $named_inputs = $form->getInputs();
427 $this->assertEquals(array_keys(
$inputs), array_keys($named_inputs));
437 ->getMockBuilder(
Input\Field\FormInputInternal::class)
456 "withAdditionalTransformation",
457 "getUpdateOnLoadCode",
460 "withAdditionalOnLoadCode",
464 "withResetTriggeredSignals",
465 "getTriggeredSignals",
468 ->setMockClassName(
"Mock_InputNo" . ($no++))
476 $inputs = [$if->text(
""), $if->text(
"")];
479 $this->assertFalse($form->hasRequiredInputs());
487 $if->text(
"")->withRequired(
true),
491 $this->assertTrue($form->hasRequiredInputs());
getNewName()
Generates a unique name on every call.
Builds a Color from either hex- or rgb values.
Provides common functionality for UI tests.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.