ILIAS  release_8 Revision v8.24
HasDynamicInputsBaseTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
25use PHPUnit\Framework\TestCase;
27use ILIAS\Refinery\Factory as Refinery;
28use ILIAS\Data\Factory as DataFactory;
29use ilLanguage;
30use Closure;
31
35class HasDynamicInputsBaseTest extends TestCase
36{
38 protected DataFactory $data_factory;
40 protected Refinery $refinery;
41
42 public function setUp(): void
43 {
44 $this->data_factory = $this->createMock(DataFactory::class);
45 $this->language = $this->createMock(ilLanguage::class);
46 $this->refinery = $this->createMock(Refinery::class);
47 $this->input = new class ($this->language, $this->data_factory, $this->refinery, 'test_input_name', $this->getTestInputTemplate(), 'test_byline') extends HasDynamicInputsBase {
48 public function getUpdateOnLoadCode(): Closure
49 {
50 return static function () {
51 };
52 }
53
54 protected function getConstraintForRequirement(): ?Constraint
55 {
56 return null;
57 }
58
59 public function isClientSideValueOk($value): bool
60 {
61 return true;
62 }
63 };
64 }
65
67 {
68 $dynamic_input = $this->input->withValue([
69 'val1',
70 'val2'
71 ]);
72
73 $this->assertCount(
74 2,
75 $dynamic_input->getDynamicInputs()
76 );
77 }
78
79 public function testDynamicInputWithValue(): void
80 {
81 $input_value_1 = 'val1';
82 $input_value_2 = 'val2';
83 $dynamic_input = $this->input->withValue([
84 $input_value_1,
85 $input_value_2,
86 ]);
87
88 $generated_inputs = $dynamic_input->getDynamicInputs();
89 $this->assertEquals($input_value_1, $generated_inputs[0]->getValue());
90 $this->assertEquals($input_value_2, $generated_inputs[1]->getValue());
91 }
92
94 {
95 $dynamic_input = $this->input;
96 $this->assertFalse($dynamic_input->getTemplateForDynamicInputs()->isDisabled());
97 $this->assertFalse($dynamic_input->isDisabled());
98
99 $dynamic_input = $this->input->withDisabled(true);
100
101 $this->assertTrue($dynamic_input->getTemplateForDynamicInputs()->isDisabled());
102 $this->assertTrue($dynamic_input->isDisabled());
103 }
104
106 {
107 $dynamic_input = $this->input->withValue(['', '']);
108 $generated_inputs = $dynamic_input->getDynamicInputs();
109
110 $this->assertFalse($generated_inputs[0]->isDisabled());
111 $this->assertFalse($generated_inputs[1]->isDisabled());
112 $this->assertFalse($dynamic_input->getTemplateForDynamicInputs()->isDisabled());
113 $this->assertFalse($dynamic_input->isDisabled());
114
115 $dynamic_input = $dynamic_input->withDisabled(true);
116 $generated_inputs = $dynamic_input->getDynamicInputs();
117
118 $this->assertTrue($generated_inputs[0]->isDisabled());
119 $this->assertTrue($generated_inputs[1]->isDisabled());
120 $this->assertTrue($dynamic_input->getTemplateForDynamicInputs()->isDisabled());
121 $this->assertTrue($dynamic_input->isDisabled());
122 }
123
128 public function testDynamicInputNameGeneration(): void
129 {
130 $input_name = 'test_name[input_0][]';
131 $dynamic_input = $this->input->withValue(['', '']);
132 $dynamic_input = $dynamic_input->withNameFrom(
133 $this->getTestNameSource()
134 );
135
136 $this->assertEquals(
137 $input_name,
138 $dynamic_input->getTemplateForDynamicInputs()->getName()
139 );
140
141 $generated_inputs = $dynamic_input->getDynamicInputs();
142 $this->assertEquals(
143 $input_name,
144 $generated_inputs[0]->getName()
145 );
146
147 $this->assertEquals(
148 $input_name,
149 $generated_inputs[1]->getName()
150 );
151 }
152
153 protected function getTestNameSource(): NameSource
154 {
155 return new class () implements NameSource {
156 public function getNewName(): string
157 {
158 return 'test_name';
159 }
160 };
161 }
162
163 protected function getTestInputTemplate()
164 {
165 return new class ($this->data_factory, $this->refinery, 'input_template_name', 'input_template_byline') extends \ILIAS\UI\Implementation\Component\Input\Field\FormInput {
166 public function getUpdateOnLoadCode(): Closure
167 {
168 return static function () {
169 };
170 }
171
172 protected function getConstraintForRequirement(): ?Constraint
173 {
174 return null;
175 }
176
177 public function isClientSideValueOk($value): bool
178 {
179 return true;
180 }
181 };
182 }
183}
Builds data types.
Definition: Factory.php:21
testDynamicInputNameGeneration()
the input names are always the same, because the names generated from DynamicInputsNameSource are sta...
language handling
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:47
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.