ILIAS  release_8 Revision v8.24
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 ()
 
 getDataFactory ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Protected Member Functions

 buildFactory ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Protected Attributes

DefNamesource $name_source
 
Refinery $refinery
 

Detailed Description

Definition at line 32 of file CheckboxInputTest.php.

Member Function Documentation

◆ buildFactory()

CheckboxInputTest::buildFactory ( )
protected

Definition at line 43 of file CheckboxInputTest.php.

43 : I\Input\Field\Factory
44 {
45 $df = new Data\Factory();
46 $language = $this->createMock(ilLanguage::class);
47 return new I\Input\Field\Factory(
48 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
49 new SignalGenerator(),
50 $df,
51 new Refinery($df, $language),
52 $language
53 );
54 }
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: Input.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.

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 37 of file CheckboxInputTest.php.

37 : void
38 {
39 $this->name_source = new DefNamesource();
40 $this->refinery = new Refinery($this->createMock(Data\Factory::class), $this->createMock(ilLanguage::class));
41 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testDisabledContent()

CheckboxInputTest::testDisabledContent ( )

Definition at line 241 of file CheckboxInputTest.php.

241 : void
242 {
243 $f = $this->buildFactory();
244 $label = "label";
245 $checkbox = $f->checkbox($label)
246 ->withNameFrom($this->name_source)
247 ->withDisabled(true)
248 ->withValue(true)
249 ->withInput($this->createMock(InputData::class))
250 ;
251
252 $this->assertIsBool($checkbox->getContent()->value());
253 $this->assertTrue($checkbox->getContent()->value());
254 }

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

+ Here is the call graph for this function:

◆ testFalseContent()

CheckboxInputTest::testFalseContent ( )

Definition at line 222 of file CheckboxInputTest.php.

222 : void
223 {
224 $f = $this->buildFactory();
225 $label = "label";
226 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
227
228 $input_data = $this->createMock(InputData::class);
229 $input_data
230 ->expects($this->atLeastOnce())
231 ->method("getOr")
232 ->with("name_0", "")
233 ->willReturn("");
234
235 $checkbox_false = $checkbox->withInput($input_data);
236
237 $this->assertIsBool($checkbox_false->getContent()->value());
238 $this->assertFalse($checkbox_false->getContent()->value());
239 }

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

+ Here is the call graph for this function:

◆ testHandleInvalidValue()

CheckboxInputTest::testHandleInvalidValue ( )

Definition at line 152 of file CheckboxInputTest.php.

152 : void
153 {
154 $f = $this->buildFactory();
155 $label = "label";
156 $value = "invalid";
157 try {
158 $f->checkbox($label)->withValue($value);
159 $this->fail();
160 } catch (InvalidArgumentException $e) {
161 $this->assertTrue(true);
162 }
163 }

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

+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

CheckboxInputTest::testImplementsFactoryInterface ( )

Definition at line 56 of file CheckboxInputTest.php.

56 : void
57 {
58 $f = $this->buildFactory();
59
60 $checkbox = $f->checkbox("label", "byline");
61
62 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $checkbox);
63 $this->assertInstanceOf(Field\Checkbox::class, $checkbox);
64 }

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

+ Here is the call graph for this function:

◆ testNullValue()

CheckboxInputTest::testNullValue ( )

Definition at line 276 of file CheckboxInputTest.php.

276 : void
277 {
278 $f = $this->buildFactory();
279 $checkbox = $f->checkbox("label");
280 $checkbox->withValue(null);
281 $this->assertEquals(false, $checkbox->getValue());
282 }

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

+ Here is the call graph for this function:

◆ testRender()

CheckboxInputTest::testRender ( )

Definition at line 66 of file CheckboxInputTest.php.

