19 declare(strict_types=1);
31 protected function getFieldFactory():
I\Input\Field\
Factory 33 $df =
new Data\Factory();
34 $language = $this->createMock(ilLanguage::class);
35 return new I\Input\Field\Factory(
36 $this->createMock(UploadLimitResolver::class),
44 protected function render(
FormInput $component): string
46 return $this->brutallyTrimHTML(
47 $this->getDefaultRenderer()->render($component)
51 protected function testWithError(
FormInput $component): void
54 $expected =
'<div class="c-input__error-msg alert alert-danger"';
55 $expected2 =
'ui_error:</span>' . $error .
'</div>';
56 $html = $this->render($component->withError($error));
57 $this->assertStringContainsString($expected, $html);
58 $this->assertStringContainsString($expected2, $html);
61 protected function testWithRequired(
FormInput $component): void
63 $expected =
'<span class="asterisk" aria-label="required_field">*</span></label>';
64 $this->assertStringContainsString($expected, $this->render($component->
withRequired(
true)));
67 protected function testWithNoByline(
FormInput $component): void
69 $expected =
'<div class="c-input__help-byline">';
70 $this->assertStringNotContainsString($expected, $this->render($component));
73 protected function testWithDisabled(
FormInput $component): void
75 $type = $this->getDefaultRenderer()->getComponentCanonicalNameAttribute($component);
76 $expected =
'<fieldset class="c-input" data-il-ui-component="' . $type .
'" data-il-ui-input-name="name_0" disabled="disabled"';
77 $this->assertStringContainsString($expected, $this->render($component->
withDisabled(
true)));
80 protected function testWithAdditionalOnloadCodeRendersId(
FormInput $component): void
83 function (
string $id):
string {
89 public function createId(): string
91 return 'THE COMPONENT ID';
93 public function addOnLoadCode(
string $code): void
96 public function getOnLoadCodeAsync(): string
103 $renderer = $this->getDefaultRenderer($js_binding);
104 $outerhtml = $this->brutallyTrimHTML(
$renderer->render($component));
105 if (method_exists($component,
'getInputs')) {
106 $innerhtml = $this->brutallyTrimHTML(
$renderer->render($component->getInputs()));
107 $outerhtml = str_replace($innerhtml,
'', $outerhtml);
110 $this->assertStringContainsString(
111 'id="THE COMPONENT ID"',
116 protected function getFormWrappedHtml(
119 string $payload_field,
120 ?
string $byline =
null,
121 ?
string $label_id =
null,
122 ?
string $js_id =
null,
123 ?
string $name =
'name_0',
125 $label_id = $label_id ?
" for=\"$label_id\"" :
'';
126 $tab = $label_id ?
'' :
' tabindex="0"';
127 $js_id = $js_id ?
" id=\"$js_id\"" :
'';
128 if ($type ===
'section-field-input') {
129 $headline_tag_open =
"<h2>";
130 $headline_tag_close =
"</h2>";
132 $headline_tag_open =
"";
133 $headline_tag_close =
"";
137 <fieldset class="c-input" data-il-ui-component="' . $type .
'" data-il-ui-input-name="' . $name .
'"' . $js_id . $tab .
'> 138 <label' . $label_id .
'>' . $headline_tag_open . $label . $headline_tag_close .
'</label> 139 <div class="c-input__field">';
140 $html .= $payload_field;
145 <div class="c-input__help-byline">' . $byline .
'</div>';
150 return $this->brutallyTrimHTML($html);
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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.