5 require_once(__DIR__ .
"/../../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ .
"/../../../Base.php");
30 $this->child1 = $this->createMock(Input11::class);
31 $this->child2 = $this->createMock(Input12::class);
32 $this->data_factory =
new Data\Factory();
33 $this->
language = $this->createMock(\ilLanguage::class);
37 ->method(
"withNameFrom")
38 ->willReturn($this->child1);
40 ->method(
"withNameFrom")
41 ->willReturn($this->child2);
47 [$this->child1, $this->child2],
51 public function getNewName()
60 $this->assertNotSame($this->child1, $this->child2);
63 ->expects($this->once())
64 ->method(
"withDisabled")
66 ->willReturn($this->child2);
68 ->expects($this->once())
69 ->method(
"withDisabled")
71 ->willReturn($this->child1);
73 $new_group = $this->optional_group->withDisabled(
true);
75 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
76 $this->assertInstanceOf(OptionalGroup::class, $new_group);
77 $this->assertNotSame($this->optional_group, $new_group);
82 $this->assertNotSame($this->child1, $this->child2);
85 ->expects($this->never())
86 ->method(
"withRequired");
88 ->expects($this->never())
89 ->method(
"withRequired");
91 $new_group = $this->optional_group->withRequired(
true);
93 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
94 $this->assertInstanceOf(OptionalGroup::class, $new_group);
95 $this->assertNotSame($this->optional_group, $new_group);
100 $this->expectException(\InvalidArgumentException::class);
114 $this->assertNotSame($this->child1, $this->child2);
117 ->expects($this->once())
118 ->method(
"withValue")
120 ->willReturn($this->child2);
122 ->expects($this->once())
123 ->method(
"isClientSideValueOk")
127 ->expects($this->once())
128 ->method(
"withValue")
130 ->willReturn($this->child1);
132 ->expects($this->once())
133 ->method(
"isClientSideValueOk")
137 $new_group = $this->optional_group->withValue([1,2]);
139 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
140 $this->assertInstanceOf(OptionalGroup::class, $new_group);
141 $this->assertNotSame($this->optional_group, $new_group);
146 $this->expectException(\InvalidArgumentException::class);
148 $new_group = $this->optional_group->withValue(1);
153 $this->expectException(\InvalidArgumentException::class);
155 $new_group = $this->optional_group->withValue([1]);
160 $this->assertNotSame($this->child1, $this->child2);
163 ->expects($this->never())
164 ->method(
"withValue");
166 ->expects($this->never())
167 ->method(
"isClientSideValueOk");
169 ->expects($this->never())
170 ->method(
"withValue");
172 ->expects($this->never())
173 ->method(
"isClientSideValueOk");
175 $new_group = $this->optional_group->withValue(null);
177 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
178 $this->assertInstanceOf(OptionalGroup::class, $new_group);
179 $this->assertNotSame($this->optional_group, $new_group);
180 $this->assertEquals(null, $new_group->getValue());
185 $this->assertNotSame($this->child1, $this->child2);
188 ->expects($this->once())
193 ->expects($this->once())
198 $vals = $this->optional_group->getValue();
200 $this->assertEquals([
"one",
"two"], $vals);
205 $this->assertNotSame($this->child1, $this->child2);
207 $input_data = $this->createMock(InputData::class);
210 ->expects($this->once())
212 ->with(
"name0", null)
213 ->willReturn(
"checked");
216 ->expects($this->once())
217 ->method(
"withInput")
219 ->willReturn($this->child2);
221 ->expects($this->once())
222 ->method(
"getContent")
224 ->willReturn($this->data_factory->ok(
"one"));
226 ->expects($this->once())
227 ->method(
"withInput")
229 ->willReturn($this->child1);
231 ->expects($this->once())
232 ->method(
"getContent")
234 ->willReturn($this->data_factory->ok(
"two"));
237 $new_group = $this->optional_group
238 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) use (&$called) {
240 $this->assertEquals([
"two",
"one"], $v);
243 ->withInput($input_data);
245 $this->assertTrue($called);
246 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
247 $this->assertInstanceOf(OptionalGroup::class, $new_group);
248 $this->assertNotSame($this->optional_group, $new_group);
249 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
254 $this->assertNotSame($this->child1, $this->child2);
256 $input_data = $this->createMock(InputData::class);
259 ->expects($this->once())
261 ->with(
"name0", null)
262 ->willReturn(
"checked");
265 ->expects($this->once())
266 ->method(
"withInput")
268 ->willReturn($this->child2);
270 ->expects($this->once())
271 ->method(
"getContent")
272 ->willReturn($this->data_factory->error(
""));
274 ->expects($this->once())
275 ->method(
"withInput")
277 ->willReturn($this->child1);
279 ->expects($this->once())
280 ->method(
"getContent")
281 ->willReturn($this->data_factory->ok(
"two"));
283 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
285 ->expects($this->once())
287 ->with(
"ui_error_in_group")
290 $new_group = $this->optional_group
291 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) {
292 $this->assertFalse(
true,
"This should not happen.");
294 ->withInput($input_data);
296 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
297 $this->assertInstanceOf(OptionalGroup::class, $new_group);
298 $this->assertNotSame($this->optional_group, $new_group);
299 $this->assertTrue($new_group->getContent()->isError());
304 $this->assertNotSame($this->child1, $this->child2);
306 $input_data = $this->createMock(InputData::class);
309 ->expects($this->once())
311 ->with(
"name0", null)
315 ->expects($this->never())
316 ->method(
"withInput");
318 ->expects($this->never())
319 ->method(
"getContent");
321 ->expects($this->never())
322 ->method(
"withInput");
324 ->expects($this->never())
325 ->method(
"getContent");
328 $new_group = $this->optional_group
329 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) use (&$called) {
331 $this->assertEquals(null, $v);
334 ->withInput($input_data);
336 $this->assertTrue($called);
337 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
338 $this->assertInstanceOf(OptionalGroup::class, $new_group);
339 $this->assertNotSame($this->optional_group, $new_group);
340 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
Provides common functionality for UI tests.