ILIAS  release_8 Revision v8.24
URITest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("libs/composer/vendor/autoload.php");
22
23use ILIAS\Data;
24use PHPUnit\Framework\TestCase;
25
26class URITest extends TestCase
27{
28 private const URI_COMPLETE = 'g+it://github.com:8080/someaccount/somerepo/somerepo.git?query_par_1=val_1&query_par_2=val_2#fragment';
29
30 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';
31
32 private const URI_COMPLETE_LOCALHOST = 'g+it://localhost:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
33
34
35 private const URI_NO_PATH_1 = 'g-it://ilias%2Da.de:8080?query_par_1=val_1&query_par_2=val_2#fragment';
36 private const URI_NO_PATH_2 = 'g.it://amaz;on.co.uk:8080/?query_par_1=val_1&query_par_2=val_2#fragment';
37
38 private const URI_NO_QUERY_1 = 'git://one-letter-top-level.a:8080/someaccount/somerepo/somerepo.git/#fragment';
39 private const URI_NO_QUERY_2 = 'git://github.com:8080/someaccount/somerepo/somerepo.git#fragment';
40
41 private const URI_AUTHORITY_AND_QUERY_1 = 'git://github.com?query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
42 private const URI_AUTHORITY_AND_QUERY_2 = 'git://github.com/?qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
43
44 private const URI_AUTHORITY_AND_FRAGMENT = 'git://github.com:8080/#fragment$,;:A!\'*+()ar_1=val_1&';
45
46 private const URI_AUTHORITY_PATH_FRAGMENT = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git#frag:A!\'*+()arment';
47
48 private const URI_PATH = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
49
50 private const URI_AUTHORITY_ONLY = 'git://git$,;hub.com';
51
52 private const URI_NO_SCHEMA = 'git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
53
54 private const URI_NO_AUTHORITY = 'git://:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
55
56 private const URI_WRONG_SCHEMA = 'gi$t://git$,;hub.com';
57
58 private const URI_WRONG_AUTHORITY_1 = 'git://git$,;hu<b.com:8080/someacc$,;ount/somerepo/somerepo.git/';
59 private const URI_WRONG_AUTHORITY_2 = 'git://git$,;hu=b.com/someacc$,;ount/somerepo/somerepo.git/';
60
61
62 private const URI_INVALID = 'https://host.de/ilias.php/"><script>alert(1)</script>?baseClass=ilObjChatroomGUI&cmd=getOSDNotifications&cmdMode=asynch&max_age=15192913';
63
64 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';
65
66 private const URI_REALPCTENC = 'g+it://github.com:8080/someaccount%2Fsomerepo/som%2brepo.git/?par_lower=val_%2b&par_upper=val_%C3%A1#fragment';
67 private const PATH_REALPCTENC = 'someaccount%2Fsomerepo/som%2brepo.git';
68 private const PARAMS_REALPCTENC = [
69 'par_lower' => 'val_+',
70 'par_upper' => 'val_รก'
71 ];
72
73 private const URI_HOST_ALPHADIG_START_1 = 'g+it://-github.com:8080/someaccount';
74 private const URI_HOST_ALPHADIG_START_2 = 'g+it://github-.com:8080/someaccount';
75 private const URI_HOST_ALPHADIG_START_3 = 'http://.';
76 private const URI_HOST_ALPHADIG_START_4 = 'http://../';
77 private const URI_HOST_ALPHADIG_START_5 = 'http://-error-.invalid/';
78
79 private const URI_BASE = 'git://github.com:8080/someaccount/somerepo/somerepo.git';
80 private const PARAMS = [
81 'par_1' => 'val_1',
82 'par_2' => 'val_2'
83 ];
84
85
89 public function test_init(): \ILIAS\Data\URI
90 {
91 return new ILIAS\Data\URI(self::URI_COMPLETE);
92 }
93
97 public function test_ipv4(): void
98 {
99 $uri = new ILIAS\Data\URI(self::URI_COMPLETE_IPV4);
100 $this->assertEquals('g+it', $uri->getSchema());
101 $this->assertEquals('10.0.0.86:8080', $uri->getAuthority());
102 $this->assertEquals('10.0.0.86', $uri->getHost());
103 $this->assertEquals(8080, $uri->getPort());
104 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
105 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
106 $this->assertEquals('fragment', $uri->getFragment());
107 }
108
113 public function testIPv6(string $host): void
114 {
115 $uri = new ILIAS\Data\URI('http://' . $host);
116 $this->assertEquals('http', $uri->getSchema());
117 $this->assertEquals($host, $uri->getAuthority());
118 $this->assertEquals($host, $uri->getHost());
119 $this->assertEquals(null, $uri->getPort());
120 $this->assertEquals(null, $uri->getPath());
121 $this->assertEquals(null, $uri->getQuery());
122 $this->assertEquals(null, $uri->getFragment());
123 }
124
125 public function provideIPv6addresses(): array
126 {
127 return [
128 // Long form.
129 ['[1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0]'],
130 ['[1:2:3:4:5:6:7:8]'],
131 // Short form.
132 ['[::1]'],
133 ['[::]'],
134 ['[::Ff00]'],
135 ['[1::]'],
136 ['[::3:4:5:6:7:8]'],
137 ['[3:4:5:6:7:8::]'],
138 ['[12::34]'],
139 // Embedded IPv4 (long).
140 ['[1234:5678:9ABC:DEF0:1234:5678:123.123.123.123]'],
141 // Embedded IPv4 (short).
142 ['[::123.123.123.123]'],
143 ['[1::123.123.123.123]'],
144 ['[1:3:4::123.123.123.123]'],
145 ['[::f:a:123.123.123.123]'],
146 ];
147 }
148
152 public function test_localhost(): void
153 {
154 $uri = new ILIAS\Data\URI(self::URI_COMPLETE_LOCALHOST);
155 $this->assertEquals('g+it', $uri->getSchema());
156 $this->assertEquals('localhost:8080', $uri->getAuthority());
157 $this->assertEquals('localhost', $uri->getHost());
158 $this->assertEquals(8080, $uri->getPort());
159 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
160 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
161 $this->assertEquals('fragment', $uri->getFragment());
162 }
163
164
168 public function test_components($uri): void
169 {
170 $this->assertEquals('g+it', $uri->getSchema());
171 $this->assertEquals('github.com:8080', $uri->getAuthority());
172 $this->assertEquals('github.com', $uri->getHost());
173 $this->assertEquals('8080', $uri->getPort());
174 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
175 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
176 $this->assertEquals('fragment', $uri->getFragment());
177 }
178
182 public function test_base_uri($uri): void
183 {
184 $this->assertEquals('g+it://github.com:8080/someaccount/somerepo/somerepo.git', $uri->getBaseURI());
185 }
186
190 public function test_base_uri_idempotent($uri): void
191 {
192 $base_uri = $uri->getBaseURI();
193 $this->assertEquals('g+it://github.com:8080/someaccount/somerepo/somerepo.git', $base_uri);
194 $this->assertEquals('g+it', $uri->getSchema());
195 $this->assertEquals('github.com:8080', $uri->getAuthority());
196 $this->assertEquals('github.com', $uri->getHost());
197 $this->assertEquals('8080', $uri->getPort());
198 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
199 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
200 $this->assertEquals('fragment', $uri->getFragment());
201
202 $uri = new ILIAS\Data\URI($base_uri);
203 $this->assertEquals($base_uri, $uri->getBaseURI());
204 $this->assertEquals('g+it', $uri->getSchema());
205 $this->assertEquals('github.com:8080', $uri->getAuthority());
206 $this->assertEquals('github.com', $uri->getHost());
207 $this->assertEquals('8080', $uri->getPort());
208 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
209 $this->assertNull($uri->getQuery());
210 $this->assertNull($uri->getFragment());
211 }
212
213
217 public function test_no_path(): void
218 {
219 $uri = new ILIAS\Data\URI(self::URI_NO_PATH_1);
220 $this->assertEquals('g-it', $uri->getSchema());
221 $this->assertEquals('ilias%2Da.de:8080', $uri->getAuthority());
222 $this->assertEquals('ilias%2Da.de', $uri->getHost());
223 $this->assertEquals('8080', $uri->getPort());
224 $this->assertNull($uri->getPath());
225 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
226 $this->assertEquals('fragment', $uri->getFragment());
227
228 $uri = new ILIAS\Data\URI(self::URI_NO_PATH_2);
229 $this->assertEquals('g.it', $uri->getSchema());
230 $this->assertEquals('amaz;on.co.uk:8080', $uri->getAuthority());
231 $this->assertEquals('amaz;on.co.uk', $uri->getHost());
232 $this->assertEquals('8080', $uri->getPort());
233 $this->assertNull($uri->getPath());
234 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
235 $this->assertEquals('fragment', $uri->getFragment());
236 }
237
241 public function test_no_query(): void
242 {
243 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_1);
244 $this->assertEquals('git', $uri->getSchema());
245 $this->assertEquals('one-letter-top-level.a:8080', $uri->getAuthority());
246 $this->assertEquals('one-letter-top-level.a', $uri->getHost());
247 $this->assertEquals('8080', $uri->getPort());
248 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
249 $this->assertNull($uri->getQuery());
250 $this->assertEquals('fragment', $uri->getFragment());
251
252 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
253 $this->assertEquals('git', $uri->getSchema());
254 $this->assertEquals('github.com:8080', $uri->getAuthority());
255 $this->assertEquals('github.com', $uri->getHost());
256 $this->assertEquals('8080', $uri->getPort());
257 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
258 $this->assertNull($uri->getQuery());
259 $this->assertEquals('fragment', $uri->getFragment());
260 }
261
265 public function test_authority_and_query(): void
266 {
267 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_1);
268 $this->assertEquals('git', $uri->getSchema());
269 $this->assertEquals('github.com', $uri->getAuthority());
270 $this->assertEquals('github.com', $uri->getHost());
271 $this->assertNull($uri->getPort());
272 $this->assertNull($uri->getPath());
273 $this->assertEquals('query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2', $uri->getQuery());
274 $this->assertNull($uri->getFragment());
275
276 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_2);
277 $this->assertEquals('git', $uri->getSchema());
278 $this->assertEquals('github.com', $uri->getAuthority());
279 $this->assertEquals('github.com', $uri->getHost());
280 $this->assertNull($uri->getPort());
281 $this->assertNull($uri->getPath());
282 $this->assertEquals('qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2', $uri->getQuery());
283 $this->assertNull($uri->getFragment());
284 }
285
289 public function test_authority_and_fragment(): void
290 {
291 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_FRAGMENT);
292 $this->assertEquals('git', $uri->getSchema());
293 $this->assertEquals('github.com:8080', $uri->getAuthority());
294 $this->assertEquals('github.com', $uri->getHost());
295 $this->assertEquals('8080', $uri->getPort());
296 $this->assertNull($uri->getPath());
297 $this->assertNull($uri->getQuery());
298 $this->assertEquals('fragment$,;:A!\'*+()ar_1=val_1&', $uri->getFragment());
299 }
303 public function test_authority_path_fragment(): void
304 {
305 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_PATH_FRAGMENT);
306 $this->assertEquals('git', $uri->getSchema());
307 $this->assertEquals('git$,;hub.com:8080', $uri->getAuthority());
308 $this->assertEquals('git$,;hub.com', $uri->getHost());
309 $this->assertEquals('8080', $uri->getPort());
310 $this->assertEquals('someacc$,;ount/somerepo/somerepo.git', $uri->getPath());
311 $this->assertNull($uri->getQuery());
312 $this->assertEquals('frag:A!\'*+()arment', $uri->getFragment());
313 }
314
318 public function test_path(): void
319 {
320 $uri = new ILIAS\Data\URI(self::URI_PATH);
321 $this->assertEquals('git', $uri->getSchema());
322 $this->assertEquals('git$,;hub.com:8080', $uri->getAuthority());
323 $this->assertEquals('git$,;hub.com', $uri->getHost());
324 $this->assertEquals('8080', $uri->getPort());
325 $this->assertEquals('someacc$,;ount/somerepo/somerepo.git', $uri->getPath());
326 $this->assertNull($uri->getQuery());
327 $this->assertNull($uri->getFragment());
328 $this->assertEquals('git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git', $uri->getBaseURI());
329 }
330
334 public function test_authority_only(): void
335 {
336 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_ONLY);
337 $this->assertEquals('git', $uri->getSchema());
338 $this->assertEquals('git$,;hub.com', $uri->getAuthority());
339 $this->assertEquals('git$,;hub.com', $uri->getHost());
340 $this->assertNull($uri->getPort());
341 $this->assertNull($uri->getPath());
342 $this->assertNull($uri->getQuery());
343 $this->assertNull($uri->getFragment());
344 $this->assertEquals('git://git$,;hub.com', $uri->getBaseURI());
345 }
346
350 public function test_no_schema(): void
351 {
352 $this->expectException(TypeError::class);
353 new ILIAS\Data\URI(self::URI_NO_SCHEMA);
354 }
355
359 public function test_no_authority(): void
360 {
361 $this->expectException(TypeError::class);
362 new ILIAS\Data\URI(self::URI_NO_AUTHORITY);
363 }
364
368 public function test_wrong_char_in_schema(): void
369 {
370 $this->expectException(TypeError::class);
371 new ILIAS\Data\URI(self::URI_WRONG_SCHEMA);
372 }
373
377 public function test_wrong_authority_in_schema_1(): void
378 {
379 $this->expectException(InvalidArgumentException::class);
380 new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_1);
381 }
382
386 public function test_wrong_authority_in_schema_2(): void
387 {
388 $this->expectException(InvalidArgumentException::class);
389 new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_2);
390 }
391
395 public function test_uri_invalid(): void
396 {
397 $this->expectException(InvalidArgumentException::class);
398 new ILIAS\Data\URI(self::URI_INVALID);
399 }
400
404 public function test_realpctenc(): void
405 {
406 $uri = new ILIAS\Data\URI(self::URI_REALPCTENC);
407 $this->assertEquals(self::PATH_REALPCTENC, $uri->getPath());
408 $this->assertEquals(self::PARAMS_REALPCTENC, $uri->getParameters());
409 }
410
414 public function test_fakepcenc(): void
415 {
416 $this->expectException(InvalidArgumentException::class);
417 new ILIAS\Data\URI(self::URI_FAKEPCENC);
418 }
419
423 public function test_alphadigit_start_host(): void
424 {
425 $this->expectException(InvalidArgumentException::class);
426 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_1);
427 }
428
432 public function test_alphadigit_start_host_2(): void
433 {
434 $this->expectException(InvalidArgumentException::class);
435 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_2);
436 }
437
441 public function test_alphadigit_start_host_3(): void
442 {
443 $this->expectException(InvalidArgumentException::class);
444 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_3);
445 }
446
450 public function test_alphadigit_start_host_4(): void
451 {
452 $this->expectException(InvalidArgumentException::class);
453 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_4);
454 }
455
459 public function test_alphadigit_start_host_5(): void
460 {
461 $this->expectException(InvalidArgumentException::class);
462 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_5);
463 }
464
468 public function test_with_schema($uri): void
469 {
470 $this->assertEquals('g+it', $uri->getSchema());
471 $this->assertEquals('github.com:8080', $uri->getAuthority());
472 $this->assertEquals('github.com', $uri->getHost());
473 $this->assertEquals('8080', $uri->getPort());
474 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
475 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
476 $this->assertEquals('fragment', $uri->getFragment());
477 $uri = $uri->withSchema('http');
478 $this->assertEquals('http', $uri->getSchema());
479 $this->assertEquals('github.com:8080', $uri->getAuthority());
480 $this->assertEquals('github.com', $uri->getHost());
481 $this->assertEquals('8080', $uri->getPort());
482 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
483 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
484 $this->assertEquals('fragment', $uri->getFragment());
485 }
486
490 public function test_with_schema_invalid_1(): void
491 {
492 $this->expectException(InvalidArgumentException::class);
493 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
494 $uri->withSchema('');
495 }
496
500 public function test_with_schema_invalid_2(): void
501 {
502 $this->expectException(InvalidArgumentException::class);
503 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
504 $uri->withSchema('1aa');
505 }
506
510 public function test_with_port($uri): void
511 {
512 $this->assertEquals('g+it', $uri->getSchema());
513 $this->assertEquals('github.com:8080', $uri->getAuthority());
514 $this->assertEquals('github.com', $uri->getHost());
515 $this->assertEquals('8080', $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 $uri = $uri->withPort(80);
520 $this->assertEquals('g+it', $uri->getSchema());
521 $this->assertEquals('github.com:80', $uri->getAuthority());
522 $this->assertEquals('github.com', $uri->getHost());
523 $this->assertEquals('80', $uri->getPort());
524 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
525 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
526 $this->assertEquals('fragment', $uri->getFragment());
527 $uri = $uri->withPort();
528 $this->assertEquals('g+it', $uri->getSchema());
529 $this->assertEquals('github.com', $uri->getAuthority());
530 $this->assertEquals('github.com', $uri->getHost());
531 $this->assertNull($uri->getPort());
532 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
533 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
534 $this->assertEquals('fragment', $uri->getFragment());
535 }
536
537
541 public function test_with_port_invalid_1(): void
542 {
543 $this->expectException(TypeError::class);
544 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
545 $uri->withPort('a111');
546 }
547
551 public function test_with_port_invalid_2(): void
552 {
553 $this->expectException(TypeError::class);
554 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
555 $uri->withPort('foo');
556 }
557
561 public function test_with_host($uri): void
562 {
563 $this->assertEquals('g+it', $uri->getSchema());
564 $this->assertEquals('github.com:8080', $uri->getAuthority());
565 $this->assertEquals('github.com', $uri->getHost());
566 $this->assertEquals('8080', $uri->getPort());
567 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
568 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
569 $this->assertEquals('fragment', $uri->getFragment());
570 $uri = $uri->withHost('ilias.de');
571 $this->assertEquals('g+it', $uri->getSchema());
572 $this->assertEquals('ilias.de:8080', $uri->getAuthority());
573 $this->assertEquals('ilias.de', $uri->getHost());
574 $this->assertEquals('8080', $uri->getPort());
575 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
576 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
577 $this->assertEquals('fragment', $uri->getFragment());
578 }
579
580
584 public function test_with_host_invalid_1(): void
585 {
586 $this->expectException(InvalidArgumentException::class);
587 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
588 $uri->withHost('-foo-.de');
589 }
590
594 public function test_with_host_invalid_3(): void
595 {
596 $this->expectException(InvalidArgumentException::class);
597 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
598 $uri->withHost('');
599 }
600
604 public function test_with_host_invalid_4(): void
605 {
606 $this->expectException(InvalidArgumentException::class);
607 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
608 $uri->withHost('ilias.de"><script');
609 }
610
614 public function test_with_authority($uri): void
615 {
616 $this->assertEquals('g+it', $uri->getSchema());
617 $this->assertEquals('github.com:8080', $uri->getAuthority());
618 $this->assertEquals('github.com', $uri->getHost());
619 $this->assertEquals('8080', $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('www1.ilias.de');
624 $this->assertEquals('g+it', $uri->getSchema());
625 $this->assertEquals('www1.ilias.de', $uri->getAuthority());
626 $this->assertEquals('www1.ilias.de', $uri->getHost());
627 $this->assertNull($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('ilias.de:80');
632 $this->assertEquals('g+it', $uri->getSchema());
633 $this->assertEquals('ilias.de:80', $uri->getAuthority());
634 $this->assertEquals('ilias.de', $uri->getHost());
635 $this->assertEquals('80', $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('a:1');
640 $this->assertEquals('g+it', $uri->getSchema());
641 $this->assertEquals('a:1', $uri->getAuthority());
642 $this->assertEquals('a', $uri->getHost());
643 $this->assertEquals(1, $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('a');
648 $this->assertEquals('g+it', $uri->getSchema());
649 $this->assertEquals('a', $uri->getAuthority());
650 $this->assertEquals('a', $uri->getHost());
651 $this->assertNull($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('1.2.3.4');
656 $this->assertEquals('g+it', $uri->getSchema());
657 $this->assertEquals('1.2.3.4', $uri->getAuthority());
658 $this->assertEquals('1.2.3.4', $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('1.2.3.4:5');
664 $this->assertEquals('g+it', $uri->getSchema());
665 $this->assertEquals('1.2.3.4:5', $uri->getAuthority());
666 $this->assertEquals('1.2.3.4', $uri->getHost());
667 $this->assertEquals(5, $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 $uri = $uri->withAuthority('localhost1');
672 $this->assertEquals('g+it', $uri->getSchema());
673 $this->assertEquals('localhost1', $uri->getAuthority());
674 $this->assertEquals('localhost1', $uri->getHost());
675 $this->assertNull($uri->getPort());
676 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
677 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
678 $this->assertEquals('fragment', $uri->getFragment());
679 $uri = $uri->withAuthority('localhost1:10');
680 $this->assertEquals('g+it', $uri->getSchema());
681 $this->assertEquals('localhost1:10', $uri->getAuthority());
682 $this->assertEquals('localhost1', $uri->getHost());
683 $this->assertEquals(10, $uri->getPort());
684 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
685 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
686 $this->assertEquals('fragment', $uri->getFragment());
687 }
688
692 public function test_with_authority_invalid_1(): void
693 {
694 $this->expectException(InvalidArgumentException::class);
695 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
696 $uri->withAuthority('-foo-.de');
697 }
698
702 public function test_with_authority_invalid_2(): void
703 {
704 $this->expectException(InvalidArgumentException::class);
705 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
706 $uri->withAuthority('-bar-.de:6060');
707 }
708
709
713 public function test_with_authority_invalid_3(): void
714 {
715 $this->expectException(InvalidArgumentException::class);
716 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
717 $uri->withHost('ilias.de:');
718 }
719
723 public function test_with_authority_invalid_4(): void
724 {
725 $this->expectException(InvalidArgumentException::class);
726 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
727 $uri->withHost('ilias.de: ');
728 }
729
733 public function test_with_authority_invalid_5(): void
734 {
735 $this->expectException(InvalidArgumentException::class);
736 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
737 $uri->withHost('ilias.de:aaa');
738 }
739
743 public function test_with_authority_invalid_6(): void
744 {
745 $this->expectException(InvalidArgumentException::class);
746 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
747 $uri->withAuthority('foo.de&<script>');
748 }
749
750
754 public function test_with_authority_invalid_7(): void
755 {
756 $this->expectException(InvalidArgumentException::class);
757 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
758 $uri->withAuthority('foo.de"><script>alert');
759 }
760
761
765 public function test_with_authority_invalid_8(): void
766 {
767 $this->expectException(InvalidArgumentException::class);
768 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
769 $uri->withAuthority(' :80');
770 }
771
775 public function test_with_path($uri): void
776 {
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->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
782 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
783 $this->assertEquals('fragment', $uri->getFragment());
784 $uri = $uri->withPath('a/b');
785 $this->assertEquals('g+it', $uri->getSchema());
786 $this->assertEquals('github.com:8080', $uri->getAuthority());
787 $this->assertEquals('github.com', $uri->getHost());
788 $this->assertEquals('8080', $uri->getPort());
789 $this->assertEquals('a/b', $uri->getPath());
790 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
791 $this->assertEquals('fragment', $uri->getFragment());
792 $uri = $uri->withPath();
793 $this->assertEquals('g+it', $uri->getSchema());
794 $this->assertEquals('github.com:8080', $uri->getAuthority());
795 $this->assertEquals('github.com', $uri->getHost());
796 $this->assertEquals('8080', $uri->getPort());
797 $this->assertNull($uri->getPath());
798 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
799 $this->assertEquals('fragment', $uri->getFragment());
800 }
801
805 public function test_with_path_invalid_1(): void
806 {
807 $this->expectException(InvalidArgumentException::class);
808 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
809 $uri->withPath('/<script>/a');
810 }
811
815 public function test_with_path_invalid_2(): void
816 {
817 $this->expectException(InvalidArgumentException::class);
818 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
819 $uri->withPath('//a/b');
820 }
821
825 public function test_with_path_invalid_3(): void
826 {
827 $this->expectException(InvalidArgumentException::class);
828 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
829 $uri->withPath(':a/b');
830 }
831
835 public function test_with_query($uri): void
836 {
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->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
843 $this->assertEquals('fragment', $uri->getFragment());
844 $uri = $uri->withQuery('query_par_a1=val_a1');
845 $this->assertEquals('g+it', $uri->getSchema());
846 $this->assertEquals('github.com:8080', $uri->getAuthority());
847 $this->assertEquals('github.com', $uri->getHost());
848 $this->assertEquals('8080', $uri->getPort());
849 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
850 $this->assertEquals('query_par_a1=val_a1', $uri->getQuery());
851 $this->assertEquals('fragment', $uri->getFragment());
852 $uri = $uri->withQuery();
853 $this->assertEquals('g+it', $uri->getSchema());
854 $this->assertEquals('github.com:8080', $uri->getAuthority());
855 $this->assertEquals('github.com', $uri->getHost());
856 $this->assertEquals('8080', $uri->getPort());
857 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
858 $this->assertNull($uri->getQuery());
859 $this->assertEquals('fragment', $uri->getFragment());
860 }
861
865 public function test_with_query_invalid_1(): void
866 {
867 $this->expectException(InvalidArgumentException::class);
868 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
869 $uri->withQuery('<script>a');
870 }
871
875 public function test_with_query_invalid_2(): void
876 {
877 $this->expectException(InvalidArgumentException::class);
878 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
879 $uri->withQuery('aa[]');
880 }
881
885 public function test_with_fragment($uri): void
886 {
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->assertEquals('fragment', $uri->getFragment());
894 $uri = $uri->withFragment('someFragment');
895 $this->assertEquals('g+it', $uri->getSchema());
896 $this->assertEquals('github.com:8080', $uri->getAuthority());
897 $this->assertEquals('github.com', $uri->getHost());
898 $this->assertEquals('8080', $uri->getPort());
899 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
900 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
901 $this->assertEquals('someFragment', $uri->getFragment());
902 $uri = $uri->withFragment();
903 $this->assertEquals('g+it', $uri->getSchema());
904 $this->assertEquals('github.com:8080', $uri->getAuthority());
905 $this->assertEquals('github.com', $uri->getHost());
906 $this->assertEquals('8080', $uri->getPort());
907 $this->assertEquals('someaccount/somerepo/somerepo.git', $uri->getPath());
908 $this->assertEquals('query_par_1=val_1&query_par_2=val_2', $uri->getQuery());
909 $this->assertNull($uri->getFragment());
910 }
911
915 public function test_with_fragment_invalid_1(): void
916 {
917 $this->expectException(InvalidArgumentException::class);
918 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
919 $uri->withFragment('aaa[]');
920 }
921
925 public function test_with_fragment_invalid_2(): void
926 {
927 $this->expectException(InvalidArgumentException::class);
928 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
929 $uri->withFragment('script>');
930 }
931
932 public function testToString(): void
933 {
934 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
935 $this->assertEquals(
936 self::URI_COMPLETE,
937 $uri
938 );
939 }
940
941 public function testGetParameters(): ILIAS\Data\URI
942 {
943 $url = self::URI_BASE . '?' . http_build_query(self::PARAMS);
944 $uri = new ILIAS\Data\URI($url);
945 $this->assertEquals(
946 self::PARAMS,
947 $uri->getParameters()
948 );
949 return $uri;
950 }
951
955 public function testGetParameter(ILIAS\Data\URI $uri): void
956 {
957 $k = array_keys(self::PARAMS)[0];
958 $this->assertEquals(
959 self::PARAMS[$k],
960 $uri->getParameter($k)
961 );
962 }
963
967 public function testWithParameters(ILIAS\Data\URI $uri): ILIAS\Data\URI
968 {
969 $params = ['x' => 1, 'y' => 2];
970 $uri = $uri->withParameters($params);
971 $this->assertEquals(
972 $params,
973 $uri->getParameters()
974 );
975 return $uri;
976 }
977
981 public function testSubstituteParameter(ILIAS\Data\URI $uri): void
982 {
983 $uri = $uri->withParameter('x', 5);
984 $this->assertEquals(
985 5,
986 $uri->getParameter('x')
987 );
988 }
992 public function testAppendParameter(ILIAS\Data\URI $uri): void
993 {
994 $params = [
995 'x' => 1, 'y' => 2,
996 'z' => 5
997 ];
998 $uri = $uri->withParameter('z', 5);
999 $this->assertEquals(
1000 $params,
1001 $uri->getParameters()
1002 );
1003 }
1004
1008 public function testWithArrayParameters(ILIAS\Data\URI $uri): void
1009 {
1010 $params = ['x' => 1, 'y' => [10, 11, 12]];
1011 $uri = $uri->withParameters($params);
1012 $this->assertEquals(
1013 $params,
1014 $uri->getParameters()
1015 );
1016 $this->assertEquals(
1017 'git://github.com:8080/someaccount/somerepo/somerepo.git?x=1&y%5B0%5D=10&y%5B1%5D=11&y%5B2%5D=12',
1018 $uri
1019 );
1020 $this->assertEquals(
1021 $params['y'],
1022 $uri->getParameter('y')
1023 );
1024 }
1025
1026 public function testWithOutParameters(): void
1027 {
1028 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
1029 $this->assertEquals(
1030 [],
1031 $uri->getParameters()
1032 );
1033
1034 $this->assertNull($uri->getParameter('y'));
1035
1036 $this->assertEquals(
1037 self::URI_NO_QUERY_2,
1038 (string) $uri
1039 );
1040 }
1041}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
test_with_schema_invalid_2()
@depends test_with_schema
Definition: URITest.php:500
test_wrong_char_in_schema()
@depends test_init
Definition: URITest.php:368
const URI_AUTHORITY_ONLY
Definition: URITest.php:50
const URI_HOST_ALPHADIG_START_1
Definition: URITest.php:73
test_with_host_invalid_3()
@depends test_with_host
Definition: URITest.php:594
test_with_authority_invalid_2()
@depends test_with_authority
Definition: URITest.php:702
testWithParameters(ILIAS\Data\URI $uri)
@depends testGetParameters
Definition: URITest.php:967
test_authority_and_query()
@depends test_init
Definition: URITest.php:265
const URI_HOST_ALPHADIG_START_4
Definition: URITest.php:76
const PARAMS
Definition: URITest.php:80
const URI_FAKEPCENC
Definition: URITest.php:64
const URI_COMPLETE_IPV4
Definition: URITest.php:30
test_wrong_authority_in_schema_2()
@depends test_init
Definition: URITest.php:386
test_with_authority_invalid_4()
@depends test_with_authority
Definition: URITest.php:723
test_with_schema($uri)
@depends test_init
Definition: URITest.php:468
const URI_HOST_ALPHADIG_START_3
Definition: URITest.php:75
const URI_NO_PATH_1
Definition: URITest.php:35
const URI_NO_QUERY_2
Definition: URITest.php:39
test_with_path_invalid_1()
@depends test_with_path
Definition: URITest.php:805
test_no_path()
@depends test_init
Definition: URITest.php:217
test_with_authority_invalid_8()
@depends test_with_authority
Definition: URITest.php:765
const URI_NO_AUTHORITY
Definition: URITest.php:54
const URI_COMPLETE
Definition: URITest.php:28
testWithArrayParameters(ILIAS\Data\URI $uri)
@depends testGetParameters
Definition: URITest.php:1008
provideIPv6addresses()
Definition: URITest.php:125
const URI_NO_PATH_2
Definition: URITest.php:36
test_with_port_invalid_2()
@depends test_with_port
Definition: URITest.php:551
test_with_schema_invalid_1()
@depends test_with_schema
Definition: URITest.php:490
test_alphadigit_start_host()
@depends test_init
Definition: URITest.php:423
test_no_schema()
@depends test_init
Definition: URITest.php:350
const URI_WRONG_SCHEMA
Definition: URITest.php:56
test_no_authority()
@depends test_init
Definition: URITest.php:359
test_with_path($uri)
@depends test_init
Definition: URITest.php:775
const URI_AUTHORITY_AND_FRAGMENT
Definition: URITest.php:44
testSubstituteParameter(ILIAS\Data\URI $uri)
@depends testWithParameters
Definition: URITest.php:981
test_uri_invalid()
@depends test_init
Definition: URITest.php:395
test_fakepcenc()
@depends test_init
Definition: URITest.php:414
const URI_REALPCTENC
Definition: URITest.php:66
test_base_uri_idempotent($uri)
@depends test_init
Definition: URITest.php:190
test_alphadigit_start_host_4()
@depends test_init
Definition: URITest.php:450
test_ipv4()
@depends test_init
Definition: URITest.php:97
const URI_AUTHORITY_AND_QUERY_2
Definition: URITest.php:42
const URI_WRONG_AUTHORITY_1
Definition: URITest.php:58
test_with_host_invalid_1()
@depends test_with_host
Definition: URITest.php:584
test_with_query_invalid_1()
@depends test_with_query
Definition: URITest.php:865
test_alphadigit_start_host_2()
@depends test_init
Definition: URITest.php:432
const URI_COMPLETE_LOCALHOST
Definition: URITest.php:32
const URI_BASE
Definition: URITest.php:79
testWithOutParameters()
Definition: URITest.php:1026
test_with_port_invalid_1()
@depends test_with_port
Definition: URITest.php:541
const URI_NO_SCHEMA
Definition: URITest.php:52
testGetParameter(ILIAS\Data\URI $uri)
@depends testGetParameters
Definition: URITest.php:955
testToString()
Definition: URITest.php:932
test_realpctenc()
@depends test_init
Definition: URITest.php:404
const URI_NO_QUERY_1
Definition: URITest.php:38
test_authority_path_fragment()
@depends test_init
Definition: URITest.php:303
test_with_query($uri)
@depends test_init
Definition: URITest.php:835
test_with_authority($uri)
@depends test_init
Definition: URITest.php:614
test_localhost()
@depends test_init
Definition: URITest.php:152
test_with_fragment_invalid_1()
@depends test_with_fragment
Definition: URITest.php:915
test_with_host_invalid_4()
@depends test_with_host
Definition: URITest.php:604
test_with_authority_invalid_6()
@depends test_with_authority
Definition: URITest.php:743
test_with_host($uri)
@depends test_init
Definition: URITest.php:561
test_with_authority_invalid_7()
@depends test_with_authority
Definition: URITest.php:754
const URI_HOST_ALPHADIG_START_5
Definition: URITest.php:77
test_base_uri($uri)
@depends test_init
Definition: URITest.php:182
const URI_AUTHORITY_AND_QUERY_1
Definition: URITest.php:41
const URI_HOST_ALPHADIG_START_2
Definition: URITest.php:74
test_alphadigit_start_host_5()
@depends test_init
Definition: URITest.php:459
test_path()
@depends test_init
Definition: URITest.php:318
const PARAMS_REALPCTENC
Definition: URITest.php:68
test_with_path_invalid_3()
@depends test_with_path
Definition: URITest.php:825
testIPv6(string $host)
@depends test_init @dataProvider provideIPv6addresses
Definition: URITest.php:113
test_with_fragment($uri)
@depends test_init
Definition: URITest.php:885
const URI_INVALID
Definition: URITest.php:62
test_components($uri)
@depends test_init
Definition: URITest.php:168
testGetParameters()
Definition: URITest.php:941
const PATH_REALPCTENC
Definition: URITest.php:67
test_with_fragment_invalid_2()
@depends test_with_fragment
Definition: URITest.php:925
test_with_authority_invalid_5()
@depends test_with_authority
Definition: URITest.php:733
test_with_path_invalid_2()
@depends test_with_path
Definition: URITest.php:815
test_init()
@doesNotPerformAssertions
Definition: URITest.php:89
test_authority_only()
@depends test_init
Definition: URITest.php:334
test_with_query_invalid_2()
@depends test_with_query
Definition: URITest.php:875
test_with_authority_invalid_1()
@depends test_with_authority
Definition: URITest.php:692
testAppendParameter(ILIAS\Data\URI $uri)
@depends testWithParameters
Definition: URITest.php:992
test_no_query()
@depends test_init
Definition: URITest.php:241
test_with_port($uri)
@depends test_init
Definition: URITest.php:510
test_authority_and_fragment()
@depends test_init
Definition: URITest.php:289
test_wrong_authority_in_schema_1()
@depends test_init
Definition: URITest.php:377
const URI_WRONG_AUTHORITY_2
Definition: URITest.php:59
test_with_authority_invalid_3()
@depends test_with_authority
Definition: URITest.php:713
const URI_AUTHORITY_PATH_FRAGMENT
Definition: URITest.php:46
test_alphadigit_start_host_3()
@depends test_init
Definition: URITest.php:441
const URI_PATH
Definition: URITest.php:48
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
Class ChatMainBarProvider \MainMenu\Provider.
$url