ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FileInputTest Class Reference
+ Inheritance diagram for FileInputTest:
+ Collaboration diagram for FileInputTest:

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testRender ()
 
 testCommonRendering ()
 
 testRenderValue ()
 
 testRenderWithMetadata ()
 
 testRenderWithMetadataValue ()
 
 getUIFactory ()
 

Protected Member Functions

 brutallyTrimHTML (string $html)
 
 buildButtonFactory ()
 
 buildSymbolFactory ()
 

Protected Attributes

DefNamesource $name_source
 

Private Member Functions

 getUploadHandler (?FileInfoResult $file=null)
 

Detailed Description

Definition at line 57 of file FileInputTest.php.

Member Function Documentation

◆ brutallyTrimHTML()

FileInputTest::brutallyTrimHTML ( string  $html)
protected

Definition at line 68 of file FileInputTest.php.

68  : string
69  {
70  $html = str_replace(" />", "/>", $html);
71  return parent::brutallyTrimHTML($html);
72  }

◆ buildButtonFactory()

FileInputTest::buildButtonFactory ( )
protected

Definition at line 480 of file FileInputTest.php.

480  : I\Button\Factory
481  {
482  return new I\Button\Factory();
483  }

◆ buildSymbolFactory()

FileInputTest::buildSymbolFactory ( )
protected

Definition at line 485 of file FileInputTest.php.

485  : I\Symbol\Factory
486  {
487  return new I\Symbol\Factory(
488  new I\Symbol\Icon\Factory(),
489  new I\Symbol\Glyph\Factory(),
490  new I\Symbol\Avatar\Factory()
491  );
492  }
Builds data types.
Definition: Factory.php:35

◆ getUIFactory()

FileInputTest::getUIFactory ( )

Definition at line 494 of file FileInputTest.php.

◆ getUploadHandler()

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

Definition at line 74 of file FileInputTest.php.

References WithButtonAndSymbolButNoUIFactory\__construct(), and null.

