ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 450 of file FileInputTest.php.

450 : I\Button\Factory
451 {
452 return new I\Button\Factory();
453 }

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ buildSymbolFactory()

FileInputTest::buildSymbolFactory ( )
protected

Definition at line 455 of file FileInputTest.php.

455 : I\Symbol\Factory
456 {
457 return new I\Symbol\Factory(
458 new I\Symbol\Icon\Factory(),
459 new I\Symbol\Glyph\Factory(),
460 new I\Symbol\Avatar\Factory()
461 );
462 }
Builds data types.
Definition: Factory.php:36

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ getUIFactory()

FileInputTest::getUIFactory ( )

Definition at line 464 of file FileInputTest.php.

References buildButtonFactory(), and buildSymbolFactory().

+ Here is the call graph for this function:

◆ getUploadHandler()

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

@inheritDoc

@inheritDoc

Definition at line 74 of file FileInputTest.php.

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 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

Referenced by testCommonRendering(), testImplementsFactoryInterface(), testRender(), testRenderValue(), testRenderWithMetadata(), and testRenderWithMetadataValue().

+ Here is the call graph for this function:
+ Here is the caller 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.

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 }
getUploadHandler(?FileInfoResult $file=null)

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

+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

FileInputTest::testImplementsFactoryInterface ( )

Definition at line 132 of file FileInputTest.php.

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 \BackgroundTasks Contains several chained tasks and infos about them.

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

+ Here is the call graph for this function:

◆ testRender()

FileInputTest::testRender ( )

Definition at line 143 of file FileInputTest.php.

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 }

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

+ Here is the call graph for this function:

◆ testRenderValue()

FileInputTest::testRenderValue ( )

Definition at line 197 of file FileInputTest.php.

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 }

References getUploadHandler().

+ Here is the call graph for this function:

◆ testRenderWithMetadata()

FileInputTest::testRenderWithMetadata ( )

Definition at line 270 of file FileInputTest.php.

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 "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"><span data-action="expand"><a tabindex="0" class="glyph" href="#"
295 aria-label="expand_content"><span class="glyphicon glyphicon-triangle-right"
296 aria-hidden="true"></span></a></span><span data-action="collapse"><a tabindex="0"
297 class="glyph" href="#" aria-label="collapse_content"><span
298 class="glyphicon glyphicon-triangle-bottom"
299 aria-hidden="true"></span></a></span><span data-dz-name></span><span
300 data-dz-size></span><span data-action="remove"><a tabindex="0" class="glyph" href="#"
301 aria-label="close"><span class="glyphicon glyphicon-remove"
302 aria-hidden="true"></span></a></span><span class="ui-input-file-input-error-msg"
303 data-dz-error-msg></span></div>
304 <div class="ui-input-file-metadata" style="display: none;"><input id="id_1" type="hidden"
305 name="name_0[input_1][]" value="file_id" />
306 <fieldset class="c-input" data-il-ui-component="text-field-input"
307 data-il-ui-input-name="name_0[input_2][]"><label for="id_2">text_input</label>
308 <div class="c-input__field"><input id="id_2" type="text" name="name_0[input_2][]"
309 class="c-field-text" /></div>
310 </fieldset>
311 </div>
312 <div class="ui-input-file-input-progress-container">
313 <div class="ui-input-file-input-progress-indicator"></div>
314 </div>
315 </div><template>
316 <div class="ui-input-file-input">
317 <div class="ui-input-file-info"><span data-action="expand"><a tabindex="0" class="glyph"
318 href="#" aria-label="expand_content"><span
319 class="glyphicon glyphicon-triangle-right"
320 aria-hidden="true"></span></a></span><span data-action="collapse"><a
321 tabindex="0" class="glyph" href="#" aria-label="collapse_content"><span
322 class="glyphicon glyphicon-triangle-bottom"
323 aria-hidden="true"></span></a></span><span data-dz-name></span><span
324 data-dz-size></span><span data-action="remove"><a tabindex="0" class="glyph" href="#"
325 aria-label="close"><span class="glyphicon glyphicon-remove"
326 aria-hidden="true"></span></a></span><span class="ui-input-file-input-error-msg"
327 data-dz-error-msg></span></div>
328 <div class="ui-input-file-metadata" style="display: none;"><input id="id_3" type="hidden"
329 name="name_0[input_1][]" value="" />
330 <fieldset class="c-input" data-il-ui-component="text-field-input"
331 data-il-ui-input-name="name_0[input_2][]"><label for="id_4">text_input</label>
332 <div class="c-input__field"><input id="id_4" type="text" name="name_0[input_2][]"
333 class="c-field-text" /></div>
334 </fieldset>
335 </div>
336 <div class="ui-input-file-input-progress-container">
337 <div class="ui-input-file-input-progress-indicator"></div>
338 </div>
339 </div>
340 </template>
341 </div>
342 <div class="ui-input-file-input-dropzone"><button class="btn btn-link" data-action="#"
343 id="id_5">select_files_from_computer</button><span class="ui-input-file-input-error-msg"
344 data-dz-error-msg></span></div>
345 <div class="help-block"> file_notice 0 B | ui_file_upload_max_nr 1</div>
346 </div>
347 ',
348 null,
349 null,
350 'id_6',
351 );
352 $this->assertEquals($expected, $this->render($file_input));
353 }

