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");
79 $this->nested_child = $this->createMock(
I\Input\Field\FormInputInternal::class);
80 $this->child1 = $this->createMock(Group1::class);
81 $this->child2 = $this->createMock(Group2::class);
82 $this->data_factory =
new Data\Factory();
83 $this->
refinery =
new Refinery($this->data_factory, $this->createMock(
ILIAS\Language\Language::class));
84 $this->
lng = $this->createMock(
ILIAS\Language\Language::class);
87 ->method(
"withNameFrom")
88 ->willReturn($this->nested_child);
91 ->method(
"withNameFrom")
92 ->willReturn($this->child1);
95 ->willReturn([$this->nested_child]);
98 ->method(
"withNameFrom")
99 ->willReturn($this->child2);
101 ->method(
"getInputs")
102 ->willReturn([$this->nested_child]);
108 [
"child1" => $this->child1,
"child2" => $this->child2],
112 public function getNewName():
string 121 return new I\Input\Field\Factory(
133 $this->assertNotSame($this->child1, $this->child2);
136 ->expects($this->once())
137 ->method(
"withDisabled")
139 ->willReturn($this->child2);
141 ->expects($this->once())
142 ->method(
"withDisabled")
144 ->willReturn($this->child1);
146 $new_group = $this->switchable_group->withDisabled(
true);
148 $this->assertEquals([
"child1" => $this->child2,
"child2" => $this->child1], $new_group->getInputs());
149 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
150 $this->assertNotSame($this->switchable_group, $new_group);
155 $this->assertNotSame($this->child1, $this->child2);
158 ->expects($this->never())
159 ->method(
"withRequired");
161 ->expects($this->never())
162 ->method(
"withRequired");
164 $new_group = $this->switchable_group->withRequired(
true);
166 $this->assertEquals([
"child1" => $this->child1,
"child2" => $this->child2], $new_group->getInputs());
167 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
168 $this->assertNotSame($this->switchable_group, $new_group);
173 $this->expectException(InvalidArgumentException::class);
179 [$this->createMock(
I\Input\Field\FormInput::class)],
187 $this->assertNotSame($this->child1, $this->child2);
190 ->expects($this->never())
191 ->method(
"withValue");
193 ->method(
'isClientSideValueOk')
196 ->expects($this->once())
197 ->method(
"withValue")
199 ->willReturn($this->child2);
201 $new_group = $this->switchable_group->withValue([
"child2", [2]]);
203 $this->assertEquals([
"child1" => $this->child1,
"child2" => $this->child2], $new_group->getInputs());
204 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
205 $this->assertNotSame($this->switchable_group, $new_group);
210 $this->expectException(InvalidArgumentException::class);
211 $this->switchable_group->withValue(
null);
216 $this->expectException(InvalidArgumentException::class);
217 $this->switchable_group->withValue([1, 2, 3]);
222 $new_group = $this->switchable_group->withValue(
"child1");
223 $this->assertEquals([
"child1" => $this->child1,
"child2" => $this->child2], $new_group->getInputs());
224 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
225 $this->assertNotSame($this->switchable_group, $new_group);
230 $this->expectException(InvalidArgumentException::class);
231 $this->switchable_group->withValue(
"child3");
236 $this->assertNotSame($this->child1, $this->child2);
239 ->expects($this->once())
244 ->expects($this->never())
245 ->method(
"getValue");
247 $vals = $this->switchable_group->withValue(
"child1")->getValue();
249 $this->assertEquals([
"child1",
"one"], $vals);
254 $this->assertNotSame($this->child1, $this->child2);
256 $input_data = $this->createMock(InputData::class);
259 ->expects($this->once())
262 ->willReturn(
"child1");
264 $expected_result = $this->data_factory->ok(
"one");
267 ->expects($this->once())
268 ->method(
"withInput")
270 ->willReturn($this->child1);
272 ->expects($this->once())
273 ->method(
"getContent")
275 ->willReturn($expected_result);
277 ->expects($this->once())
278 ->method(
"getContent")
280 ->willReturn($expected_result);
282 ->expects($this->never())
283 ->method(
"withInput");
285 ->expects($this->never())
286 ->method(
"getContent");
289 $new_group = $this->switchable_group
290 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
function ($v) use (&$called):
string {
292 $this->assertEquals([
"child1", [
"one"]], $v);
295 ->withInput($input_data);
297 $this->assertTrue($called);
298 $this->assertEquals([
"child1" => $this->child1,
"child2" => $this->child2], $new_group->getInputs());
299 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
300 $this->assertNotSame($this->switchable_group, $new_group);
301 $this->assertEquals($this->data_factory->ok(
"result"), $new_group->getContent());
306 $this->assertNotSame($this->child1, $this->child2);
308 $input_data = $this->createMock(InputData::class);
311 ->expects($this->once())
314 ->willReturn(
"child2");
317 ->expects($this->never())
318 ->method(
"withInput");
320 ->expects($this->never())
321 ->method(
"getContent");
323 ->expects($this->once())
324 ->method(
"withInput")
326 ->willReturn($this->child2);
328 ->expects($this->once())
329 ->method(
"getContent")
330 ->willReturn($this->data_factory->error(
""));
332 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
334 ->expects($this->once())
336 ->with(
"ui_error_in_group")
339 $new_group = $this->switchable_group
340 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
function ():
void {
341 $this->fail(
"This should not happen.");
343 ->withInput($input_data);
345 $this->assertEquals([
"child1" => $this->child1,
"child2" => $this->child2], $new_group->getInputs());
346 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
347 $this->assertNotSame($this->switchable_group, $new_group);
348 $this->assertTrue($new_group->getContent()->isError());
353 $this->assertNotSame($this->child1, $this->child2);
355 $input_data = $this->createMock(InputData::class);
358 ->expects($this->once())
361 ->willReturn(
"child2");
364 ->method(
"withInput")
365 ->willReturn($this->child2);
367 ->method(
"getContent")
368 ->willReturn($this->data_factory->error(
""));
370 $i18n =
"THERE IS SOME ERROR IN THIS GROUP";
372 ->expects($this->once())
374 ->with(
"ui_error_in_group")
377 $switchable_group = $this->switchable_group
378 ->withInput($input_data);
380 $this->assertTrue($switchable_group->getContent()->isError());
381 $this->assertEquals($i18n, $switchable_group->getContent()->error());
386 $this->expectException(InvalidArgumentException::class);
388 $input_data = $this->createMock(InputData::class);
391 ->expects($this->once())
397 ->expects($this->never())
398 ->method(
"withInput");
400 ->expects($this->never())
401 ->method(
"getContent");
403 ->expects($this->never())
404 ->method(
"withInput");
406 ->expects($this->never())
407 ->method(
"getContent");
409 $this->switchable_group
410 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
function () use (&$called):
void {
411 $this->fail(
"This should not happen.");
413 ->withInput($input_data);
418 $f = $this->buildFactory();
422 $group1 =
$f->group([
423 "field_1" =>
$f->text(
"f",
"some field")
425 $group2 =
$f->group([
426 "field_2" =>
$f->text(
"f2",
"some other field")
429 $sg =
$f->switchableGroup(
439 <fieldset
class=
"c-input" data-il-
ui-component=
"switchable-group-field-input" data-il-
ui-input-name=
"" tabindex=
"0">
441 <div
class=
"c-input__field">
442 <fieldset
class=
"c-input" data-il-
ui-component=
"group-field-input" data-il-
ui-input-name=
"">
444 <input type=
"radio" id=
"id_1" value=
"g1" />
447 <div
class=
"c-input__field">
448 <fieldset
class=
"c-input" data-il-
ui-component=
"text-field-input" data-il-
ui-input-name=
""><label
450 <div
class=
"c-input__field"><input
id=
"id_2" type=
"text" class=
"c-field-text" /></div>
451 <div
class=
"c-input__help-byline">some field</div>
455 <fieldset
class=
"c-input" data-il-
ui-component=
"group-field-input" data-il-
ui-input-name=
"">
457 <input type=
"radio" id=
"id_3" value=
"g2" />
460 <div
class=
"c-input__field">
461 <fieldset
class=
"c-input" data-il-
ui-component=
"text-field-input" data-il-
ui-input-name=
""><label
462 for=
"id_4">f2</label>
463 <div
class=
"c-input__field"><input
id=
"id_4" type=
"text" class=
"c-field-text" /></div>
464 <div
class=
"c-input__help-byline">some other field</div>
469 <div
class=
"c-input__help-byline">byline</div>
473 $this->brutallyTrimHTML($expected),
479 #[\PHPUnit\Framework\Attributes\Depends('testRender')] 482 $r = $this->getDefaultRenderer();
483 $html = $this->render($sg->withValue(
'g2'));
484 $expected =
'<label for="id_3"><input type="radio" id="id_3" value="g2" checked="checked" />';
485 $this->assertStringContainsString($expected, $this->render($sg->withValue(
'g2')));
490 $f = $this->buildFactory();
494 $group1 =
$f->group([
495 "field_1" =>
$f->text(
"f",
"some field")
497 $group2 =
$f->group([
498 "field_2" =>
$f->text(
"f2",
"some other field")
500 $empty_group_title =
'empty group, the title';
501 $empty_group_byline =
'empty group, the byline';
502 $group3 =
$f->group([], $empty_group_title, $empty_group_byline);
504 $sg =
$f->switchableGroup([$group1, $group2, $group3], $label, $byline);
506 $expected =
'<label for="id_3"><input type="radio" id="id_3" value="1" checked="checked" />';
507 $this->assertStringContainsString($expected, $this->render($sg->withValue(
'1')));
512 $f = $this->getFieldFactory();
515 $group1 =
$f->group([
516 "field_1" =>
$f->text(
"f")
518 $group2 =
$f->group([
519 "field_2" =>
$f->text(
"f2")
522 $sg =
$f->switchableGroup(
530 $this->testWithError($sg);
531 $this->testWithNoByline($sg);
532 $this->testWithRequired($sg);
533 $this->testWithDisabled($sg);
534 $this->testWithAdditionalOnloadCodeRendersId($sg);
Interface Observer Contains several chained tasks and infos about them.
isClientSideValueOk($value)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null