ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
MultiSelectInputTest Class Reference
+ Inheritance diagram for MultiSelectInputTest:
+ Collaboration diagram for MultiSelectInputTest:

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testOptions ()
 
 testOnlyAcceptsActualOptionsFromClientSide ()
 
 testRender ()
 
 testRenderValue ()
 
 testRenderWithHasOptionFilter ()
 
 testCommonRendering ()
 
 testRenderNoOptions ()
 

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Definition at line 34 of file MultiSelectInputTest.php.

Member Function Documentation

◆ setUp()

MultiSelectInputTest::setUp ( )

Definition at line 41 of file MultiSelectInputTest.php.

41 : void
42 {
43 $this->name_source = new DefNamesource();
44 }

◆ testCommonRendering()

MultiSelectInputTest::testCommonRendering ( )

Definition at line 196 of file MultiSelectInputTest.php.

196 : void
197 {
198 $f = $this->getFieldFactory();
199 $label = "label";
200 $multi_select = $f->multiSelect($label, [], null)->withNameFrom($this->name_source);
201
202 $this->testWithError($multi_select);
203 $this->testWithNoByline($multi_select);
204 $this->testWithRequired($multi_select);
205 $this->testWithDisabled($multi_select);
206 $this->testWithAdditionalOnloadCodeRendersId($multi_select);
207 }

References Vendor\Package\$f.

◆ testImplementsFactoryInterface()

MultiSelectInputTest::testImplementsFactoryInterface ( )

Definition at line 46 of file MultiSelectInputTest.php.

46 : void
47 {
48 $f = $this->getFieldFactory();
49 $options = array(
50 "1" => "Pick 1",
51 "2" => "Pick 2"
52 );
53 $ms = $f->multiSelect("label", $options, "byline");
54 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $ms);
55 $this->assertInstanceOf(Field\MultiSelect::class, $ms);
56 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Field\$options.

◆ testOnlyAcceptsActualOptionsFromClientSide()

MultiSelectInputTest::testOnlyAcceptsActualOptionsFromClientSide ( )
Returns
string[]

Definition at line 69 of file MultiSelectInputTest.php.

69 : void
70 {
71 $this->expectException(InvalidArgumentException::class);
72 $f = $this->getFieldFactory();
73 $options = array(
74 "1" => "Pick 1",
75 "2" => "Pick 2"
76 );
77 $ms = $f->multiSelect("label", $options, "byline")
78 ->withNameFrom(new class () implements NameSource {
79 public function getNewName(): string
80 {
81 return "name";
82 }
83 });
84 $ms = $ms->withInput(new class () implements InputData {
88 public function getOr($_, $__): array
89 {
90 return ["3"];
91 }
92 public function get($_): void
93 {
94 }
95 public function has($name): bool
96 {
97 }
98 });
99 $ms->getContent();
100 }
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
Describes a source for input names.
Definition: NameSource.php:27
has(string $class_name)

References Vendor\Package\$f, ILIAS\UI\Implementation\Component\Input\Field\$options, and ILIAS\GlobalScreen\has().

+ Here is the call graph for this function:

◆ testOptions()

MultiSelectInputTest::testOptions ( )

Definition at line 58 of file MultiSelectInputTest.php.

58 : void
59 {
60 $f = $this->getFieldFactory();
61 $options = array(
62 "1" => "Pick 1",
63 "2" => "Pick 2"
64 );
65 $ms = $f->multiSelect("label", $options, "byline");
66 $this->assertEquals($options, $ms->getOptions());
67 }

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Field\$options.

◆ testRender()

MultiSelectInputTest::testRender ( )

Definition at line 102 of file MultiSelectInputTest.php.

