ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
FileInputTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../../Base.php");
7 require_once(__DIR__ . "/InputTest.php");
8 
9 use ILIAS\Data;
19 
21 {
22  protected $button_factory;
23 
24 
25  public function __construct($button_factory)
26  {
27  $this->button_factory = $button_factory;
28  }
29 
30 
31  public function button()
32  {
33  return $this->button_factory;
34  }
35 }
36 
38 {
39  public function setUp() : void
40  {
41  $this->name_source = new DefNamesource();
42  }
43 
44 
45  protected function buildFactory()
46  {
47  $df = new Data\Factory();
48  $language = $this->createMock(\ilLanguage::class);
49 
51  new SignalGenerator(),
52  $df,
53  new ILIAS\Refinery\Factory($df, $language),
54  $language
55  );
56  }
57 
58 
59  private function getUploadHandler() : Field\UploadHandler
60  {
61  return new class implements Field\UploadHandler {
62  public function getFileIdentifierParameterName() : string
63  {
64  return 'file_id';
65  }
66 
67 
68  public function getUploadURL() : string
69  {
70  return 'uploadurl';
71  }
72 
73 
74  public function getFileRemovalURL() : string
75  {
76  return 'removalurl';
77  }
78 
79 
83  public function getExistingFileInfoURL() : string
84  {
85  return 'infourl';
86  }
87 
88 
92  public function getInfoForExistingFiles(array $file_ids) : array
93  {
94  return [];
95  }
96  };
97  }
98 
99 
101  {
102  $f = $this->buildFactory();
103 
104  $text = $f->file($this->getUploadHandler(), "label", "byline");
105 
106  $this->assertInstanceOf(Field\Input::class, $text);
107  $this->assertInstanceOf(Field\File::class, $text);
108  }
109 
110 
111  public function test_render()
112  {
113  $f = $this->buildFactory();
114  $label = "label";
115  $byline = "byline";
116  $name = "name_0";
117  $text = $f->file($this->getUploadHandler(), $label, $byline)->withNameFrom($this->name_source);
118 
119  $r = $this->getDefaultRenderer();
120  $html = $this->brutallyTrimHTML($r->render($text));
121 
122  $expected = $this->brutallyTrimHTML('
123  <div class="form-group row">
124  <label for="id_1" class="control-label col-sm-3">label</label>
125  <div class="col-sm-9">
126  <div class="il-input-file" id="id_1">
127  <div class="il-input-file-dropzone"> <button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button></div>
128  <div class="il-input-file-filelist">
129  <div class="il-input-file-template dz-preview dz-file-preview" style="display: block; border: 1px solid red;" data-file-id="">
130  <div class="dz-details">
131  <div class="il-input-file-fileinfo">
132  <div class="il-input-file-fileinfo-title"><span data-dz-name></span></div>
133  <div data-dz-size class="il-input-file-fileinfo-size"></div>
134  <div class="il-input-file-fileinfo-close"> <button type="button" class="close" data-dz-remove> <span aria-hidden="true">&times;</span> <span class="sr-only">Close</span> </button> </div>
135  </div>
136  <!-- <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>--> <!-- <div class="dz-success-mark"><span>✔</span></div>--> <!-- <div class="dz-error-mark"><span>✘</span></div>-->
137  <div class="dz-error-message il-input-file-error"><span data-dz-errormessage></span></div>
138  </div>
139  </div>
140  </div>
141  <input class="input-template" type="hidden" name="name_0[]" value="" data-file-id="" />
142  </div>
143  <div class="help-block">byline</div>
144  </div>
145  </div>
146  ');
147  $this->assertEquals($expected, $html);
148  }
149 
150 
151  public function test_render_error()
152  {
153  $f = $this->buildFactory();
154  $label = "label";
155  $byline = "byline";
156  $name = "name_0";
157  $error = "an_error";
158  $text = $f->file($this->getUploadHandler(), $label, $byline)->withNameFrom($this->name_source)->withError($error);
159 
160  $r = $this->getDefaultRenderer();
161  $html = $this->brutallyTrimHTML($r->render($text));
162 
163  $expected = $this->brutallyTrimHTML('
164  <div class="form-group row">
165  <label for="id_1" class="control-label col-sm-3">label</label>
166  <div class="col-sm-9">
167  <div class="help-block alert alert-danger" role="alert">an_error</div>
168  <div class="il-input-file" id="id_1">
169  <div class="il-input-file-dropzone"><button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button></div>
170  <div class="il-input-file-filelist">
171  <div class="il-input-file-template dz-preview dz-file-preview" style="display: block; border: 1px solid red;" data-file-id="">
172  <div class="dz-details">
173  <div class="il-input-file-fileinfo">
174  <div class="il-input-file-fileinfo-title"><span data-dz-name></span></div>
175  <div data-dz-size class="il-input-file-fileinfo-size"></div>
176  <div class="il-input-file-fileinfo-close">
177  <button type="button" class="close" data-dz-remove><span aria-hidden="true">&times;</span> <span class="sr-only">Close</span></button>
178  </div>
179  </div>
180  <!-- <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>-->
181  <!-- <div class="dz-success-mark"><span>✔</span></div>-->
182  <!-- <div class="dz-error-mark"><span>✘</span></div>-->
183  <div class="dz-error-message il-input-file-error"><span data-dz-errormessage></span></div>
184  </div>
185  </div>
186  </div>
187  <input class="input-template" type="hidden" name="name_0[]" value="" data-file-id="" />
188  </div>
189  <div class="help-block">byline</div>
190  </div>
191  </div>
192  ');
193  $this->assertEquals($expected, $html);
194  }
195 
196 
197  public function test_render_no_byline()
198  {
199  $f = $this->buildFactory();
200  $label = "label";
201  $name = "name_0";
202  $text = $f->file($this->getUploadHandler(), $label)->withNameFrom($this->name_source);
203 
204  $r = $this->getDefaultRenderer();
205  $html = $this->brutallyTrimHTML($r->render($text));
206 
207  $expected = $this->brutallyTrimHTML('
208  <div class="form-group row">
209  <label for="id_1" class="control-label col-sm-3">label</label>
210  <div class="col-sm-9">
211  <div class="il-input-file" id="id_1">
212  <div class="il-input-file-dropzone"><button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button></div>
213  <div class="il-input-file-filelist">
214  <div class="il-input-file-template dz-preview dz-file-preview" style="display: block; border: 1px solid red;" data-file-id="">
215  <div class="dz-details">
216  <div class="il-input-file-fileinfo">
217  <div class="il-input-file-fileinfo-title"><span data-dz-name></span></div>
218  <div data-dz-size class="il-input-file-fileinfo-size"></div>
219  <div class="il-input-file-fileinfo-close">
220  <button type="button" class="close" data-dz-remove><span aria-hidden="true">&times;</span> <span class="sr-only">Close</span></button>
221  </div>
222  </div>
223  <!-- <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>-->
224  <!-- <div class="dz-success-mark"><span>✔</span></div>-->
225  <!-- <div class="dz-error-mark"><span>✘</span></div>-->
226  <div class="dz-error-message il-input-file-error"><span data-dz-errormessage></span></div>
227  </div>
228  </div>
229  </div>
230  <input class="input-template" type="hidden" name="name_0[]" value="" data-file-id="" />
231  </div>
232  </div>
233  </div>
234  ');
235  $this->assertEquals($expected, $html);
236  }
237 
238 
239  public function test_render_value()
240  {
241  $f = $this->buildFactory();
242  $label = "label";
243  $value = ["value"];
244  $name = "name_0";
245  $text = $f->file($this->getUploadHandler(), $label)->withValue($value)->withNameFrom($this->name_source);
246 
247  $r = $this->getDefaultRenderer();
248  $html = $this->brutallyTrimHTML($r->render($text));
249 
250  $expected = $this->brutallyTrimHTML('
251  <div class="form-group row">
252  <label for="id_1" class="control-label col-sm-3">label</label>
253  <div class="col-sm-9">
254  <div class="il-input-file" id="id_1">
255  <div class="il-input-file-dropzone"><button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button></div>
256  <div class="il-input-file-filelist">
257  <div class="il-input-file-template dz-preview dz-file-preview" style="display: block; border: 1px solid red;" data-file-id="">
258  <div class="dz-details">
259  <div class="il-input-file-fileinfo">
260  <div class="il-input-file-fileinfo-title"><span data-dz-name></span></div>
261  <div data-dz-size class="il-input-file-fileinfo-size"></div>
262  <div class="il-input-file-fileinfo-close">
263  <button type="button" class="close" data-dz-remove><span aria-hidden="true">&times;</span> <span class="sr-only">Close</span></button>
264  </div>
265  </div>
266  <!-- <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>-->
267  <!-- <div class="dz-success-mark"><span>✔</span></div>-->
268  <!-- <div class="dz-error-mark"><span>✘</span></div>-->
269  <div class="dz-error-message il-input-file-error"><span data-dz-errormessage></span></div>
270  </div>
271  </div>
272  </div>
273  <input class="input-template" type="hidden" name="name_0[]" value="" data-file-id="" />
274  </div>
275  </div>
276  </div>
277  ');
278  $this->assertEquals($expected, $html);
279  }
280 
281 
282  public function test_render_required()
283  {
284  $f = $this->buildFactory();
285  $label = "label";
286  $text = $f->file($this->getUploadHandler(), $label)->withNameFrom($this->name_source)->withRequired(true);
287 
288  $r = $this->getDefaultRenderer();
289  $html = $this->brutallyTrimHTML($r->render($text));
290 
291  $expected = $this->brutallyTrimHTML('
292  <div class="form-group row">
293  <label for="id_1" class="control-label col-sm-3">label<span class="asterisk">*</span></label>
294  <div class="col-sm-9">
295  <div class="il-input-file" id="id_1">
296  <div class="il-input-file-dropzone"><button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button></div>
297  <div class="il-input-file-filelist">
298  <div class="il-input-file-template dz-preview dz-file-preview" style="display: block; border: 1px solid red;" data-file-id="">
299  <div class="dz-details">
300  <div class="il-input-file-fileinfo">
301  <div class="il-input-file-fileinfo-title"><span data-dz-name></span></div>
302  <div data-dz-size class="il-input-file-fileinfo-size"></div>
303  <div class="il-input-file-fileinfo-close">
304  <button type="button" class="close" data-dz-remove><span aria-hidden="true">&times;</span> <span class="sr-only">Close</span></button>
305  </div>
306  </div>
307  <!-- <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>-->
308  <!-- <div class="dz-success-mark"><span>✔</span></div>-->
309  <!-- <div class="dz-error-mark"><span>✘</span></div>-->
310  <div class="dz-error-message il-input-file-error"><span data-dz-errormessage></span></div>
311  </div>
312  </div>
313  </div>
314  <input class="input-template" type="hidden" name="name_0[]" value="" data-file-id="" />
315  </div>
316  </div>
317  </div>
318  ');
319  $this->assertEquals($expected, $html);
320  }
321 
322 
323  public function test_render_disabled()
324  {
325  $f = $this->buildFactory();
326  $label = "label";
327  $text = $f->file($this->getUploadHandler(), $label)->withNameFrom($this->name_source)->withDisabled(true);
328 
329  $r = $this->getDefaultRenderer();
330  $html = $this->brutallyTrimHTML($r->render($text));
331 
332  $expected = $this->brutallyTrimHTML('
333  <div class="form-group row">
334  <label for="id_1" class="control-label col-sm-3">label</label>
335  <div class="col-sm-9">
336  <div class="il-input-file" id="id_1">
337  <div class="il-input-file-dropzone"><button class="btn btn-link" data-action="#" id="id_2">select_files_from_computer</button></div>
338  <div class="il-input-file-filelist">
339  <div class="il-input-file-template dz-preview dz-file-preview" style="display: block; border: 1px solid red;" data-file-id="">
340  <div class="dz-details">
341  <div class="il-input-file-fileinfo">
342  <div class="il-input-file-fileinfo-title"><span data-dz-name></span></div>
343  <div data-dz-size class="il-input-file-fileinfo-size"></div>
344  <div class="il-input-file-fileinfo-close">
345  <button type="button" class="close" data-dz-remove><span aria-hidden="true">&times;</span> <span class="sr-only">Close</span></button>
346  </div>
347  </div>
348  <!-- <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>-->
349  <!-- <div class="dz-success-mark"><span>✔</span></div>-->
350  <!-- <div class="dz-error-mark"><span>✘</span></div>-->
351  <div class="dz-error-message il-input-file-error"><span data-dz-errormessage></span></div>
352  </div>
353  </div>
354  </div>
355  <input class="input-template" type="hidden" name="name_0[]" value="" data-file-id="" />
356  </div>
357  </div>
358  </div>
359  ');
360 
361  $this->assertEquals($expected, $html);
362  }
363 
364  protected function buildButtonFactory()
365  {
367  }
368 
369 
370  public function getUIFactory()
371  {
372  return new WithSomeButtonNoUIFactory($this->buildButtonFactory());
373  }
374 
375  public function getDefaultRenderer(JavaScriptBinding $js_binding = null, $with_stub_renderings = [])
376  {
377  $ui_factory = $this->getUIFactory();
378  $tpl_factory = $this->getTemplateFactory();
379  $resource_registry = $this->getResourceRegistry();
380  $lng = $this->getLanguage();
381  if (!$js_binding) {
382  $js_binding = $this->getJavaScriptBinding();
383  }
384 
385  $refinery = $this->getRefinery();
386  $img_resolver = new ilImagePathResolver();
387 
388  $component_renderer_loader
389  = new LoaderCachingWrapper(
391  $resource_registry,
392  new FSLoader(
394  $ui_factory,
395  $tpl_factory,
396  $lng,
397  $js_binding,
398  $refinery,
399  $img_resolver
400  ),
402  $ui_factory,
403  $tpl_factory,
404  $lng,
405  $js_binding,
406  $refinery,
407  $img_resolver
408  ),
410  $ui_factory,
411  $tpl_factory,
412  $lng,
413  $js_binding,
414  $refinery,
415  $img_resolver
416  )
417  )
418  )
419  );
420 
421  return new TestDefaultRenderer($component_renderer_loader);
422  }
423 }
test_implements_factory_interface()
Loads renderers for components from the file system.
Definition: FSLoader.php:20
Class ChatMainBarProvider .
button()
description: purpose: > Buttons trigger interactions that change the system’s or view&#39;s status...
Caches renderers loaded by another loader.
Registers resources for retreived renderers at a ResourceRegistry.
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
if($format !==null) $name
Definition: metadata.php:230
Provides common functionality for UI tests.
Definition: Base.php:262
$lng
__construct($button_factory)
Builds data types.
Definition: Factory.php:19
Provides methods to interface with javascript.