74  : Field\UploadHandler
75  {
76  return new class ($file) implements Field\UploadHandler {
77  protected ?FileInfoResult $file;
78 
79  public function __construct(?FileInfoResult $file)
80  {
81  $this->file = $file;
82  }
83 
84  public function getFileIdentifierParameterName(): string
85  {
86  return 'file_id';
87  }
88 
89  public function getUploadURL(): string
90  {
91  return 'uploadurl';
92  }
93 
94  public function getFileRemovalURL(): string
95  {
96  return 'removalurl';
97  }
98 
102  public function getExistingFileInfoURL(): string
103  {
104  return 'infourl';
105  }
106 
110  public function getInfoForExistingFiles(array $file_ids): array
111  {
112  return [];
113  }
114 
115  public function getInfoResult(string $identifier): ?FileInfoResult
116  {
117  if (null !== $this->file && $identifier === $this->file->getFileIdentifier()) {
118  return $this->file;
119  }
120 
121  return null;
122  }
123 
124  public function supportsChunkedUploads(): bool
125  {
126  return false;
127  }
128  };
129  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

◆ setUp()

FileInputTest::setUp ( )

Definition at line 63 of file FileInputTest.php.

63  : void
64  {
65  $this->name_source = new DefNamesource();
66  }

◆ testCommonRendering()

FileInputTest::testCommonRendering ( )

Definition at line 185 of file FileInputTest.php.

References Vendor\Package\$f, and null.

185  : void
186  {
187  $f = $this->getFieldFactory();
188  $file_input = $f->file($this->getUploadHandler(), 'label', null)
189  ->withNameFrom($this->name_source);
190  $this->testWithError($file_input);
191  $this->testWithNoByline($file_input);
192  $this->testWithRequired($file_input);
193  $this->testWithDisabled($file_input);
194  $this->testWithAdditionalOnloadCodeRendersId($file_input);
195  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getUploadHandler(?FileInfoResult $file=null)

◆ testImplementsFactoryInterface()

FileInputTest::testImplementsFactoryInterface ( )

Definition at line 132 of file FileInputTest.php.

References Vendor\Package\$f.

132  : void
133  {
134  $f = $this->getFieldFactory();
135 
136  $text = $f->file($this->getUploadHandler(), "label", "byline");
137 
138  $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $text);
139  $this->assertInstanceOf(Field\File::class, $text);
140  }
Interface Observer Contains several chained tasks and infos about them.
getUploadHandler(?FileInfoResult $file=null)

◆ testRender()

FileInputTest::testRender ( )

Definition at line 143 of file FileInputTest.php.

References Vendor\Package\$f, and null.

143  : void
144  {
145  $f = $this->getFieldFactory();
146  $label = "label";
147  $byline = "byline";
148  $file_input = $f->file($this->getUploadHandler(), $label, $byline)->withNameFrom($this->name_source);
149 
150  $expected = $this->getFormWrappedHtml(
151  'file-field-input',
152  $label,
153  '
154  <div class="ui-input-file">
155  <div class="ui-input-file-input-list">
156  <template>
157  <div class="ui-input-file-input">
158  <div class="ui-input-file-info"><span data-action="expand"></span><span
159  data-action="collapse"></span><span data-dz-name></span><span data-dz-size></span><span
160  data-action="remove"><a tabindex="0" class="glyph" href="#" aria-label="close"><span
161  class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></span><span
162  class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
163  <div class="ui-input-file-metadata" style="display: none;"><input id="id_1" type="hidden"
164  name="name_0[input_0][]" value="" /></div>
165  <div class="ui-input-file-input-progress-container">
166  <div class="ui-input-file-input-progress-indicator"></div>
167  </div>
168  </div>
169  </template>
170  </div>
171  <div class="ui-input-file-input-dropzone">
172  <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button>
173  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
174  </div>
175  <div class="help-block"> file_notice 0 B | ui_file_upload_max_nr 1</div>
176  </div>
177  ',
178  $byline,
179  null,
180  'id_3'
181  );
182  $this->assertEquals($expected, $this->render($file_input));
183  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getUploadHandler(?FileInfoResult $file=null)

◆ testRenderValue()

FileInputTest::testRenderValue ( )

Definition at line 197 of file FileInputTest.php.

References null.

197  : void
198  {
199  $test_file_id = "test_file_id_1";
200  $test_file_name = "test file name 1";
201 
202  $test_file_info = $this->createMock(FileInfoResult::class);
203  $test_file_info->method('getFileIdentifier')->willReturn("test_file_id_1");
204  $test_file_info->method('getName')->willReturn("test file name 1");
205  $test_file_info->method('getSize')->willReturn(1001);
206 
207  $file_input = $this->getFieldFactory()->file(
208  $this->getUploadHandler($test_file_info),
209  "",
210  )->withValue([
211  $test_file_id,
212  ])->withNameFrom($this->name_source);
213 
214  $expected = $this->getFormWrappedHtml(
215  'file-field-input',
216  '',
217  '
218  <div class="ui-input-file">
219  <div class="ui-input-file-input-list">
220  <div class="ui-input-file-input">
221  <div class="ui-input-file-info">
222  <span data-action="expand"></span>
223  <span data-action="collapse"></span>
224  <span data-dz-name>test file name 1</span>
225  <span data-dz-size>1 KB</span>
226  <span data-action="remove">
227  <a tabindex="0" class="glyph" href="#" aria-label="close">
228  <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
229  </a>
230  </span>
231  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
232  </div>
233  <div class="ui-input-file-metadata" style="display: none;">
234  <input id="id_1" type="hidden" name="name_0[input_0][]" value="test_file_id_1"/>
235  </div>
236  <div class="ui-input-file-input-progress-container">
237  <div class="ui-input-file-input-progress-indicator"></div>
238  </div>
239  </div>
240  <template>
241  <div class="ui-input-file-input">
242  <div class="ui-input-file-info"><span data-action="expand"></span><span
243  data-action="collapse"></span><span data-dz-name></span><span data-dz-size></span><span
244  data-action="remove"><a tabindex="0" class="glyph" href="#" aria-label="close"><span
245  class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></span><span
246  class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
247  <div class="ui-input-file-metadata" style="display: none;"><input id="id_2" type="hidden"
248  name="name_0[input_0][]" value="" /></div>
249  <div class="ui-input-file-input-progress-container">
250  <div class="ui-input-file-input-progress-indicator"></div>
251  </div>
252  </div>
253  </template>
254  </div>
255  <div class="ui-input-file-input-dropzone">
256  <button class="btn btn-link" data-action="#" id="id_3">select_files_from_computer</button>
257  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
258  </div>
259  <div class="help-block"> file_notice 0 B | ui_file_upload_max_nr 1</div>
260  </div>
261  ',
262  null,
263  null,
264  'id_4'
265  );
266  $this->assertEquals($expected, $this->render($file_input));
267  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getUploadHandler(?FileInfoResult $file=null)

◆ testRenderWithMetadata()

FileInputTest::testRenderWithMetadata ( )

Definition at line 270 of file FileInputTest.php.

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

270  : void
271  {
272  $factory = $this->getFieldFactory();
273  $label = 'file_input';
274  $metadata_input = $factory->text("text_input");
275  $file_input = $factory->file(
276  ($u = $this->getUploadHandler()),
277  $label,
278  null,
279  $metadata_input
280  )->withValue([
281  [
282  $u->getFileIdentifierParameterName() => "file_id",
283  ""
284  ]
285  ])->withNameFrom($this->name_source);
286 
287  $expected = $this->getFormWrappedHtml(
288  'file-field-input',
289  $label,
290  '
291  <div class="ui-input-file">
292  <div class="ui-input-file-input-list">
293  <div class="ui-input-file-input">
294  <div class="ui-input-file-info">
295  <span data-action="expand">
296  <a tabindex="0" class="glyph" href="#" aria-label="expand_content">
297  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
298  </a>
299  </span>
300  <span data-action="collapse">
301  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content">
302  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
303  </a>
304  </span>
305  <span data-dz-name></span>
306  <span data-dz-size></span>
307  <span data-action="remove">
308  <a tabindex="0" class="glyph" href="#" aria-label="close">
309  <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
310  </a>
311  </span>
312  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
313  </div>
314  <div class="ui-input-file-metadata" style="display: none;">
315  <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="name_0[input_1][]">
316  <label for="id_1">text_input</label>
317  <div class="c-input__field">
318  <input id="id_1" type="text" name="name_0[input_1][]" class="c-field-text"/>
319  </div>
320  </fieldset>
321  <input id="id_2" type="hidden" name="name_0[input_2][]" value="file_id"/>
322  </div>
323  <div class="ui-input-file-input-progress-container">
324  <div class="ui-input-file-input-progress-indicator"></div>
325  </div>
326  </div>
327  <template>
328  <div class="ui-input-file-input">
329  <div class="ui-input-file-info"><span data-action="expand"><a tabindex="0" class="glyph"
330  href="#" aria-label="expand_content"><span
331  class="glyphicon glyphicon-triangle-right"
332  aria-hidden="true"></span></a></span><span data-action="collapse"><a
333  tabindex="0" class="glyph" href="#" aria-label="collapse_content"><span
334  class="glyphicon glyphicon-triangle-bottom"
335  aria-hidden="true"></span></a></span><span data-dz-name></span><span
336  data-dz-size></span><span data-action="remove"><a tabindex="0" class="glyph" href="#"
337  aria-label="close"><span class="glyphicon glyphicon-remove"
338  aria-hidden="true"></span></a></span><span class="ui-input-file-input-error-msg"
339  data-dz-error-msg></span></div>
340  <div class="ui-input-file-metadata" style="display: none;">
341  <fieldset class="c-input" data-il-ui-component="text-field-input"
342  data-il-ui-input-name="name_0[input_1][]"><label for="id_3">text_input</label>
343  <div class="c-input__field"><input id="id_3" type="text" name="name_0[input_1][]"
344  class="c-field-text" /></div>
345  </fieldset><input id="id_4" type="hidden" name="name_0[input_2][]" value="" />
346  </div>
347  <div class="ui-input-file-input-progress-container">
348  <div class="ui-input-file-input-progress-indicator"></div>
349  </div>
350  </div>
351  </template>
352  </div>
353  <div class="ui-input-file-input-dropzone">
354  <button class="btn btn-link" data-action="#" id="id_5">select_files_from_computer</button>
355  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
356  </div>
357  <div class="help-block"> file_notice 0 B | ui_file_upload_max_nr 1</div>
358  </div>
359  ',
360  null,
361  null,
362  'id_6',
363  );
364  $this->assertEquals($expected, $this->render($file_input));
365  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withNameFrom(NameSource $source, ?string $parent_name=null)
getUploadHandler(?FileInfoResult $file=null)
+ Here is the call graph for this function:

◆ testRenderWithMetadataValue()

FileInputTest::testRenderWithMetadataValue ( )

Definition at line 368 of file FileInputTest.php.

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

368  : void
369  {
370  $test_file_id = "test_file_id_1";
371  $test_file_name = "test file name 1";
372 
373  $test_file_info = $this->createMock(FileInfoResult::class);
374  $test_file_info->method('getFileIdentifier')->willReturn("test_file_id_1");
375  $test_file_info->method('getName')->willReturn("test file name 1");
376  $test_file_info->method('getSize')->willReturn(1000 * 1000 + 1);
377 
378  $factory = $this->getFieldFactory();
379  $label = 'file_input';
380  $metadata_input = $factory->text("text_input");
381  $file_input = $factory->file(
382  $u = $this->getUploadHandler($test_file_info),
383  $label,
384  null,
385  $metadata_input
386  )->withValue([
387  [
388  $u->getFileIdentifierParameterName() => $test_file_id,
389  "test",
390  ]
391  ])->withNameFrom($this->name_source);
392 
393 
394  $expected = $this->getFormWrappedHtml(
395  'file-field-input',
396  $label,
397  '
398  <div class="ui-input-file">
399  <div class="ui-input-file-input-list">
400  <div class="ui-input-file-input">
401  <div class="ui-input-file-info">
402  <span data-action="expand">
403  <a tabindex="0" class="glyph" href="#" aria-label="expand_content">
404  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
405  </a>
406  </span>
407  <span data-action="collapse">
408  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content">
409  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
410  </a>
411  </span>
412  <span data-dz-name>test file name 1</span>
413  <span data-dz-size>1 MB</span>
414  <span data-action="remove">
415  <a tabindex="0" class="glyph" href="#" aria-label="close">
416  <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
417  </a>
418  </span>
419  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
420  </div>
421  <div class="ui-input-file-metadata" style="display: none;">
422  <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="name_0[input_1][]">
423  <label for="id_1">text_input</label>
424  <div class="c-input__field">
425  <input id="id_1" type="text" value="test" name="name_0[input_1][]" class="c-field-text"/>
426  </div>
427  </fieldset>
428  <input id="id_2" type="hidden" name="name_0[input_2][]" value="test_file_id_1"/>
429  </div>
430  <div class="ui-input-file-input-progress-container">
431  <div class="ui-input-file-input-progress-indicator"></div>
432  </div>
433  </div>
434  <template>
435  <div class="ui-input-file-input">
436  <div class="ui-input-file-info">
437  <span data-action="expand">
438  <a tabindex="0" class="glyph" href="#" aria-label="expand_content">
439  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
440  </a>
441  </span>
442  <span data-action="collapse">
443  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content">
444  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
445  </a>
446  </span>
447  <span data-dz-name></span>
448  <span data-dz-size></span>
449  <span
450  data-action="remove"><a tabindex="0" class="glyph" href="#" aria-label="close"><span
451  class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></span><span
452  class="ui-input-file-input-error-msg" data-dz-error-msg></span></div>
453  <div class="ui-input-file-metadata" style="display: none;">
454  <fieldset class="c-input" data-il-ui-component="text-field-input"
455  data-il-ui-input-name="name_0[input_1][]"><label for="id_3">text_input</label>
456  <div class="c-input__field"><input id="id_3" type="text" name="name_0[input_1][]"
457  class="c-field-text" /></div>
458  </fieldset><input id="id_4" type="hidden" name="name_0[input_2][]" value="" />
459  </div>
460  <div class="ui-input-file-input-progress-container">
461  <div class="ui-input-file-input-progress-indicator"></div>
462  </div>
463  </div>
464  </template>
465  </div>
466  <div class="ui-input-file-input-dropzone">
467  <button class="btn btn-link" data-action="#" id="id_5">select_files_from_computer</button>
468  <span class="ui-input-file-input-error-msg" data-dz-error-msg></span>
469  </div>
470  <div class="help-block"> file_notice 0 B | ui_file_upload_max_nr 1</div>
471  </div>
472  ',
473  null,
474  null,
475  'id_6'
476  );
477  $this->assertEquals($expected, $this->render($file_input));
478  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withNameFrom(NameSource $source, ?string $parent_name=null)
getUploadHandler(?FileInfoResult $file=null)
+ Here is the call graph for this function:

Field Documentation

◆ $name_source

DefNamesource FileInputTest::$name_source
protected

Definition at line 61 of file FileInputTest.php.


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