ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
URITest.php
Go to the documentation of this file.
1<?php
2require_once("libs/composer/vendor/autoload.php");
3
4use ILIAS\Data;
5
7{
8 const URI_COMPLETE = 'g+it://github.com:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
9
10 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';
11
12 const URI_COMPLETE_LOCALHOST = 'g+it://localhost:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
13
14
15 const URI_NO_PATH_1 = 'g-it://ilias%2Da.de:8080?query_par_1=val_1&query_par_2=val_2#fragment';
16 const URI_NO_PATH_2 = 'g.it://amaz;on.co.uk:8080/?query_par_1=val_1&query_par_2=val_2#fragment';
17
18 const URI_NO_QUERY_1 = 'git://one-letter-top-level.a:8080/someaccount/somerepo/somerepo.git/#fragment';
19 const URI_NO_QUERY_2 = 'git://github.com:8080/someaccount/somerepo/somerepo.git#fragment';
20
21 const URI_AUTHORITY_AND_QUERY_1 = 'git://github.com?query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
22 const URI_AUTHORITY_AND_QUERY_2 = 'git://github.com/?qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
23
24 const URI_AUTHORITY_AND_FRAGMENT = 'git://github.com:8080/#fragment$,;:A!\'*+()ar_1=val_1&';
25
26 const URI_AUTHORITY_PATH_FRAGMENT = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git#frag:A!\'*+()arment';
27
28 const URI_PATH = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
29
30 const URI_AUTHORITY_ONLY = 'git://git$,;hub.com';
31
32 const URI_NO_SCHEMA = 'git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
33
34 const URI_NO_AUTHORITY = 'git://:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
35
36 const URI_WRONG_SCHEMA = 'gi$t://git$,;hub.com';
37
38 const URI_WRONG_AUTHORITY_1 = 'git://git$,;hu<b.com:8080/someacc$,;ount/somerepo/somerepo.git/';
39 const URI_WRONG_AUTHORITY_2 = 'git://git$,;hu=b.com/someacc$,;ount/somerepo/somerepo.git/';
40
41
42 const URI_INVALID = 'https://host.de/ilias.php/"><script>alert(1)</script>?baseClass=ilObjChatroomGUI&cmd=getOSDNotifications&cmdMode=asynch&max_age=15192913';
43
44 const URI_FAKEPCENC = 'g+it://github.com:8080/someaccoun%t/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
45
46 const URI_HOST_ALPHADIG_START_1 = 'g+it://-github.com:8080/someaccount';
47 const URI_HOST_ALPHADIG_START_2 = 'g+it://github-.com:8080/someaccount';
48 const URI_HOST_ALPHADIG_START_3 = 'http://.';
49 const URI_HOST_ALPHADIG_START_4 = 'http://../';
50 const URI_HOST_ALPHADIG_START_5 = 'http://-error-.invalid/';
51
52
53 public function test_init()
54 {
55 return new ILIAS\Data\URI(self::URI_COMPLETE);
56 }
57
61 public function test_ipv4()
62 {
63 $uri = new ILIAS\Data\URI(self::URI_COMPLETE_IPV4);
64 $this->assertEquals($uri->schema(), 'g+it');
65 $this->assertEquals($uri->authority(), '10.0.0.86:8080');
66 $this->assertEquals($uri->host(), '10.0.0.86');
67 $this->assertEquals($uri->port(), 8080);
68 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
69 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
70 $this->assertEquals($uri->fragment(), 'fragment');
71 }
72
73
77 public function test_localhost()
78 {
79 $uri = new ILIAS\Data\URI(self::URI_COMPLETE_LOCALHOST);
80 $this->assertEquals($uri->schema(), 'g+it');
81 $this->assertEquals($uri->authority(), 'localhost:8080');
82 $this->assertEquals($uri->host(), 'localhost');
83 $this->assertEquals($uri->port(), 8080);
84 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
85 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
86 $this->assertEquals($uri->fragment(), 'fragment');
87 }
88
89
93 public function test_components($uri)
94 {
95 $this->assertEquals($uri->schema(), 'g+it');
96 $this->assertEquals($uri->authority(), 'github.com:8080');
97 $this->assertEquals($uri->host(), 'github.com');
98 $this->assertEquals($uri->port(), '8080');
99 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
100 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
101 $this->assertEquals($uri->fragment(), 'fragment');
102 }
103
107 public function test_base_uri($uri)
108 {
109 $this->assertEquals($uri->baseURI(), 'g+it://github.com:8080/someaccount/somerepo/somerepo.git');
110 }
111
115 public function test_base_uri_idempotent($uri)
116 {
117 $base_uri = $uri->baseURI();
118 $this->assertEquals($base_uri, 'g+it://github.com:8080/someaccount/somerepo/somerepo.git');
119 $this->assertEquals($uri->schema(), 'g+it');
120 $this->assertEquals($uri->authority(), 'github.com:8080');
121 $this->assertEquals($uri->host(), 'github.com');
122 $this->assertEquals($uri->port(), '8080');
123 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
124 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
125 $this->assertEquals($uri->fragment(), 'fragment');
126
127 $uri = new ILIAS\Data\URI($base_uri);
128 $this->assertEquals($base_uri, $uri->baseURI());
129 $this->assertEquals($uri->schema(), 'g+it');
130 $this->assertEquals($uri->authority(), 'github.com:8080');
131 $this->assertEquals($uri->host(), 'github.com');
132 $this->assertEquals($uri->port(), '8080');
133 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
134 $this->assertNull($uri->query());
135 $this->assertNull($uri->fragment());
136 }
137
138
142 public function test_no_path()
143 {
144 $uri = new ILIAS\Data\URI(self::URI_NO_PATH_1);
145 $this->assertEquals($uri->schema(), 'g-it');
146 $this->assertEquals($uri->authority(), 'ilias%2Da.de:8080');
147 $this->assertEquals($uri->host(), 'ilias%2Da.de');
148 $this->assertEquals($uri->port(), '8080');
149 $this->assertNull($uri->path());
150 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
151 $this->assertEquals($uri->fragment(), 'fragment');
152
153 $uri = new ILIAS\Data\URI(self::URI_NO_PATH_2);
154 $this->assertEquals($uri->schema(), 'g.it');
155 $this->assertEquals($uri->authority(), 'amaz;on.co.uk:8080');
156 $this->assertEquals($uri->host(), 'amaz;on.co.uk');
157 $this->assertEquals($uri->port(), '8080');
158 $this->assertNull($uri->path());
159 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
160 $this->assertEquals($uri->fragment(), 'fragment');
161 }
162
166 public function test_no_query()
167 {
168 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_1);
169 $this->assertEquals($uri->schema(), 'git');
170 $this->assertEquals($uri->authority(), 'one-letter-top-level.a:8080');
171 $this->assertEquals($uri->host(), 'one-letter-top-level.a');
172 $this->assertEquals($uri->port(), '8080');
173 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
174 $this->assertNull($uri->query());
175 $this->assertEquals($uri->fragment(), 'fragment');
176
177 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
178 $this->assertEquals($uri->schema(), 'git');
179 $this->assertEquals($uri->authority(), 'github.com:8080');
180 $this->assertEquals($uri->host(), 'github.com');
181 $this->assertEquals($uri->port(), '8080');
182 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
183 $this->assertNull($uri->query());
184 $this->assertEquals($uri->fragment(), 'fragment');
185 }
186
190 public function test_authority_and_query()
191 {
192 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_1);
193 $this->assertEquals($uri->schema(), 'git');
194 $this->assertEquals($uri->authority(), 'github.com');
195 $this->assertEquals($uri->host(), 'github.com');
196 $this->assertNull($uri->port());
197 $this->assertNull($uri->path());
198 $this->assertEquals($uri->query(), 'query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2');
199 $this->assertNull($uri->fragment());
200
201 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_2);
202 $this->assertEquals($uri->schema(), 'git');
203 $this->assertEquals($uri->authority(), 'github.com');
204 $this->assertEquals($uri->host(), 'github.com');
205 $this->assertNull($uri->port());
206 $this->assertNull($uri->path());
207 $this->assertEquals($uri->query(), 'qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2');
208 $this->assertNull($uri->fragment());
209 }
210
215 {
216 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_FRAGMENT);
217 $this->assertEquals($uri->schema(), 'git');
218 $this->assertEquals($uri->authority(), 'github.com:8080');
219 $this->assertEquals($uri->host(), 'github.com');
220 $this->assertEquals($uri->port(), '8080');
221 $this->assertNull($uri->path());
222 $this->assertNull($uri->query());
223 $this->assertEquals($uri->fragment(), 'fragment$,;:A!\'*+()ar_1=val_1&');
224 }
229 {
230 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_PATH_FRAGMENT);
231 $this->assertEquals($uri->schema(), 'git');
232 $this->assertEquals($uri->authority(), 'git$,;hub.com:8080');
233 $this->assertEquals($uri->host(), 'git$,;hub.com');
234 $this->assertEquals($uri->port(), '8080');
235 $this->assertEquals($uri->path(), 'someacc$,;ount/somerepo/somerepo.git');
236 $this->assertNull($uri->query());
237 $this->assertEquals($uri->fragment(), 'frag:A!\'*+()arment');
238 }
239
243 public function test_path()
244 {
245 $uri = new ILIAS\Data\URI(self::URI_PATH);
246 $this->assertEquals($uri->schema(), 'git');
247 $this->assertEquals($uri->authority(), 'git$,;hub.com:8080');
248 $this->assertEquals($uri->host(), 'git$,;hub.com');
249 $this->assertEquals($uri->port(), '8080');
250 $this->assertEquals($uri->path(), 'someacc$,;ount/somerepo/somerepo.git');
251 $this->assertNull($uri->query());
252 $this->assertNull($uri->fragment());
253 $this->assertEquals($uri->baseURI(), 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git');
254 }
255
259 public function test_authority_only()
260 {
261 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_ONLY);
262 $this->assertEquals($uri->schema(), 'git');
263 $this->assertEquals($uri->authority(), 'git$,;hub.com');
264 $this->assertEquals($uri->host(), 'git$,;hub.com');
265 $this->assertNull($uri->port());
266 $this->assertNull($uri->path());
267 $this->assertNull($uri->query());
268 $this->assertNull($uri->fragment());
269 $this->assertEquals($uri->baseURI(), 'git://git$,;hub.com');
270 }
271
276 public function test_no_schema()
277 {
278 new ILIAS\Data\URI(self::URI_NO_SCHEMA);
279 }
280
285 public function test_no_authority()
286 {
287 new ILIAS\Data\URI(self::URI_NO_AUTHORITY);
288 }
289
295 {
296 new ILIAS\Data\URI(self::URI_WRONG_SCHEMA);
297 }
298
304 {
305 new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_1);
306 }
307
313 {
314 new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_2);
315 }
316
321 public function test_uri_invalid()
322 {
323 new ILIAS\Data\URI(self::URI_INVALID);
324 }
325
330 public function test_fakepcenc()
331 {
332 new ILIAS\Data\URI(self::URI_FAKEPCENC);
333 }
334
340 {
341 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_1);
342 }
343
349 {
350 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_2);
351 }
352
358 {
359 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_3);
360 }
361
367 {
368 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_4);
369 }
370
376 {
377 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_5);
378 }
379
383 public function test_with_schema($uri)
384 {
385 $this->assertEquals($uri->schema(), 'g+it');
386 $this->assertEquals($uri->authority(), 'github.com:8080');
387 $this->assertEquals($uri->host(), 'github.com');
388 $this->assertEquals($uri->port(), '8080');
389 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
390 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
391 $this->assertEquals($uri->fragment(), 'fragment');
392 $uri = $uri->withSchema('http');
393 $this->assertEquals($uri->schema(), 'http');
394 $this->assertEquals($uri->authority(), 'github.com:8080');
395 $this->assertEquals($uri->host(), 'github.com');
396 $this->assertEquals($uri->port(), '8080');
397 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
398 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
399 $this->assertEquals($uri->fragment(), 'fragment');
400 }
401
407 {
408 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
409 $uri->withSchema('');
410 }
411
417 {
418 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
419 $uri->withSchema('1aa');
420 }
421
425 public function test_with_port($uri)
426 {
427 $this->assertEquals($uri->schema(), 'g+it');
428 $this->assertEquals($uri->authority(), 'github.com:8080');
429 $this->assertEquals($uri->host(), 'github.com');
430 $this->assertEquals($uri->port(), '8080');
431 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
432 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
433 $this->assertEquals($uri->fragment(), 'fragment');
434 $uri = $uri->withPort(80);
435 $this->assertEquals($uri->schema(), 'g+it');
436 $this->assertEquals($uri->authority(), 'github.com:80');
437 $this->assertEquals($uri->host(), 'github.com');
438 $this->assertEquals($uri->port(), '80');
439 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
440 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
441 $this->assertEquals($uri->fragment(), 'fragment');
442 $uri = $uri->withPort();
443 $this->assertEquals($uri->schema(), 'g+it');
444 $this->assertEquals($uri->authority(), 'github.com');
445 $this->assertEquals($uri->host(), 'github.com');
446 $this->assertNull($uri->port());
447 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
448 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
449 $this->assertEquals($uri->fragment(), 'fragment');
450 }
451
452
457 public function test_with_port_invalid_1()
458 {
459 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
460 $uri->withPort('a111');
461 }
462
467 public function test_with_port_invalid_2()
468 {
469 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
470 $uri->withPort('foo');
471 }
472
476 public function test_with_host($uri)
477 {
478 $this->assertEquals($uri->schema(), 'g+it');
479 $this->assertEquals($uri->authority(), 'github.com:8080');
480 $this->assertEquals($uri->host(), 'github.com');
481 $this->assertEquals($uri->port(), '8080');
482 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
483 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
484 $this->assertEquals($uri->fragment(), 'fragment');
485 $uri = $uri->withHost('ilias.de');
486 $this->assertEquals($uri->schema(), 'g+it');
487 $this->assertEquals($uri->authority(), 'ilias.de:8080');
488 $this->assertEquals($uri->host(), 'ilias.de');
489 $this->assertEquals($uri->port(), '8080');
490 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
491 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
492 $this->assertEquals($uri->fragment(), 'fragment');
493 }
494
495
500 public function test_with_host_invalid_1()
501 {
502 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
503 $uri->withHost('-foo-.de');
504 }
505
510 public function test_with_host_invalid_2()
511 {
512 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
513 $uri->withHost(null);
514 }
515
516
521 public function test_with_host_invalid_3()
522 {
523 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
524 $uri->withHost('');
525 }
526
531 public function test_with_host_invalid_4()
532 {
533 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
534 $uri->withHost('ilias.de"><script');
535 }
536
540 public function test_with_authority($uri)
541 {
542 $this->assertEquals($uri->schema(), 'g+it');
543 $this->assertEquals($uri->authority(), 'github.com:8080');
544 $this->assertEquals($uri->host(), 'github.com');
545 $this->assertEquals($uri->port(), '8080');
546 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
547 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
548 $this->assertEquals($uri->fragment(), 'fragment');
549 $uri = $uri->withAuthority('www1.ilias.de');
550 $this->assertEquals($uri->schema(), 'g+it');
551 $this->assertEquals($uri->authority(), 'www1.ilias.de');
552 $this->assertEquals($uri->host(), 'www1.ilias.de');
553 $this->assertNull($uri->port());
554 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
555 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
556 $this->assertEquals($uri->fragment(), 'fragment');
557 $uri = $uri->withAuthority('ilias.de:80');
558 $this->assertEquals($uri->schema(), 'g+it');
559 $this->assertEquals($uri->authority(), 'ilias.de:80');
560 $this->assertEquals($uri->host(), 'ilias.de');
561 $this->assertEquals($uri->port(), '80');
562 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
563 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
564 $this->assertEquals($uri->fragment(), 'fragment');
565 $uri = $uri->withAuthority('a:1');
566 $this->assertEquals($uri->schema(), 'g+it');
567 $this->assertEquals($uri->authority(), 'a:1');
568 $this->assertEquals($uri->host(), 'a');
569 $this->assertEquals($uri->port(), 1);
570 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
571 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
572 $this->assertEquals($uri->fragment(), 'fragment');
573 $uri = $uri->withAuthority('a');
574 $this->assertEquals($uri->schema(), 'g+it');
575 $this->assertEquals($uri->authority(), 'a');
576 $this->assertEquals($uri->host(), 'a');
577 $this->assertNull($uri->port());
578 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
579 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
580 $this->assertEquals($uri->fragment(), 'fragment');
581 $uri = $uri->withAuthority('1.2.3.4');
582 $this->assertEquals($uri->schema(), 'g+it');
583 $this->assertEquals($uri->authority(), '1.2.3.4');
584 $this->assertEquals($uri->host(), '1.2.3.4');
585 $this->assertNull($uri->port());
586 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
587 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
588 $this->assertEquals($uri->fragment(), 'fragment');
589 $uri = $uri->withAuthority('1.2.3.4:5');
590 $this->assertEquals($uri->schema(), 'g+it');
591 $this->assertEquals($uri->authority(), '1.2.3.4:5');
592 $this->assertEquals($uri->host(), '1.2.3.4');
593 $this->assertEquals($uri->port(), 5);
594 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
595 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
596 $this->assertEquals($uri->fragment(), 'fragment');
597 $uri = $uri->withAuthority('localhost1');
598 $this->assertEquals($uri->schema(), 'g+it');
599 $this->assertEquals($uri->authority(), 'localhost1');
600 $this->assertEquals($uri->host(), 'localhost1');
601 $this->assertNull($uri->port());
602 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
603 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
604 $this->assertEquals($uri->fragment(), 'fragment');
605 $uri = $uri->withAuthority('localhost1:10');
606 $this->assertEquals($uri->schema(), 'g+it');
607 $this->assertEquals($uri->authority(), 'localhost1:10');
608 $this->assertEquals($uri->host(), 'localhost1');
609 $this->assertEquals($uri->port(), 10);
610 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
611 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
612 $this->assertEquals($uri->fragment(), 'fragment');
613 }
614
620 {
621 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
622 $uri->withAuthority('-foo-.de');
623 }
624
630 {
631 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
632 $uri->withHost(null);
633 }
634
635
641 {
642 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
643 $uri->withHost('ilias.de:');
644 }
645
651 {
652 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
653 $uri->withHost('ilias.de: ');
654 }
655
661 {
662 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
663 $uri->withHost('ilias.de:aaa');
664 }
665
671 {
672 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
673 $uri->withAuthority('foo.de&<script>');
674 }
675
676
682 {
683 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
684 $uri->withAuthority('foo.de"><script>alert');
685 }
686
687
693 {
694 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
695 $uri->withAuthority(' :80');
696 }
697
701 public function test_with_path($uri)
702 {
703 $this->assertEquals($uri->schema(), 'g+it');
704 $this->assertEquals($uri->authority(), 'github.com:8080');
705 $this->assertEquals($uri->host(), 'github.com');
706 $this->assertEquals($uri->port(), '8080');
707 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
708 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
709 $this->assertEquals($uri->fragment(), 'fragment');
710 $uri = $uri->withPath('a/b');
711 $this->assertEquals($uri->schema(), 'g+it');
712 $this->assertEquals($uri->authority(), 'github.com:8080');
713 $this->assertEquals($uri->host(), 'github.com');
714 $this->assertEquals($uri->port(), '8080');
715 $this->assertEquals($uri->path(), 'a/b');
716 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
717 $this->assertEquals($uri->fragment(), 'fragment');
718 $uri = $uri->withPath();
719 $this->assertEquals($uri->schema(), 'g+it');
720 $this->assertEquals($uri->authority(), 'github.com:8080');
721 $this->assertEquals($uri->host(), 'github.com');
722 $this->assertEquals($uri->port(), '8080');
723 $this->assertNull($uri->path());
724 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
725 $this->assertEquals($uri->fragment(), 'fragment');
726 }
727
732 public function test_with_path_invalid_1()
733 {
734 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
735 $uri->withPath('/<script>/a');
736 }
737
742 public function test_with_path_invalid_2()
743 {
744 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
745 $uri->withPath('//a/b');
746 }
747
752 public function test_with_path_invalid_3()
753 {
754 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
755 $uri->withPath(':a/b');
756 }
757
761 public function test_with_query($uri)
762 {
763 $this->assertEquals($uri->schema(), 'g+it');
764 $this->assertEquals($uri->authority(), 'github.com:8080');
765 $this->assertEquals($uri->host(), 'github.com');
766 $this->assertEquals($uri->port(), '8080');
767 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
768 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
769 $this->assertEquals($uri->fragment(), 'fragment');
770 $uri = $uri->withQuery('query_par_a1=val_a1');
771 $this->assertEquals($uri->schema(), 'g+it');
772 $this->assertEquals($uri->authority(), 'github.com:8080');
773 $this->assertEquals($uri->host(), 'github.com');
774 $this->assertEquals($uri->port(), '8080');
775 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
776 $this->assertEquals($uri->query(), 'query_par_a1=val_a1');
777 $this->assertEquals($uri->fragment(), 'fragment');
778 $uri = $uri->withQuery();
779 $this->assertEquals($uri->schema(), 'g+it');
780 $this->assertEquals($uri->authority(), 'github.com:8080');
781 $this->assertEquals($uri->host(), 'github.com');
782 $this->assertEquals($uri->port(), '8080');
783 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
784 $this->assertNull($uri->query());
785 $this->assertEquals($uri->fragment(), 'fragment');
786 }
787
793 {
794 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
795 $uri->withQuery('<script>a');
796 }
797
803 {
804 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
805 $uri->withQuery('aa[]');
806 }
807
811 public function test_with_fragment($uri)
812 {
813 $this->assertEquals($uri->schema(), 'g+it');
814 $this->assertEquals($uri->authority(), 'github.com:8080');
815 $this->assertEquals($uri->host(), 'github.com');
816 $this->assertEquals($uri->port(), '8080');
817 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
818 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
819 $this->assertEquals($uri->fragment(), 'fragment');
820 $uri = $uri->withFragment('someFragment');
821 $this->assertEquals($uri->schema(), 'g+it');
822 $this->assertEquals($uri->authority(), 'github.com:8080');
823 $this->assertEquals($uri->host(), 'github.com');
824 $this->assertEquals($uri->port(), '8080');
825 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
826 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
827 $this->assertEquals($uri->fragment(), 'someFragment');
828 $uri = $uri->withFragment();
829 $this->assertEquals($uri->schema(), 'g+it');
830 $this->assertEquals($uri->authority(), 'github.com:8080');
831 $this->assertEquals($uri->host(), 'github.com');
832 $this->assertEquals($uri->port(), '8080');
833 $this->assertEquals($uri->path(), 'someaccount/somerepo/somerepo.git');
834 $this->assertEquals($uri->query(), 'query_par_1=val_1&query_par_2=val_2');
835 $this->assertNull($uri->fragment());
836 }
837
843 {
844 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
845 $uri->withFragment('aaa[]');
846 }
847
853 {
854 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
855 $uri->withFragment('script>');
856 }
857}
An exception for terminatinating execution or to throw for unit testing.
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:18
test_with_schema_invalid_2()
@depends test_with_schema @expectedException \InvalidArgumentException
Definition: URITest.php:416
test_wrong_char_in_schema()
@depends test_init @expectedException \TypeError
Definition: URITest.php:294
const URI_AUTHORITY_ONLY
Definition: URITest.php:30
const URI_HOST_ALPHADIG_START_1
Definition: URITest.php:46
test_with_host_invalid_3()
@depends test_with_host @expectedException \InvalidArgumentException
Definition: URITest.php:521
test_with_authority_invalid_2()
@depends test_with_authority @expectedException \TypeError
Definition: URITest.php:629
test_with_host_invalid_2()
@depends test_with_host @expectedException \TypeError
Definition: URITest.php:510
test_authority_and_query()
@depends test_init
Definition: URITest.php:190
const URI_HOST_ALPHADIG_START_4
Definition: URITest.php:49
const URI_FAKEPCENC
Definition: URITest.php:44
const URI_COMPLETE_IPV4
Definition: URITest.php:10
test_wrong_authority_in_schema_2()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:312
test_with_authority_invalid_4()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:650
test_with_schema($uri)
@depends test_init
Definition: URITest.php:383
const URI_HOST_ALPHADIG_START_3
Definition: URITest.php:48
const URI_NO_PATH_1
Definition: URITest.php:15
const URI_NO_QUERY_2
Definition: URITest.php:19
test_with_path_invalid_1()
@depends test_with_path @expectedException \InvalidArgumentException
Definition: URITest.php:732
test_no_path()
@depends test_init
Definition: URITest.php:142
test_with_authority_invalid_8()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:692
const URI_NO_AUTHORITY
Definition: URITest.php:34
const URI_COMPLETE
Definition: URITest.php:8
const URI_NO_PATH_2
Definition: URITest.php:16
test_with_port_invalid_2()
@depends test_with_port @expectedException \TypeError
Definition: URITest.php:467
test_with_schema_invalid_1()
@depends test_with_schema @expectedException \InvalidArgumentException
Definition: URITest.php:406
test_alphadigit_start_host()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:339
test_no_schema()
@depends test_init @expectedException \TypeError
Definition: URITest.php:276
const URI_WRONG_SCHEMA
Definition: URITest.php:36
test_no_authority()
@depends test_init @expectedException \TypeError
Definition: URITest.php:285
test_with_path($uri)
@depends test_init
Definition: URITest.php:701
const URI_AUTHORITY_AND_FRAGMENT
Definition: URITest.php:24
test_uri_invalid()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:321
test_fakepcenc()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:330
test_base_uri_idempotent($uri)
@depends test_init
Definition: URITest.php:115
test_alphadigit_start_host_4()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:366
test_ipv4()
@depends test_init
Definition: URITest.php:61
const URI_AUTHORITY_AND_QUERY_2
Definition: URITest.php:22
const URI_WRONG_AUTHORITY_1
Definition: URITest.php:38
test_with_host_invalid_1()
@depends test_with_host @expectedException \InvalidArgumentException
Definition: URITest.php:500
test_with_query_invalid_1()
@depends test_with_query @expectedException \InvalidArgumentException
Definition: URITest.php:792
test_alphadigit_start_host_2()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:348
const URI_COMPLETE_LOCALHOST
Definition: URITest.php:12
test_with_port_invalid_1()
@depends test_with_port @expectedException \TypeError
Definition: URITest.php:457
const URI_NO_SCHEMA
Definition: URITest.php:32
const URI_NO_QUERY_1
Definition: URITest.php:18
test_authority_path_fragment()
@depends test_init
Definition: URITest.php:228
test_with_query($uri)
@depends test_init
Definition: URITest.php:761
test_with_authority($uri)
@depends test_init
Definition: URITest.php:540
test_localhost()
@depends test_init
Definition: URITest.php:77
test_with_fragment_invalid_1()
@depends test_with_fragment @expectedException \InvalidArgumentException
Definition: URITest.php:842
test_with_host_invalid_4()
@depends test_with_host @expectedException \InvalidArgumentException
Definition: URITest.php:531
test_with_authority_invalid_6()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:670
test_with_host($uri)
@depends test_init
Definition: URITest.php:476
test_with_authority_invalid_7()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:681
const URI_HOST_ALPHADIG_START_5
Definition: URITest.php:50
test_base_uri($uri)
@depends test_init
Definition: URITest.php:107
const URI_AUTHORITY_AND_QUERY_1
Definition: URITest.php:21
const URI_HOST_ALPHADIG_START_2
Definition: URITest.php:47
test_alphadigit_start_host_5()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:375
test_path()
@depends test_init
Definition: URITest.php:243
test_with_path_invalid_3()
@depends test_with_path @expectedException \InvalidArgumentException
Definition: URITest.php:752
test_with_fragment($uri)
@depends test_init
Definition: URITest.php:811
const URI_INVALID
Definition: URITest.php:42
test_components($uri)
@depends test_init
Definition: URITest.php:93
test_with_fragment_invalid_2()
@depends test_with_fragment @expectedException \InvalidArgumentException
Definition: URITest.php:852
test_with_authority_invalid_5()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:660
test_with_path_invalid_2()
@depends test_with_path @expectedException \InvalidArgumentException
Definition: URITest.php:742
test_init()
Definition: URITest.php:53
test_authority_only()
@depends test_init
Definition: URITest.php:259
test_with_query_invalid_2()
@depends test_with_query @expectedException \InvalidArgumentException
Definition: URITest.php:802
test_with_authority_invalid_1()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:619
test_no_query()
@depends test_init
Definition: URITest.php:166
test_with_port($uri)
@depends test_init
Definition: URITest.php:425
test_authority_and_fragment()
@depends test_init
Definition: URITest.php:214
test_wrong_authority_in_schema_1()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:303
const URI_WRONG_AUTHORITY_2
Definition: URITest.php:39
test_with_authority_invalid_3()
@depends test_with_authority @expectedException \InvalidArgumentException
Definition: URITest.php:640
const URI_AUTHORITY_PATH_FRAGMENT
Definition: URITest.php:26
test_alphadigit_start_host_3()
@depends test_init @expectedException \InvalidArgumentException
Definition: URITest.php:357
const URI_PATH
Definition: URITest.php:28