19declare(strict_types=1);
21require_once(__DIR__ .
"/../../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ .
"/../../../Base.php");
49 return function ():
void {
60 $name =
"name_{$this->count}";
68 $name = $dedicated_name .
"_{$this->count}";
87 public function get(
string $name)
89 if (!is_string($name)) {
90 throw new InvalidArgumentException(
'$name is no string.');
92 if (!isset($this->values[$name])) {
93 throw new LogicException(
"'$name' does not exist.");
96 return $this->values[$name];
102 public function getOr(
string $name, $default)
104 if (!is_string($name)) {
105 throw new InvalidArgumentException(
'$name is no string.');
107 if (!isset($this->values[$name])) {
111 return $this->values[$name];
114 public function has($name): bool
116 return array_key_exists($name, $this->values);
134 $this->data_factory =
new DataFactory();
135 $language = $this->createMock(
ILIAS\
Language\Language::class);
143 $this->named_input = $this->input->withDedicatedName(
'dedicated_name');
149 $this->assertEquals(
"label", $this->input->getLabel());
150 $this->assertEquals(
"byline", $this->input->getByline());
155 $label =
"new label";
158 $this->assertNotSame($this->input,
$input);
163 $byline =
"new byline";
166 $this->assertNotSame($this->input,
$input);
171 $this->assertFalse($this->input->isRequired());
180 $custom_constraint = $this->
refinery->custom()->constraint(
182 return (substr($value, 0, 1) ===
'H') ?
true :
false;
184 "Your name does not start with an H"
188 $this->assertEquals(
$input->requirement_constraint, $custom_constraint);
193 $this->assertFalse($this->input->isDisabled());
202 $value =
"some value";
204 $this->assertEquals(
null, $this->input->getValue());
206 $this->assertNotSame($this->input,
$input);
211 $this->input->value_ok =
false;
214 $this->input->withValue(
"foo");
215 $this->assertFalse(
"This should not happen.");
216 }
catch (InvalidArgumentException
$e) {
219 $this->assertTrue($raised);
220 $this->assertEquals(
null, $this->input->getValue());
227 $this->assertEquals(
null, $this->input->getName());
229 $this->assertNotSame($this->input,
$input);
230 $this->assertEquals(1, $this->name_source->count);
235 $name =
"dedicated_name_0";
237 $this->assertEquals(
null, $this->named_input->getName());
239 $this->assertNotSame($this->named_input,
$input);
240 $this->assertEquals(1, $this->name_source->count);
247 $this->assertEquals(
null, $this->input->getError());
249 $this->assertNotSame($this->input,
$input);
254 $this->expectException(LogicException::class);
256 $this->input->getContent();
267 $res = $input2->getContent();
269 $this->assertInstanceOf(Result::class,
$res);
270 $this->assertTrue(
$res->isOk());
271 $this->assertEquals($value,
$res->value());
273 $this->assertNotSame(
$input, $input2);
274 $this->assertEquals($value, $input2->getValue());
282 $this->assertFalse(
"This should not happen.");
283 }
catch (LogicException
$e) {
286 $this->assertTrue($raised);
293 $transform_to =
"other value";
298 $this->
refinery->custom()->transformation(function ($v) use ($value, $transform_to):
string {
299 $this->assertEquals($value, $v);
300 return $transform_to;
302 )->withInput($values);
304 $res = $input2->getContent();
306 $this->assertInstanceOf(Result::class,
$res);
307 $this->assertTrue(
$res->isOk());
308 $this->assertEquals($transform_to,
$res->value());
310 $this->assertNotSame(
$input, $input2);
311 $this->assertEquals($value, $input2->getValue());
318 $transform_to =
"other value";
323 $this->
refinery->custom()->transformation(function ($v) use ($value, $transform_to):
string {
324 $this->assertEquals($value, $v);
325 return $transform_to;
329 $res = $input2->getContent();
331 $this->assertInstanceOf(Result::class,
$res);
332 $this->assertTrue(
$res->isOk());
333 $this->assertEquals($transform_to,
$res->value());
335 $this->assertNotSame(
$input, $input2);
336 $this->assertEquals($value, $input2->getValue());
349 }, $error))->withInput($values);
350 $res = $input2->getContent();
352 $this->assertInstanceOf(Result::class,
$res);
353 $this->assertTrue(
$res->isOk());
354 $this->assertEquals($value,
$res->value());
356 $this->assertNotSame(
$input, $input2);
357 $this->assertEquals($value, $input2->getValue());
358 $this->assertEquals(
null, $input2->getError());
371 }, $error))->withInput($values);
372 $res = $input2->getContent();
374 $this->assertInstanceOf(Result::class,
$res);
375 $this->assertTrue(
$res->isError());
376 $this->assertEquals($error,
$res->error());
378 $this->assertNotSame(
$input, $input2);
379 $this->assertEquals($value, $input2->getValue());
380 $this->assertEquals($error, $input2->getError());
395 ->withAdditionalTransformation($rc->constraint(function () {
399 $res = $input2->getContent();
401 $this->assertInstanceOf(Result::class,
$res);
402 $this->assertTrue(
$res->isError());
403 $this->assertEquals($error,
$res->error());
405 $this->assertNotSame(
$input, $input2);
406 $this->assertEquals($value, $input2->getValue());
407 $this->assertEquals($error, $input2->getError());
414 $transform_to =
"other value";
420 $this->
refinery->custom()->transformation(function ($v) use ($value, $transform_to):
string {
421 $this->assertEquals($value, $v);
422 return $transform_to;
424 )->withAdditionalTransformation(
425 $this->
refinery->custom()->constraint(
function ($v) use ($transform_to):
bool {
426 $this->assertEquals($transform_to, $v);
429 )->withInput($values);
431 $res = $input2->getContent();
433 $this->assertInstanceOf(Result::class,
$res);
434 $this->assertTrue(
$res->isOk());
435 $this->assertEquals($transform_to,
$res->value());
437 $this->assertNotSame(
$input, $input2);
438 $this->assertEquals($value, $input2->getValue());
439 $this->assertEquals(
null, $input2->getError());
446 $transform_to =
"other value";
452 $this->
refinery->custom()->transformation(function ($v) use ($value, $transform_to):
string {
453 $this->assertEquals($value, $v);
454 return $transform_to;
456 )->withAdditionalTransformation(
457 $this->
refinery->custom()->constraint(
function ($v) use ($transform_to):
bool {
458 $this->assertEquals($transform_to, $v);
463 $res = $input2->getContent();
465 $this->assertInstanceOf(Result::class,
$res);
466 $this->assertTrue(
$res->isOk());
467 $this->assertEquals($transform_to,
$res->value());
469 $this->assertNotSame(
$input, $input2);
470 $this->assertEquals($value, $input2->getValue());
471 $this->assertEquals(
null, $input2->getError());
478 $transform_to =
"other value";
484 $this->
refinery->custom()->constraint(function ($v) use ($value):
bool {
485 $this->assertEquals($value, $v);
488 )->withAdditionalTransformation(
489 $this->
refinery->custom()->transformation(
function ($v) use ($value, $transform_to):
string {
490 $this->assertEquals($value, $v);
491 return $transform_to;
493 )->withInput($values);
495 $res = $input2->getContent();
497 $this->assertInstanceOf(Result::class,
$res);
498 $this->assertTrue(
$res->isOk());
499 $this->assertEquals($transform_to,
$res->value());
501 $this->assertNotSame(
$input, $input2);
502 $this->assertEquals($value, $input2->getValue());
503 $this->assertEquals(
null, $input2->getError());
512 $transform_to =
"other value";
519 $this->assertEquals($value, $v);
523 ->withAdditionalTransformation($rc->transformation(function () use ($value, $transform_to):
string {
524 $this->assertFalse(
"This should not happen");
526 return $transform_to;
527 }))->withInput($values);
528 $res = $input2->getContent();
530 $this->assertInstanceOf(Result::class,
$res);
531 $this->assertTrue(
$res->isError());
532 $this->assertEquals($error,
$res->error());
534 $this->assertNotSame(
$input, $input2);
535 $this->assertEquals($value, $input2->getValue());
536 $this->assertEquals($error, $input2->getError());
543 $transform_to =
"other value";
549 $this->
refinery->custom()->constraint(function ($v) use ($value):
bool {
550 $this->assertEquals($value, $v);
553 )->withAdditionalTransformation(
554 $this->
refinery->custom()->transformation(
function () use ($value, $transform_to):
string {
555 $this->assertFalse(
"This should not happen");
556 return $transform_to;
560 $res = $input2->getContent();
562 $this->assertInstanceOf(Result::class,
$res);
563 $this->assertTrue(
$res->isError());
564 $this->assertEquals($error,
$res->error());
566 $this->assertNotSame(
$input, $input2);
567 $this->assertEquals($value, $input2->getValue());
568 $this->assertEquals($error, $input2->getError());
575 $error =
"Your name does not start with an H";
578 $custom_constraint = $this->
refinery->custom()->constraint(
580 return (substr($value, 0, 1) ===
'H') ?
true :
false;
585 $res = $input2->getContent();
586 $this->assertInstanceOf(Result::class,
$res);
587 $this->assertFalse(
$res->isOk());
588 $this->assertEquals($error, $input2->getError());
599 $custom_constraint = $this->
refinery->custom()->constraint(
function () {
603 $input2 =
$input->
withRequired(
true, $custom_constraint)->withRequired(
false)->withInput($values);
604 $res = $input2->getContent();
606 $this->assertInstanceOf(Result::class,
$res);
607 $this->assertFalse(
$res->isError());
608 $this->assertEquals($value,
$res->value());
getNewName()
Generates a unique name on every call.
getNewDedicatedName($dedicated_name='dedicated_name')
Provides common functionality for UI tests.
A constraint encodes some resrtictions on values.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.