ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FormTest Class Reference

Test on form implementation. More...

+ Inheritance diagram for FormTest:
+ Collaboration diagram for FormTest:

Public Member Functions

 getUIFactory ()
 
 buildDataFactory ()
 
 tearDown ()
 
 test_getInputs ()
 
 test_extractPostData ()
 
 test_withRequest ()
 
 test_withRequest_respects_keys ()
 
 test_getData ()
 
 test_getData_respects_keys ()
 
 test_getData_faulty ()
 
 test_withAdditionalTransformation ()
 
 test_nameInputs_respects_keys ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Member Functions

 buildFactory ()
 
 buildInputFactory ()
 
 buildButtonFactory ()
 
 buildTransformation (\Closure $trafo)
 

Detailed Description

Test on form implementation.

Definition at line 74 of file FormTest.php.

Member Function Documentation

◆ buildButtonFactory()

FormTest::buildButtonFactory ( )
protected

Definition at line 94 of file FormTest.php.

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ buildDataFactory()

FormTest::buildDataFactory ( )

Definition at line 114 of file FormTest.php.

115 {
116 return new \ILIAS\Data\Factory;
117 }

Referenced by test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), and test_withRequest_respects_keys().

+ Here is the caller graph for this function:

◆ buildFactory()

FormTest::buildFactory ( )
protected

Definition at line 76 of file FormTest.php.

References buildInputFactory().

Referenced by test_getInputs().

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

◆ buildInputFactory()

FormTest::buildInputFactory ( )
protected

Definition at line 82 of file FormTest.php.

83 {
84 $df = new Data\Factory();
86 new SignalGenerator(),
87 $df,
88 new Validation\Factory($df, $this->createMock(\ilLanguage::class)),
90 );
91 }
A transformation is a function from one datatype to another.

Referenced by buildFactory(), test_extractPostData(), test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_getInputs(), test_nameInputs_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), and test_withRequest_respects_keys().

+ Here is the caller graph for this function:

◆ buildTransformation()

FormTest::buildTransformation ( \Closure  $trafo)
protected

Definition at line 100 of file FormTest.php.

101 {
102 $f = new TransformationFactory();
103
104 return $f->custom($trafo);
105 }

References $f.

Referenced by test_withAdditionalTransformation().

+ Here is the caller graph for this function:

◆ getUIFactory()

FormTest::getUIFactory ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 108 of file FormTest.php.

109 {
110 return new WithButtonNoUIFactory($this->buildButtonFactory());
111 }
buildButtonFactory()
Definition: FormTest.php:94

References buildButtonFactory().

+ Here is the call graph for this function:

◆ tearDown()

FormTest::tearDown ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 120 of file FormTest.php.

121 {
122 \Mockery::close();
123 }

◆ test_extractPostData()

FormTest::test_extractPostData ( )

Definition at line 157 of file FormTest.php.

158 {
159 $form = new ConcreteForm($this->buildInputFactory(), []);
160 $request = \Mockery::mock(ServerRequestInterface::class);
161 $request->shouldReceive("getParsedBody")->once()->andReturn([]);
162 $post_data = $form->_extractPostData($request);
163 $this->assertInstanceOf(PostData::class, $post_data);
164 }
foreach($paths as $path) $request
Definition: asyncclient.php:32
if(isset($_POST['submit'])) $form

References $form, $request, and buildInputFactory().

+ Here is the call graph for this function:

◆ test_getData()

FormTest::test_getData ( )

Definition at line 225 of file FormTest.php.

226 {
227 $df = $this->buildDataFactory();
228 $request = \Mockery::mock(ServerRequestInterface::class);
229 $request->shouldReceive("getParsedBody")->once()->andReturn([]);
230
231 $input_1 = \Mockery::mock(InputInternal::class);
232 $input_1->shouldReceive("getContent")->once()->andReturn($df->ok(1));
233
234 $input_1->shouldReceive("withInput")->once()->andReturn($input_1);
235
236 $input_2 = \Mockery::mock(InputInternal::class);
237 $input_2->shouldReceive("getContent")->once()->andReturn($df->ok(2));
238
239 $input_2->shouldReceive("withInput")->once()->andReturn($input_2);
240
241 $form = new ConcreteForm($this->buildInputFactory(), []);
242 $form->setInputs([$input_1, $input_2]);
243 $form = $form->withRequest($request);
244 $this->assertEquals([1, 2], $form->getData());
245 }
buildDataFactory()
Definition: FormTest.php:114

