ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ViewControlInputGenericTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\Data;
26use ILIAS\Refinery\Factory as Refinery;
28
29require_once('ViewControlTestBase.php');
30
32{
33 protected function getViewControl(): Control\ViewControlInput
34 {
35 return new class (
36 $this->buildDataFactory(),
37 $this->buildRefinery(),
38 ''
39 ) extends Control\ViewControlInput {
40 public function isClientSideValueOk($value): bool
41 {
42 return true;
43 }
44 protected function getDefaultValue(): string
45 {
46 return 'default';
47 }
48 };
49 }
50
51 public function testViewControlSortationMutators(): void
52 {
53 $vc = $this->getViewControl();
54 $v = 'some value';
55 $l = 'some label';
56 $s = (new SignalGenerator())->create();
57 $this->assertEquals($v, $vc->withValue($v)->getValue());
58 $this->assertEquals($s, $vc->withOnChange($s)->getOnChangeSignal());
59 }
60
61 public function testViewControlWithInput(): void
62 {
63 $v = 'some input value';
64
65 $input = $this->createMock(InputData::class);
66 $input->expects($this->exactly(2))
67 ->method("getOr")
68 ->willReturn($v);
69
70 $vc = $this->getViewControl()
71 ->withNameFrom($this->getNamesource())
72 ->withInput($input);
73
74 $df = $this->buildDataFactory();
75 $this->assertEquals(
76 $df->ok($v),
77 $vc->getContent()
78 );
79 $this->assertEquals($v, $vc->getValue());
80
81 $transform = $this->buildRefinery()->custom()->transformation(
82 fn($v) => ['mod' => $v]
83 );
84 $vc = $vc->withAdditionalTransformation($transform);
85 $this->assertEquals(
86 ['mod' => $v],
87 $vc->withInput($input)->getContent()->value()
88 );
89 }
90}
Builds data types.
Definition: Factory.php:36
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
Describes a source for input names.
Definition: NameSource.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21