66 : void
67 {
68 $f = $this->buildFactory();
69 $label = "label";
70 $byline = "byline";
71 $checkbox = $f->checkbox($label, $byline)->withNameFrom($this->name_source);
72
73 $r = $this->getDefaultRenderer();
74 $html = $this->brutallyTrimHTML($r->render($checkbox));
75
76 $expected = $this->brutallyTrimHTML('
77 <div class="form-group row">
78 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
79 <div class="col-sm-8 col-md-9 col-lg-10">
80 <input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm"/>
81 <div class="help-block">byline</div>
82 </div>
83 </div>
84 ');
85 $this->assertHTMLEquals($expected, $html);
86 }
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355

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 184 of file CheckboxInputTest.php.

184 : void
185 {
186 $f = $this->buildFactory();
187 $label = "label";
188 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source)->withDisabled(true);
189
190 $r = $this->getDefaultRenderer();
191 $html = $this->brutallyTrimHTML($r->render($checkbox));
192
193 $expected = $this->brutallyTrimHTML('
194 <div class="form-group row">
195 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
196 <div class="col-sm-8 col-md-9 col-lg-10"><input type="checkbox" id="id_1" value="checked" name="name_0" disabled="disabled" class="form-control form-control-sm"/></div>
197 </div>
198 ');
199
200 $this->assertHTMLEquals($expected, $html);
201 }

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 88 of file CheckboxInputTest.php.

88 : void
89 {
90 $f = $this->buildFactory();
91 $label = "label";
92 $byline = "byline";
93 $error = "an_error";
94 $checkbox = $f->checkbox($label, $byline)->withNameFrom($this->name_source)->withError($error);
95
96 $r = $this->getDefaultRenderer();
97 $html = $this->brutallyTrimHTML($r->render($checkbox));
98 $expected = $this->brutallyTrimHTML('
99 <div class="form-group row">
100 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
101 <div class="col-sm-8 col-md-9 col-lg-10">
102 <div class="help-block alert alert-danger" aria-describedby="id_1" role="alert">an_error</div>
103 <input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm"/>
104 <div class="help-block">byline</div>
105 </div>
106 </div>
107 ');
108
109 $this->assertHTMLEquals($expected, $html);
110 }

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 112 of file CheckboxInputTest.php.

112 : void
113 {
114 $f = $this->buildFactory();
115 $label = "label";
116 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
117
118 $r = $this->getDefaultRenderer();
119 $html = $this->brutallyTrimHTML($r->render($checkbox));
120
121 $expected = $this->brutallyTrimHTML('
122 <div class="form-group row">
123 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
124 <div class="col-sm-8 col-md-9 col-lg-10">
125 <input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm" />
126 </div>
127 </div>
128 ');
129 $this->assertHTMLEquals($expected, $html);
130 }

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 165 of file CheckboxInputTest.php.

165 : void
166 {
167 $f = $this->buildFactory();
168 $label = "label";
169 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source)->withRequired(true);
170
171 $r = $this->getDefaultRenderer();
172 $html = $this->brutallyTrimHTML($r->render($checkbox));
173
174 $expected = $this->brutallyTrimHTML('
175 <div class="form-group row">
176 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label<span class="asterisk">*</span></label>
177 <div class="col-sm-8 col-md-9 col-lg-10"><input type="checkbox" id="id_1" value="checked" name="name_0" class="form-control form-control-sm"/></div>
178 </div>
179 ');
180
181 $this->assertHTMLEquals($expected, $html);
182 }

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 132 of file CheckboxInputTest.php.

132 : void
133 {
134 $f = $this->buildFactory();
135 $label = "label";
136 $value = true;
137 $checkbox = $f->checkbox($label)->withValue($value)->withNameFrom($this->name_source);
138
139 $r = $this->getDefaultRenderer();
140 $html = $this->brutallyTrimHTML($r->render($checkbox));
141 $expected = $this->brutallyTrimHTML('
142 <div class="form-group row">
143 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
144 <div class="col-sm-8 col-md-9 col-lg-10">
145 <input type="checkbox" id="id_1" value="checked" checked="checked" name="name_0" class="form-control form-control-sm" />
146 </div>
147 </div>
148 ');
149 $this->assertHTMLEquals($expected, $html);
150 }

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 256 of file CheckboxInputTest.php.

256 : void
257 {
258 $f = $this->buildFactory();
259 $label = "label";
260 $new_value = "NEW_VALUE";
261 $checkbox = $f->checkbox($label)
262 ->withNameFrom($this->name_source)
263 ->withDisabled(true)
264 ->withValue(true)
265 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called, $new_value): string {
266 $called = $v;
267 return $new_value;
268 }))
269 ->withInput($this->createMock(InputData::class))
270 ;
271
272 $this->assertIsString($checkbox->getContent()->value());
273 $this->assertEquals($new_value, $checkbox->getContent()->value());
274 }
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9

References Vendor\Package\$f, buildFactory(), function, and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testTrueContent()

CheckboxInputTest::testTrueContent ( )

Definition at line 203 of file CheckboxInputTest.php.

203 : void
204 {
205 $f = $this->buildFactory();
206 $label = "label";
207 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
208
209 $input_data = $this->createMock(InputData::class);
210 $input_data
211 ->expects($this->atLeastOnce())
212 ->method("getOr")
213 ->with("name_0", "")
214 ->willReturn("checked");
215
216 $checkbox_true = $checkbox->withInput($input_data);
217
218 $this->assertIsBool($checkbox_true->getContent()->value());
219 $this->assertTrue($checkbox_true->getContent()->value());
220 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $name_source

DefNamesource CheckboxInputTest::$name_source
protected

Definition at line 34 of file CheckboxInputTest.php.

◆ $refinery

Refinery CheckboxInputTest::$refinery
protected

Definition at line 35 of file CheckboxInputTest.php.


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