ILIAS  release_7 Revision v7.30-3-g800a261c036
CheckboxInputTest Class Reference
+ Inheritance diagram for CheckboxInputTest:
+ Collaboration diagram for CheckboxInputTest:

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testRender ()
 
 testRenderError ()
 
 testRenderNoByline ()
 
 testRenderValue ()
 
 testHandleInvalidValue ()
 
 testRenderRequired ()
 
 testRenderDisabled ()
 
 testTrueContent ()
 
 testFalseContent ()
 
 testDisabledContent ()
 
 testTransformation ()
 
 testNullValue ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Member Functions

 buildFactory ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Definition at line 15 of file CheckboxInputTest.php.

Member Function Documentation

◆ buildFactory()

CheckboxInputTest::buildFactory ( )
protected

Definition at line 24 of file CheckboxInputTest.php.

25 {
26 $df = new Data\Factory();
27 $language = $this->createMock(\ilLanguage::class);
29 new SignalGenerator(),
30 $df,
31 new \ILIAS\Refinery\Factory($df, $language),
32 $language
33 );
34 }
Builds data types.
Definition: Factory.php:20
Class ChatMainBarProvider \MainMenu\Provider.

Referenced by testDisabledContent(), testFalseContent(), testHandleInvalidValue(), testImplementsFactoryInterface(), testNullValue(), testRender(), testRenderDisabled(), testRenderError(), testRenderNoByline(), testRenderRequired(), testRenderValue(), testTransformation(), and testTrueContent().

+ Here is the caller graph for this function:

◆ setUp()

CheckboxInputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 17 of file CheckboxInputTest.php.

17 : void
18 {
19 $this->name_source = new DefNamesource();
20 $this->refinery = new Refinery($this->createMock(Data\Factory::class), $this->createMock(\ilLanguage::class));
21 }

◆ testDisabledContent()

CheckboxInputTest::testDisabledContent ( )

Definition at line 227 of file CheckboxInputTest.php.

