ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MultiSelectInputTest Class Reference
+ Inheritance diagram for MultiSelectInputTest:
+ Collaboration diagram for MultiSelectInputTest:

Public Member Functions

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

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Definition at line 33 of file MultiSelectInputTest.php.

Member Function Documentation

◆ setUp()

MultiSelectInputTest::setUp ( )

Definition at line 39 of file MultiSelectInputTest.php.

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

◆ testCommonRendering()

MultiSelectInputTest::testCommonRendering ( )

Definition at line 181 of file MultiSelectInputTest.php.

References Vendor\Package\$f, and null.

181  : void
182  {
183  $f = $this->getFieldFactory();
184  $label = "label";
185  $multi_select = $f->multiSelect($label, [], null)->withNameFrom($this->name_source);
186 
187  $this->testWithError($multi_select);
188  $this->testWithNoByline($multi_select);
189  $this->testWithRequired($multi_select);
190  $this->testWithDisabled($multi_select);
191  $this->testWithAdditionalOnloadCodeRendersId($multi_select);
192  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ testImplementsFactoryInterface()

MultiSelectInputTest::testImplementsFactoryInterface ( )

Definition at line 44 of file MultiSelectInputTest.php.

References Vendor\Package\$f.

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

◆ testOnlyAcceptsActualOptionsFromClientSide()

MultiSelectInputTest::testOnlyAcceptsActualOptionsFromClientSide ( )
Returns
string[]

Definition at line 67 of file MultiSelectInputTest.php.

References Vendor\Package\$f, and ILIAS\GlobalScreen\has().

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

◆ testOptions()

MultiSelectInputTest::testOptions ( )

Definition at line 56 of file MultiSelectInputTest.php.

References Vendor\Package\$f.

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

◆ testRender()

MultiSelectInputTest::testRender ( )

Definition at line 100 of file MultiSelectInputTest.php.

References Vendor\Package\$f, $r, and null.

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

◆ testRenderNoOptions()

MultiSelectInputTest::testRenderNoOptions ( )

Definition at line 194 of file MultiSelectInputTest.php.

References Vendor\Package\$f, and $r.

194  : void
195  {
196  $r = $this->getDefaultRenderer();
197  $f = $this->getFieldFactory();
198  $options = [];
199  $ms = $f->multiSelect("label", $options, "byline")
200  ->withNameFrom($this->name_source)->withDisabled(true);
201 
202  $name = $ms->getName();
203  $label = $ms->getLabel();
204  $byline = $ms->getByline();
205  $expected = '
206  <fieldset class="c-input" data-il-ui-component="multi-select-field-input" data-il-ui-input-name="name_0" disabled="disabled" tabindex="0">
207  <label>label</label>
208  <div class="c-input__field">
209  <ul class="c-field-multiselect">
210  <li>-</li>
211  </ul>
212  </div>
213  <div class="c-input__help-byline">byline</div>
214  </fieldset>';
215 
216  $this->assertHTMLEquals($expected, $r->render($ms));
217  }
$r

◆ testRenderValue()

MultiSelectInputTest::testRenderValue ( )

Definition at line 135 of file MultiSelectInputTest.php.

References Vendor\Package\$f, $r, and null.

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

Field Documentation

◆ $name_source

DefNamesource MultiSelectInputTest::$name_source
protected

Definition at line 37 of file MultiSelectInputTest.php.


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