18declare(strict_types=1);
20require_once(__DIR__ .
"/../../../../Base.php");
30use Psr\Http\Message\ServerRequestInterface;
34use PHPUnit\Framework\MockObject\MockObject;
66 if ($this->input_data !==
null) {
70 return parent::extractRequestData($request);
76 $this->input_group = $this->input_factory->group(
$inputs);
100 $this->
language = $this->createMock(ilLanguage::class);
112 return new I\Button\Factory();
118 $language = $this->createMock(ilLanguage::class);
121 return $refinery->custom()->transformation($trafo);
140 $inputs = [$if->text(
""), $if->text(
"")];
144 $form_inputs = $form->getInputs();
145 $this->assertSameSize(
$inputs, $form_inputs);
147 foreach ($form_inputs as $input) {
148 $name = $input->getName();
149 $name_source->name =
$name;
152 $this->assertIsString(
$name);
155 $input = array_shift($form_inputs);
156 $this->assertEquals($input->withNameFrom($name_source), $input);
159 $this->assertNotContains(
$name, $seen_names);
160 $seen_names[] =
$name;
167 $request = $this->createMock(ServerRequestInterface::class);
169 ->expects($this->once())
170 ->method(
"getParsedBody")
172 $input_data = $form->_extractRequestData($request);
173 $this->assertInstanceOf(InputData::class, $input_data);
179 $request = $this->createMock(ServerRequestInterface::class);
180 $input_data = $this->createMock(InputData::class);
184 ->expects($this->once())
185 ->method(
"withInput")
187 ->willReturn($input_1);
189 ->expects($this->once())
190 ->method(
"getContent")
191 ->willReturn($df->ok(0));
195 ->expects($this->once())
196 ->method(
"withInput")
198 ->willReturn($input_2);
200 ->expects($this->once())
201 ->method(
"getContent")
202 ->willReturn($df->ok(0));
205 $form->setInputs([$input_1, $input_2]);
206 $form->input_data = $input_data;
208 $form2 = $form->withRequest($request);
210 $this->assertNotSame($form2, $form);
211 $this->assertInstanceOf(Form::class, $form2);
212 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
218 $request = $this->createMock(ServerRequestInterface::class);
219 $input_data = $this->createMock(InputData::class);
223 ->expects($this->once())
224 ->method(
"withInput")
226 ->willReturn($input_1);
228 ->expects($this->once())
229 ->method(
"getContent")
230 ->willReturn($df->ok(0));
234 ->expects($this->once())
235 ->method(
"withInput")
237 ->willReturn($input_2);
239 ->expects($this->once())
240 ->method(
"getContent")
241 ->willReturn($df->ok(0));
244 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
245 $form->input_data = $input_data;
247 $form2 = $form->withRequest($request);
249 $this->assertNotSame($form2, $form);
250 $this->assertInstanceOf(Form::class, $form2);
251 $this->assertEquals([
"foo" => $input_1,
"bar" => $input_2], $form2->getInputs());
257 $request = $this->createMock(ServerRequestInterface::class);
259 ->expects($this->once())
260 ->method(
"getParsedBody")
265 ->expects($this->once())
266 ->method(
"getContent")
267 ->willReturn($df->ok(1));
269 ->expects($this->once())
270 ->method(
"withInput")
271 ->willReturn($input_1);
275 ->expects($this->once())
276 ->method(
"getContent")
277 ->willReturn($df->ok(2));
279 ->expects($this->once())
280 ->method(
"withInput")
281 ->willReturn($input_2);
284 $form->setInputs([$input_1, $input_2]);
285 $form = $form->withRequest($request);
286 $this->assertEquals([1, 2], $form->getData());
292 $request = $this->createMock(ServerRequestInterface::class);
294 ->expects($this->once())
295 ->method(
"getParsedBody")
300 ->expects($this->once())
301 ->method(
"getContent")
302 ->willReturn($df->ok(1));
304 ->expects($this->once())
305 ->method(
"withInput")
306 ->willReturn($input_1);
310 ->expects($this->once())
311 ->method(
"getContent")
312 ->willReturn($df->ok(2));
314 ->expects($this->once())
315 ->method(
"withInput")
316 ->willReturn($input_2);
319 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
320 $form = $form->withRequest($request);
321 $this->assertEquals([
"foo" => 1,
"bar" => 2], $form->getData());
327 $request = $this->createMock(ServerRequestInterface::class);
329 ->expects($this->once())
330 ->method(
"getParsedBody")
335 ->expects($this->once())
336 ->method(
"getContent")
337 ->willReturn($df->error(
"error"));
339 ->expects($this->once())
340 ->method(
"withInput")
341 ->willReturn($input_1);
345 ->expects($this->once())
346 ->method(
"getContent")
347 ->willReturn($df->ok(2));
349 ->expects($this->once())
350 ->method(
"withInput")
351 ->willReturn($input_2);
354 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
356 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
358 ->expects($this->once())
360 ->with(
"ui_error_in_group")
364 $form = $form->withRequest($request);
365 $this->assertEquals(
null,
null);
371 $request = $this->createMock(ServerRequestInterface::class);
373 ->expects($this->once())
374 ->method(
"getParsedBody")
379 ->expects($this->once())
380 ->method(
"getContent")
381 ->willReturn($df->ok(1));
383 ->expects($this->once())
384 ->method(
"withInput")
385 ->willReturn($input_1);
389 ->expects($this->once())
390 ->method(
"getContent")
391 ->willReturn($df->ok(2));
393 ->expects($this->once())
394 ->method(
"withInput")
395 ->willReturn($input_2);
398 $form->setInputs([$input_1, $input_2]);
401 return "transformed";
404 $this->assertNotSame($form2, $form);
405 $form2 = $form2->withRequest($request);
407 $this->assertEquals(
"transformed", $form2->getData());
415 "foo" => $if->text(
""),
421 $named_inputs = $form->getInputs();
422 $this->assertEquals(array_keys(
$inputs), array_keys($named_inputs));
432 ->getMockBuilder(
Input\Field\FormInputInternal::class)
451 "withAdditionalTransformation",
452 "getUpdateOnLoadCode",
455 "withAdditionalOnLoadCode",
459 "withResetTriggeredSignals",
460 "getTriggeredSignals"
462 ->setMockClassName(
"Mock_InputNo" . ($no++))
470 $inputs = [$if->text(
""), $if->text(
"")];
473 $this->assertFalse($form->hasRequiredInputs());
481 $if->text(
"")->withRequired(
true),
485 $this->assertTrue($form->hasRequiredInputs());
getNewName()
Generates a unique name on every call.
Provides common functionality for UI tests.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
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 \MainMenu\Provider.