References $form, $request, buildDataFactory(), and buildInputFactory().

+ Here is the call graph for this function:

◆ test_getData_faulty()

FormTest::test_getData_faulty ( )

Definition at line 271 of file FormTest.php.

272 {
273 $df = $this->buildDataFactory();
274 $request = \Mockery::mock(ServerRequestInterface::class);
275 $request->shouldReceive("getParsedBody")->once()->andReturn([]);
276
277 $input_1 = \Mockery::mock(InputInternal::class);
278 $input_1->shouldReceive("getContent")->once()->andReturn($df->error("error"));
279
280 $input_1->shouldReceive("withInput")->once()->andReturn($input_1);
281
282 $input_2 = \Mockery::mock(InputInternal::class);
283 $input_2->shouldReceive("getContent")->once()->andReturn($df->ok(2));
284
285 $input_2->shouldReceive("withInput")->once()->andReturn($input_2);
286
287 $form = new ConcreteForm($this->buildInputFactory(), []);
288 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
289
290 //Todo: This is not good, this should throw an error or similar.
291 $form = $form->withRequest($request);
292 $this->assertEquals(null, null);
293 }

References $form, $request, buildDataFactory(), and buildInputFactory().

+ Here is the call graph for this function:

◆ test_getData_respects_keys()

FormTest::test_getData_respects_keys ( )

Definition at line 248 of file FormTest.php.

249 {
250 $df = $this->buildDataFactory();
251 $request = \Mockery::mock(ServerRequestInterface::class);
252 $request->shouldReceive("getParsedBody")->once()->andReturn([]);
253
254 $input_1 = \Mockery::mock(InputInternal::class);
255 $input_1->shouldReceive("getContent")->once()->andReturn($df->ok(1));
256
257 $input_1->shouldReceive("withInput")->once()->andReturn($input_1);
258
259 $input_2 = \Mockery::mock(InputInternal::class);
260 $input_2->shouldReceive("getContent")->once()->andReturn($df->ok(2));
261
262 $input_2->shouldReceive("withInput")->once()->andReturn($input_2);
263
264 $form = new ConcreteForm($this->buildInputFactory(), []);
265 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
266 $form = $form->withRequest($request);
267 $this->assertEquals(["foo" => 1, "bar" => 2], $form->getData());
268 }

References $form, $request, buildDataFactory(), and buildInputFactory().

+ Here is the call graph for this function:

◆ test_getInputs()

FormTest::test_getInputs ( )

Definition at line 126 of file FormTest.php.

127 {
128 $f = $this->buildFactory();
129 $if = $this->buildInputFactory();
130 $name_source = new FixedNameSource();
131
132 $inputs = [$if->text(""), $if->text("")];
133 $form = new ConcreteForm($this->buildInputFactory(), $inputs);
134
135 $seen_names = [];
136 $inputs = $form->getInputs();
137 $this->assertEquals(count($inputs), count($inputs));
138
139 foreach ($inputs as $input) {
140 $name = $input->getName();
141 $name_source->name = $name;
142
143 // name is a string
144 $this->assertInternalType("string", $name);
145
146 // only name is attached
147 $input = array_shift($inputs);
148 $this->assertEquals($input->withNameFrom($name_source), $input);
149
150 // every name can only be contained once.
151 $this->assertNotContains($name, $seen_names);
152 $seen_names[] = $name;
153 }
154 }
buildFactory()
Definition: FormTest.php:76

References $f, $form, $input, $name, buildFactory(), and buildInputFactory().

+ Here is the call graph for this function:

◆ test_nameInputs_respects_keys()

FormTest::test_nameInputs_respects_keys ( )

Definition at line 326 of file FormTest.php.

327 {
328 $if = $this->buildInputFactory();
329 $inputs = [
330 2 => $if->text(""),
331 "foo" => $if->text(""),
332 1 => $if->text(""),
333 $if->text(""),
334 ];
335 $form = new ConcreteForm($this->buildInputFactory(), []);
336 $form->setInputs($inputs);
337 $named_inputs = $form->getInputs();
338 $this->assertEquals(array_keys($inputs), array_keys($named_inputs));
339 }

