5require_once(__DIR__ .
"/../../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ .
"/../../../Base.php");
8use \ILIAS\UI\Implementation\Component\Input\Field\Input;
9use \ILIAS\UI\Implementation\Component\Input\NameSource;
10use \ILIAS\UI\Implementation\Component\Input\InputData;
11use \ILIAS\Data\Factory as DataFactory;
12use \ILIAS\Data\Result;
48 $name =
"name_{$this->count}";
68 if (!is_string(
$name)) {
69 throw new \InvalidArgumentException(
'$name is no string.');
71 if (!isset($this->values[
$name])) {
72 throw new \LogicException(
"'$name' does not exist.");
75 return $this->values[
$name];
81 if (!is_string(
$name)) {
82 throw new \InvalidArgumentException(
'$name is no string.');
84 if (!isset($this->values[
$name])) {
88 return $this->values[
$name];
105 $this->data_factory =
new DataFactory();
106 $language = $this->createMock(\ilLanguage::class);
107 $this->refinery = new \ILIAS\Refinery\Factory($this->data_factory, $language);
120 $this->assertEquals(
"label", $this->input->getLabel());
121 $this->assertEquals(
"byline", $this->input->getByline());
127 $label =
"new label";
128 $input = $this->input->withLabel($label);
129 $this->assertEquals($label, $input->getLabel());
130 $this->assertNotSame($this->input, $input);
136 $byline =
"new byline";
137 $input = $this->input->withByline($byline);
138 $this->assertEquals($byline, $input->getByline());
139 $this->assertNotSame($this->input, $input);
145 $this->assertFalse($this->input->isRequired());
146 $input = $this->input->withRequired(
true);
147 $this->assertTrue($input->isRequired());
148 $input = $input->withRequired(
false);
149 $this->assertFalse($input->isRequired());
155 $this->assertFalse($this->input->isDisabled());
156 $input = $this->input->withDisabled(
true);
157 $this->assertTrue($input->isDisabled());
158 $input = $input->withDisabled(
false);
159 $this->assertFalse($input->isDisabled());
165 $value =
"some value";
166 $input = $this->input->withValue($value);
167 $this->assertEquals(
null, $this->input->getValue());
168 $this->assertEquals($value, $input->getValue());
169 $this->assertNotSame($this->input, $input);
175 $this->input->value_ok =
false;
178 $this->input->withValue(
"foo");
179 $this->assertFalse(
"This should not happen.");
180 }
catch (\InvalidArgumentException
$e) {
183 $this->assertTrue($raised);
184 $this->assertEquals(
null, $this->input->getValue());
191 $input = $this->input->withNameFrom($this->name_source);
192 $this->assertEquals(
null, $this->input->getName());
193 $this->assertEquals(
$name, $input->getName());
194 $this->assertNotSame($this->input, $input);
195 $this->assertEquals(1, $this->name_source->count);
202 $input = $this->input->withError($error);
203 $this->assertEquals(
null, $this->input->getError());
204 $this->assertEquals($error, $input->getError());
205 $this->assertNotSame($this->input, $input);
211 $this->expectException(\LogicException::class);
213 $this->input->getContent();
221 $input = $this->input->withNameFrom($this->name_source);
224 $input2 = $input->withInput($values);
225 $res = $input2->getContent();
227 $this->assertInstanceOf(Result::class,
$res);
228 $this->assertTrue(
$res->isOk());
229 $this->assertEquals($value,
$res->value());
231 $this->assertNotSame($input, $input2);
232 $this->assertEquals($value, $input2->getValue());
241 $this->assertFalse(
"This should not happen.");
242 }
catch (\LogicException
$e) {
245 $this->assertTrue($raised);
253 $transform_to =
"other value";
254 $input = $this->input->withNameFrom($this->name_source);
257 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use ($value, $transform_to) {
258 $this->assertEquals($value, $v);
260 return $transform_to;
261 }))->withInput($values);
262 $res = $input2->getContent();
264 $this->assertInstanceOf(Result::class,
$res);
265 $this->assertTrue(
$res->isOk());
266 $this->assertEquals($transform_to,
$res->value());
268 $this->assertNotSame($input, $input2);
269 $this->assertEquals($value, $input2->getValue());
277 $transform_to =
"other value";
278 $input = $this->input->withNameFrom($this->name_source);
281 $input2 = $input->withInput($values)->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (
285 $this->assertEquals($value, $v);
287 return $transform_to;
289 $res = $input2->getContent();
291 $this->assertInstanceOf(Result::class,
$res);
292 $this->assertTrue(
$res->isOk());
293 $this->assertEquals($transform_to,
$res->value());
295 $this->assertNotSame($input, $input2);
296 $this->assertEquals($value, $input2->getValue());
305 $input = $this->input->withNameFrom($this->name_source);
308 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->constraint(function ($_) {
310 }, $error))->withInput($values);
311 $res = $input2->getContent();
313 $this->assertInstanceOf(Result::class,
$res);
314 $this->assertTrue(
$res->isOk());
315 $this->assertEquals($value,
$res->value());
317 $this->assertNotSame($input, $input2);
318 $this->assertEquals($value, $input2->getValue());
319 $this->assertEquals(
null, $input2->getError());
328 $input = $this->input->withNameFrom($this->name_source);
331 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->constraint(function ($_) {
333 }, $error))->withInput($values);
334 $res = $input2->getContent();
336 $this->assertInstanceOf(Result::class,
$res);
337 $this->assertTrue(
$res->isError());
338 $this->assertEquals($error,
$res->error());
340 $this->assertNotSame($input, $input2);
341 $this->assertEquals($value, $input2->getValue());
342 $this->assertEquals($error, $input2->getError());
348 $rc = $this->refinery->custom();
353 $input = $this->input->withNameFrom($this->name_source);
358 ->withAdditionalTransformation($rc->constraint(function ($_) {
362 $res = $input2->getContent();
364 $this->assertInstanceOf(Result::class,
$res);
365 $this->assertTrue(
$res->isError());
366 $this->assertEquals($error,
$res->error());
368 $this->assertNotSame($input, $input2);
369 $this->assertEquals($value, $input2->getValue());
370 $this->assertEquals($error, $input2->getError());
378 $transform_to =
"other value";
380 $input = $this->input->withNameFrom($this->name_source);
383 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use ($value, $transform_to) {
384 $this->assertEquals($value, $v);
386 return $transform_to;
387 }))->withAdditionalTransformation($this->refinery->custom()->constraint(
function ($v) use ($transform_to) {
388 $this->assertEquals($transform_to, $v);
391 }, $error))->withInput($values);
392 $res = $input2->getContent();
394 $this->assertInstanceOf(Result::class,
$res);
395 $this->assertTrue(
$res->isOk());
396 $this->assertEquals($transform_to,
$res->value());
398 $this->assertNotSame($input, $input2);
399 $this->assertEquals($value, $input2->getValue());
400 $this->assertEquals(
null, $input2->getError());
408 $transform_to =
"other value";
410 $input = $this->input->withNameFrom($this->name_source);
413 $input2 = $input->withInput($values)->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (
417 $this->assertEquals($value, $v);
419 return $transform_to;
420 }))->withAdditionalTransformation($this->refinery->custom()->constraint(
function ($v) use ($transform_to) {
421 $this->assertEquals($transform_to, $v);
425 $res = $input2->getContent();
427 $this->assertInstanceOf(Result::class,
$res);
428 $this->assertTrue(
$res->isOk());
429 $this->assertEquals($transform_to,
$res->value());
431 $this->assertNotSame($input, $input2);
432 $this->assertEquals($value, $input2->getValue());
433 $this->assertEquals(
null, $input2->getError());
441 $transform_to =
"other value";
443 $input = $this->input->withNameFrom($this->name_source);
446 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->constraint(function ($v) use ($value) {
447 $this->assertEquals($value, $v);
450 }, $error))->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) use ($value, $transform_to) {
451 $this->assertEquals($value, $v);
453 return $transform_to;
454 }))->withInput($values);
455 $res = $input2->getContent();
457 $this->assertInstanceOf(Result::class,
$res);
458 $this->assertTrue(
$res->isOk());
459 $this->assertEquals($transform_to,
$res->value());
461 $this->assertNotSame($input, $input2);
462 $this->assertEquals($value, $input2->getValue());
463 $this->assertEquals(
null, $input2->getError());
469 $rc = $this->refinery->custom();
473 $transform_to =
"other value";
475 $input = $this->input->withNameFrom($this->name_source);
479 ->withAdditionalTransformation($rc->constraint(function ($v) use ($value) {
480 $this->assertEquals($value, $v);
484 ->withAdditionalTransformation($rc->transformation(function ($v) use ($value, $transform_to) {
485 $this->assertFalse(
"This should not happen");
487 return $transform_to;
488 }))->withInput($values);
489 $res = $input2->getContent();
491 $this->assertInstanceOf(Result::class,
$res);
492 $this->assertTrue(
$res->isError());
493 $this->assertEquals($error,
$res->error());
495 $this->assertNotSame($input, $input2);
496 $this->assertEquals($value, $input2->getValue());
497 $this->assertEquals($error, $input2->getError());
505 $transform_to =
"other value";
507 $input = $this->input->withNameFrom($this->name_source);
510 $input2 = $input->withInput($values)->withAdditionalTransformation($this->refinery->custom()->constraint(function ($v) use ($value) {
511 $this->assertEquals($value, $v);
514 }, $error))->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) use ($value, $transform_to) {
515 $this->assertFalse(
"This should not happen");
517 return $transform_to;
519 $res = $input2->getContent();
521 $this->assertInstanceOf(Result::class,
$res);
522 $this->assertTrue(
$res->isError());
523 $this->assertEquals($error,
$res->error());
525 $this->assertNotSame($input, $input2);
526 $this->assertEquals($value, $input2->getValue());
527 $this->assertEquals($error, $input2->getError());
536 $input = $this->input->withNameFrom($this->name_source);
539 $input->requirement_constraint = $this->refinery->custom()->constraint(
function ($_) {
543 $input2 = $input->withRequired(
true)->withInput($values);
544 $res = $input2->getContent();
546 $this->assertInstanceOf(Result::class,
$res);
547 $this->assertTrue(
$res->isError());
548 $this->assertEquals($error,
$res->error());
550 $this->assertNotSame($input, $input2);
551 $this->assertEquals($value, $input2->getValue());
552 $this->assertEquals($error, $input2->getError());
561 $input = $this->input->withNameFrom($this->name_source);
564 $input->requirement_constraint = $this->refinery->custom()->constraint(
function ($_) {
568 $input2 = $input->withRequired(
true)->withRequired(
false)->withInput($values);
569 $res = $input2->getContent();
571 $this->assertInstanceOf(Result::class,
$res);
572 $this->assertFalse(
$res->isError());
573 $this->assertEquals($value,
$res->value());
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.
foreach($_POST as $key=> $value) $res