19 declare(strict_types=1);
21 require_once(__DIR__ .
"/../../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ .
"/../../../Base.php");
23 require_once(__DIR__ .
"/CommonFieldRendering.php");
67 $this->child1 = $this->createMock(Input11::class);
68 $this->child2 = $this->createMock(Input12::class);
69 $this->data_factory =
new Data\Factory();
70 $this->
language = $this->createMock(
ILIAS\Language\Language::class);
74 ->method(
"withNameFrom")
75 ->willReturn($this->child1);
77 ->method(
"withNameFrom")
78 ->willReturn($this->child2);
84 [$this->child1, $this->child2],
88 public function getNewName():
string 97 $this->assertNotSame($this->child1, $this->child2);
100 ->expects($this->once())
101 ->method(
"withDisabled")
103 ->willReturn($this->child2);
105 ->expects($this->once())
106 ->method(
"withDisabled")
108 ->willReturn($this->child1);
110 $new_group = $this->optional_group->withDisabled(
true);
112 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
113 $this->assertInstanceOf(OptionalGroup::class, $new_group);
114 $this->assertNotSame($this->optional_group, $new_group);
119 $this->assertNotSame($this->child1, $this->child2);
122 ->expects($this->never())
123 ->method(
"withRequired");
125 ->expects($this->never())
126 ->method(
"withRequired");
128 $new_group = $this->optional_group->withRequired(
true);
130 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
131 $this->assertInstanceOf(OptionalGroup::class, $new_group);
132 $this->assertNotSame($this->optional_group, $new_group);
137 $this->assertNotSame($this->child1, $this->child2);
138 $this->child1->method(
'isRequired')->willReturn(
true);
139 $this->child2->method(
'isRequired')->willReturn(
true);
141 $new_group = $this->optional_group;
143 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
144 $this->assertInstanceOf(OptionalGroup::class, $new_group);
145 $this->assertFalse($new_group->isRequired());
150 $this->expectException(InvalidArgumentException::class);
164 $this->assertNotSame($this->child1, $this->child2);
167 ->expects($this->once())
168 ->method(
"withValue")
170 ->willReturn($this->child2);
172 ->expects($this->once())
173 ->method(
"isClientSideValueOk")
177 ->expects($this->once())
178 ->method(
"withValue")
180 ->willReturn($this->child1);
182 ->expects($this->once())
183 ->method(
"isClientSideValueOk")
187 $new_group = $this->optional_group->withValue([1,2]);
189 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
190 $this->assertInstanceOf(OptionalGroup::class, $new_group);
191 $this->assertNotSame($this->optional_group, $new_group);
196 $this->expectException(InvalidArgumentException::class);
197 $this->optional_group->withValue(1);
202 $this->expectException(InvalidArgumentException::class);
203 $this->optional_group->withValue([1]);
208 $this->assertNotSame($this->child1, $this->child2);
211 ->expects($this->never())
212 ->method(
"withValue");
214 ->expects($this->never())
215 ->method(
"isClientSideValueOk");
217 ->expects($this->never())
218 ->method(
"withValue");
220 ->expects($this->never())
221 ->method(
"isClientSideValueOk");
223 $new_group = $this->optional_group->withValue(
null);
225 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
226 $this->assertInstanceOf(OptionalGroup::class, $new_group);
227 $this->assertNotSame($this->optional_group, $new_group);
228 $this->assertEquals(
null, $new_group->getValue());
233 $this->assertNotSame($this->child1, $this->child2);
236 ->expects($this->once())
241 ->expects($this->once())
246 $vals = $this->optional_group->getValue();
248 $this->assertEquals([
"one",
"two"], $vals);
253 $this->assertNotSame($this->child1, $this->child2);
255 $input_data = $this->createMock(InputData::class);
258 ->expects($this->once())
260 ->with(
"name0",
null)
261 ->willReturn(
"checked");
264 ->expects($this->once())
265 ->method(
"withInput")
267 ->willReturn($this->child2);
269 ->expects($this->once())
270 ->method(
"getContent")
272 ->willReturn($this->data_factory->ok(
"one"));
274 ->expects($this->once())
275 ->method(
"withInput")
277 ->willReturn($this->child1);
279 ->expects($this->once())
280 ->method(
"getContent")
282 ->willReturn($this->data_factory->ok(
"two"));
285 $new_group = $this->optional_group
286 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
function ($v) use (&$called):
string {
288 $this->assertEquals([
"two",
"one"], $v);
291 ->withInput($input_data);
293 $this->assertTrue($called);
294 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
295 $this->assertInstanceOf(OptionalGroup::class, $new_group);
296 $this->assertNotSame($this->optional_group, $new_group);
297 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
302 $this->assertNotSame($this->child1, $this->child2);
304 $input_data = $this->createMock(InputData::class);
307 ->expects($this->once())
309 ->with(
"name0",
null)
310 ->willReturn(
"checked");
313 ->expects($this->once())
314 ->method(
"withInput")
316 ->willReturn($this->child2);
318 ->expects($this->once())
319 ->method(
"getContent")
320 ->willReturn($this->data_factory->error(
""));
322 ->expects($this->once())
323 ->method(
"withInput")
325 ->willReturn($this->child1);
327 ->expects($this->once())
328 ->method(
"getContent")
329 ->willReturn($this->data_factory->ok(
"two"));
331 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
333 ->expects($this->once())
335 ->with(
"ui_error_in_group")
338 $new_group = $this->optional_group
339 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
function ():
void {
340 $this->fail(
"This should not happen.");
342 ->withInput($input_data);
344 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
345 $this->assertInstanceOf(OptionalGroup::class, $new_group);
346 $this->assertNotSame($this->optional_group, $new_group);
347 $this->assertTrue($new_group->getContent()->isError());
352 $this->assertNotSame($this->child1, $this->child2);
354 $input_data = $this->createMock(InputData::class);
357 ->expects($this->once())
359 ->with(
"name0",
null)
363 ->expects($this->never())
364 ->method(
"withInput");
366 ->expects($this->never())
367 ->method(
"getContent");
369 ->expects($this->never())
370 ->method(
"withInput");
372 ->expects($this->never())
373 ->method(
"getContent");
376 $new_group = $this->optional_group
377 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
function ($v) use (&$called):
string {
379 $this->assertEquals(
null, $v);
382 ->withInput($input_data);
384 $this->assertTrue($called);
385 $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
386 $this->assertInstanceOf(OptionalGroup::class, $new_group);
387 $this->assertNotSame($this->optional_group, $new_group);
388 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
393 $f = $this->getFieldFactory();
395 $og =
$f->optionalGroup(
397 "field_1" =>
$f->text(
"f"),
398 "field_2" =>
$f->text(
"f2")
403 $this->testWithError($og);
404 $this->testWithNoByline($og);
405 $this->testWithRequired($og);
406 $this->testWithDisabled($og);
407 $this->testWithAdditionalOnloadCodeRendersId($og);
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
language()
description: > Example for rendring a language glyph.