References $form, and buildInputFactory().

+ Here is the call graph for this function:

◆ test_withAdditionalTransformation()

FormTest::test_withAdditionalTransformation ( )

Definition at line 296 of file FormTest.php.

297 {
298 $df = $this->buildDataFactory();
299 $request = \Mockery::mock(ServerRequestInterface::class);
300 $request->shouldReceive("getParsedBody")->once()->andReturn([]);
301
302 $input_1 = \Mockery::mock(InputInternal::class);
303 $input_1->shouldReceive("getContent")->once()->andReturn($df->ok(1));
304
305 $input_1->shouldReceive("withInput")->once()->andReturn($input_1);
306
307 $input_2 = \Mockery::mock(InputInternal::class);
308 $input_2->shouldReceive("getContent")->once()->andReturn($df->ok(2));
309
310 $input_2->shouldReceive("withInput")->once()->andReturn($input_2);
311
312 $form = new ConcreteForm($this->buildInputFactory(), []);
313 $form->setInputs([$input_1, $input_2]);
314
315 $form2 = $form->withAdditionalTransformation($this->buildTransformation(function ($v) {
316 return "transformed";
317 }));
318
319 $this->assertNotSame($form2, $form);
320 $form2 = $form2->withRequest($request);
321
322 $this->assertEquals("transformed", $form2->getData());
323 }
buildTransformation(\Closure $trafo)
Definition: FormTest.php:100

References $form, $request, buildDataFactory(), buildInputFactory(), and buildTransformation().

+ Here is the call graph for this function:

◆ test_withRequest()

FormTest::test_withRequest ( )

Definition at line 167 of file FormTest.php.

168 {
169 $request = \Mockery::mock(ServerRequestInterface::class);
170 $post_data = \Mockery::Mock(PostData::class);
171 $post_data->shouldReceive("getOr")->once()->andReturn("");
172
173 $df = $this->buildDataFactory();
174
175 $input_1 = \Mockery::mock(InputInternal::class);
176 $input_1->shouldReceive("withInput")->once()->with($post_data)->andReturn($input_1);
177
178 $input_1->shouldReceive("getContent")->once()->andReturn($df->ok(0));
179
180 $input_2 = \Mockery::mock(InputInternal::class);
181 $input_2->shouldReceive("withInput")->once()->with($post_data)->andReturn($input_2);
182
183 $input_2->shouldReceive("getContent")->once()->andReturn($df->ok(0));
184
185 $form = new ConcreteForm($this->buildInputFactory(), []);
186 $form->setInputs([$input_1, $input_2]);
187 $form->post_data = $post_data;
188
189 $form2 = $form->withRequest($request);
190
191 $this->assertNotSame($form2, $form);
192 $this->assertInstanceOf(Form::class, $form2);
193 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
194 }

References $form, $request, buildDataFactory(), and buildInputFactory().

+ Here is the call graph for this function:

◆ test_withRequest_respects_keys()

FormTest::test_withRequest_respects_keys ( )

Definition at line 197 of file FormTest.php.

198 {
199 $request = \Mockery::mock(ServerRequestInterface::class);
200 $post_data = \Mockery::Mock(PostData::class);
201 $post_data->shouldReceive("getOr")->once()->andReturn("");
202
203 $df = $this->buildDataFactory();
204
205 $input_1 = \Mockery::mock(InputInternal::class);
206 $input_1->shouldReceive("withInput")->once()->with($post_data)->andReturn($input_1);
207 $input_1->shouldReceive("getContent")->once()->andReturn($df->ok(0));
208
209 $input_2 = \Mockery::mock(InputInternal::class);
210 $input_2->shouldReceive("withInput")->once()->with($post_data)->andReturn($input_2);
211 $input_2->shouldReceive("getContent")->once()->andReturn($df->ok(0));
212
213 $form = new ConcreteForm($this->buildInputFactory(), []);
214 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
215 $form->post_data = $post_data;
216
217 $form2 = $form->withRequest($request);
218
219 $this->assertNotSame($form2, $form);
220 $this->assertInstanceOf(Form::class, $form2);
221 $this->assertEquals(["foo" => $input_1, "bar" => $input_2], $form2->getInputs());
222 }

References $form, $request, buildDataFactory(), and buildInputFactory().

+ Here is the call graph for this function:

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