ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
URITest.php
Go to the documentation of this file.
1<?php
2require_once("libs/composer/vendor/autoload.php");
3
4use ILIAS\Data;
5use PHPUnit\Framework\TestCase;
6
7class URITest extends TestCase
8{
9 const URI_COMPLETE = 'g+it://github.com:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
10
11 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';
12
13 const URI_COMPLETE_LOCALHOST = 'g+it://localhost:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
14
15
16 const URI_NO_PATH_1 = 'g-it://ilias%2Da.de:8080?query_par_1=val_1&query_par_2=val_2#fragment';
17 const URI_NO_PATH_2 = 'g.it://amaz;on.co.uk:8080/?query_par_1=val_1&query_par_2=val_2#fragment';
18
19 const URI_NO_QUERY_1 = 'git://one-letter-top-level.a:8080/someaccount/somerepo/somerepo.git/#fragment';
20 const URI_NO_QUERY_2 = 'git://github.com:8080/someaccount/somerepo/somerepo.git#fragment';
21
22 const URI_AUTHORITY_AND_QUERY_1 = 'git://github.com?query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
23 const URI_AUTHORITY_AND_QUERY_2 = 'git://github.com/?qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2';
24
25 const URI_AUTHORITY_AND_FRAGMENT = 'git://github.com:8080/#fragment$,;:A!\'*+()ar_1=val_1&';
26
27 const URI_AUTHORITY_PATH_FRAGMENT = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git#frag:A!\'*+()arment';
28
29 const URI_PATH = 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
30
31 const URI_AUTHORITY_ONLY = 'git://git$,;hub.com';
32
33 const URI_NO_SCHEMA = 'git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git/';
34
35 const URI_NO_AUTHORITY = 'git://:8080/someaccount/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
36
37 const URI_WRONG_SCHEMA = 'gi$t://git$,;hub.com';
38
39 const URI_WRONG_AUTHORITY_1 = 'git://git$,;hu<b.com:8080/someacc$,;ount/somerepo/somerepo.git/';
40 const URI_WRONG_AUTHORITY_2 = 'git://git$,;hu=b.com/someacc$,;ount/somerepo/somerepo.git/';
41
42
43 const URI_INVALID = 'https://host.de/ilias.php/"><script>alert(1)</script>?baseClass=ilObjChatroomGUI&cmd=getOSDNotifications&cmdMode=asynch&max_age=15192913';
44
45 const URI_FAKEPCENC = 'g+it://github.com:8080/someaccoun%t/somerepo/somerepo.git/?query_par_1=val_1&query_par_2=val_2#fragment';
46
47 const URI_HOST_ALPHADIG_START_1 = 'g+it://-github.com:8080/someaccount';
48 const URI_HOST_ALPHADIG_START_2 = 'g+it://github-.com:8080/someaccount';
49 const URI_HOST_ALPHADIG_START_3 = 'http://.';
50 const URI_HOST_ALPHADIG_START_4 = 'http://../';
51 const URI_HOST_ALPHADIG_START_5 = 'http://-error-.invalid/';
52
53
57 public function test_init()
58 {
59 return new ILIAS\Data\URI(self::URI_COMPLETE);
60 }
61
65 public function test_ipv4()
66 {
67 $uri = new ILIAS\Data\URI(self::URI_COMPLETE_IPV4);
68 $this->assertEquals($uri->getSchema(), 'g+it');
69 $this->assertEquals($uri->getAuthority(), '10.0.0.86:8080');
70 $this->assertEquals($uri->getHost(), '10.0.0.86');
71 $this->assertEquals($uri->getPort(), 8080);
72 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
73 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
74 $this->assertEquals($uri->getFragment(), 'fragment');
75 }
76
77
81 public function test_localhost()
82 {
83 $uri = new ILIAS\Data\URI(self::URI_COMPLETE_LOCALHOST);
84 $this->assertEquals($uri->getSchema(), 'g+it');
85 $this->assertEquals($uri->getAuthority(), 'localhost:8080');
86 $this->assertEquals($uri->getHost(), 'localhost');
87 $this->assertEquals($uri->getPort(), 8080);
88 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
89 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
90 $this->assertEquals($uri->getFragment(), 'fragment');
91 }
92
93
97 public function test_components($uri)
98 {
99 $this->assertEquals($uri->getSchema(), 'g+it');
100 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
101 $this->assertEquals($uri->getHost(), 'github.com');
102 $this->assertEquals($uri->getPort(), '8080');
103 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
104 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
105 $this->assertEquals($uri->getFragment(), 'fragment');
106 }
107
111 public function test_base_uri($uri)
112 {
113 $this->assertEquals($uri->getBaseURI(), 'g+it://github.com:8080/someaccount/somerepo/somerepo.git');
114 }
115
119 public function test_base_uri_idempotent($uri)
120 {
121 $base_uri = $uri->getBaseURI();
122 $this->assertEquals($base_uri, 'g+it://github.com:8080/someaccount/somerepo/somerepo.git');
123 $this->assertEquals($uri->getSchema(), 'g+it');
124 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
125 $this->assertEquals($uri->getHost(), 'github.com');
126 $this->assertEquals($uri->getPort(), '8080');
127 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
128 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
129 $this->assertEquals($uri->getFragment(), 'fragment');
130
131 $uri = new ILIAS\Data\URI($base_uri);
132 $this->assertEquals($base_uri, $uri->getBaseURI());
133 $this->assertEquals($uri->getSchema(), 'g+it');
134 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
135 $this->assertEquals($uri->getHost(), 'github.com');
136 $this->assertEquals($uri->getPort(), '8080');
137 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
138 $this->assertNull($uri->getQuery());
139 $this->assertNull($uri->getFragment());
140 }
141
142
146 public function test_no_path()
147 {
148 $uri = new ILIAS\Data\URI(self::URI_NO_PATH_1);
149 $this->assertEquals($uri->getSchema(), 'g-it');
150 $this->assertEquals($uri->getAuthority(), 'ilias%2Da.de:8080');
151 $this->assertEquals($uri->getHost(), 'ilias%2Da.de');
152 $this->assertEquals($uri->getPort(), '8080');
153 $this->assertNull($uri->getPath());
154 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
155 $this->assertEquals($uri->getFragment(), 'fragment');
156
157 $uri = new ILIAS\Data\URI(self::URI_NO_PATH_2);
158 $this->assertEquals($uri->getSchema(), 'g.it');
159 $this->assertEquals($uri->getAuthority(), 'amaz;on.co.uk:8080');
160 $this->assertEquals($uri->getHost(), 'amaz;on.co.uk');
161 $this->assertEquals($uri->getPort(), '8080');
162 $this->assertNull($uri->getPath());
163 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
164 $this->assertEquals($uri->getFragment(), 'fragment');
165 }
166
170 public function test_no_query()
171 {
172 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_1);
173 $this->assertEquals($uri->getSchema(), 'git');
174 $this->assertEquals($uri->getAuthority(), 'one-letter-top-level.a:8080');
175 $this->assertEquals($uri->getHost(), 'one-letter-top-level.a');
176 $this->assertEquals($uri->getPort(), '8080');
177 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
178 $this->assertNull($uri->getQuery());
179 $this->assertEquals($uri->getFragment(), 'fragment');
180
181 $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
182 $this->assertEquals($uri->getSchema(), 'git');
183 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
184 $this->assertEquals($uri->getHost(), 'github.com');
185 $this->assertEquals($uri->getPort(), '8080');
186 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
187 $this->assertNull($uri->getQuery());
188 $this->assertEquals($uri->getFragment(), 'fragment');
189 }
190
194 public function test_authority_and_query()
195 {
196 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_1);
197 $this->assertEquals($uri->getSchema(), 'git');
198 $this->assertEquals($uri->getAuthority(), 'github.com');
199 $this->assertEquals($uri->getHost(), 'github.com');
200 $this->assertNull($uri->getPort());
201 $this->assertNull($uri->getPath());
202 $this->assertEquals($uri->getQuery(), 'query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2');
203 $this->assertNull($uri->getFragment());
204
205 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_2);
206 $this->assertEquals($uri->getSchema(), 'git');
207 $this->assertEquals($uri->getAuthority(), 'github.com');
208 $this->assertEquals($uri->getHost(), 'github.com');
209 $this->assertNull($uri->getPort());
210 $this->assertNull($uri->getPath());
211 $this->assertEquals($uri->getQuery(), 'qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2');
212 $this->assertNull($uri->getFragment());
213 }
214
219 {
220 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_FRAGMENT);
221 $this->assertEquals($uri->getSchema(), 'git');
222 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
223 $this->assertEquals($uri->getHost(), 'github.com');
224 $this->assertEquals($uri->getPort(), '8080');
225 $this->assertNull($uri->getPath());
226 $this->assertNull($uri->getQuery());
227 $this->assertEquals($uri->getFragment(), 'fragment$,;:A!\'*+()ar_1=val_1&');
228 }
233 {
234 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_PATH_FRAGMENT);
235 $this->assertEquals($uri->getSchema(), 'git');
236 $this->assertEquals($uri->getAuthority(), 'git$,;hub.com:8080');
237 $this->assertEquals($uri->getHost(), 'git$,;hub.com');
238 $this->assertEquals($uri->getPort(), '8080');
239 $this->assertEquals($uri->getPath(), 'someacc$,;ount/somerepo/somerepo.git');
240 $this->assertNull($uri->getQuery());
241 $this->assertEquals($uri->getFragment(), 'frag:A!\'*+()arment');
242 }
243
247 public function test_path()
248 {
249 $uri = new ILIAS\Data\URI(self::URI_PATH);
250 $this->assertEquals($uri->getSchema(), 'git');
251 $this->assertEquals($uri->getAuthority(), 'git$,;hub.com:8080');
252 $this->assertEquals($uri->getHost(), 'git$,;hub.com');
253 $this->assertEquals($uri->getPort(), '8080');
254 $this->assertEquals($uri->getPath(), 'someacc$,;ount/somerepo/somerepo.git');
255 $this->assertNull($uri->getQuery());
256 $this->assertNull($uri->getFragment());
257 $this->assertEquals($uri->getBaseURI(), 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git');
258 }
259
263 public function test_authority_only()
264 {
265 $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_ONLY);
266 $this->assertEquals($uri->getSchema(), 'git');
267 $this->assertEquals($uri->getAuthority(), 'git$,;hub.com');
268 $this->assertEquals($uri->getHost(), 'git$,;hub.com');
269 $this->assertNull($uri->getPort());
270 $this->assertNull($uri->getPath());
271 $this->assertNull($uri->getQuery());
272 $this->assertNull($uri->getFragment());
273 $this->assertEquals($uri->getBaseURI(), 'git://git$,;hub.com');
274 }
275
279 public function test_no_schema()
280 {
281 $this->expectException(\TypeError::class);
282 new ILIAS\Data\URI(self::URI_NO_SCHEMA);
283 }
284
288 public function test_no_authority()
289 {
290 $this->expectException(\TypeError::class);
291 new ILIAS\Data\URI(self::URI_NO_AUTHORITY);
292 }
293
298 {
299 $this->expectException(\TypeError::class);
300 new ILIAS\Data\URI(self::URI_WRONG_SCHEMA);
301 }
302
307 {
308 $this->expectException(\InvalidArgumentException::class);
309 new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_1);
310 }
311
316 {
317 $this->expectException(\InvalidArgumentException::class);
318 new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_2);
319 }
320
324 public function test_uri_invalid()
325 {
326 $this->expectException(\InvalidArgumentException::class);
327 new ILIAS\Data\URI(self::URI_INVALID);
328 }
329
333 public function test_fakepcenc()
334 {
335 $this->expectException(\InvalidArgumentException::class);
336 new ILIAS\Data\URI(self::URI_FAKEPCENC);
337 }
338
343 {
344 $this->expectException(\InvalidArgumentException::class);
345 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_1);
346 }
347
352 {
353 $this->expectException(\InvalidArgumentException::class);
354 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_2);
355 }
356
361 {
362 $this->expectException(\InvalidArgumentException::class);
363 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_3);
364 }
365
370 {
371 $this->expectException(\InvalidArgumentException::class);
372 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_4);
373 }
374
379 {
380 $this->expectException(\InvalidArgumentException::class);
381 new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_5);
382 }
383
387 public function test_with_schema($uri)
388 {
389 $this->assertEquals($uri->getSchema(), 'g+it');
390 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
391 $this->assertEquals($uri->getHost(), 'github.com');
392 $this->assertEquals($uri->getPort(), '8080');
393 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
394 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
395 $this->assertEquals($uri->getFragment(), 'fragment');
396 $uri = $uri->withSchema('http');
397 $this->assertEquals($uri->getSchema(), 'http');
398 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
399 $this->assertEquals($uri->getHost(), 'github.com');
400 $this->assertEquals($uri->getPort(), '8080');
401 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
402 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
403 $this->assertEquals($uri->getFragment(), 'fragment');
404 }
405
410 {
411 $this->expectException(\InvalidArgumentException::class);
412 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
413 $uri->withSchema('');
414 }
415
420 {
421 $this->expectException(\InvalidArgumentException::class);
422 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
423 $uri->withSchema('1aa');
424 }
425
429 public function test_with_port($uri)
430 {
431 $this->assertEquals($uri->getSchema(), 'g+it');
432 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
433 $this->assertEquals($uri->getHost(), 'github.com');
434 $this->assertEquals($uri->getPort(), '8080');
435 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
436 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
437 $this->assertEquals($uri->getFragment(), 'fragment');
438 $uri = $uri->withPort(80);
439 $this->assertEquals($uri->getSchema(), 'g+it');
440 $this->assertEquals($uri->getAuthority(), 'github.com:80');
441 $this->assertEquals($uri->getHost(), 'github.com');
442 $this->assertEquals($uri->getPort(), '80');
443 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
444 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
445 $this->assertEquals($uri->getFragment(), 'fragment');
446 $uri = $uri->withPort();
447 $this->assertEquals($uri->getSchema(), 'g+it');
448 $this->assertEquals($uri->getAuthority(), 'github.com');
449 $this->assertEquals($uri->getHost(), 'github.com');
450 $this->assertNull($uri->getPort());
451 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
452 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
453 $this->assertEquals($uri->getFragment(), 'fragment');
454 }
455
456
460 public function test_with_port_invalid_1()
461 {
462 $this->expectException(\TypeError::class);
463 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
464 $uri->withPort('a111');
465 }
466
470 public function test_with_port_invalid_2()
471 {
472 $this->expectException(\TypeError::class);
473 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
474 $uri->withPort('foo');
475 }
476
480 public function test_with_host($uri)
481 {
482 $this->assertEquals($uri->getSchema(), 'g+it');
483 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
484 $this->assertEquals($uri->getHost(), 'github.com');
485 $this->assertEquals($uri->getPort(), '8080');
486 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
487 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
488 $this->assertEquals($uri->getFragment(), 'fragment');
489 $uri = $uri->withHost('ilias.de');
490 $this->assertEquals($uri->getSchema(), 'g+it');
491 $this->assertEquals($uri->getAuthority(), 'ilias.de:8080');
492 $this->assertEquals($uri->getHost(), 'ilias.de');
493 $this->assertEquals($uri->getPort(), '8080');
494 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
495 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
496 $this->assertEquals($uri->getFragment(), 'fragment');
497 }
498
499
503 public function test_with_host_invalid_1()
504 {
505 $this->expectException(\InvalidArgumentException::class);
506 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
507 $uri->withHost('-foo-.de');
508 }
509
513 public function test_with_host_invalid_3()
514 {
515 $this->expectException(\InvalidArgumentException::class);
516 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
517 $uri->withHost('');
518 }
519
523 public function test_with_host_invalid_4()
524 {
525 $this->expectException(\InvalidArgumentException::class);
526 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
527 $uri->withHost('ilias.de"><script');
528 }
529
533 public function test_with_authority($uri)
534 {
535 $this->assertEquals($uri->getSchema(), 'g+it');
536 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
537 $this->assertEquals($uri->getHost(), 'github.com');
538 $this->assertEquals($uri->getPort(), '8080');
539 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
540 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
541 $this->assertEquals($uri->getFragment(), 'fragment');
542 $uri = $uri->withAuthority('www1.ilias.de');
543 $this->assertEquals($uri->getSchema(), 'g+it');
544 $this->assertEquals($uri->getAuthority(), 'www1.ilias.de');
545 $this->assertEquals($uri->getHost(), 'www1.ilias.de');
546 $this->assertNull($uri->getPort());
547 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
548 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
549 $this->assertEquals($uri->getFragment(), 'fragment');
550 $uri = $uri->withAuthority('ilias.de:80');
551 $this->assertEquals($uri->getSchema(), 'g+it');
552 $this->assertEquals($uri->getAuthority(), 'ilias.de:80');
553 $this->assertEquals($uri->getHost(), 'ilias.de');
554 $this->assertEquals($uri->getPort(), '80');
555 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
556 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
557 $this->assertEquals($uri->getFragment(), 'fragment');
558 $uri = $uri->withAuthority('a:1');
559 $this->assertEquals($uri->getSchema(), 'g+it');
560 $this->assertEquals($uri->getAuthority(), 'a:1');
561 $this->assertEquals($uri->getHost(), 'a');
562 $this->assertEquals($uri->getPort(), 1);
563 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
564 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
565 $this->assertEquals($uri->getFragment(), 'fragment');
566 $uri = $uri->withAuthority('a');
567 $this->assertEquals($uri->getSchema(), 'g+it');
568 $this->assertEquals($uri->getAuthority(), 'a');
569 $this->assertEquals($uri->getHost(), 'a');
570 $this->assertNull($uri->getPort());
571 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
572 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
573 $this->assertEquals($uri->getFragment(), 'fragment');
574 $uri = $uri->withAuthority('1.2.3.4');
575 $this->assertEquals($uri->getSchema(), 'g+it');
576 $this->assertEquals($uri->getAuthority(), '1.2.3.4');
577 $this->assertEquals($uri->getHost(), '1.2.3.4');
578 $this->assertNull($uri->getPort());
579 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
580 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
581 $this->assertEquals($uri->getFragment(), 'fragment');
582 $uri = $uri->withAuthority('1.2.3.4:5');
583 $this->assertEquals($uri->getSchema(), 'g+it');
584 $this->assertEquals($uri->getAuthority(), '1.2.3.4:5');
585 $this->assertEquals($uri->getHost(), '1.2.3.4');
586 $this->assertEquals($uri->getPort(), 5);
587 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
588 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
589 $this->assertEquals($uri->getFragment(), 'fragment');
590 $uri = $uri->withAuthority('localhost1');
591 $this->assertEquals($uri->getSchema(), 'g+it');
592 $this->assertEquals($uri->getAuthority(), 'localhost1');
593 $this->assertEquals($uri->getHost(), 'localhost1');
594 $this->assertNull($uri->getPort());
595 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
596 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
597 $this->assertEquals($uri->getFragment(), 'fragment');
598 $uri = $uri->withAuthority('localhost1:10');
599 $this->assertEquals($uri->getSchema(), 'g+it');
600 $this->assertEquals($uri->getAuthority(), 'localhost1:10');
601 $this->assertEquals($uri->getHost(), 'localhost1');
602 $this->assertEquals($uri->getPort(), 10);
603 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
604 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
605 $this->assertEquals($uri->getFragment(), 'fragment');
606 }
607
612 {
613 $this->expectException(\InvalidArgumentException::class);
614 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
615 $uri->withAuthority('-foo-.de');
616 }
617
622 {
623 $this->expectException(\InvalidArgumentException::class);
624 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
625 $uri->withAuthority('-bar-.de:6060');
626 }
627
628
633 {
634 $this->expectException(\InvalidArgumentException::class);
635 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
636 $uri->withHost('ilias.de:');
637 }
638
643 {
644 $this->expectException(\InvalidArgumentException::class);
645 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
646 $uri->withHost('ilias.de: ');
647 }
648
653 {
654 $this->expectException(\InvalidArgumentException::class);
655 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
656 $uri->withHost('ilias.de:aaa');
657 }
658
663 {
664 $this->expectException(\InvalidArgumentException::class);
665 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
666 $uri->withAuthority('foo.de&<script>');
667 }
668
669
674 {
675 $this->expectException(\InvalidArgumentException::class);
676 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
677 $uri->withAuthority('foo.de"><script>alert');
678 }
679
680
685 {
686 $this->expectException(\InvalidArgumentException::class);
687 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
688 $uri->withAuthority(' :80');
689 }
690
694 public function test_with_path($uri)
695 {
696 $this->assertEquals($uri->getSchema(), 'g+it');
697 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
698 $this->assertEquals($uri->getHost(), 'github.com');
699 $this->assertEquals($uri->getPort(), '8080');
700 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
701 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
702 $this->assertEquals($uri->getFragment(), 'fragment');
703 $uri = $uri->withPath('a/b');
704 $this->assertEquals($uri->getSchema(), 'g+it');
705 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
706 $this->assertEquals($uri->getHost(), 'github.com');
707 $this->assertEquals($uri->getPort(), '8080');
708 $this->assertEquals($uri->getPath(), 'a/b');
709 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
710 $this->assertEquals($uri->getFragment(), 'fragment');
711 $uri = $uri->withPath();
712 $this->assertEquals($uri->getSchema(), 'g+it');
713 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
714 $this->assertEquals($uri->getHost(), 'github.com');
715 $this->assertEquals($uri->getPort(), '8080');
716 $this->assertNull($uri->getPath());
717 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
718 $this->assertEquals($uri->getFragment(), 'fragment');
719 }
720
724 public function test_with_path_invalid_1()
725 {
726 $this->expectException(\InvalidArgumentException::class);
727 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
728 $uri->withPath('/<script>/a');
729 }
730
734 public function test_with_path_invalid_2()
735 {
736 $this->expectException(\InvalidArgumentException::class);
737 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
738 $uri->withPath('//a/b');
739 }
740
744 public function test_with_path_invalid_3()
745 {
746 $this->expectException(\InvalidArgumentException::class);
747 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
748 $uri->withPath(':a/b');
749 }
750
754 public function test_with_query($uri)
755 {
756 $this->assertEquals($uri->getSchema(), 'g+it');
757 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
758 $this->assertEquals($uri->getHost(), 'github.com');
759 $this->assertEquals($uri->getPort(), '8080');
760 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
761 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
762 $this->assertEquals($uri->getFragment(), 'fragment');
763 $uri = $uri->withQuery('query_par_a1=val_a1');
764 $this->assertEquals($uri->getSchema(), 'g+it');
765 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
766 $this->assertEquals($uri->getHost(), 'github.com');
767 $this->assertEquals($uri->getPort(), '8080');
768 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
769 $this->assertEquals($uri->getQuery(), 'query_par_a1=val_a1');
770 $this->assertEquals($uri->getFragment(), 'fragment');
771 $uri = $uri->withQuery();
772 $this->assertEquals($uri->getSchema(), 'g+it');
773 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
774 $this->assertEquals($uri->getHost(), 'github.com');
775 $this->assertEquals($uri->getPort(), '8080');
776 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
777 $this->assertNull($uri->getQuery());
778 $this->assertEquals($uri->getFragment(), 'fragment');
779 }
780
785 {
786 $this->expectException(\InvalidArgumentException::class);
787 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
788 $uri->withQuery('<script>a');
789 }
790
795 {
796 $this->expectException(\InvalidArgumentException::class);
797 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
798 $uri->withQuery('aa[]');
799 }
800
804 public function test_with_fragment($uri)
805 {
806 $this->assertEquals($uri->getSchema(), 'g+it');
807 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
808 $this->assertEquals($uri->getHost(), 'github.com');
809 $this->assertEquals($uri->getPort(), '8080');
810 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
811 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
812 $this->assertEquals($uri->getFragment(), 'fragment');
813 $uri = $uri->withFragment('someFragment');
814 $this->assertEquals($uri->getSchema(), 'g+it');
815 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
816 $this->assertEquals($uri->getHost(), 'github.com');
817 $this->assertEquals($uri->getPort(), '8080');
818 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
819 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
820 $this->assertEquals($uri->getFragment(), 'someFragment');
821 $uri = $uri->withFragment();
822 $this->assertEquals($uri->getSchema(), 'g+it');
823 $this->assertEquals($uri->getAuthority(), 'github.com:8080');
824 $this->assertEquals($uri->getHost(), 'github.com');
825 $this->assertEquals($uri->getPort(), '8080');
826 $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
827 $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
828 $this->assertNull($uri->getFragment());
829 }
830
835 {
836 $this->expectException(\InvalidArgumentException::class);
837 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
838 $uri->withFragment('aaa[]');
839 }
840
845 {
846 $this->expectException(\InvalidArgumentException::class);
847 $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
848 $uri->withFragment('script>');
849 }
850}
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
Definition: URITest.php:419
test_wrong_char_in_schema()
@depends test_init
Definition: URITest.php:297
const URI_AUTHORITY_ONLY
Definition: URITest.php:31
const URI_HOST_ALPHADIG_START_1
Definition: URITest.php:47
test_with_host_invalid_3()
@depends test_with_host
Definition: URITest.php:513
test_with_authority_invalid_2()
@depends test_with_authority
Definition: URITest.php:621
test_authority_and_query()
@depends test_init
Definition: URITest.php:194
const URI_HOST_ALPHADIG_START_4
Definition: URITest.php:50
const URI_FAKEPCENC
Definition: URITest.php:45
const URI_COMPLETE_IPV4
Definition: URITest.php:11
test_wrong_authority_in_schema_2()
@depends test_init
Definition: URITest.php:315
test_with_authority_invalid_4()
@depends test_with_authority
Definition: URITest.php:642
test_with_schema($uri)
@depends test_init
Definition: URITest.php:387
const URI_HOST_ALPHADIG_START_3
Definition: URITest.php:49
const URI_NO_PATH_1
Definition: URITest.php:16
const URI_NO_QUERY_2
Definition: URITest.php:20
test_with_path_invalid_1()
@depends test_with_path
Definition: URITest.php:724
test_no_path()
@depends test_init
Definition: URITest.php:146
test_with_authority_invalid_8()
@depends test_with_authority
Definition: URITest.php:684
const URI_NO_AUTHORITY
Definition: URITest.php:35
const URI_COMPLETE
Definition: URITest.php:9
const URI_NO_PATH_2
Definition: URITest.php:17
test_with_port_invalid_2()
@depends test_with_port
Definition: URITest.php:470
test_with_schema_invalid_1()
@depends test_with_schema
Definition: URITest.php:409
test_alphadigit_start_host()
@depends test_init
Definition: URITest.php:342
test_no_schema()
@depends test_init
Definition: URITest.php:279
const URI_WRONG_SCHEMA
Definition: URITest.php:37
test_no_authority()
@depends test_init
Definition: URITest.php:288
test_with_path($uri)
@depends test_init
Definition: URITest.php:694
const URI_AUTHORITY_AND_FRAGMENT
Definition: URITest.php:25
test_uri_invalid()
@depends test_init
Definition: URITest.php:324
test_fakepcenc()
@depends test_init
Definition: URITest.php:333
test_base_uri_idempotent($uri)
@depends test_init
Definition: URITest.php:119
test_alphadigit_start_host_4()
@depends test_init
Definition: URITest.php:369
test_ipv4()
@depends test_init
Definition: URITest.php:65
const URI_AUTHORITY_AND_QUERY_2
Definition: URITest.php:23
const URI_WRONG_AUTHORITY_1
Definition: URITest.php:39
test_with_host_invalid_1()
@depends test_with_host
Definition: URITest.php:503
test_with_query_invalid_1()
@depends test_with_query
Definition: URITest.php:784
test_alphadigit_start_host_2()
@depends test_init
Definition: URITest.php:351
const URI_COMPLETE_LOCALHOST
Definition: URITest.php:13
test_with_port_invalid_1()
@depends test_with_port
Definition: URITest.php:460
const URI_NO_SCHEMA
Definition: URITest.php:33
const URI_NO_QUERY_1
Definition: URITest.php:19
test_authority_path_fragment()
@depends test_init
Definition: URITest.php:232
test_with_query($uri)
@depends test_init
Definition: URITest.php:754
test_with_authority($uri)
@depends test_init
Definition: URITest.php:533
test_localhost()
@depends test_init
Definition: URITest.php:81
test_with_fragment_invalid_1()
@depends test_with_fragment
Definition: URITest.php:834
test_with_host_invalid_4()
@depends test_with_host
Definition: URITest.php:523
test_with_authority_invalid_6()
@depends test_with_authority
Definition: URITest.php:662
test_with_host($uri)
@depends test_init
Definition: URITest.php:480
test_with_authority_invalid_7()
@depends test_with_authority
Definition: URITest.php:673
const URI_HOST_ALPHADIG_START_5
Definition: URITest.php:51
test_base_uri($uri)
@depends test_init
Definition: URITest.php:111
const URI_AUTHORITY_AND_QUERY_1
Definition: URITest.php:22
const URI_HOST_ALPHADIG_START_2
Definition: URITest.php:48
test_alphadigit_start_host_5()
@depends test_init
Definition: URITest.php:378
test_path()
@depends test_init
Definition: URITest.php:247
test_with_path_invalid_3()
@depends test_with_path
Definition: URITest.php:744
test_with_fragment($uri)
@depends test_init
Definition: URITest.php:804
const URI_INVALID
Definition: URITest.php:43
test_components($uri)
@depends test_init
Definition: URITest.php:97
test_with_fragment_invalid_2()
@depends test_with_fragment
Definition: URITest.php:844
test_with_authority_invalid_5()
@depends test_with_authority
Definition: URITest.php:652
test_with_path_invalid_2()
@depends test_with_path
Definition: URITest.php:734
test_init()
@doesNotPerformAssertions
Definition: URITest.php:57
test_authority_only()
@depends test_init
Definition: URITest.php:263
test_with_query_invalid_2()
@depends test_with_query
Definition: URITest.php:794
test_with_authority_invalid_1()
@depends test_with_authority
Definition: URITest.php:611
test_no_query()
@depends test_init
Definition: URITest.php:170
test_with_port($uri)
@depends test_init
Definition: URITest.php:429
test_authority_and_fragment()
@depends test_init
Definition: URITest.php:218
test_wrong_authority_in_schema_1()
@depends test_init
Definition: URITest.php:306
const URI_WRONG_AUTHORITY_2
Definition: URITest.php:40
test_with_authority_invalid_3()
@depends test_with_authority
Definition: URITest.php:632
const URI_AUTHORITY_PATH_FRAGMENT
Definition: URITest.php:27
test_alphadigit_start_host_3()
@depends test_init
Definition: URITest.php:360
const URI_PATH
Definition: URITest.php:29