ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
FileInputTest Class Reference
+ Inheritance diagram for FileInputTest:
+ Collaboration diagram for FileInputTest:

Public Member Functions

 setUp ()
 
 test_implements_factory_interface ()
 
 test_render ()
 
 test_render_error ()
 
 test_render_no_byline ()
 
 test_render_value ()
 
 test_render_with_metadata ()
 
 test_render_with_metadata_value ()
 
 test_render_required ()
 
 test_render_disabled ()
 
 getUIFactory ()
 
- 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

 brutallyTrimHTML (string $html)
 
 buildFactory ()
 
 buildButtonFactory ()
 
 buildSymbolFactory ()
 
- 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
 

Private Member Functions

 getUploadHandler (?FileInfoResult $file=null)
 

Detailed Description

Definition at line 55 of file FileInputTest.php.

Member Function Documentation

◆ brutallyTrimHTML()

FileInputTest::brutallyTrimHTML ( string  $html)
protected

Definition at line 64 of file FileInputTest.php.

64  : string
65  {
66  $html = str_replace(" />", "/>", $html);
67  return parent::brutallyTrimHTML($html);
68  }

◆ buildButtonFactory()

FileInputTest::buildButtonFactory ( )
protected

Definition at line 501 of file FileInputTest.php.

501  : I\Button\Factory
502  {
503  return new I\Button\Factory();
504  }

◆ buildFactory()

FileInputTest::buildFactory ( )
protected

Definition at line 70 of file FileInputTest.php.

70  : I\Input\Field\Factory
71  {
72  $df = new Data\Factory();
73  $language = $this->createMock(ilLanguage::class);
74 
75  return new I\Input\Field\Factory(
76  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
77  new SignalGenerator(),
78  $df,
79  new ILIAS\Refinery\Factory($df, $language),
80  $language
81  );
82  }
Class Factory.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ buildSymbolFactory()

FileInputTest::buildSymbolFactory ( )
protected

Definition at line 506 of file FileInputTest.php.

