ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SelectInputTest Class Reference
+ Inheritance diagram for SelectInputTest:
+ Collaboration diagram for SelectInputTest:

Public Member Functions

 setUp ()
 
 testOnlyValuesFromOptionsAreAcceptableClientSideValues ()
 
 testEmptyStringIsAcceptableClientSideValueIfSelectIsNotRequired ()
 
 testEmptyStringCreatesErrorIfSelectIsRequired ()
 
 testEmptyStringIsAnAcceptableClientSideValueEvenIfSelectIsRequired ()
 
 testRender ()
 
 testRenderValue ()
 
 testCommonRendering ()
 
 testWithValueAndRequiredDoesNotContainNull ()
 

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Definition at line 38 of file SelectInputTest.php.

Member Function Documentation

◆ setUp()

SelectInputTest::setUp ( )

Definition at line 44 of file SelectInputTest.php.

44 : void
45 {
46 $this->name_source = new DefNamesource();
47 }

◆ testCommonRendering()

SelectInputTest::testCommonRendering ( )

Definition at line 165 of file SelectInputTest.php.

165 : void
166 {
167 $f = $this->getFieldFactory();
168 $label = "label";
169 $select = $f->select($label, [], null)->withNameFrom($this->name_source);
170
171 $this->testWithError($select);
172 $this->testWithNoByline($select);
173 $this->testWithRequired($select);
174 $this->testWithDisabled($select);
175 $this->testWithAdditionalOnloadCodeRendersId($select);
176 }

References Vendor\Package\$f.

◆ testEmptyStringCreatesErrorIfSelectIsRequired()

SelectInputTest::testEmptyStringCreatesErrorIfSelectIsRequired ( )

Definition at line 80 of file SelectInputTest.php.

80 : void
81 {
82 $options = [];
83 $select = $this->getFieldFactory()->select(
84 "",
85 $options,
86 ""
87 )
88 ->withRequired(true)
89 ->withNameFrom($this->name_source);
90
91 $data = $this->createMock(InputData::class);
92 $data->expects($this->once())
93 ->method("getOr")
94 ->willReturn(null);
95 $select = $select->withInput(
96 $data
97 );
98
99 $this->assertNotEquals(null, $select->getError());
100 }

References $data.

◆ testEmptyStringIsAcceptableClientSideValueIfSelectIsNotRequired()

SelectInputTest::testEmptyStringIsAcceptableClientSideValueIfSelectIsNotRequired ( )

Definition at line 66 of file SelectInputTest.php.

66 : void
67 {
68 $options = [];
69 $select = new SelectForTest(
70 $this->createMock(ILIAS\Data\Factory::class),
71 $this->createMock(ILIAS\Refinery\Factory::class),
72 "",
73 $options,
74 ""
75 );
76
77 $this->assertTrue($select->_isClientSideValueOk(""));
78 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

◆ testEmptyStringIsAnAcceptableClientSideValueEvenIfSelectIsRequired()

SelectInputTest::testEmptyStringIsAnAcceptableClientSideValueEvenIfSelectIsRequired ( )

Definition at line 102 of file SelectInputTest.php.

102 : void
103 {
104 $options = [];
105 $select = (new SelectForTest(
106 $this->createMock(ILIAS\Data\Factory::class),
107 $this->createMock(ILIAS\Refinery\Factory::class),
108 "",
109 $options,
110 ""
111 ))->withRequired(true);
112
113 $this->assertTrue($select->_isClientSideValueOk(""));
114 }

◆ testOnlyValuesFromOptionsAreAcceptableClientSideValues()

SelectInputTest::testOnlyValuesFromOptionsAreAcceptableClientSideValues ( )

Definition at line 49 of file SelectInputTest.php.

49 : void
50 {
51 $options = ["one" => "Eins", "two" => "Zwei", "three" => "Drei"];
52 $select = new SelectForTest(
53 $this->createMock(ILIAS\Data\Factory::class),
54 $this->createMock(ILIAS\Refinery\Factory::class),
55 "",
56 $options,
57 ""
58 );
59
60 $this->assertTrue($select->_isClientSideValueOk("one"));
61 $this->assertTrue($select->_isClientSideValueOk("two"));
62 $this->assertTrue($select->_isClientSideValueOk("three"));
63 $this->assertFalse($select->_isClientSideValueOk("four"));
64 }

◆ testRender()

SelectInputTest::testRender ( )

Definition at line 116 of file SelectInputTest.php.

116 : void
117 {
118 $f = $this->getFieldFactory();
119 $label = "label";
120 $byline = "byline";
121 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
122 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source);
123 $expected = $this->getFormWrappedHtml(
124 'select-field-input',
125 $label,
126 '
127 <select id="id_1" name="name_0">
128 <option selected="selected" value="">-</option>
129 <option value="one">One</option>
130 <option value="two">Two</option>
131 <option value="three">Three</option>
132 </select>
133 ',
134 $byline,
135 'id_1'
136 );
137 $this->assertEquals($expected, $this->render($select));
138 }

References Vendor\Package\$f.

◆ testRenderValue()

SelectInputTest::testRenderValue ( )

Definition at line 141 of file SelectInputTest.php.

141 : void
142 {
143 $f = $this->getFieldFactory();
144 $label = "label";
145 $byline = "byline";
146 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
147 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source)->withValue("one");
148 $expected = $this->getFormWrappedHtml(
149 'select-field-input',
150 $label,
151 '
152 <select id="id_1" name="name_0">
153 <option value="">-</option>
154 <option selected="selected" value="one">One</option>
155 <option value="two">Two</option>
156 <option value="three">Three</option>
157 </select>
158 ',
159 $byline,
160 'id_1'
161 );
162 $this->assertEquals($expected, $this->render($select));
163 }

References Vendor\Package\$f.

◆ testWithValueAndRequiredDoesNotContainNull()

SelectInputTest::testWithValueAndRequiredDoesNotContainNull ( )

Definition at line 179 of file SelectInputTest.php.

179 : void
180 {
181 $f = $this->getFieldFactory();
182 $label = "label";
183 $byline = "byline";
184 $options = ["something_value" => "something"];
185 $select = $f->select($label, $options, $byline)
186 ->withNameFrom($this->name_source);
187
188 $html_without = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($select));
189
190 $this->assertTrue(str_contains($html_without, ">-</option>"));
191 $this->assertTrue(str_contains($html_without, "value=\"\""));
192
193 $select = $select->withRequired(true);
194 $html_with_required = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($select));
195
196 $this->assertTrue(str_contains($html_with_required, ">ui_select_dropdown_label</option>"));
197 $this->assertTrue(str_contains($html_with_required, "value=\"\""));
198
199 $select = $select->withRequired(false)->withValue("something_value");
200 $html_with_value = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($select));
201
202 $this->assertTrue(str_contains($html_with_value, ">-</option>"));
203 $this->assertTrue(str_contains($html_with_value, "value=\"\""));
204
205 $select = $select->withRequired(true);
206
207 $html_with_value_and_required = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($select));
208
209 $this->assertFalse(str_contains($html_with_value_and_required, ">-</option>"));
210 $this->assertFalse(str_contains($html_with_value_and_required, "value=\"\""));
211 }

References Vendor\Package\$f.

Field Documentation

◆ $name_source

DefNamesource SelectInputTest::$name_source
protected

Definition at line 42 of file SelectInputTest.php.


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