5require_once(__DIR__ .
"/../../../../Base.php");
8use \ILIAS\UI\Implementation\Component\Input\Field\InputInternal;
9use \ILIAS\UI\Implementation\Component\Input\NameSource;
10use \ILIAS\UI\Implementation\Component\Input\InputData;
11use \ILIAS\UI\Implementation\Component\Input\Container\Form\Form;
17use Psr\Http\Message\ServerRequestInterface;
35 $this->input_factory = $field_factory;
47 if ($this->input_data !==
null) {
51 return parent::extractPostData($request);
57 $this->input_group = $this->input_factory->group($inputs);
58 $this->inputs = $inputs;
64 return $this->getPostInput($request);
82 $this->
language = $this->createMock(\ilLanguage::class);
101 $language = $this->createMock(\ilLanguage::class);
102 $refinery = new \ILIAS\Refinery\Factory($dataFactory, $language);
104 return $refinery->custom()->transformation($trafo);
116 return new \ILIAS\Data\Factory;
126 $inputs = [
$if->text(
""),
$if->text(
"")];
130 $inputs = $form->getInputs();
131 $this->assertEquals(count($inputs), count($inputs));
133 foreach ($inputs as $input) {
134 $name = $input->getName();
135 $name_source->name =
$name;
138 $this->assertIsString(
$name);
141 $input = array_shift($inputs);
142 $this->assertEquals($input->withNameFrom($name_source), $input);
145 $this->assertNotContains(
$name, $seen_names);
146 $seen_names[] =
$name;
154 $request = $this->createMock(ServerRequestInterface::class);
156 ->expects($this->once())
157 ->method(
"getParsedBody")
159 $input_data = $form->_extractPostData($request);
160 $this->assertInstanceOf(InputData::class, $input_data);
167 $request = $this->createMock(ServerRequestInterface::class);
168 $input_data = $this->createMock(InputData::class);
172 ->expects($this->once())
173 ->method(
"withInput")
175 ->willReturn($input_1);
177 ->expects($this->once())
178 ->method(
"getContent")
179 ->willReturn($df->ok(0));
183 ->expects($this->once())
184 ->method(
"withInput")
186 ->willReturn($input_2);
188 ->expects($this->once())
189 ->method(
"getContent")
190 ->willReturn($df->ok(0));
193 $form->setInputs([$input_1, $input_2]);
194 $form->input_data = $input_data;
196 $form2 = $form->withRequest($request);
198 $this->assertNotSame($form2, $form);
199 $this->assertInstanceOf(Form::class, $form2);
200 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
207 $request = $this->createMock(ServerRequestInterface::class);
208 $input_data = $this->createMock(InputData::class);
212 ->expects($this->once())
213 ->method(
"withInput")
215 ->willReturn($input_1);
217 ->expects($this->once())
218 ->method(
"getContent")
219 ->willReturn($df->ok(0));
223 ->expects($this->once())
224 ->method(
"withInput")
226 ->willReturn($input_2);
228 ->expects($this->once())
229 ->method(
"getContent")
230 ->willReturn($df->ok(0));
233 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
234 $form->input_data = $input_data;
236 $form2 = $form->withRequest($request);
238 $this->assertNotSame($form2, $form);
239 $this->assertInstanceOf(Form::class, $form2);
240 $this->assertEquals([
"foo" => $input_1,
"bar" => $input_2], $form2->getInputs());
247 $request = $this->createMock(ServerRequestInterface::class);
249 ->expects($this->once())
250 ->method(
"getParsedBody")
255 ->expects($this->once())
256 ->method(
"getContent")
257 ->willReturn($df->ok(1));
259 ->expects($this->once())
260 ->method(
"withInput")
261 ->willReturn($input_1);
265 ->expects($this->once())
266 ->method(
"getContent")
267 ->willReturn($df->ok(2));
269 ->expects($this->once())
270 ->method(
"withInput")
271 ->willReturn($input_2);
274 $form->setInputs([$input_1, $input_2]);
275 $form = $form->withRequest($request);
276 $this->assertEquals([1, 2], $form->getData());
283 $request = $this->createMock(ServerRequestInterface::class);
285 ->expects($this->once())
286 ->method(
"getParsedBody")
291 ->expects($this->once())
292 ->method(
"getContent")
293 ->willReturn($df->ok(1));
295 ->expects($this->once())
296 ->method(
"withInput")
297 ->willReturn($input_1);
301 ->expects($this->once())
302 ->method(
"getContent")
303 ->willReturn($df->ok(2));
305 ->expects($this->once())
306 ->method(
"withInput")
307 ->willReturn($input_2);
310 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
311 $form = $form->withRequest($request);
312 $this->assertEquals([
"foo" => 1,
"bar" => 2], $form->getData());
319 $request = $this->createMock(ServerRequestInterface::class);
321 ->expects($this->once())
322 ->method(
"getParsedBody")
327 ->expects($this->once())
328 ->method(
"getContent")
329 ->willReturn($df->error(
"error"));
331 ->expects($this->once())
332 ->method(
"withInput")
333 ->willReturn($input_1);
337 ->expects($this->once())
338 ->method(
"getContent")
339 ->willReturn($df->ok(2));
341 ->expects($this->once())
342 ->method(
"withInput")
343 ->willReturn($input_2);
346 $form->setInputs([
"foo" => $input_1,
"bar" => $input_2]);
348 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
350 ->expects($this->once())
352 ->with(
"ui_error_in_group")
356 $form = $form->withRequest($request);
357 $this->assertEquals(
null,
null);
364 $request = $this->createMock(ServerRequestInterface::class);
366 ->expects($this->once())
367 ->method(
"getParsedBody")
372 ->expects($this->once())
373 ->method(
"getContent")
374 ->willReturn($df->ok(1));
376 ->expects($this->once())
377 ->method(
"withInput")
378 ->willReturn($input_1);
382 ->expects($this->once())
383 ->method(
"getContent")
384 ->willReturn($df->ok(2));
386 ->expects($this->once())
387 ->method(
"withInput")
388 ->willReturn($input_2);
391 $form->setInputs([$input_1, $input_2]);
394 return "transformed";
397 $this->assertNotSame($form2, $form);
398 $form2 = $form2->withRequest($request);
400 $this->assertEquals(
"transformed", $form2->getData());
409 "foo" =>
$if->text(
""),
414 $form->setInputs($inputs);
415 $named_inputs = $form->getInputs();
416 $this->assertEquals(array_keys($inputs), array_keys($named_inputs));
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++))
An exception for terminatinating execution or to throw for unit testing.
getNewName()
Generates a unique name on every call.
Provides common functionality for UI tests.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.