102 : void
103 {
104 $r = $this->getDefaultRenderer();
105 $f = $this->getFieldFactory();
106 $options = array(
107 "1" => "Pick 1",
108 "2" => "Pick 2"
109 );
110 $ms = $f->multiSelect("label", $options, "byline")
111 ->withNameFrom($this->name_source);
112
113 $name = $ms->getName();
114 $label = $ms->getLabel();
115 $byline = $ms->getByline();
116 $expected_options = "";
117 foreach ($options as $opt_value => $opt_label) {
118 $expected_options .= ""
119 . "<li><label>"
120 . "<input type=\"checkbox\" name=\"$name" . "[]\" value=\"$opt_value\" />"
121 . ' <span class="c-field-multiselect__label-text">'
122 . $opt_label
123 . "</span></label></li>";
124 }
125 $expected = $this->getFormWrappedHtml(
126 'multi-select-field-input',
127 $label,
128 '<ul class="c-field-multiselect">'
129 . $expected_options .
130 '</ul>',
131 $byline,
132 null
133 );
134 $this->assertEquals($expected, $this->render($ms));
135 }

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Field\$options.

◆ testRenderNoOptions()

MultiSelectInputTest::testRenderNoOptions ( )

Definition at line 209 of file MultiSelectInputTest.php.

209 : void
210 {
211 $r = $this->getDefaultRenderer();
212 $f = $this->getFieldFactory();
213 $options = [];
214 $ms = $f->multiSelect("label", $options, "byline")
215 ->withNameFrom($this->name_source)->withDisabled(true);
216
217 $name = $ms->getName();
218 $label = $ms->getLabel();
219 $byline = $ms->getByline();
220 $expected = '
221 <fieldset class="c-input" data-il-ui-component="multi-select-field-input" data-il-ui-input-name="name_0" disabled="disabled" tabindex="0">
222 <label>label</label>
223 <div class="c-input__field">
224 <ul class="c-field-multiselect">
225 <li>-</li>
226 </ul>
227 </div>
228 <div class="c-input__help-byline">byline</div>
229 </fieldset>';
230
231 $this->assertHTMLEquals($expected, $r->render($ms));
232 }

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Field\$options.

◆ testRenderValue()

MultiSelectInputTest::testRenderValue ( )

Definition at line 137 of file MultiSelectInputTest.php.

137 : void
138 {
139 $r = $this->getDefaultRenderer();
140 $f = $this->getFieldFactory();
141 $options = array(
142 "1" => "Pick 1",
143 "2" => "Pick 2"
144 );
145 $value = array_keys($options)[1];
146 $ms = $f->multiSelect("label", $options, "byline")
147 ->withNameFrom($this->name_source)
148 ->withValue([$value]);
149
150 $name = $ms->getName();
151 $label = $ms->getLabel();
152 $byline = $ms->getByline();
153 $expected_options = "";
154 foreach ($options as $opt_value => $opt_label) {
155 if ($opt_value === $value) {
156 $expected_options .= ""
157 . "<li><label>"
158 . "<input type=\"checkbox\" name=\"$name" . "[]\" value=\"$opt_value\" checked=\"checked\" />"
159 . '<span class="c-field-multiselect__label-text">'
160 . $opt_label
161 . "</span></label></li>";
162 } else {
163 $expected_options .= ""
164 . "<li><label>"
165 . "<input type=\"checkbox\" name=\"$name" . "[]\" value=\"$opt_value\" />"
166 . '<span class="c-field-multiselect__label-text">'
167 . $opt_label
168 . "</span></label></li>";
169 }
170 }
171 $expected = $this->getFormWrappedHtml(
172 'multi-select-field-input',
173 $label,
174 '<ul class="c-field-multiselect">'
175 . $expected_options .
176 '</ul>',
177 $byline,
178 null
179 );
180 $this->assertEquals($expected, $this->render($ms));
181 }

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Field\$options.

◆ testRenderWithHasOptionFilter()

MultiSelectInputTest::testRenderWithHasOptionFilter ( )

Definition at line 183 of file MultiSelectInputTest.php.

183 : void
184 {
185 $f = $this->getFieldFactory();
186 $options = array(
187 "1" => "Pick 1",
188 "2" => "Pick 2"
189 );
190 $ms = $f->multiSelect("label", $options, "byline");
191 $ms = $ms->withHasOptionFilter(true);
192
193 $this->testHasOptionFilter($ms);
194 }

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Field\$options.

Field Documentation

◆ $name_source

DefNamesource MultiSelectInputTest::$name_source
protected

Definition at line 39 of file MultiSelectInputTest.php.


The documentation for this class was generated from the following file: