ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
URITest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 require_once("libs/composer/vendor/autoload.php");
6 
7 use ILIAS\Data;
9 
10 class URITest extends TestCase
11 {
12  private const URI_COMPLETE = 'g+it://github.com:8080/someaccount/somerepo/somerepo.git?query_par_1=val_1&query_par_2=val_2#fragment';
13 
14  private const URI_COMPLETE_IPV4 = 'g+it://10.0.0.86:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
15 
16  private const URI_COMPLETE_LOCALHOST = 'g+it://localhost:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
17 
18 
19  private const URI_NO_PATH_1 = 'g-it://ilias%2Da.de:8080?query_par_1=val_1&query_par_2=val_2#fragment';
20  private const URI_NO_PATH_2 = 'g.it://amaz;on.co.uk:8080/?query_par_1=val_1&query_par_2=val_2#fragment';
21 
22  private const URI_NO_QUERY_1 = 'git://one-letter-top-level.a:8080/someaccount/somerepo/somerepo.git/#fragment';
23  private const URI_NO_QUERY_2 = 'git://github.com:8080/someaccount/somerepo/somerepo.git#fragment';
24 
25  private const URI_AUTHORITY_AND_QUERY_1 = 'git://github.com?query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
26  private const URI_AUTHORITY_AND_QUERY_2 = 'git://github.com/?qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
27 
28  private const URI_AUTHORITY_AND_FRAGMENT = 'git://github.com:8080/#fragment$,;:A!\'*+()ar_1=val_1&';
29 
30  private const URI_AUTHORITY_PATH_FRAGMENT = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git#frag:A!\'*+()arment';
31 
32  private const URI_PATH = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
33 
34  private const URI_AUTHORITY_ONLY = 'git://git$,;hub.com';
35 
36  private const URI_NO_SCHEMA = 'git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
37 
38  private const URI_NO_AUTHORITY = 'git://:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
39 
40  private const URI_WRONG_SCHEMA = 'gi$t://git$,;hub.com';
41 
42  private const URI_WRONG_AUTHORITY_1 = 'git://git$,;hu<b.com:8080/someacc$,;ount/somerepo/somerepo.git/';
43  private const URI_WRONG_AUTHORITY_2 = 'git://git$,;hu=b.com/someacc$,;ount/somerepo/somerepo.git/';
44 
45 
46  private const URI_INVALID = 'https://host.de/ilias.php/"><script>alert(1)</script>?baseClass=ilObjChatroomGUI&cmd=getOSDNotifications&cmdMode=asynch&max_age=15192913';
47 
48  private const URI_FAKEPCENC = 'g+it://github.com:8080/someaccoun%t/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
49 
50  private const URI_REALPCTENC = 'g+it://github.com:8080/someaccount%2Fsomerepo/som%2brepo.git/?par_lower=val_%2b&par_upper=val_%C3%A1#fragment';
51  private const PATH_REALPCTENC = 'someaccount%2Fsomerepo/som%2brepo.git';
52  private const PARAMS_REALPCTENC = [
53  'par_lower' => 'val_+',
54  'par_upper' => 'val_รก'
55  ];
56 
57  private const URI_HOST_ALPHADIG_START_1 = 'g+it://-github.com:8080/someaccount';
58  private const URI_HOST_ALPHADIG_START_2 = 'g+it://github-.com:8080/someaccount';
59  private const URI_HOST_ALPHADIG_START_3 = 'http://.';
60  private const URI_HOST_ALPHADIG_START_4 = 'http://../';
61  private const URI_HOST_ALPHADIG_START_5 = 'http://-error-.invalid/';
62 
63  private const URI_BASE = 'git://github.com:8080/someaccount/somerepo/somerepo.git';
64  private const PARAMS = [
65  'par_1' => 'val_1',
66  'par_2' => 'val_2'
67  ];
68 
69 
73  public function test_init(): \ILIAS\Data\URI
74  {
75  return new ILIAS\Data\URI(self::URI_COMPLETE);
76  }
77 
81  public function test_ipv4(): void
82  {
83  $uri = new ILIAS\Data\URI(self::URI_COMPLETE_IPV4);
84  $this->assertEquals('g+it', $uri->getSchema());
85  $this->assertEquals('10.0.0.86:8080', $uri->getAuthority());
86  $this->assertEquals('10.0.0.86', $uri->getHost());
87  $this->assertEquals(8080, $uri->getPort());
88  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
89  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
90  $this->assertEquals('fragment', $uri->getFragment());
91  }
92 
97  public function testIPv6(string $host): void
98  {
99  $uri = new ILIAS\Data\URI('http://' . $host);
100  $this->assertEquals('http', $uri->getSchema());
101  $this->assertEquals($host, $uri->getAuthority());
102  $this->assertEquals($host, $uri->getHost());
103  $this->assertEquals(null, $uri->getPort());
104  $this->assertEquals(null, $uri->getPath());
105  $this->assertEquals(null, $uri->getQuery());
106  $this->assertEquals(null, $uri->getFragment());
107  }
108 
109  public function provideIPv6addresses(): array
110  {
111  return [
112  // Long form.
113  ['[1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0]'],
114  ['[1:2:3:4:5:6:7:8]'],
115  // Short form.
116  ['[::1]'],
117  ['[::]'],
118  ['[::Ff00]'],
119  ['[1::]'],
120  ['[::3:4:5:6:7:8]'],
121  ['[3:4:5:6:7:8::]'],
122  ['[12::34]'],
123  // Embedded IPv4 (long).
124  ['[1234:5678:9ABC:DEF0:1234:5678:123.123.123.123]'],
125  // Embedded IPv4 (short).
126  ['[::123.123.123.123]'],
127  ['[1::123.123.123.123]'],
128  ['[1:3:4::123.123.123.123]'],
129  ['[::f:a:123.123.123.123]'],
130  ];
131  }
132 
136  public function test_localhost(): void
137  {
138  $uri = new ILIAS\Data\URI(self::URI_COMPLETE_LOCALHOST);
139  $this->assertEquals('g+it', $uri->getSchema());
140  $this->assertEquals('localhost:8080', $uri->getAuthority());
141  $this->assertEquals('localhost', $uri->getHost());
142  $this->assertEquals(8080, $uri->getPort());
143  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
144  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
145  $this->assertEquals('fragment', $uri->getFragment());
146  }
147 
148 
152  public function test_components($uri): void
153  {
154  $this->assertEquals('g+it', $uri->getSchema());
155  $this->assertEquals('github.com:8080', $uri->getAuthority());
156  $this->assertEquals('github.com', $uri->getHost());
157  $this->assertEquals('8080', $uri->getPort());
158  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
159  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
160  $this->assertEquals('fragment', $uri->getFragment());
161  }
162 
166  public function test_base_uri($uri): void
167  {
168  $this->assertEquals('g+it://github.com:8080/someaccount/somerepo/somerepo.git', $uri->getBaseURI());
169  }
170 
174  public function test_base_uri_idempotent($uri): void
175  {
176  $base_uri = $uri->getBaseURI();
177  $this->assertEquals('g+it://github.com:8080/someaccount/somerepo/somerepo.git', $base_uri);
178  $this->assertEquals('g+it', $uri->getSchema());
179  $this->assertEquals('github.com:8080', $uri->getAuthority());
180  $this->assertEquals('github.com', $uri->getHost());
181  $this->assertEquals('8080', $uri->getPort());
182  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
183  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
184  $this->assertEquals('fragment', $uri->getFragment());
185 
186  $uri = new ILIAS\Data\URI($base_uri);
187  $this->assertEquals($base_uri, $uri->getBaseURI());
188  $this->assertEquals('g+it', $uri->getSchema());
189  $this->assertEquals('github.com:8080', $uri->getAuthority());
190  $this->assertEquals('github.com', $uri->getHost());
191  $this->assertEquals('8080', $uri->getPort());
192  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
193  $this->assertNull($uri->getQuery());
194  $this->assertNull($uri->getFragment());
195  }
196 
197 
201  public function test_no_path(): void
202  {
203  $uri = new ILIAS\Data\URI(self::URI_NO_PATH_1);
204  $this->assertEquals('g-it', $uri->getSchema());
205  $this->assertEquals('ilias%2Da.de:8080', $uri->getAuthority());
206  $this->assertEquals('ilias%2Da.de', $uri->getHost());
207  $this->assertEquals('8080', $uri->getPort());
208  $this->assertNull($uri->getPath());
209  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
210  $this->assertEquals('fragment', $uri->getFragment());
211 
212  $uri = new ILIAS\Data\URI(self::URI_NO_PATH_2);
213  $this->assertEquals('g.it', $uri->getSchema());
214  $this->assertEquals('amaz;on.co.uk:8080', $uri->getAuthority());
215  $this->assertEquals('amaz;on.co.uk', $uri->getHost());
216  $this->assertEquals('8080', $uri->getPort());
217  $this->assertNull($uri->getPath());
218  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
219  $this->assertEquals('fragment', $uri->getFragment());
220  }
221 
225  public function test_no_query(): void
226  {
227  $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_1);
228  $this->assertEquals('git', $uri->getSchema());
229  $this->assertEquals('one-letter-top-level.a:8080', $uri->getAuthority());
230  $this->assertEquals('one-letter-top-level.a', $uri->getHost());
231  $this->assertEquals('8080', $uri->getPort());
232  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
233  $this->assertNull($uri->getQuery());
234  $this->assertEquals('fragment', $uri->getFragment());
235 
236  $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
237  $this->assertEquals('git', $uri->getSchema());
238  $this->assertEquals('github.com:8080', $uri->getAuthority());
239  $this->assertEquals('github.com', $uri->getHost());
240  $this->assertEquals('8080', $uri->getPort());
241  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
242  $this->assertNull($uri->getQuery());
243  $this->assertEquals('fragment', $uri->getFragment());
244  }
245 
249  public function test_authority_and_query(): void
250  {
251  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_1);
252  $this->assertEquals('git', $uri->getSchema());
253  $this->assertEquals('github.com', $uri->getAuthority());
254  $this->assertEquals('github.com', $uri->getHost());
255  $this->assertNull($uri->getPort());
256  $this->assertNull($uri->getPath());
257  $this->assertEquals('query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2', $uri->getQuery());
258  $this->assertNull($uri->getFragment());
259 
260  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_2);
261  $this->assertEquals('git', $uri->getSchema());
262  $this->assertEquals('github.com', $uri->getAuthority());
263  $this->assertEquals('github.com', $uri->getHost());
264  $this->assertNull($uri->getPort());
265  $this->assertNull($uri->getPath());
266  $this->assertEquals('qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2', $uri->getQuery());
267  $this->assertNull($uri->getFragment());
268  }
269 
273  public function test_authority_and_fragment(): void
274  {
275  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_FRAGMENT);
276  $this->assertEquals('git', $uri->getSchema());
277  $this->assertEquals('github.com:8080', $uri->getAuthority());
278  $this->assertEquals('github.com', $uri->getHost());
279  $this->assertEquals('8080', $uri->getPort());
280  $this->assertNull($uri->getPath());
281  $this->assertNull($uri->getQuery());
282  $this->assertEquals('fragment$,;:A!\'*+()ar_1=val_1&', $uri->getFragment());
283  }
287  public function test_authority_path_fragment(): void
288  {
289  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_PATH_FRAGMENT);
290  $this->assertEquals('git', $uri->getSchema());
291  $this->assertEquals('git$,;hub.com:8080', $uri->getAuthority());
292  $this->assertEquals('git$,;hub.com', $uri->getHost());
293  $this->assertEquals('8080', $uri->getPort());
294  $this->assertEquals('someacc$,;ount/somerepo/somerepo.git', $uri->getPath());
295  $this->assertNull($uri->getQuery());
296  $this->assertEquals('frag:A!\'*+()arment', $uri->getFragment());
297  }
298 
302  public function test_path(): void
303  {
304  $uri = new ILIAS\Data\URI(self::URI_PATH);
305  $this->assertEquals('git', $uri->getSchema());
306  $this->assertEquals('git$,;hub.com:8080', $uri->getAuthority());
307  $this->assertEquals('git$,;hub.com', $uri->getHost());
308  $this->assertEquals('8080', $uri->getPort());
309  $this->assertEquals('someacc$,;ount/somerepo/somerepo.git', $uri->getPath());
310  $this->assertNull($uri->getQuery());
311  $this->assertNull($uri->getFragment());
312  $this->assertEquals('git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git', $uri->getBaseURI());
313  }
314 
318  public function test_authority_only(): void
319  {
320  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_ONLY);
321  $this->assertEquals('git', $uri->getSchema());
322  $this->assertEquals('git$,;hub.com', $uri->getAuthority());
323  $this->assertEquals('git$,;hub.com', $uri->getHost());
324  $this->assertNull($uri->getPort());
325  $this->assertNull($uri->getPath());
326  $this->assertNull($uri->getQuery());
327  $this->assertNull($uri->getFragment());
328  $this->assertEquals('git://git$,;hub.com', $uri->getBaseURI());
329  }
330 
334  public function test_no_schema(): void
335  {
336  $this->expectException(TypeError::class);
337  new ILIAS\Data\URI(self::URI_NO_SCHEMA);
338  }
339 
343  public function test_no_authority(): void
344  {
345  $this->expectException(TypeError::class);
346  new ILIAS\Data\URI(self::URI_NO_AUTHORITY);
347  }
348 
352  public function test_wrong_char_in_schema(): void
353  {
354  $this->expectException(TypeError::class);
355  new ILIAS\Data\URI(self::URI_WRONG_SCHEMA);
356  }
357 
361  public function test_wrong_authority_in_schema_1(): void
362  {
363  $this->expectException(InvalidArgumentException::class);
364  new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_1);
365  }
366 
370  public function test_wrong_authority_in_schema_2(): void
371  {
372  $this->expectException(InvalidArgumentException::class);
373  new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_2);
374  }
375 
379  public function test_uri_invalid(): void
380  {
381  $this->expectException(InvalidArgumentException::class);
382  new ILIAS\Data\URI(self::URI_INVALID);
383  }
384 
388  public function test_realpctenc(): void
389  {
390  $uri = new ILIAS\Data\URI(self::URI_REALPCTENC);
391  $this->assertEquals(self::PATH_REALPCTENC, $uri->getPath());
392  $this->assertEquals(self::PARAMS_REALPCTENC, $uri->getParameters());
393  }
394 
398  public function test_fakepcenc(): void
399  {
400  $this->expectException(InvalidArgumentException::class);
401  new ILIAS\Data\URI(self::URI_FAKEPCENC);
402  }
403 
407  public function test_alphadigit_start_host(): void
408  {
409  $this->expectException(InvalidArgumentException::class);
410  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_1);
411  }
412 
416  public function test_alphadigit_start_host_2(): void
417  {
418  $this->expectException(InvalidArgumentException::class);
419  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_2);
420  }
421 
425  public function test_alphadigit_start_host_3(): void
426  {
427  $this->expectException(InvalidArgumentException::class);
428  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_3);
429  }
430 
434  public function test_alphadigit_start_host_4(): void
435  {
436  $this->expectException(InvalidArgumentException::class);
437  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_4);
438  }
439 
443  public function test_alphadigit_start_host_5(): void
444  {
445  $this->expectException(InvalidArgumentException::class);
446  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_5);
447  }
448 
452  public function test_with_schema($uri): void
453  {
454  $this->assertEquals('g+it', $uri->getSchema());
455  $this->assertEquals('github.com:8080', $uri->getAuthority());
456  $this->assertEquals('github.com', $uri->getHost());
457  $this->assertEquals('8080', $uri->getPort());
458  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
459  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
460  $this->assertEquals('fragment', $uri->getFragment());
461  $uri = $uri->withSchema('http');
462  $this->assertEquals('http', $uri->getSchema());
463  $this->assertEquals('github.com:8080', $uri->getAuthority());
464  $this->assertEquals('github.com', $uri->getHost());
465  $this->assertEquals('8080', $uri->getPort());
466  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
467  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
468  $this->assertEquals('fragment', $uri->getFragment());
469  }
470 
474  public function test_with_schema_invalid_1(): void
475  {
476  $this->expectException(InvalidArgumentException::class);
477  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
478  $uri->withSchema('');
479  }
480 
484  public function test_with_schema_invalid_2(): void
485  {
486  $this->expectException(InvalidArgumentException::class);
487  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
488  $uri->withSchema('1aa');
489  }
490 
494  public function test_with_port($uri): void
495  {
496  $this->assertEquals('g+it', $uri->getSchema());
497  $this->assertEquals('github.com:8080', $uri->getAuthority());
498  $this->assertEquals('github.com', $uri->getHost());
499  $this->assertEquals('8080', $uri->getPort());
500  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
501  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
502  $this->assertEquals('fragment', $uri->getFragment());
503  $uri = $uri->withPort(80);
504  $this->assertEquals('g+it', $uri->getSchema());
505  $this->assertEquals('github.com:80', $uri->getAuthority());
506  $this->assertEquals('github.com', $uri->getHost());
507  $this->assertEquals('80', $uri->getPort());
508  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
509  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
510  $this->assertEquals('fragment', $uri->getFragment());
511  $uri = $uri->withPort();
512  $this->assertEquals('g+it', $uri->getSchema());
513  $this->assertEquals('github.com', $uri->getAuthority());
514  $this->assertEquals('github.com', $uri->getHost());
515  $this->assertNull($uri->getPort());
516  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
517  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
518  $this->assertEquals('fragment', $uri->getFragment());
519  }
520 
521 
525  public function test_with_port_invalid_1(): void
526  {
527  $this->expectException(TypeError::class);
528  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
529  $uri->withPort('a111');
530  }
531 
535  public function test_with_port_invalid_2(): void
536  {
537  $this->expectException(TypeError::class);
538  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
539  $uri->withPort('foo');
540  }
541 
545  public function test_with_host($uri): void
546  {
547  $this->assertEquals('g+it', $uri->getSchema());
548  $this->assertEquals('github.com:8080', $uri->getAuthority());
549  $this->assertEquals('github.com', $uri->getHost());
550  $this->assertEquals('8080', $uri->getPort());
551  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
552  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
553  $this->assertEquals('fragment', $uri->getFragment());
554  $uri = $uri->withHost('ilias.de');
555  $this->assertEquals('g+it', $uri->getSchema());
556  $this->assertEquals('ilias.de:8080', $uri->getAuthority());
557  $this->assertEquals('ilias.de', $uri->getHost());
558  $this->assertEquals('8080', $uri->getPort());
559  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
560  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
561  $this->assertEquals('fragment', $uri->getFragment());
562  }
563 
564 
568  public function test_with_host_invalid_1(): void
569  {
570  $this->expectException(InvalidArgumentException::class);
571  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
572  $uri->withHost('-foo-.de');
573  }
574 
578  public function test_with_host_invalid_3(): void
579  {
580  $this->expectException(InvalidArgumentException::class);
581  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
582  $uri->withHost('');
583  }
584 
588  public function test_with_host_invalid_4(): void
589  {
590  $this->expectException(InvalidArgumentException::class);
591  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
592  $uri->withHost('ilias.de"><script');
593  }
594 
598  public function test_with_authority($uri): void
599  {
600  $this->assertEquals('g+it', $uri->getSchema());
601  $this->assertEquals('github.com:8080', $uri->getAuthority());
602  $this->assertEquals('github.com', $uri->getHost());
603  $this->assertEquals('8080', $uri->getPort());
604  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
605  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
606  $this->assertEquals('fragment', $uri->getFragment());
607  $uri = $uri->withAuthority('www1.ilias.de');
608  $this->assertEquals('g+it', $uri->getSchema());
609  $this->assertEquals('www1.ilias.de', $uri->getAuthority());
610  $this->assertEquals('www1.ilias.de', $uri->getHost());
611  $this->assertNull($uri->getPort());
612  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
613  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
614  $this->assertEquals('fragment', $uri->getFragment());
615  $uri = $uri->withAuthority('ilias.de:80');
616  $this->assertEquals('g+it', $uri->getSchema());
617  $this->assertEquals('ilias.de:80', $uri->getAuthority());
618  $this->assertEquals('ilias.de', $uri->getHost());
619  $this->assertEquals('80', $uri->getPort());
620  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
621  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
622  $this->assertEquals('fragment', $uri->getFragment());
623  $uri = $uri->withAuthority('a:1');
624  $this->assertEquals('g+it', $uri->getSchema());
625  $this->assertEquals('a:1', $uri->getAuthority());
626  $this->assertEquals('a', $uri->getHost());
627  $this->assertEquals(1, $uri->getPort());
628  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
629  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
630  $this->assertEquals('fragment', $uri->getFragment());
631  $uri = $uri->withAuthority('a');
632  $this->assertEquals('g+it', $uri->getSchema());
633  $this->assertEquals('a', $uri->getAuthority());
634  $this->assertEquals('a', $uri->getHost());
635  $this->assertNull($uri->getPort());
636  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
637  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
638  $this->assertEquals('fragment', $uri->getFragment());
639  $uri = $uri->withAuthority('1.2.3.4');
640  $this->assertEquals('g+it', $uri->getSchema());
641  $this->assertEquals('1.2.3.4', $uri->getAuthority());
642  $this->assertEquals('1.2.3.4', $uri->getHost());
643  $this->assertNull($uri->getPort());
644  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
645  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
646  $this->assertEquals('fragment', $uri->getFragment());
647  $uri = $uri->withAuthority('1.2.3.4:5');
648  $this->assertEquals('g+it', $uri->getSchema());
649  $this->assertEquals('1.2.3.4:5', $uri->getAuthority());
650  $this->assertEquals('1.2.3.4', $uri->getHost());
651  $this->assertEquals(5, $uri->getPort());
652  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
653  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
654  $this->assertEquals('fragment', $uri->getFragment());
655  $uri = $uri->withAuthority('localhost1');
656  $this->assertEquals('g+it', $uri->getSchema());
657  $this->assertEquals('localhost1', $uri->getAuthority());
658  $this->assertEquals('localhost1', $uri->getHost());
659  $this->assertNull($uri->getPort());
660  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
661  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
662  $this->assertEquals('fragment', $uri->getFragment());
663  $uri = $uri->withAuthority('localhost1:10');
664  $this->assertEquals('g+it', $uri->getSchema());
665  $this->assertEquals('localhost1:10', $uri->getAuthority());
666  $this->assertEquals('localhost1', $uri->getHost());
667  $this->assertEquals(10, $uri->getPort());
668  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
669  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
670  $this->assertEquals('fragment', $uri->getFragment());
671  }
672 
676  public function test_with_authority_invalid_1(): void
677  {
678  $this->expectException(InvalidArgumentException::class);
679  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
680  $uri->withAuthority('-foo-.de');
681  }
682 
686  public function test_with_authority_invalid_2(): void
687  {
688  $this->expectException(InvalidArgumentException::class);
689  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
690  $uri->withAuthority('-bar-.de:6060');
691  }
692 
693 
697  public function test_with_authority_invalid_3(): void
698  {
699  $this->expectException(InvalidArgumentException::class);
700  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
701  $uri->withHost('ilias.de:');
702  }
703 
707  public function test_with_authority_invalid_4(): void
708  {
709  $this->expectException(InvalidArgumentException::class);
710  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
711  $uri->withHost('ilias.de: ');
712  }
713 
717  public function test_with_authority_invalid_5(): void
718  {
719  $this->expectException(InvalidArgumentException::class);
720  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
721  $uri->withHost('ilias.de:aaa');
722  }
723 
727  public function test_with_authority_invalid_6(): void
728  {
729  $this->expectException(InvalidArgumentException::class);
730  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
731  $uri->withAuthority('foo.de&<script>');
732  }
733 
734 
738  public function test_with_authority_invalid_7(): void
739  {
740  $this->expectException(InvalidArgumentException::class);
741  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
742  $uri->withAuthority('foo.de"><script>alert');
743  }
744 
745 
749  public function test_with_authority_invalid_8(): void
750  {
751  $this->expectException(InvalidArgumentException::class);
752  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
753  $uri->withAuthority(' :80');
754  }
755 
759  public function test_with_path($uri): void
760  {
761  $this->assertEquals('g+it', $uri->getSchema());
762  $this->assertEquals('github.com:8080', $uri->getAuthority());
763  $this->assertEquals('github.com', $uri->getHost());
764  $this->assertEquals('8080', $uri->getPort());
765  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
766  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
767  $this->assertEquals('fragment', $uri->getFragment());
768  $uri = $uri->withPath('a/b');
769  $this->assertEquals('g+it', $uri->getSchema());
770  $this->assertEquals('github.com:8080', $uri->getAuthority());
771  $this->assertEquals('github.com', $uri->getHost());
772  $this->assertEquals('8080', $uri->getPort());
773  $this->assertEquals('a/b', $uri->getPath());
774  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
775  $this->assertEquals('fragment', $uri->getFragment());
776  $uri = $uri->withPath();
777  $this->assertEquals('g+it', $uri->getSchema());
778  $this->assertEquals('github.com:8080', $uri->getAuthority());
779  $this->assertEquals('github.com', $uri->getHost());
780  $this->assertEquals('8080', $uri->getPort());
781  $this->assertNull($uri->getPath());
782  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
783  $this->assertEquals('fragment', $uri->getFragment());
784  }
785 
789  public function test_with_path_invalid_1(): void
790  {
791  $this->expectException(InvalidArgumentException::class);
792  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
793  $uri->withPath('/<script>/a');
794  }
795 
799  public function test_with_path_invalid_2(): void
800  {
801  $this->expectException(InvalidArgumentException::class);
802  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
803  $uri->withPath('//a/b');
804  }
805 
809  public function test_with_path_invalid_3(): void
810  {
811  $this->expectException(InvalidArgumentException::class);
812  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
813  $uri->withPath(':a/b');
814  }
815 
819  public function test_with_query($uri): void
820  {
821  $this->assertEquals('g+it', $uri->getSchema());
822  $this->assertEquals('github.com:8080', $uri->getAuthority());
823  $this->assertEquals('github.com', $uri->getHost());
824  $this->assertEquals('8080', $uri->getPort());
825  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
826  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
827  $this->assertEquals('fragment', $uri->getFragment());
828  $uri = $uri->withQuery('query_par_a1=val_a1');
829  $this->assertEquals('g+it', $uri->getSchema());
830  $this->assertEquals('github.com:8080', $uri->getAuthority());
831  $this->assertEquals('github.com', $uri->getHost());
832  $this->assertEquals('8080', $uri->getPort());
833  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
834  $this->assertEquals('query_par_a1=val_a1', $uri->getQuery());
835  $this->assertEquals('fragment', $uri->getFragment());
836  $uri = $uri->withQuery();
837  $this->assertEquals('g+it', $uri->getSchema());
838  $this->assertEquals('github.com:8080', $uri->getAuthority());
839  $this->assertEquals('github.com', $uri->getHost());
840  $this->assertEquals('8080', $uri->getPort());
841  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
842  $this->assertNull($uri->getQuery());
843  $this->assertEquals('fragment', $uri->getFragment());
844  }
845 
849  public function test_with_query_invalid_1(): void
850  {
851  $this->expectException(InvalidArgumentException::class);
852  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
853  $uri->withQuery('<script>a');
854  }
855 
859  public function test_with_query_invalid_2(): void
860  {
861  $this->expectException(InvalidArgumentException::class);
862  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
863  $uri->withQuery('aa[]');
864  }
865 
869  public function test_with_fragment($uri): void
870  {
871  $this->assertEquals('g+it', $uri->getSchema());
872  $this->assertEquals('github.com:8080', $uri->getAuthority());
873  $this->assertEquals('github.com', $uri->getHost());
874  $this->assertEquals('8080', $uri->getPort());
875  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
876  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
877  $this->assertEquals('fragment', $uri->getFragment());
878  $uri = $uri->withFragment('someFragment');
879  $this->assertEquals('g+it', $uri->getSchema());
880  $this->assertEquals('github.com:8080', $uri->getAuthority());
881  $this->assertEquals('github.com', $uri->getHost());
882  $this->assertEquals('8080', $uri->getPort());
883  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
884  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
885  $this->assertEquals('someFragment', $uri->getFragment());
886  $uri = $uri->withFragment();
887  $this->assertEquals('g+it', $uri->getSchema());
888  $this->assertEquals('github.com:8080', $uri->getAuthority());
889  $this->assertEquals('github.com', $uri->getHost());
890  $this->assertEquals('8080', $uri->getPort());
891  $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
892  $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
893  $this->assertNull($uri->getFragment());
894  }
895 
899  public function test_with_fragment_invalid_1(): void
900  {
901  $this->expectException(InvalidArgumentException::class);
902  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
903  $uri->withFragment('aaa[]');
904  }
905 
909  public function test_with_fragment_invalid_2(): void
910  {
911  $this->expectException(InvalidArgumentException::class);
912  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
913  $uri->withFragment('script>');
914  }
915 
916  public function testToString(): void
917  {
918  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
919  $this->assertEquals(
920  self::URI_COMPLETE,
921  $uri
922  );
923  }
924 
925  public function testGetParameters(): ILIAS\Data\URI
926  {
927  $url = self::URI_BASE . '?' . http_build_query(self::PARAMS);
928  $uri = new ILIAS\Data\URI($url);
929  $this->assertEquals(
930  self::PARAMS,
931  $uri->getParameters()
932  );
933  return $uri;
934  }
935 
939  public function testGetParameter(ILIAS\Data\URI $uri): void
940  {
941  $k = array_keys(self::PARAMS)[0];
942  $this->assertEquals(
943  self::PARAMS[$k],
944  $uri->getParameter($k)
945  );
946  }
947 
951  public function testWithParameters(ILIAS\Data\URI $uri): ILIAS\Data\URI
952  {
953  $params = ['x' => 1, 'y' => 2];
954  $uri = $uri->withParameters($params);
955  $this->assertEquals(
956  $params,
957  $uri->getParameters()
958  );
959  return $uri;
960  }
961 
965  public function testSubstituteParameter(ILIAS\Data\URI $uri): void
966  {
967  $uri = $uri->withParameter('x', 5);
968  $this->assertEquals(
969  5,
970  $uri->getParameter('x')
971  );
972  }
976  public function testAppendParameter(ILIAS\Data\URI $uri): void
977  {
978  $params = [
979  'x' => 1, 'y' => 2,
980  'z' => 5
981  ];
982  $uri = $uri->withParameter('z', 5);
983  $this->assertEquals(
984  $params,
985  $uri->getParameters()
986  );
987  }
988 
992  public function testWithArrayParameters(ILIAS\Data\URI $uri): void
993  {
994  $params = ['x' => 1, 'y' => [10, 11, 12]];
995  $uri = $uri->withParameters($params);
996  $this->assertEquals(
997  $params,
998  $uri->getParameters()
999  );
1000  $this->assertEquals(
1001  'git://github.com:8080/someaccount/somerepo/somerepo.git?x=1&y%5B0%5D=10&y%5B1%5D=11&y%5B2%5D=12',
1002  $uri
1003  );
1004  $this->assertEquals(
1005  $params['y'],
1006  $uri->getParameter('y')
1007  );
1008  }
1009 
1010  public function testWithOutParameters(): void
1011  {
1012  $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
1013  $this->assertEquals(
1014  [],
1015  $uri->getParameters()
1016  );
1017 
1018  $this->assertNull($uri->getParameter('y'));
1019 
1020  $this->assertEquals(
1021  self::URI_NO_QUERY_2,
1022  (string) $uri
1023  );
1024  }
1025 }
test_with_authority_invalid_3()
test_with_authority
Definition: URITest.php:697
testWithArrayParameters(ILIAS\Data\URI $uri)
testGetParameters
Definition: URITest.php:992
const URI_HOST_ALPHADIG_START_2
Definition: URITest.php:58
test_with_path_invalid_3()
test_with_path
Definition: URITest.php:809
test_alphadigit_start_host_5()
test_init
Definition: URITest.php:443
const URI_COMPLETE_LOCALHOST
Definition: URITest.php:16
test_base_uri_idempotent($uri)
test_init
Definition: URITest.php:174
const URI_HOST_ALPHADIG_START_3
Definition: URITest.php:59
const URI_NO_QUERY_2
Definition: URITest.php:23
const URI_NO_SCHEMA
Definition: URITest.php:36
const const URI_HOST_ALPHADIG_START_1
Definition: URITest.php:57
test_with_authority_invalid_7()
test_with_authority
Definition: URITest.php:738
test_with_authority_invalid_6()
test_with_authority
Definition: URITest.php:727
test_authority_only()
test_init
Definition: URITest.php:318
testWithOutParameters()
Definition: URITest.php:1010
test_wrong_authority_in_schema_1()
test_init
Definition: URITest.php:361
test_with_authority_invalid_4()
test_with_authority
Definition: URITest.php:707
test_with_path_invalid_2()
test_with_path
Definition: URITest.php:799
test_with_fragment($uri)
test_init
Definition: URITest.php:869
test_realpctenc()
test_init
Definition: URITest.php:388
test_with_authority_invalid_2()
test_with_authority
Definition: URITest.php:686
const PARAMS_REALPCTENC
Definition: URITest.php:52
test_with_host_invalid_4()
test_with_host
Definition: URITest.php:588
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
test_alphadigit_start_host_4()
test_init
Definition: URITest.php:434
test_fakepcenc()
test_init
Definition: URITest.php:398
const URI_AUTHORITY_AND_FRAGMENT
Definition: URITest.php:28
Class ChatMainBarProvider .
const URI_PATH
Definition: URITest.php:32
const URI_WRONG_SCHEMA
Definition: URITest.php:40
const URI_HOST_ALPHADIG_START_5
Definition: URITest.php:61
test_with_authority_invalid_1()
test_with_authority
Definition: URITest.php:676
testAppendParameter(ILIAS\Data\URI $uri)
testWithParameters
Definition: URITest.php:976
test_no_authority()
test_init
Definition: URITest.php:343
testGetParameter(ILIAS\Data\URI $uri)
testGetParameters
Definition: URITest.php:939
test_with_host_invalid_1()
test_with_host
Definition: URITest.php:568
test_with_schema($uri)
test_init
Definition: URITest.php:452
const test_init()
Definition: URITest.php:73
const URI_REALPCTENC
Definition: URITest.php:50
const URI_INVALID
Definition: URITest.php:46
test_wrong_char_in_schema()
test_init
Definition: URITest.php:352
test_with_query_invalid_1()
test_with_query
Definition: URITest.php:849
const URI_WRONG_AUTHORITY_1
Definition: URITest.php:42
testIPv6(string $host)
test_init provideIPv6addresses
Definition: URITest.php:97
const URI_NO_PATH_1
Definition: URITest.php:19
test_with_fragment_invalid_1()
test_with_fragment
Definition: URITest.php:899
const URI_FAKEPCENC
Definition: URITest.php:48
test_no_path()
test_init
Definition: URITest.php:201
test_path()
test_init
Definition: URITest.php:302
test_with_query_invalid_2()
test_with_query
Definition: URITest.php:859
test_with_fragment_invalid_2()
test_with_fragment
Definition: URITest.php:909
testWithParameters(ILIAS\Data\URI $uri)
testGetParameters
Definition: URITest.php:951
const URI_HOST_ALPHADIG_START_4
Definition: URITest.php:60
const PARAMS
Definition: URITest.php:64
test_with_port_invalid_1()
test_with_port
Definition: URITest.php:525
provideIPv6addresses()
Definition: URITest.php:109
const URI_AUTHORITY_ONLY
Definition: URITest.php:34
const URI_NO_PATH_2
Definition: URITest.php:20
const URI_COMPLETE
Definition: URITest.php:12
test_with_host_invalid_3()
test_with_host
Definition: URITest.php:578
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:18
test_with_query($uri)
test_init
Definition: URITest.php:819
test_with_authority_invalid_8()
test_with_authority
Definition: URITest.php:749
test_authority_path_fragment()
test_init
Definition: URITest.php:287
test_base_uri($uri)
test_init
Definition: URITest.php:166
$url
Definition: ltiregstart.php:35
test_with_host($uri)
test_init
Definition: URITest.php:545
test_with_path($uri)
test_init
Definition: URITest.php:759
test_authority_and_query()
test_init
Definition: URITest.php:249
const URI_AUTHORITY_AND_QUERY_2
Definition: URITest.php:26
test_with_port($uri)
test_init
Definition: URITest.php:494
testSubstituteParameter(ILIAS\Data\URI $uri)
testWithParameters
Definition: URITest.php:965
test_with_authority($uri)
test_init
Definition: URITest.php:598
const URI_COMPLETE_IPV4
Definition: URITest.php:14
test_alphadigit_start_host_3()
test_init
Definition: URITest.php:425
test_alphadigit_start_host_2()
test_init
Definition: URITest.php:416
test_with_authority_invalid_5()
test_with_authority
Definition: URITest.php:717
test_no_schema()
test_init
Definition: URITest.php:334
test_localhost()
test_init
Definition: URITest.php:136
test_with_schema_invalid_1()
test_with_schema
Definition: URITest.php:474
const URI_NO_QUERY_1
Definition: URITest.php:22
test_uri_invalid()
test_init
Definition: URITest.php:379
testGetParameters()
Definition: URITest.php:925
test_components($uri)
test_init
Definition: URITest.php:152
test_ipv4()
test_init
Definition: URITest.php:81
test_with_port_invalid_2()
test_with_port
Definition: URITest.php:535
const URI_BASE
Definition: URITest.php:63
test_no_query()
test_init
Definition: URITest.php:225
const PATH_REALPCTENC
Definition: URITest.php:51
testToString()
Definition: URITest.php:916
test_authority_and_fragment()
test_init
Definition: URITest.php:273
const URI_AUTHORITY_PATH_FRAGMENT
Definition: URITest.php:30
test_wrong_authority_in_schema_2()
test_init
Definition: URITest.php:370
const URI_NO_AUTHORITY
Definition: URITest.php:38
const URI_AUTHORITY_AND_QUERY_1
Definition: URITest.php:25
test_alphadigit_start_host()
test_init
Definition: URITest.php:407
test_with_path_invalid_1()
test_with_path
Definition: URITest.php:789
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_with_schema_invalid_2()
test_with_schema
Definition: URITest.php:484
const URI_WRONG_AUTHORITY_2
Definition: URITest.php:43