506  : I\Symbol\Factory
507  {
508  return new I\Symbol\Factory(
509  new I\Symbol\Icon\Factory(),
510  new I\Symbol\Glyph\Factory(),
511  new I\Symbol\Avatar\Factory()
512  );
513  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getUIFactory()

FileInputTest::getUIFactory ( )

Definition at line 515 of file FileInputTest.php.

◆ getUploadHandler()

FileInputTest::getUploadHandler ( ?FileInfoResult  $file = null)
private

Definition at line 85 of file FileInputTest.php.

References WithButtonAndSymbolButNoUIFactory\__construct().

85  : Field\UploadHandler
86  {
87  return new class ($file) implements Field\UploadHandler {
88  protected ?FileInfoResult $file;
89 
90  public function __construct(?FileInfoResult $file)
91  {
92  $this->file = $file;
93  }
94 
95  public function getFileIdentifierParameterName(): string
96  {
97  return 'file_id';
98  }
99 
100  public function getUploadURL(): string
101  {
102  return 'uploadurl';
103  }
104 
105  public function getFileRemovalURL(): string
106  {
107  return 'removalurl';
108  }
109 
113  public function getExistingFileInfoURL(): string
114  {
115  return 'infourl';
116  }
117 
121  public function getInfoForExistingFiles(array $file_ids): array
122  {
123  return [];
124  }
125 
126  public function getInfoResult(string $identifier): ?FileInfoResult
127  {
128  if (null !== $this->file && $identifier === $this->file->getFileIdentifier()) {
129  return $this->file;
130  }
131 
132  return null;
133  }
134 
135  public function supportsChunkedUploads(): bool
136  {
137  return false;
138  }
139  };
140  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

◆ setUp()

FileInputTest::setUp ( )

Definition at line 59 of file FileInputTest.php.

59  : void
60  {
61  $this->name_source = new DefNamesource();
62  }

◆ test_implements_factory_interface()

FileInputTest::test_implements_factory_interface ( )

Definition at line 143 of file FileInputTest.php.

References Vendor\Package\$f.

143  : void
144  {
145  $f = $this->buildFactory();
146 
147  $text = $f->file($this->getUploadHandler(), "label", "byline");
148 
149  $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $text);
150  $this->assertInstanceOf(Field\File::class, $text);
151  }
Class Factory.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getUploadHandler(?FileInfoResult $file=null)

◆ test_render()

FileInputTest::test_render ( )

Definition at line 154 of file FileInputTest.php.

References Vendor\Package\$f.

154  : void
155  {
156  $f = $this->buildFactory();
157  $label = "label";
158  $byline = "byline";
159  $text = $f->file($this->getUploadHandler(), $label, $byline)->withNameFrom($this->name_source);
160 
161  $r = $this->getDefaultRenderer();
162  $html = $this->brutallyTrimHTML($r->render($text));
163 
164  $expected = $this->brutallyTrimHTML('
165  <div class="form-group row">
166  <label class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
167  <div class="col-sm-8 col-md-9 col-lg-10">
168  <div id="id_3" class="ui-input-file">
169  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list"></div>
170  <div class="ui-input-file-input-dropzone">
171  <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button>
172  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
173  </div>
174  </div>
175  <div class="help-block">byline</div>
176  </div>
177  </div>
178  ');
179  $this->assertEquals($expected, $html);
180  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)

◆ test_render_disabled()

FileInputTest::test_render_disabled ( )

Definition at line 476 of file FileInputTest.php.

References Vendor\Package\$f.

476  : void
477  {
478  $f = $this->buildFactory();
479  $label = "label";
480  $text = $f->file($this->getUploadHandler(), $label)->withNameFrom($this->name_source)->withDisabled(true);
481 
482  $r = $this->getDefaultRenderer();
483  $html = $this->brutallyTrimHTML($r->render($text));
484 
485  $expected = $this->brutallyTrimHTML('
486  <div class="form-group row"><label class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
487  <div class="col-sm-8 col-md-9 col-lg-10">
488  <div id="id_3" class="ui-input-file">
489  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list"></div>
490  <div class="ui-input-file-input-dropzone">
491  <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button>
492  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
493  </div>
494  </div>
495  </div>
496  ');
497 
498  $this->assertEquals($expected, $html);
499  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)

◆ test_render_error()

FileInputTest::test_render_error ( )

Definition at line 183 of file FileInputTest.php.

References Vendor\Package\$f.

183  : void
184  {
185  $f = $this->buildFactory();
186  $label = "label";
187  $byline = "byline";
188  $error = "an_error";
189  $text = $f->file($this->getUploadHandler(), $label, $byline)->withNameFrom($this->name_source)->withError($error);
190 
191  $r = $this->getDefaultRenderer();
192  $html = $this->brutallyTrimHTML($r->render($text));
193 
194  $expected = $this->brutallyTrimHTML('
195  <div class="form-group row"><label 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">
197  <div class="help-block alert alert-danger" aria-describedby="id_3" role="alert">an_error</div>
198  <div id="id_3" class="ui-input-file">
199  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list"></div>
200  <div class="ui-input-file-input-dropzone">
201  <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button>
202  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
203  </div>
204  <div class="help-block">byline</div>
205  </div>
206  </div>
207  ');
208  $this->assertEquals($expected, $html);
209  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)

◆ test_render_no_byline()

FileInputTest::test_render_no_byline ( )

Definition at line 212 of file FileInputTest.php.

References Vendor\Package\$f.

212  : void
213  {
214  $f = $this->buildFactory();
215  $label = "label";
216  $text = $f->file($this->getUploadHandler(), $label)->withNameFrom($this->name_source);
217 
218  $r = $this->getDefaultRenderer();
219  $html = $this->brutallyTrimHTML($r->render($text));
220 
221  $expected = $this->brutallyTrimHTML('
222  <div class="form-group row"><label class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
223  <div class="col-sm-8 col-md-9 col-lg-10">
224  <div id="id_3" class="ui-input-file">
225  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list"></div>
226  <div class="ui-input-file-input-dropzone">
227  <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button>
228  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
229  </div>
230  </div>
231  </div>
232  ');
233  $this->assertEquals($expected, $html);
234  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)

◆ test_render_required()

FileInputTest::test_render_required ( )

Definition at line 451 of file FileInputTest.php.

References Vendor\Package\$f.

451  : void
452  {
453  $f = $this->buildFactory();
454  $label = "label";
455  $text = $f->file($this->getUploadHandler(), $label)->withNameFrom($this->name_source)->withRequired(true);
456 
457  $r = $this->getDefaultRenderer();
458  $html = $this->brutallyTrimHTML($r->render($text));
459 
460  $expected = $this->brutallyTrimHTML('
461  <div class="form-group row"><label class="control-label col-sm-4 col-md-3 col-lg-2">label<span class="asterisk">*</span></label>
462  <div class="col-sm-8 col-md-9 col-lg-10">
463  <div id="id_3" class="ui-input-file">
464  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list"></div>
465  <div class="ui-input-file-input-dropzone">
466  <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button>
467  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
468  </div>
469  </div>
470  </div>
471  ');
472  $this->assertEquals($expected, $html);
473  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)

◆ test_render_value()

FileInputTest::test_render_value ( )

Definition at line 237 of file FileInputTest.php.

237  : void
238  {
239  $test_file_id = "test_file_id_1";
240  $test_file_name = "test file name 1";
241 
242  $test_file_info = $this->createMock(FileInfoResult::class);
243  $test_file_info->method('getFileIdentifier')->willReturn("test_file_id_1");
244  $test_file_info->method('getName')->willReturn("test file name 1");
245  $test_file_info->method('getSize')->willReturn(1001);
246 
247  $file_input = $this->buildFactory()->file(
248  $this->getUploadHandler($test_file_info),
249  "",
250  )->withValue([
251  $test_file_id,
252  ])->withNameFrom($this->name_source);
253 
254  $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($file_input));
255 
256  $expected = $this->brutallyTrimHTML('
257 <div class="form-group row">
258  <label class="control-label col-sm-4 col-md-3 col-lg-2"></label>
259  <div class="col-sm-8 col-md-9 col-lg-10">
260  <div id="id_4" class="ui-input-file">
261  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list">
262  <div class="ui-input-file-input ui-input-dynamic-input">
263  <div class="ui-input-file-info">
264  <span data-action="expand"></span>
265  <span data-action="collapse"></span>
266  <span data-dz-name>test file name 1</span>
267  <span data-dz-size>1 KB</span>
268  <span data-action="remove">
269  <a tabindex="0" class="glyph" href="#" aria-label="close">
270  <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
271  </a>
272  </span>
273  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
274  </div>
275  <div class="ui-input-file-metadata" style="display: none;">
276  <input id="id_1" type="hidden" name="name_0[input_0][]" value="test_file_id_1"/>
277  </div>
278  <div class="ui-input-file-input-progress-container">
279  <div class="ui-input-file-input-progress-indicator"></div>
280  </div>
281  </div>
282  </div>
283  <div class="ui-input-file-input-dropzone">
284  <button class="btn btn-link" data-action="#" id="id_3">select_files_from_computer</button>
285  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
286  </div>
287  </div>
288  </div>
289 </div>
290  ');
291  $this->assertEquals($expected, $html);
292  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)

◆ test_render_with_metadata()

FileInputTest::test_render_with_metadata ( )

Definition at line 295 of file FileInputTest.php.

References $factory, and ILIAS\UI\Implementation\Component\Input\ViewControl\withNameFrom().

295  : void
296  {
297  $factory = $this->buildFactory();
298 
299  $metadata_input = $factory->text("text_input");
300  $file_input = $factory->file(
301  ($u = $this->getUploadHandler()),
302  "file_input",
303  null,
304  $metadata_input
305  )->withValue([
306  [
307  $u->getFileIdentifierParameterName() => "file_id",
308  ""
309  ]
310  ])->withNameFrom($this->name_source);
311 
312  $r = $this->getDefaultRenderer();
313  $html = $this->brutallyTrimHTML($r->render($file_input));
314 
315  $expected = $this->brutallyTrimHTML('
316 <div class="form-group row">
317  <label class="control-label col-sm-4 col-md-3 col-lg-2">file_input</label>
318  <div class="col-sm-8 col-md-9 col-lg-10">
319  <div id="id_6" class="ui-input-file">
320  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list">
321  <div class="ui-input-file-input ui-input-dynamic-input">
322  <div class="ui-input-file-info">
323  <span data-action="expand">
324  <a tabindex="0" class="glyph" href="#" aria-label="expand_content">
325  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
326  </a>
327  </span>
328  <span data-action="collapse">
329  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content">
330  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
331  </a>
332  </span>
333  <span data-dz-name></span>
334  <span data-dz-size></span>
335  <span data-action="remove">
336  <a tabindex="0" class="glyph" href="#" aria-label="close">
337  <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
338  </a>
339  </span>
340  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
341  </div>
342  <div class="ui-input-file-metadata" style="display: none;">
343  <div class="form-group row">
344  <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">text_input</label>
345  <div class="col-sm-8 col-md-9 col-lg-10">
346  <input id="id_1" type="text" name="name_0[input_1][]" class="form-control form-control-sm"/>
347  </div>
348  </div>
349  <input id="id_2" type="hidden" name="name_0[input_2][]" value="file_id"/>
350  </div>
351  <div class="ui-input-file-input-progress-container">
352  <div class="ui-input-file-input-progress-indicator"></div>
353  </div>
354  </div>
355  </div>
356  <div class="ui-input-file-input-dropzone">
357  <button class="btn btn-link" data-action="#" id="id_5">select_files_from_computer</button>
358  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
359  </div>
360  </div>
361  </div>
362 </div>
363  ');
364 
365  $this->assertEquals($expected, $html);
366  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
withNameFrom(NameSource $source, ?string $parent_name=null)
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

◆ test_render_with_metadata_value()

FileInputTest::test_render_with_metadata_value ( )

Definition at line 369 of file FileInputTest.php.

References $factory, and ILIAS\UI\Implementation\Component\Input\ViewControl\withNameFrom().

369  : void
370  {
371  $test_file_id = "test_file_id_1";
372  $test_file_name = "test file name 1";
373 
374  $test_file_info = $this->createMock(FileInfoResult::class);
375  $test_file_info->method('getFileIdentifier')->willReturn("test_file_id_1");
376  $test_file_info->method('getName')->willReturn("test file name 1");
377  $test_file_info->method('getSize')->willReturn(1000 * 1000 + 1);
378 
379  $factory = $this->buildFactory();
380 
381  $metadata_input = $factory->text("text_input");
382  $file_input = $factory->file(
383  $u = $this->getUploadHandler($test_file_info),
384  "file_input",
385  null,
386  $metadata_input
387  )->withValue([
388  [
389  $u->getFileIdentifierParameterName() => $test_file_id,
390  "test",
391  ]
392  ])->withNameFrom($this->name_source);
393 
394  $r = $this->getDefaultRenderer();
395  $html = $this->brutallyTrimHTML($r->render($file_input));
396 
397  $expected = $this->brutallyTrimHTML('
398 <div class="form-group row">
399  <label class="control-label col-sm-4 col-md-3 col-lg-2">file_input</label>
400  <div class="col-sm-8 col-md-9 col-lg-10">
401  <div id="id_6" class="ui-input-file">
402  <div class="ui-input-file-input-list ui-input-dynamic-inputs-list">
403  <div class="ui-input-file-input ui-input-dynamic-input">
404  <div class="ui-input-file-info">
405  <span data-action="expand">
406  <a tabindex="0" class="glyph" href="#" aria-label="expand_content">
407  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
408  </a>
409  </span>
410  <span data-action="collapse">
411  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content">
412  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
413  </a>
414  </span>
415  <span data-dz-name>test file name 1</span>
416  <span data-dz-size>1 MB</span>
417  <span data-action="remove">
418  <a tabindex="0" class="glyph" href="#" aria-label="close">
419  <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
420  </a>
421  </span>
422  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
423  </div>
424  <div class="ui-input-file-metadata" style="display: none;">
425  <div class="form-group row">
426  <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">text_input</label>
427  <div class="col-sm-8 col-md-9 col-lg-10">
428  <input id="id_1" type="text" value="test" name="name_0[input_1][]" class="form-control form-control-sm"/>
429  </div>
430  </div>
431  <input id="id_2" type="hidden" name="name_0[input_2][]" value="test_file_id_1"/>
432  </div>
433  <div class="ui-input-file-input-progress-container">
434  <div class="ui-input-file-input-progress-indicator"></div>
435  </div>
436  </div>
437  </div>
438  <div class="ui-input-file-input-dropzone">
439  <button class="btn btn-link" data-action="#" id="id_5">select_files_from_computer</button>
440  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
441  </div>
442  </div>
443  </div>
444 </div>
445  ');
446 
447  $this->assertEquals($expected, $html);
448  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
withNameFrom(NameSource $source, ?string $parent_name=null)
getUploadHandler(?FileInfoResult $file=null)
brutallyTrimHTML(string $html)
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

Field Documentation

◆ $name_source

DefNamesource FileInputTest::$name_source
protected

Definition at line 57 of file FileInputTest.php.


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