19 declare(strict_types=1);
31 protected function getFieldFactory():
I\Input\Field\
Factory 33 $df =
new Data\Factory();
34 return new I\Input\Field\Factory(
35 $this->createMock(UploadLimitResolver::class),
43 protected function render(
FormInput $component): string
45 return $this->brutallyTrimHTML(
46 $this->getDefaultRenderer()->render($component)
50 protected function testWithError(
FormInput $component): void
53 $expected =
'<div class="c-input__error-msg alert alert-danger"';
54 $expected2 =
'ui_error:</span>' . $error .
'</div>';
55 $html = $this->render($component->withError($error));
56 $this->assertStringContainsString($expected, $html);
57 $this->assertStringContainsString($expected2, $html);
60 protected function testWithRequired(
FormInput $component): void
62 $expected =
'<span class="asterisk" aria-label="required_field">*</span></label>';
63 $this->assertStringContainsString($expected, $this->render($component->
withRequired(
true)));
66 protected function testWithNoByline(
FormInput $component): void
68 $expected =
'<div class="c-input__help-byline">';
69 $this->assertStringNotContainsString($expected, $this->render($component));
72 protected function testWithDisabled(
FormInput $component): void
74 $type = $this->getDefaultRenderer()->getComponentCanonicalNameAttribute($component);
75 $expected =
'<fieldset class="c-input" data-il-ui-component="' . $type .
'" data-il-ui-input-name="name_0" disabled="disabled"';
76 $this->assertStringContainsString($expected, $this->render($component->
withDisabled(
true)));
79 protected function testWithAdditionalOnloadCodeRendersId(
FormInput $component): void
82 function (
string $id):
string {
88 public function createId(): string
90 return 'THE COMPONENT ID';
92 public function addOnLoadCode(
string $code): void
95 public function getOnLoadCodeAsync(): string
102 $renderer = $this->getDefaultRenderer($js_binding);
103 $outerhtml = $this->brutallyTrimHTML(
$renderer->render($component));
104 if (method_exists($component,
'getInputs')) {
105 $innerhtml = $this->brutallyTrimHTML(
$renderer->render($component->getInputs()));
106 $outerhtml = str_replace($innerhtml,
'', $outerhtml);
109 $this->assertStringContainsString(
110 'id="THE COMPONENT ID"',
115 protected function getFormWrappedHtml(
118 string $payload_field,
119 ?
string $byline = null,
120 ?
string $label_id = null,
121 ?
string $js_id = null,
122 ?
string $name =
'name_0',
124 $label_id = $label_id ?
" for=\"$label_id\"" :
'';
125 $tab = $label_id ?
'' :
' tabindex="0"';
126 $js_id = $js_id ?
" id=\"$js_id\"" :
'';
127 if ($type ===
'section-field-input') {
128 $headline_tag_open =
"<h2>";
129 $headline_tag_close =
"</h2>";
131 $headline_tag_open =
"";
132 $headline_tag_close =
"";
136 <fieldset class="c-input" data-il-ui-component="' . $type .
'" data-il-ui-input-name="' . $name .
'"' . $js_id . $tab .
'> 137 <label' . $label_id .
'>' . $headline_tag_open . $label . $headline_tag_close .
'</label> 138 <div class="c-input__field">';
139 $html .= $payload_field;
144 <div class="c-input__help-byline">' . $byline .
'</div>';
149 return $this->brutallyTrimHTML($html);
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Provides methods to interface with javascript.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
withAdditionalOnLoadCode(Closure $binder)
Add some onload-code to the component instead of replacing the existing one.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...