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->assertNotSame($this->child1, $this->child2);
101 $this->child1->method(
'isRequired')->willReturn(
true);
102 $this->child2->method(
'isRequired')->willReturn(
true);
104 $new_group = $this->optional_group;
106 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
107 $this->assertInstanceOf(OptionalGroup::class, $new_group);
108 $this->assertFalse($new_group->isRequired());
113 $this->expectException(\InvalidArgumentException::class);
127 $this->assertNotSame($this->child1, $this->child2);
130 ->expects($this->once())
131 ->method(
"withValue")
133 ->willReturn($this->child2);
135 ->expects($this->once())
136 ->method(
"isClientSideValueOk")
140 ->expects($this->once())
141 ->method(
"withValue")
143 ->willReturn($this->child1);
145 ->expects($this->once())
146 ->method(
"isClientSideValueOk")
150 $new_group = $this->optional_group->withValue([1,2]);
152 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
153 $this->assertInstanceOf(OptionalGroup::class, $new_group);
154 $this->assertNotSame($this->optional_group, $new_group);
159 $this->expectException(\InvalidArgumentException::class);
161 $new_group = $this->optional_group->withValue(1);
166 $this->expectException(\InvalidArgumentException::class);
168 $new_group = $this->optional_group->withValue([1]);
173 $this->assertNotSame($this->child1, $this->child2);
176 ->expects($this->never())
177 ->method(
"withValue");
179 ->expects($this->never())
180 ->method(
"isClientSideValueOk");
182 ->expects($this->never())
183 ->method(
"withValue");
185 ->expects($this->never())
186 ->method(
"isClientSideValueOk");
188 $new_group = $this->optional_group->withValue(null);
190 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
191 $this->assertInstanceOf(OptionalGroup::class, $new_group);
192 $this->assertNotSame($this->optional_group, $new_group);
193 $this->assertEquals(null, $new_group->getValue());
198 $this->assertNotSame($this->child1, $this->child2);
201 ->expects($this->once())
206 ->expects($this->once())
211 $vals = $this->optional_group->getValue();
213 $this->assertEquals([
"one",
"two"], $vals);
218 $this->assertNotSame($this->child1, $this->child2);
220 $input_data = $this->createMock(InputData::class);
223 ->expects($this->once())
225 ->with(
"name0", null)
226 ->willReturn(
"checked");
229 ->expects($this->once())
230 ->method(
"withInput")
232 ->willReturn($this->child2);
234 ->expects($this->once())
235 ->method(
"getContent")
237 ->willReturn($this->data_factory->ok(
"one"));
239 ->expects($this->once())
240 ->method(
"withInput")
242 ->willReturn($this->child1);
244 ->expects($this->once())
245 ->method(
"getContent")
247 ->willReturn($this->data_factory->ok(
"two"));
250 $new_group = $this->optional_group
251 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) use (&$called) {
253 $this->assertEquals([
"two",
"one"], $v);
256 ->withInput($input_data);
258 $this->assertTrue($called);
259 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
260 $this->assertInstanceOf(OptionalGroup::class, $new_group);
261 $this->assertNotSame($this->optional_group, $new_group);
262 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
267 $this->assertNotSame($this->child1, $this->child2);
269 $input_data = $this->createMock(InputData::class);
272 ->expects($this->once())
274 ->with(
"name0", null)
275 ->willReturn(
"checked");
278 ->expects($this->once())
279 ->method(
"withInput")
281 ->willReturn($this->child2);
283 ->expects($this->once())
284 ->method(
"getContent")
285 ->willReturn($this->data_factory->error(
""));
287 ->expects($this->once())
288 ->method(
"withInput")
290 ->willReturn($this->child1);
292 ->expects($this->once())
293 ->method(
"getContent")
294 ->willReturn($this->data_factory->ok(
"two"));
296 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
298 ->expects($this->once())
300 ->with(
"ui_error_in_group")
303 $new_group = $this->optional_group
304 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) {
305 $this->assertFalse(
true,
"This should not happen.");
307 ->withInput($input_data);
309 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
310 $this->assertInstanceOf(OptionalGroup::class, $new_group);
311 $this->assertNotSame($this->optional_group, $new_group);
312 $this->assertTrue($new_group->getContent()->isError());
317 $this->assertNotSame($this->child1, $this->child2);
319 $input_data = $this->createMock(InputData::class);
322 ->expects($this->once())
324 ->with(
"name0", null)
328 ->expects($this->never())
329 ->method(
"withInput");
331 ->expects($this->never())
332 ->method(
"getContent");
334 ->expects($this->never())
335 ->method(
"withInput");
337 ->expects($this->never())
338 ->method(
"getContent");
341 $new_group = $this->optional_group
342 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($v) use (&$called) {
344 $this->assertEquals(null, $v);
347 ->withInput($input_data);
349 $this->assertTrue($called);
350 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
351 $this->assertInstanceOf(OptionalGroup::class, $new_group);
352 $this->assertNotSame($this->optional_group, $new_group);
353 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
Provides common functionality for UI tests.