ILIAS  release_8 Revision v8.24
NumericInputTest Class Reference
+ Inheritance diagram for NumericInputTest:
+ Collaboration diagram for NumericInputTest:

Public Member Functions

 setUp ()
 
 test_implements_factory_interface ()
 
 test_render ()
 
 test_render_error ()
 
 test_render_no_byline ()
 
 test_render_value ()
 
 test_render_disabled ()
 
 testNullValue ()
 
 testEmptyValue (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 @depends testNullValue More...
 
 testZeroIsValidValue (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 @depends testNullValue More...
 
 testConstraintForRequirementForFloat (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 @depends testNullValue More...
 
- 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
 

Detailed Description

Definition at line 31 of file NumericInputTest.php.

Member Function Documentation

◆ buildFactory()

NumericInputTest::buildFactory ( )
protected

Definition at line 40 of file NumericInputTest.php.

40 : I\Input\Field\Factory
41 {
42 $df = new Data\Factory();
43 $language = $this->getLanguage();
44 return new I\Input\Field\Factory(
45 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
46 new SignalGenerator(),
47 $df,
48 new Refinery($df, $language),
49 $language
50 );
51 }
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.

References ILIAS_UI_TestBase\getLanguage().

Referenced by test_implements_factory_interface(), test_render(), test_render_disabled(), test_render_error(), test_render_no_byline(), test_render_value(), and testNullValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

NumericInputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 35 of file NumericInputTest.php.

35 : void
36 {
37 $this->name_source = new DefNamesource();
38 }

◆ test_implements_factory_interface()

NumericInputTest::test_implements_factory_interface ( )

Definition at line 53 of file NumericInputTest.php.

53 : void
54 {
55 $f = $this->buildFactory();
56
57 $numeric = $f->numeric("label", "byline");
58
59 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $numeric);
60 $this->assertInstanceOf(Field\Numeric::class, $numeric);
61 }

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

+ Here is the call graph for this function:

◆ test_render()

NumericInputTest::test_render ( )

Definition at line 64 of file NumericInputTest.php.

64 : void
65 {
66 $f = $this->buildFactory();
67 $label = "label";
68 $byline = "byline";
69 $numeric = $f->numeric($label, $byline)->withNameFrom($this->name_source);
70
71 $r = $this->getDefaultRenderer();
72 $html = $this->brutallyTrimHTML($r->render($numeric));
73
74 $expected = $this->brutallyTrimHTML('
75<div class="form-group row">
76 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
77 <div class="col-sm-8 col-md-9 col-lg-10">
78 <input id="id_1" type="number" name="name_0" class="form-control form-control-sm" />
79 <div class="help-block">byline</div>
80 </div>
81</div>
82');
83 $this->assertEquals($expected, $html);
84 }
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\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_disabled()

NumericInputTest::test_render_disabled ( )

Definition at line 146 of file NumericInputTest.php.

146 : void
147 {
148 $f = $this->buildFactory();
149 $label = "label";
150 $numeric = $f->numeric($label)->withNameFrom($this->name_source)->withDisabled(true);
151
152 $r = $this->getDefaultRenderer();
153 $html = $this->brutallyTrimHTML($r->render($numeric));
154
155 $expected = $this->brutallyTrimHTML('
156<div class="form-group row">
157 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
158 <div class="col-sm-8 col-md-9 col-lg-10"> <input id="id_1" type="number" name="name_0" disabled="disabled" class="form-control form-control-sm" /> </div>
159</div>');
160 $this->assertEquals($expected, $html);
161 }

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

+ Here is the call graph for this function:

◆ test_render_error()

NumericInputTest::test_render_error ( )

Definition at line 86 of file NumericInputTest.php.

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

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

+ Here is the call graph for this function:

◆ test_render_no_byline()

NumericInputTest::test_render_no_byline ( )

Definition at line 109 of file NumericInputTest.php.

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

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

+ Here is the call graph for this function:

◆ test_render_value()

NumericInputTest::test_render_value ( )

Definition at line 127 of file NumericInputTest.php.

127 : void
128 {
129 $f = $this->buildFactory();
130 $label = "label";
131 $value = "10";
132 $numeric = $f->numeric($label)->withValue($value)->withNameFrom($this->name_source);
133
134 $r = $this->getDefaultRenderer();
135 $html = $this->brutallyTrimHTML($r->render($numeric));
136
137 $expected = $this->brutallyTrimHTML('
138<div class="form-group row">
139 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
140 <div class="col-sm-8 col-md-9 col-lg-10"> <input id="id_1" type="number" value="10" name="name_0" class="form-control form-control-sm" /> </div>
141</div>
142');
143 $this->assertEquals($expected, $html);
144 }

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

+ Here is the call graph for this function:

◆ testConstraintForRequirementForFloat()

NumericInputTest::testConstraintForRequirementForFloat ( \ILIAS\UI\Component\Input\Container\Form\FormInput  $field)

@depends testNullValue

Definition at line 216 of file NumericInputTest.php.

216 : void
217 {
218 $post_data = new DefInputData(['name_0' => 1.1]);
219 $field_required = $field->withRequired(true);
220
221 $value = $field->withInput($post_data)->getContent();
222 $this->assertTrue($value->isOk());
223 //Note, this float will be Transformed to int, since this input only accepts int
224 $this->assertEquals(1, $value->value());
225
226 $value = $field_required->withInput($post_data)->getContent();
227 $this->assertTrue($value->isOK());
228 $this->assertEquals(1, $value->value());
229 }

◆ testEmptyValue()

NumericInputTest::testEmptyValue ( \ILIAS\UI\Component\Input\Container\Form\FormInput  $field)

@depends testNullValue

Definition at line 182 of file NumericInputTest.php.

182 : void
183 {
184 $post_data = new DefInputData(['name_0' => '']);
185 $field_required = $field->withRequired(true);
186
187 $value = $field->withInput($post_data)->getContent();
188 $this->assertTrue($value->isOk());
189 $this->assertNull($value->value());
190
191 $field_required = $field_required->withInput($post_data);
192 $value = $field_required->getContent();
193 $this->assertTrue($value->isError());
194 }

◆ testNullValue()

NumericInputTest::testNullValue ( )

Definition at line 163 of file NumericInputTest.php.

164 {
165 $f = $this->buildFactory();
166 $post_data = new DefInputData(['name_0' => null]);
167 $field = $f->numeric('')->withNameFrom($this->name_source);
168 $field_required = $field->withRequired(true);
169
170 $value = $field->withInput($post_data)->getContent();
171 $this->assertTrue($value->isOk());
172 $this->assertNull($value->value());
173
174 $value = $field_required->withInput($post_data)->getContent();
175 $this->assertTrue($value->isError());
176 return $field;
177 }
This describes inputs that can be used in forms.
Definition: FormInput.php:32

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

+ Here is the call graph for this function:

◆ testZeroIsValidValue()

NumericInputTest::testZeroIsValidValue ( \ILIAS\UI\Component\Input\Container\Form\FormInput  $field)

@depends testNullValue

Definition at line 199 of file NumericInputTest.php.

199 : void
200 {
201 $post_data = new DefInputData(['name_0' => 0]);
202 $field_required = $field->withRequired(true);
203
204 $value = $field->withInput($post_data)->getContent();
205 $this->assertTrue($value->isOk());
206 $this->assertEquals(0, $value->value());
207
208 $value = $field_required->withInput($post_data)->getContent();
209 $this->assertTrue($value->isOK());
210 $this->assertEquals(0, $value->value());
211 }

Field Documentation

◆ $name_source

DefNamesource NumericInputTest::$name_source
protected

Definition at line 33 of file NumericInputTest.php.


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