228 {
229 $f = $this->buildFactory();
230 $label = "label";
231 $checkbox = $f->checkbox($label)
232 ->withNameFrom($this->name_source)
233 ->withDisabled(true)
234 ->withValue(true)
235 ->withInput($this->createMock(InputData::class))
236 ;
237
238 $this->assertIsBool($checkbox->getContent()->value());
239 $this->assertTrue($checkbox->getContent()->value());
240 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testFalseContent()

CheckboxInputTest::testFalseContent ( )

Definition at line 208 of file CheckboxInputTest.php.

209 {
210 $f = $this->buildFactory();
211 $label = "label";
212 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
213
214 $input_data = $this->createMock(InputData::class);
215 $input_data
216 ->expects($this->atLeastOnce())
217 ->method("getOr")
218 ->with("name_0", "")
219 ->willReturn("");
220
221 $checkbox_false = $checkbox->withInput($input_data);
222
223 $this->assertIsBool($checkbox_false->getContent()->value());
224 $this->assertFalse($checkbox_false->getContent()->value());
225 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testHandleInvalidValue()

CheckboxInputTest::testHandleInvalidValue ( )

Definition at line 137 of file CheckboxInputTest.php.

138 {
139 $f = $this->buildFactory();
140 $label = "label";
141 $value = "invalid";
142 try {
143 $f->checkbox($label)->withValue($value);
144 $this->assertFalse(true);
145 } catch (InvalidArgumentException $e) {
146 $this->assertTrue(true);
147 }
148 }

References Vendor\Package\$e, Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

CheckboxInputTest::testImplementsFactoryInterface ( )

Definition at line 37 of file CheckboxInputTest.php.

38 {
39 $f = $this->buildFactory();
40
41 $checkbox = $f->checkbox("label", "byline");
42
43 $this->assertInstanceOf(Field\Input::class, $checkbox);
44 $this->assertInstanceOf(Field\Checkbox::class, $checkbox);
45 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testNullValue()

CheckboxInputTest::testNullValue ( )

Definition at line 263 of file CheckboxInputTest.php.

263 : void
264 {
265 $f = $this->buildFactory();
266 $checkbox = $f->checkbox("label");
267 $checkbox->withValue(null);
268 $this->assertEquals(false, $checkbox->getValue());
269 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testRender()

CheckboxInputTest::testRender ( )

Definition at line 48 of file CheckboxInputTest.php.

49 {
50 $f = $this->buildFactory();
51 $label = "label";
52 $byline = "byline";
53 $checkbox = $f->checkbox($label, $byline)->withNameFrom($this->name_source);
54
55 $r = $this->getDefaultRenderer();
56 $html = $this->brutallyTrimHTML($r->render($checkbox));
57
58 $expected = $this->brutallyTrimHTML('
59 <div class="form-group row">
60 <label for="id_1" class="control-label col-sm-3">label</label>
61 <div class="col-sm-9">
62 <input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm"/>
63 <div class="help-block">byline</div>
64 </div>
65 </div>
66 ');
67 $this->assertHTMLEquals($expected, $html);
68 }
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392

References Vendor\Package\$f, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testRenderDisabled()

CheckboxInputTest::testRenderDisabled ( )

Definition at line 170 of file CheckboxInputTest.php.

171 {
172 $f = $this->buildFactory();
173 $label = "label";
174 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source)->withDisabled(true);
175
176 $r = $this->getDefaultRenderer();
177 $html = $this->brutallyTrimHTML($r->render($checkbox));
178
179 $expected = $this->brutallyTrimHTML('
180 <div class="form-group row">
181 <label for="id_1" class="control-label col-sm-3">label</label>
182 <div class="col-sm-9"><input type="checkbox" id="id_1" value="checked" name="name_0" disabled="disabled" class="form-control form-control-sm"/></div>
183 </div>
184 ');
185
186 $this->assertHTMLEquals($expected, $html);
187 }

References Vendor\Package\$f, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testRenderError()

CheckboxInputTest::testRenderError ( )

Definition at line 71 of file CheckboxInputTest.php.

72 {
73 $f = $this->buildFactory();
74 $label = "label";
75 $byline = "byline";
76 $error = "an_error";
77 $checkbox = $f->checkbox($label, $byline)->withNameFrom($this->name_source)->withError($error);
78
79 $r = $this->getDefaultRenderer();
80 $html = $this->brutallyTrimHTML($r->render($checkbox));
81 $expected = $this->brutallyTrimHTML('
82 <div class="form-group row">
83 <label for="id_1" class="control-label col-sm-3">label</label>
84 <div class="col-sm-9">
85 <div class="help-block alert alert-danger" role="alert">an_error</div>
86 <input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm"/>
87 <div class="help-block">byline</div>
88 </div>
89 </div>
90 ');
91
92 $this->assertHTMLEquals($expected, $html);
93 }

References Vendor\Package\$f, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testRenderNoByline()

CheckboxInputTest::testRenderNoByline ( )

Definition at line 96 of file CheckboxInputTest.php.

97 {
98 $f = $this->buildFactory();
99 $label = "label";
100 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
101
102 $r = $this->getDefaultRenderer();
103 $html = $this->brutallyTrimHTML($r->render($checkbox));
104
105 $expected = $this->brutallyTrimHTML('
106 <div class="form-group row">
107 <label for="id_1" class="control-label col-sm-3">label</label>
108 <div class="col-sm-9">
109 <input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm" />
110 </div>
111 </div>
112 ');
113 $this->assertHTMLEquals($expected, $html);
114 }

References Vendor\Package\$f, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testRenderRequired()

CheckboxInputTest::testRenderRequired ( )

Definition at line 151 of file CheckboxInputTest.php.

152 {
153 $f = $this->buildFactory();
154 $label = "label";
155 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source)->withRequired(true);
156
157 $r = $this->getDefaultRenderer();
158 $html = $this->brutallyTrimHTML($r->render($checkbox));
159
160 $expected = $this->brutallyTrimHTML('
161 <div class="form-group row">
162 <label for="id_1" class="control-label col-sm-3">label<span class="asterisk">*</span></label>
163 <div class="col-sm-9"><input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm"/></div>
164 </div>
165 ');
166
167 $this->assertHTMLEquals($expected, $html);
168 }

References Vendor\Package\$f, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testRenderValue()

CheckboxInputTest::testRenderValue ( )

Definition at line 117 of file CheckboxInputTest.php.

118 {
119 $f = $this->buildFactory();
120 $label = "label";
121 $value = true;
122 $checkbox = $f->checkbox($label)->withValue($value)->withNameFrom($this->name_source);
123
124 $r = $this->getDefaultRenderer();
125 $html = $this->brutallyTrimHTML($r->render($checkbox));
126 $expected = $this->brutallyTrimHTML('
127 <div class="form-group row">
128 <label for="id_1" class="control-label col-sm-3">label</label>
129 <div class="col-sm-9">
130 <input type="checkbox" id="id_1" value="checked" checked="checked" name="name_0" class="form-control form-control-sm" />
131 </div>
132 </div>
133 ');
134 $this->assertHTMLEquals($expected, $html);
135 }

References Vendor\Package\$f, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testTransformation()

CheckboxInputTest::testTransformation ( )

Definition at line 242 of file CheckboxInputTest.php.

243 {
244 $f = $this->buildFactory();
245 $label = "label";
246 $called = false;
247 $new_value = "NEW_VALUE";
248 $checkbox = $f->checkbox($label)
249 ->withNameFrom($this->name_source)
250 ->withDisabled(true)
251 ->withValue(true)
252 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called, $new_value) {
253 $called = $v;
254 return $new_value;
255 }))
256 ->withInput($this->createMock(InputData::class))
257 ;
258
259 $this->assertIsString($checkbox->getContent()->value());
260 $this->assertEquals($new_value, $checkbox->getContent()->value());
261 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testTrueContent()

CheckboxInputTest::testTrueContent ( )

Definition at line 189 of file CheckboxInputTest.php.

190 {
191 $f = $this->buildFactory();
192 $label = "label";
193 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
194
195 $input_data = $this->createMock(InputData::class);
196 $input_data
197 ->expects($this->atLeastOnce())
198 ->method("getOr")
199 ->with("name_0", "")
200 ->willReturn("checked");
201
202 $checkbox_true = $checkbox->withInput($input_data);
203
204 $this->assertIsBool($checkbox_true->getContent()->value());
205 $this->assertTrue($checkbox_true->getContent()->value());
206 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

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