References getUploadHandler().

+ Here is the call graph for this function:

◆ testRenderWithMetadataValue()

FileInputTest::testRenderWithMetadataValue ( )

Definition at line 356 of file FileInputTest.php.

356 : void
357 {
358 $test_file_id = "test_file_id_1";
359 $test_file_name = "test file name 1";
360
361 $test_file_info = $this->createMock(FileInfoResult::class);
362 $test_file_info->method('getFileIdentifier')->willReturn("test_file_id_1");
363 $test_file_info->method('getName')->willReturn("test file name 1");
364 $test_file_info->method('getSize')->willReturn(1000 * 1000 + 1);
365
366 $factory = $this->getFieldFactory();
367 $label = 'file_input';
368 $metadata_input = $factory->text("text_input");
369 $file_input = $factory->file(
370 $u = $this->getUploadHandler($test_file_info),
371 $label,
372 null,
373 $metadata_input
374 )->withValue([
375 [
376 $test_file_id,
377 "test",
378 ]
379 ])->withNameFrom($this->name_source);
380
381
382 $expected = $this->getFormWrappedHtml(
383 'file-field-input',
384 $label,
385 '
386 <div class="ui-input-file">
387 <div class="ui-input-file-input-list">
388 <div class="ui-input-file-input">
389 <div class="ui-input-file-info"><span data-action="expand"><a tabindex="0" class="glyph" href="#"
390 aria-label="expand_content"><span class="glyphicon glyphicon-triangle-right"
391 aria-hidden="true"></span></a></span><span data-action="collapse"><a tabindex="0"
392 class="glyph" href="#" aria-label="collapse_content"><span
393 class="glyphicon glyphicon-triangle-bottom"
394 aria-hidden="true"></span></a></span><span data-dz-name>test file name 1</span><span
395 data-dz-size>1 MB</span><span data-action="remove"><a tabindex="0" class="glyph" href="#"
396 aria-label="close"><span class="glyphicon glyphicon-remove"
397 aria-hidden="true"></span></a></span><span class="ui-input-file-input-error-msg"
398 data-dz-error-msg></span></div>
399 <div class="ui-input-file-metadata" style="display: none;"><input id="id_1" type="hidden"
400 name="name_0[input_1][]" value="test_file_id_1" />
401 <fieldset class="c-input" data-il-ui-component="text-field-input"
402 data-il-ui-input-name="name_0[input_2][]"><label for="id_2">text_input</label>
403 <div class="c-input__field"><input id="id_2" type="text" value="test"
404 name="name_0[input_2][]" class="c-field-text" /></div>
405 </fieldset>
406 </div>
407 <div class="ui-input-file-input-progress-container">
408 <div class="ui-input-file-input-progress-indicator"></div>
409 </div>
410 </div><template>
411 <div class="ui-input-file-input">
412 <div class="ui-input-file-info"><span data-action="expand"><a tabindex="0" class="glyph"
413 href="#" aria-label="expand_content"><span
414 class="glyphicon glyphicon-triangle-right"
415 aria-hidden="true"></span></a></span><span data-action="collapse"><a
416 tabindex="0" class="glyph" href="#" aria-label="collapse_content"><span
417 class="glyphicon glyphicon-triangle-bottom"
418 aria-hidden="true"></span></a></span><span data-dz-name></span><span
419 data-dz-size></span><span data-action="remove"><a tabindex="0" class="glyph" href="#"
420 aria-label="close"><span class="glyphicon glyphicon-remove"
421 aria-hidden="true"></span></a></span><span class="ui-input-file-input-error-msg"
422 data-dz-error-msg></span></div>
423 <div class="ui-input-file-metadata" style="display: none;"><input id="id_3" type="hidden"
424 name="name_0[input_1][]" value="" />
425 <fieldset class="c-input" data-il-ui-component="text-field-input"
426 data-il-ui-input-name="name_0[input_2][]"><label for="id_4">text_input</label>
427 <div class="c-input__field"><input id="id_4" type="text" name="name_0[input_2][]"
428 class="c-field-text" /></div>
429 </fieldset>
430 </div>
431 <div class="ui-input-file-input-progress-container">
432 <div class="ui-input-file-input-progress-indicator"></div>
433 </div>
434 </div>
435 </template>
436 </div>
437 <div class="ui-input-file-input-dropzone"><button class="btn btn-link" data-action="#"
438 id="id_5">select_files_from_computer</button><span class="ui-input-file-input-error-msg"
439 data-dz-error-msg></span></div>
440 <div class="help-block"> file_notice 0 B | ui_file_upload_max_nr 1</div>
441 </div>
442 ',
443 null,
444 null,
445 'id_6'
446 );
447 $this->assertEquals($expected, $this->render($file_input));
448 }

References getUploadHandler().

+ 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: