ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 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(), 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 186 of file CheckboxInputTest.php.

187 {
188 $f = $this->buildFactory();
189 $label = "label";
190 $checkbox = $f->checkbox($label)
191 ->withNameFrom($this->name_source)
192 ->withDisabled(true)
193 ->withValue(true)
194 ->withInput($this->createMock(InputData::class))
195 ;
196
197 $this->assertIsBool($checkbox->getContent()->value());
198 $this->assertTrue($checkbox->getContent()->value());
199 }

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

+ Here is the call graph for this function:

◆ testFalseContent()

CheckboxInputTest::testFalseContent ( )

Definition at line 167 of file CheckboxInputTest.php.

168 {
169 $f = $this->buildFactory();
170 $label = "label";
171 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
172
173 $input_data = $this->createMock(InputData::class);
174 $input_data
175 ->expects($this->atLeastOnce())
176 ->method("getOr")
177 ->with("name_0", "")
178 ->willReturn("");
179
180 $checkbox_false = $checkbox->withInput($input_data);
181
182 $this->assertIsBool($checkbox_false->getContent()->value());
183 $this->assertFalse($checkbox_false->getContent()->value());
184 }

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

+ Here is the call graph for this function:

◆ testHandleInvalidValue()

CheckboxInputTest::testHandleInvalidValue ( )

Definition at line 108 of file CheckboxInputTest.php.

109 {
110 $f = $this->buildFactory();
111 $label = "label";
112 $value = "invalid";
113 try {
114 $f->checkbox($label)->withValue($value);
115 $this->assertFalse(true);
116 } catch (InvalidArgumentException $e) {
117 $this->assertTrue(true);
118 }
119 }

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:

◆ 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 = $r->render($checkbox);
57
58 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <input type=\"checkbox\" value=\"checked\" name=\"name_0\" class=\"form-control form-control-sm\" /> <div class=\"help-block\">byline</div> </div></div>";
59 $this->assertHTMLEquals($expected, $html);
60 }
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268

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

+ Here is the call graph for this function:

◆ testRenderDisabled()

CheckboxInputTest::testRenderDisabled ( )

Definition at line 135 of file CheckboxInputTest.php.

136 {
137 $f = $this->buildFactory();
138 $label = "label";
139 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source)->withDisabled(true);
140
141 $r = $this->getDefaultRenderer();
142 $html = $r->render($checkbox);
143
144 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <input type=\"checkbox\" value=\"checked\" name=\"name_0\" disabled=\"disabled\" class=\"form-control form-control-sm\" /> </div></div>";
145 $this->assertHTMLEquals($expected, $html);
146 }

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

+ Here is the call graph for this function:

◆ testRenderError()

CheckboxInputTest::testRenderError ( )

Definition at line 63 of file CheckboxInputTest.php.

64 {
65 $f = $this->buildFactory();
66 $label = "label";
67 $byline = "byline";
68 $error = "an_error";
69 $checkbox = $f->checkbox($label, $byline)->withNameFrom($this->name_source)->withError($error);
70
71 $r = $this->getDefaultRenderer();
72 $html = $r->render($checkbox);
73
74 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <input type=\"checkbox\" value=\"checked\" name=\"name_0\" class=\"form-control form-control-sm\" /> <div class=\"help-block\">byline</div> <div class=\"help-block alert alert-danger\" role=\"alert\"> <img border=\"0\" src=\" ./templates/default/images/icon_alert.svg\" alt=\"alert\" />" . " $error"
75 . " </div></div></div>";
76 $this->assertHTMLEquals($expected, $html);
77 }

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

+ Here is the call graph for this function:

◆ testRenderNoByline()

CheckboxInputTest::testRenderNoByline ( )

Definition at line 80 of file CheckboxInputTest.php.

81 {
82 $f = $this->buildFactory();
83 $label = "label";
84 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
85
86 $r = $this->getDefaultRenderer();
87 $html = $r->render($checkbox);
88
89 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <input type=\"checkbox\" value=\"checked\" name=\"name_0\" class=\"form-control form-control-sm\" /> </div></div>";
90 $this->assertHTMLEquals($expected, $html);
91 }

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

+ Here is the call graph for this function:

◆ testRenderRequired()

CheckboxInputTest::testRenderRequired ( )

Definition at line 122 of file CheckboxInputTest.php.

123 {
124 $f = $this->buildFactory();
125 $label = "label";
126 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source)->withRequired(true);
127
128 $r = $this->getDefaultRenderer();
129 $html = $r->render($checkbox);
130
131 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label<span class=\"asterisk\">*</span></label> <div class=\"col-sm-9\"> <input type=\"checkbox\" value=\"checked\" name=\"name_0\" class=\"form-control form-control-sm\" /> </div></div>";
132 $this->assertHTMLEquals($expected, $html);
133 }

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

+ Here is the call graph for this function:

◆ testRenderValue()

CheckboxInputTest::testRenderValue ( )

Definition at line 94 of file CheckboxInputTest.php.

95 {
96 $f = $this->buildFactory();
97 $label = "label";
98 $value = true;
99 $checkbox = $f->checkbox($label)->withValue($value)->withNameFrom($this->name_source);
100
101 $r = $this->getDefaultRenderer();
102 $html = $r->render($checkbox);
103
104 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <input type=\"checkbox\" value=\"checked\" checked=\"checked\" name=\"name_0\" class=\"form-control form-control-sm\" /> </div></div>";
105 $this->assertHTMLEquals($expected, $html);
106 }

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

+ Here is the call graph for this function:

◆ testTransformation()

CheckboxInputTest::testTransformation ( )

Definition at line 201 of file CheckboxInputTest.php.

202 {
203 $f = $this->buildFactory();
204 $label = "label";
205 $called = false;
206 $new_value = "NEW_VALUE";
207 $checkbox = $f->checkbox($label)
208 ->withNameFrom($this->name_source)
209 ->withDisabled(true)
210 ->withValue(true)
211 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called, $new_value) {
212 $called = $v;
213 return $new_value;
214 }))
215 ->withInput($this->createMock(InputData::class))
216 ;
217
218 $this->assertIsString($checkbox->getContent()->value());
219 $this->assertEquals($new_value, $checkbox->getContent()->value());
220 }

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

+ Here is the call graph for this function:

◆ testTrueContent()

CheckboxInputTest::testTrueContent ( )

Definition at line 148 of file CheckboxInputTest.php.

149 {
150 $f = $this->buildFactory();
151 $label = "label";
152 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
153
154 $input_data = $this->createMock(InputData::class);
155 $input_data
156 ->expects($this->atLeastOnce())
157 ->method("getOr")
158 ->with("name_0", "")
159 ->willReturn("checked");
160
161 $checkbox_true = $checkbox->withInput($input_data);
162
163 $this->assertIsBool($checkbox_true->getContent()->value());
164 $this->assertTrue($checkbox_true->getContent()->value());
165 }

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: