5 require_once(__DIR__ .
"/../../../../Base.php");
8 use \ILIAS\UI\Implementation\Component\Input\Field\InputInternal;
9 use \ILIAS\UI\Implementation\Component\Input\NameSource;
10 use \ILIAS\UI\Implementation\Component\Input\InputData;
11 use \ILIAS\UI\Implementation\Component\Input\Container\Form\Form;
31 public $input_data = null;
35 $this->input_factory = $field_factory;
41 return $this->extractPostData($request);
47 if ($this->input_data !== null) {
48 return $this->input_data;
51 return parent::extractPostData($request);
57 $this->input_group = $this->input_factory->group($inputs);
58 $this->inputs = $inputs;
64 return $this->getPostInput($request);
81 $df =
new Data\Factory();
82 $this->
language = $this->createMock(\ilLanguage::class);
100 $dataFactory =
new Data\Factory();
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;
122 $f = $this->buildFactory();
123 $if = $this->buildInputFactory();
126 $inputs = [
$if->text(
""),
$if->text(
"")];
127 $form =
new ConcreteForm($this->buildInputFactory(), $inputs);
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;
153 $form =
new ConcreteForm($this->buildInputFactory(), []);
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);
166 $df = $this->buildDataFactory();
167 $request = $this->createMock(ServerRequestInterface::class);
168 $input_data = $this->createMock(InputData::class);
170 $input_1 = $this->inputMock();
172 ->expects($this->once())
173 ->method(
"withInput")
175 ->willReturn($input_1);
177 ->expects($this->once())
178 ->method(
"getContent")
179 ->willReturn($df->ok(0));
181 $input_2 = $this->inputMock();
183 ->expects($this->once())
184 ->method(
"withInput")
186 ->willReturn($input_2);
188 ->expects($this->once())
189 ->method(
"getContent")
190 ->willReturn($df->ok(0));
192 $form =
new ConcreteForm($this->buildInputFactory(), []);
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());
206 $df = $this->buildDataFactory();
207 $request = $this->createMock(ServerRequestInterface::class);
208 $input_data = $this->createMock(InputData::class);
210 $input_1 = $this->inputMock();
212 ->expects($this->once())
213 ->method(
"withInput")
215 ->willReturn($input_1);
217 ->expects($this->once())
218 ->method(
"getContent")
219 ->willReturn($df->ok(0));
221 $input_2 = $this->inputMock();
223 ->expects($this->once())
224 ->method(
"withInput")
226 ->willReturn($input_2);
228 ->expects($this->once())
229 ->method(
"getContent")
230 ->willReturn($df->ok(0));
232 $form =
new ConcreteForm($this->buildInputFactory(), []);
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());
246 $df = $this->buildDataFactory();
247 $request = $this->createMock(ServerRequestInterface::class);
249 ->expects($this->once())
250 ->method(
"getParsedBody")
253 $input_1 = $this->inputMock();
255 ->expects($this->once())
256 ->method(
"getContent")
257 ->willReturn($df->ok(1));
259 ->expects($this->once())
260 ->method(
"withInput")
261 ->willReturn($input_1);
263 $input_2 = $this->inputMock();
265 ->expects($this->once())
266 ->method(
"getContent")
267 ->willReturn($df->ok(2));
269 ->expects($this->once())
270 ->method(
"withInput")
271 ->willReturn($input_2);
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());
282 $df = $this->buildDataFactory();
283 $request = $this->createMock(ServerRequestInterface::class);
285 ->expects($this->once())
286 ->method(
"getParsedBody")
289 $input_1 = $this->inputMock();
291 ->expects($this->once())
292 ->method(
"getContent")
293 ->willReturn($df->ok(1));
295 ->expects($this->once())
296 ->method(
"withInput")
297 ->willReturn($input_1);
299 $input_2 = $this->inputMock();
301 ->expects($this->once())
302 ->method(
"getContent")
303 ->willReturn($df->ok(2));
305 ->expects($this->once())
306 ->method(
"withInput")
307 ->willReturn($input_2);
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());
318 $df = $this->buildDataFactory();
319 $request = $this->createMock(ServerRequestInterface::class);
321 ->expects($this->once())
322 ->method(
"getParsedBody")
325 $input_1 = $this->inputMock();
327 ->expects($this->once())
328 ->method(
"getContent")
329 ->willReturn($df->error(
"error"));
331 ->expects($this->once())
332 ->method(
"withInput")
333 ->willReturn($input_1);
335 $input_2 = $this->inputMock();
337 ->expects($this->once())
338 ->method(
"getContent")
339 ->willReturn($df->ok(2));
341 ->expects($this->once())
342 ->method(
"withInput")
343 ->willReturn($input_2);
345 $form =
new ConcreteForm($this->buildInputFactory(), []);
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);
363 $df = $this->buildDataFactory();
364 $request = $this->createMock(ServerRequestInterface::class);
366 ->expects($this->once())
367 ->method(
"getParsedBody")
370 $input_1 = $this->inputMock();
372 ->expects($this->once())
373 ->method(
"getContent")
374 ->willReturn($df->ok(1));
376 ->expects($this->once())
377 ->method(
"withInput")
378 ->willReturn($input_1);
380 $input_2 = $this->inputMock();
382 ->expects($this->once())
383 ->method(
"getContent")
384 ->willReturn($df->ok(2));
386 ->expects($this->once())
387 ->method(
"withInput")
388 ->willReturn($input_2);
390 $form =
new ConcreteForm($this->buildInputFactory(), []);
391 $form->setInputs([$input_1, $input_2]);
393 $form2 = $form->withAdditionalTransformation($this->buildTransformation(
function ($v) {
394 return "transformed";
397 $this->assertNotSame($form2, $form);
398 $form2 = $form2->withRequest($request);
400 $this->assertEquals(
"transformed", $form2->getData());
406 $if = $this->buildInputFactory();
409 "foo" =>
$if->text(
""),
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));
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++))
Class ChatMainBarProvider .
getNewName()
Generates a unique name on every call.
Provides common functionality for UI tests.
__construct(Container $dic, ilPlugin $plugin)