19declare(strict_types=1);
29trait CommonFieldRendering
31 protected function getFieldFactory():
I\Input\Field\
Factory
33 $df =
new Data\Factory();
34 return new I\Input\Field\Factory(
36 $this->createMock(UploadLimitResolver::class),
44 protected function renderInsideContainer(
FormInput $component): string
47 $context_stub = $this->createMock(\
ILIAS\UI\
Component\Component::class);
48 $context_stub->method(
'getCanonicalName')->willReturn(
'StandardFormContainerInput');
50 return $this->brutallyTrimHTML(
51 $this->getDefaultRenderer(
null, [], [$context_stub])->render($component)
55 protected function testWithError(
FormInput $component): void
58 $expected =
'<div class="c-input__error-msg alert alert-danger"';
59 $expected2 =
'ui_error:</span>' . $error .
'</div>';
60 $html = $this->renderInsideContainer($component->withError($error));
61 $this->assertStringContainsString($expected, $html);
62 $this->assertStringContainsString($expected2, $html);
65 protected function testWithRequired(
FormInput $component): void
67 $expected =
'<span class="sr-only">required_field</span><span class="asterisk" aria-hidden="true">*</span></label>';
68 $this->assertStringContainsString($expected, $this->renderInsideContainer($component->
withRequired(
true)));
71 protected function testWithNoByline(
FormInput $component): void
73 $expected =
'<div class="c-input__help-byline">';
74 $this->assertStringNotContainsString($expected, $this->renderInsideContainer($component));
77 protected function testWithDisabled(
FormInput $component): void
79 $type = $this->getDefaultRenderer()->getComponentCanonicalNameAttribute($component);
80 $expected =
'<fieldset class="c-input" data-il-ui-component="' . $type .
'" data-il-ui-input-name="name_0" disabled="disabled"';
81 $this->assertStringContainsString($expected, $this->renderInsideContainer($component->
withDisabled(
true)));
84 protected function testWithAdditionalOnloadCodeRendersId(
FormInput $component): void
87 function (
string $id):
string {
93 public function createId(): string
95 return 'THE COMPONENT ID';
97 public function addOnLoadCode(
string $code): void
100 public function getOnLoadCodeAsync(): string
107 $renderer = $this->getDefaultRenderer($js_binding);
108 $outerhtml = $this->brutallyTrimHTML(
$renderer->render($component));
109 if (method_exists($component,
'getInputs')) {
110 $innerhtml = $this->brutallyTrimHTML(
$renderer->render($component->getInputs()));
111 $outerhtml = str_replace($innerhtml,
'', $outerhtml);
114 $this->assertStringContainsString(
115 'id="THE COMPONENT ID"',
120 protected function getFormWrappedHtml(
123 string $payload_field,
124 ?
string $byline =
null,
125 ?
string $label_id =
null,
126 ?
string $js_id =
null,
127 ?
string $name =
'name_0',
129 $label_id = $label_id ?
" for=\"$label_id\"" :
'';
130 $tab = $label_id ?
'' :
' tabindex="0"';
131 $js_id = $js_id ?
" id=\"$js_id\"" :
'';
132 if ($type ===
'section-field-input') {
133 $headline_tag_open =
"<h2>";
134 $headline_tag_close =
"</h2>";
136 $headline_tag_open =
"";
137 $headline_tag_close =
"";
141 <fieldset class="c-input" data-il-ui-component="' . $type .
'" data-il-ui-input-name="' . $name .
'"' . $js_id . $tab .
'>
142 <label' . $label_id .
'>' . $headline_tag_open . $label . $headline_tag_close .
'</label>
143 <div class="c-input__field">';
144 $html .= $payload_field;
149 <div class="c-input__help-byline">' . $byline .
'</div>';
154 return $this->brutallyTrimHTML($html);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
withAdditionalOnLoadCode(Closure $binder)
Add some onload-code to the component instead of replacing the existing one.
Provides methods to interface with javascript.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.