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

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testRender ()
 
 testCommonRendering ()
 
 testRenderValue ()
 
 testNullValue ()
 
 testEmptyValue (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 
 testZeroIsValidValue (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 
 testConstraintForRequirementForFloat (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 
 testFloatValue (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 
 testFloatValueOffsetStep (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 
 testFloatValueForInt (\ILIAS\UI\Component\Input\Container\Form\FormInput $field)
 
 testDecimalsTransformationsStack ()
 

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Definition at line 33 of file NumericInputTest.php.

Member Function Documentation

◆ setUp()

NumericInputTest::setUp ( )

Definition at line 39 of file NumericInputTest.php.

39 : void
40 {
41 $this->name_source = new DefNamesource();
42 }

◆ testCommonRendering()

NumericInputTest::testCommonRendering ( )

Definition at line 72 of file NumericInputTest.php.

72 : void
73 {
74 $f = $this->getFieldFactory();
75 $label = "label";
76 $numeric = $f->numeric($label)->withNameFrom($this->name_source);
77
78 $this->testWithError($numeric);
79 $this->testWithNoByline($numeric);
80 $this->testWithRequired($numeric);
81 $this->testWithDisabled($numeric);
82 $this->testWithAdditionalOnloadCodeRendersId($numeric);
83 }

References Vendor\Package\$f.

◆ testConstraintForRequirementForFloat()

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

Definition at line 149 of file NumericInputTest.php.

149 : void
150 {
151 $post_data = new DefInputData(['name_0' => 1.1]);
152 $field_required = $field->withRequired(true);
153
154 $value = $field->withInput($post_data)->getContent();
155 $this->assertTrue($value->isOk());
156 //Note, this float will be Transformed to int, since this input only accepts int
157 $this->assertEquals(1, $value->value());
158
159 $value = $field_required->withInput($post_data)->getContent();
160 $this->assertTrue($value->isOK());
161 $this->assertEquals(1, $value->value());
162 }

◆ testDecimalsTransformationsStack()

NumericInputTest::testDecimalsTransformationsStack ( )

Definition at line 201 of file NumericInputTest.php.

201 : void
202 {
203 $data_factory = new DataFactory();
204 $language = $this->createMock(ILIAS\Language\Language::class);
205 $refinery = new Refinery($data_factory, $language);
206
207 $f = $this->getFieldFactory();
208 $field = $f->numeric('')->withNameFrom($this->name_source)
209 ->withStepSize(.2)
210 ->withAdditionalTransformation(
211 $refinery->custom()->transformation(fn(float $v): float => $v + 1)
212 );
213
214 $post_data = new DefInputData(['name_0' => 1]);
215
216 $value = $field
217 ->withInput($post_data)
218 ->getContent();
219 $this->assertTrue($value->isOk());
220 $this->assertIsFloat($value->value());
221 $this->assertEquals(2, $value->value());
222
223 $value = $field
224 ->withStepSize(0)
225 ->withInput($post_data)
226 ->getContent();
227 $this->assertIsInt($value->value());
228 $this->assertEquals(1, $value->value());
229 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References Vendor\Package\$f, and ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testEmptyValue()

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

Definition at line 119 of file NumericInputTest.php.

119 : void
120 {
121 $post_data = new DefInputData(['name_0' => '']);
122 $field_required = $field->withRequired(true);
123
124 $value = $field->withInput($post_data)->getContent();
125 $this->assertTrue($value->isOk());
126 $this->assertNull($value->value());
127
128 $field_required = $field_required->withInput($post_data);
129 $value = $field_required->getContent();
130 $this->assertTrue($value->isError());
131 }

◆ testFloatValue()

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

Definition at line 165 of file NumericInputTest.php.

165 : void
166 {
167 $post_data = new DefInputData(['name_0' => 1.1]);
168 $value = $field
169 ->withStepSize(.1)
170 ->withInput($post_data)
171 ->getContent();
172 $this->assertTrue($value->isOk());
173 $this->assertEquals(1.1, $value->value());
174 }

◆ testFloatValueForInt()

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

Definition at line 189 of file NumericInputTest.php.

189 : void
190 {
191 $post_data = new DefInputData(['name_0' => 2]);
192 $value = $field
193 ->withStepSize(.5)
194 ->withInput($post_data)
195 ->getContent();
196 $this->assertTrue($value->isOk());
197 $this->assertEquals(2, $value->value());
198 $this->assertIsFloat($value->value());
199 }

◆ testFloatValueOffsetStep()

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

Definition at line 177 of file NumericInputTest.php.

177 : void
178 {
179 $post_data = new DefInputData(['name_0' => 1.2]);
180 $value = $field
181 ->withStepSize(.5)
182 ->withInput($post_data)
183 ->getContent();
184 $this->assertTrue($value->isOk());
185 $this->assertEquals(1.2, $value->value());
186 }

◆ testImplementsFactoryInterface()

NumericInputTest::testImplementsFactoryInterface ( )

Definition at line 44 of file NumericInputTest.php.

44 : void
45 {
46 $f = $this->getFieldFactory();
47
48 $numeric = $f->numeric("label", "byline");
49
50 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $numeric);
51 $this->assertInstanceOf(Field\Numeric::class, $numeric);
52 }

References Vendor\Package\$f.

◆ testNullValue()

NumericInputTest::testNullValue ( )

Definition at line 102 of file NumericInputTest.php.

103 {
104 $f = $this->getFieldFactory();
105 $post_data = new DefInputData(['name_0' => null]);
106 $field = $f->numeric('')->withNameFrom($this->name_source);
107 $field_required = $field->withRequired(true);
108
109 $value = $field->withInput($post_data)->getContent();
110 $this->assertTrue($value->isOk());
111 $this->assertNull($value->value());
112
113 $value = $field_required->withInput($post_data)->getContent();
114 $this->assertTrue($value->isError());
115 return $field;
116 }
This describes inputs that can be used in forms.
Definition: FormInput.php:33

References Vendor\Package\$f.

◆ testRender()

NumericInputTest::testRender ( )

Definition at line 55 of file NumericInputTest.php.

55 : void
56 {
57 $f = $this->getFieldFactory();
58 $label = "label";
59 $byline = "byline";
60 $numeric = $f->numeric($label, $byline)->withNameFrom($this->name_source);
61
62 $expected = $this->getFormWrappedHtml(
63 'numeric-field-input',
64 $label,
65 '<input id="id_1" type="number" step="1" name="name_0" class="c-field-number" />',
66 $byline,
67 'id_1'
68 );
69 $this->assertEquals($expected, $this->render($numeric));
70 }

References Vendor\Package\$f.

◆ testRenderValue()

NumericInputTest::testRenderValue ( )

Definition at line 85 of file NumericInputTest.php.

85 : void
86 {
87 $f = $this->getFieldFactory();
88 $label = "label";
89 $value = "10";
90 $numeric = $f->numeric($label)->withValue($value)->withNameFrom($this->name_source);
91
92 $expected = $this->getFormWrappedHtml(
93 'numeric-field-input',
94 $label,
95 '<input id="id_1" type="number" step="1" value="10" name="name_0" class="c-field-number" />',
96 null,
97 'id_1'
98 );
99 $this->assertEquals($expected, $this->render($numeric));
100 }

References Vendor\Package\$f.

◆ testZeroIsValidValue()

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

Definition at line 134 of file NumericInputTest.php.

134 : void
135 {
136 $post_data = new DefInputData(['name_0' => 0]);
137 $field_required = $field->withRequired(true);
138
139 $value = $field->withInput($post_data)->getContent();
140 $this->assertTrue($value->isOk());
141 $this->assertEquals(0, $value->value());
142
143 $value = $field_required->withInput($post_data)->getContent();
144 $this->assertTrue($value->isOK());
145 $this->assertEquals(0, $value->value());
146 }

Field Documentation

◆ $name_source

DefNamesource NumericInputTest::$name_source
protected

Definition at line 37 of file NumericInputTest.php.


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