ILIAS  release_7 Revision v7.30-3-g800a261c036
URITest.php
Go to the documentation of this file.
1 <?php
2 require_once("libs/composer/vendor/autoload.php");
3 
4 use ILIAS\Data;
6 
7 class 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_REALPCTENC = 'g+it://github.com:8080/someaccount%2Fsomerepo/som%2brepo.git/?par_lower=val_%2b&par_upper=val_%C3%A1#fragment';
48  const PATH_REALPCTENC = 'someaccount%2Fsomerepo/som%2brepo.git';
50  'par_lower' => 'val_+',
51  'par_upper' => 'val_รก'
52  ];
53 
54  const URI_HOST_ALPHADIG_START_1 = 'g+it://-github.com:8080/someaccount';
55  const URI_HOST_ALPHADIG_START_2 = 'g+it://github-.com:8080/someaccount';
56  const URI_HOST_ALPHADIG_START_3 = 'http://.';
57  const URI_HOST_ALPHADIG_START_4 = 'http://../';
58  const URI_HOST_ALPHADIG_START_5 = 'http://-error-.invalid/';
59 
60  const URI_BASE = 'git://github.com:8080/someaccount/somerepo/somerepo.git';
61  const PARAMS = [
62  'par_1' => 'val_1',
63  'par_2' => 'val_2'
64  ];
65 
66 
70  public function test_init()
71  {
72  return new ILIAS\Data\URI(self::URI_COMPLETE);
73  }
74 
78  public function test_ipv4()
79  {
80  $uri = new ILIAS\Data\URI(self::URI_COMPLETE_IPV4);
81  $this->assertEquals($uri->getSchema(), 'g+it');
82  $this->assertEquals($uri->getAuthority(), '10.0.0.86:8080');
83  $this->assertEquals($uri->getHost(), '10.0.0.86');
84  $this->assertEquals($uri->getPort(), 8080);
85  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
86  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
87  $this->assertEquals($uri->getFragment(), 'fragment');
88  }
89 
90 
94  public function test_localhost()
95  {
96  $uri = new ILIAS\Data\URI(self::URI_COMPLETE_LOCALHOST);
97  $this->assertEquals($uri->getSchema(), 'g+it');
98  $this->assertEquals($uri->getAuthority(), 'localhost:8080');
99  $this->assertEquals($uri->getHost(), 'localhost');
100  $this->assertEquals($uri->getPort(), 8080);
101  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
102  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
103  $this->assertEquals($uri->getFragment(), 'fragment');
104  }
105 
106 
110  public function test_components($uri)
111  {
112  $this->assertEquals($uri->getSchema(), 'g+it');
113  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
114  $this->assertEquals($uri->getHost(), 'github.com');
115  $this->assertEquals($uri->getPort(), '8080');
116  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
117  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
118  $this->assertEquals($uri->getFragment(), 'fragment');
119  }
120 
124  public function test_base_uri($uri)
125  {
126  $this->assertEquals($uri->getBaseURI(), 'g+it://github.com:8080/someaccount/somerepo/somerepo.git');
127  }
128 
132  public function test_base_uri_idempotent($uri)
133  {
134  $base_uri = $uri->getBaseURI();
135  $this->assertEquals($base_uri, 'g+it://github.com:8080/someaccount/somerepo/somerepo.git');
136  $this->assertEquals($uri->getSchema(), 'g+it');
137  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
138  $this->assertEquals($uri->getHost(), 'github.com');
139  $this->assertEquals($uri->getPort(), '8080');
140  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
141  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
142  $this->assertEquals($uri->getFragment(), 'fragment');
143 
144  $uri = new ILIAS\Data\URI($base_uri);
145  $this->assertEquals($base_uri, $uri->getBaseURI());
146  $this->assertEquals($uri->getSchema(), 'g+it');
147  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
148  $this->assertEquals($uri->getHost(), 'github.com');
149  $this->assertEquals($uri->getPort(), '8080');
150  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
151  $this->assertNull($uri->getQuery());
152  $this->assertNull($uri->getFragment());
153  }
154 
155 
159  public function test_no_path()
160  {
161  $uri = new ILIAS\Data\URI(self::URI_NO_PATH_1);
162  $this->assertEquals($uri->getSchema(), 'g-it');
163  $this->assertEquals($uri->getAuthority(), 'ilias%2Da.de:8080');
164  $this->assertEquals($uri->getHost(), 'ilias%2Da.de');
165  $this->assertEquals($uri->getPort(), '8080');
166  $this->assertNull($uri->getPath());
167  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
168  $this->assertEquals($uri->getFragment(), 'fragment');
169 
170  $uri = new ILIAS\Data\URI(self::URI_NO_PATH_2);
171  $this->assertEquals($uri->getSchema(), 'g.it');
172  $this->assertEquals($uri->getAuthority(), 'amaz;on.co.uk:8080');
173  $this->assertEquals($uri->getHost(), 'amaz;on.co.uk');
174  $this->assertEquals($uri->getPort(), '8080');
175  $this->assertNull($uri->getPath());
176  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
177  $this->assertEquals($uri->getFragment(), 'fragment');
178  }
179 
183  public function test_no_query()
184  {
185  $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_1);
186  $this->assertEquals($uri->getSchema(), 'git');
187  $this->assertEquals($uri->getAuthority(), 'one-letter-top-level.a:8080');
188  $this->assertEquals($uri->getHost(), 'one-letter-top-level.a');
189  $this->assertEquals($uri->getPort(), '8080');
190  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
191  $this->assertNull($uri->getQuery());
192  $this->assertEquals($uri->getFragment(), 'fragment');
193 
194  $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
195  $this->assertEquals($uri->getSchema(), 'git');
196  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
197  $this->assertEquals($uri->getHost(), 'github.com');
198  $this->assertEquals($uri->getPort(), '8080');
199  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
200  $this->assertNull($uri->getQuery());
201  $this->assertEquals($uri->getFragment(), 'fragment');
202  }
203 
207  public function test_authority_and_query()
208  {
209  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_1);
210  $this->assertEquals($uri->getSchema(), 'git');
211  $this->assertEquals($uri->getAuthority(), 'github.com');
212  $this->assertEquals($uri->getHost(), 'github.com');
213  $this->assertNull($uri->getPort());
214  $this->assertNull($uri->getPath());
215  $this->assertEquals($uri->getQuery(), 'query_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2');
216  $this->assertNull($uri->getFragment());
217 
218  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_QUERY_2);
219  $this->assertEquals($uri->getSchema(), 'git');
220  $this->assertEquals($uri->getAuthority(), 'github.com');
221  $this->assertEquals($uri->getHost(), 'github.com');
222  $this->assertNull($uri->getPort());
223  $this->assertNull($uri->getPath());
224  $this->assertEquals($uri->getQuery(), 'qu/ery_p$,;:A!\'*+()ar_1=val_1&quer?y_par_2=val_2');
225  $this->assertNull($uri->getFragment());
226  }
227 
231  public function test_authority_and_fragment()
232  {
233  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_AND_FRAGMENT);
234  $this->assertEquals($uri->getSchema(), 'git');
235  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
236  $this->assertEquals($uri->getHost(), 'github.com');
237  $this->assertEquals($uri->getPort(), '8080');
238  $this->assertNull($uri->getPath());
239  $this->assertNull($uri->getQuery());
240  $this->assertEquals($uri->getFragment(), 'fragment$,;:A!\'*+()ar_1=val_1&');
241  }
246  {
247  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_PATH_FRAGMENT);
248  $this->assertEquals($uri->getSchema(), 'git');
249  $this->assertEquals($uri->getAuthority(), 'git$,;hub.com:8080');
250  $this->assertEquals($uri->getHost(), 'git$,;hub.com');
251  $this->assertEquals($uri->getPort(), '8080');
252  $this->assertEquals($uri->getPath(), 'someacc$,;ount/somerepo/somerepo.git');
253  $this->assertNull($uri->getQuery());
254  $this->assertEquals($uri->getFragment(), 'frag:A!\'*+()arment');
255  }
256 
260  public function test_path()
261  {
262  $uri = new ILIAS\Data\URI(self::URI_PATH);
263  $this->assertEquals($uri->getSchema(), 'git');
264  $this->assertEquals($uri->getAuthority(), 'git$,;hub.com:8080');
265  $this->assertEquals($uri->getHost(), 'git$,;hub.com');
266  $this->assertEquals($uri->getPort(), '8080');
267  $this->assertEquals($uri->getPath(), 'someacc$,;ount/somerepo/somerepo.git');
268  $this->assertNull($uri->getQuery());
269  $this->assertNull($uri->getFragment());
270  $this->assertEquals($uri->getBaseURI(), 'git://git$,;hub.com:8080/someacc$,;ount/somerepo/somerepo.git');
271  }
272 
276  public function test_authority_only()
277  {
278  $uri = new ILIAS\Data\URI(self::URI_AUTHORITY_ONLY);
279  $this->assertEquals($uri->getSchema(), 'git');
280  $this->assertEquals($uri->getAuthority(), 'git$,;hub.com');
281  $this->assertEquals($uri->getHost(), 'git$,;hub.com');
282  $this->assertNull($uri->getPort());
283  $this->assertNull($uri->getPath());
284  $this->assertNull($uri->getQuery());
285  $this->assertNull($uri->getFragment());
286  $this->assertEquals($uri->getBaseURI(), 'git://git$,;hub.com');
287  }
288 
292  public function test_no_schema()
293  {
294  $this->expectException(\TypeError::class);
295  new ILIAS\Data\URI(self::URI_NO_SCHEMA);
296  }
297 
301  public function test_no_authority()
302  {
303  $this->expectException(\TypeError::class);
304  new ILIAS\Data\URI(self::URI_NO_AUTHORITY);
305  }
306 
310  public function test_wrong_char_in_schema()
311  {
312  $this->expectException(\TypeError::class);
313  new ILIAS\Data\URI(self::URI_WRONG_SCHEMA);
314  }
315 
320  {
321  $this->expectException(\InvalidArgumentException::class);
322  new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_1);
323  }
324 
329  {
330  $this->expectException(\InvalidArgumentException::class);
331  new ILIAS\Data\URI(self::URI_WRONG_AUTHORITY_2);
332  }
333 
337  public function test_uri_invalid()
338  {
339  $this->expectException(\InvalidArgumentException::class);
340  new ILIAS\Data\URI(self::URI_INVALID);
341  }
342 
346  public function test_realpctenc()
347  {
348  $uri = new ILIAS\Data\URI(self::URI_REALPCTENC);
349  $this->assertEquals(self::PATH_REALPCTENC, $uri->getPath());
350  $this->assertEquals(self::PARAMS_REALPCTENC, $uri->getParameters());
351  }
352 
356  public function test_fakepcenc()
357  {
358  $this->expectException(\InvalidArgumentException::class);
359  new ILIAS\Data\URI(self::URI_FAKEPCENC);
360  }
361 
365  public function test_alphadigit_start_host()
366  {
367  $this->expectException(\InvalidArgumentException::class);
368  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_1);
369  }
370 
375  {
376  $this->expectException(\InvalidArgumentException::class);
377  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_2);
378  }
379 
384  {
385  $this->expectException(\InvalidArgumentException::class);
386  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_3);
387  }
388 
393  {
394  $this->expectException(\InvalidArgumentException::class);
395  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_4);
396  }
397 
402  {
403  $this->expectException(\InvalidArgumentException::class);
404  new ILIAS\Data\URI(self::URI_HOST_ALPHADIG_START_5);
405  }
406 
410  public function test_with_schema($uri)
411  {
412  $this->assertEquals($uri->getSchema(), 'g+it');
413  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
414  $this->assertEquals($uri->getHost(), 'github.com');
415  $this->assertEquals($uri->getPort(), '8080');
416  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
417  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
418  $this->assertEquals($uri->getFragment(), 'fragment');
419  $uri = $uri->withSchema('http');
420  $this->assertEquals($uri->getSchema(), 'http');
421  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
422  $this->assertEquals($uri->getHost(), 'github.com');
423  $this->assertEquals($uri->getPort(), '8080');
424  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
425  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
426  $this->assertEquals($uri->getFragment(), 'fragment');
427  }
428 
432  public function test_with_schema_invalid_1()
433  {
434  $this->expectException(\InvalidArgumentException::class);
435  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
436  $uri->withSchema('');
437  }
438 
442  public function test_with_schema_invalid_2()
443  {
444  $this->expectException(\InvalidArgumentException::class);
445  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
446  $uri->withSchema('1aa');
447  }
448 
452  public function test_with_port($uri)
453  {
454  $this->assertEquals($uri->getSchema(), 'g+it');
455  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
456  $this->assertEquals($uri->getHost(), 'github.com');
457  $this->assertEquals($uri->getPort(), '8080');
458  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
459  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
460  $this->assertEquals($uri->getFragment(), 'fragment');
461  $uri = $uri->withPort(80);
462  $this->assertEquals($uri->getSchema(), 'g+it');
463  $this->assertEquals($uri->getAuthority(), 'github.com:80');
464  $this->assertEquals($uri->getHost(), 'github.com');
465  $this->assertEquals($uri->getPort(), '80');
466  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
467  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
468  $this->assertEquals($uri->getFragment(), 'fragment');
469  $uri = $uri->withPort();
470  $this->assertEquals($uri->getSchema(), 'g+it');
471  $this->assertEquals($uri->getAuthority(), 'github.com');
472  $this->assertEquals($uri->getHost(), 'github.com');
473  $this->assertNull($uri->getPort());
474  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
475  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
476  $this->assertEquals($uri->getFragment(), 'fragment');
477  }
478 
479 
483  public function test_with_port_invalid_1()
484  {
485  $this->expectException(\TypeError::class);
486  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
487  $uri->withPort('a111');
488  }
489 
493  public function test_with_port_invalid_2()
494  {
495  $this->expectException(\TypeError::class);
496  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
497  $uri->withPort('foo');
498  }
499 
503  public function test_with_host($uri)
504  {
505  $this->assertEquals($uri->getSchema(), 'g+it');
506  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
507  $this->assertEquals($uri->getHost(), 'github.com');
508  $this->assertEquals($uri->getPort(), '8080');
509  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
510  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
511  $this->assertEquals($uri->getFragment(), 'fragment');
512  $uri = $uri->withHost('ilias.de');
513  $this->assertEquals($uri->getSchema(), 'g+it');
514  $this->assertEquals($uri->getAuthority(), 'ilias.de:8080');
515  $this->assertEquals($uri->getHost(), 'ilias.de');
516  $this->assertEquals($uri->getPort(), '8080');
517  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
518  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
519  $this->assertEquals($uri->getFragment(), 'fragment');
520  }
521 
522 
526  public function test_with_host_invalid_1()
527  {
528  $this->expectException(\InvalidArgumentException::class);
529  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
530  $uri->withHost('-foo-.de');
531  }
532 
536  public function test_with_host_invalid_3()
537  {
538  $this->expectException(\InvalidArgumentException::class);
539  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
540  $uri->withHost('');
541  }
542 
546  public function test_with_host_invalid_4()
547  {
548  $this->expectException(\InvalidArgumentException::class);
549  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
550  $uri->withHost('ilias.de"><script');
551  }
552 
556  public function test_with_authority($uri)
557  {
558  $this->assertEquals($uri->getSchema(), 'g+it');
559  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
560  $this->assertEquals($uri->getHost(), 'github.com');
561  $this->assertEquals($uri->getPort(), '8080');
562  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
563  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
564  $this->assertEquals($uri->getFragment(), 'fragment');
565  $uri = $uri->withAuthority('www1.ilias.de');
566  $this->assertEquals($uri->getSchema(), 'g+it');
567  $this->assertEquals($uri->getAuthority(), 'www1.ilias.de');
568  $this->assertEquals($uri->getHost(), 'www1.ilias.de');
569  $this->assertNull($uri->getPort());
570  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
571  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
572  $this->assertEquals($uri->getFragment(), 'fragment');
573  $uri = $uri->withAuthority('ilias.de:80');
574  $this->assertEquals($uri->getSchema(), 'g+it');
575  $this->assertEquals($uri->getAuthority(), 'ilias.de:80');
576  $this->assertEquals($uri->getHost(), 'ilias.de');
577  $this->assertEquals($uri->getPort(), '80');
578  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
579  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
580  $this->assertEquals($uri->getFragment(), 'fragment');
581  $uri = $uri->withAuthority('a:1');
582  $this->assertEquals($uri->getSchema(), 'g+it');
583  $this->assertEquals($uri->getAuthority(), 'a:1');
584  $this->assertEquals($uri->getHost(), 'a');
585  $this->assertEquals($uri->getPort(), 1);
586  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
587  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
588  $this->assertEquals($uri->getFragment(), 'fragment');
589  $uri = $uri->withAuthority('a');
590  $this->assertEquals($uri->getSchema(), 'g+it');
591  $this->assertEquals($uri->getAuthority(), 'a');
592  $this->assertEquals($uri->getHost(), 'a');
593  $this->assertNull($uri->getPort());
594  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
595  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
596  $this->assertEquals($uri->getFragment(), 'fragment');
597  $uri = $uri->withAuthority('1.2.3.4');
598  $this->assertEquals($uri->getSchema(), 'g+it');
599  $this->assertEquals($uri->getAuthority(), '1.2.3.4');
600  $this->assertEquals($uri->getHost(), '1.2.3.4');
601  $this->assertNull($uri->getPort());
602  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
603  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
604  $this->assertEquals($uri->getFragment(), 'fragment');
605  $uri = $uri->withAuthority('1.2.3.4:5');
606  $this->assertEquals($uri->getSchema(), 'g+it');
607  $this->assertEquals($uri->getAuthority(), '1.2.3.4:5');
608  $this->assertEquals($uri->getHost(), '1.2.3.4');
609  $this->assertEquals($uri->getPort(), 5);
610  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
611  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
612  $this->assertEquals($uri->getFragment(), 'fragment');
613  $uri = $uri->withAuthority('localhost1');
614  $this->assertEquals($uri->getSchema(), 'g+it');
615  $this->assertEquals($uri->getAuthority(), 'localhost1');
616  $this->assertEquals($uri->getHost(), 'localhost1');
617  $this->assertNull($uri->getPort());
618  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
619  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
620  $this->assertEquals($uri->getFragment(), 'fragment');
621  $uri = $uri->withAuthority('localhost1:10');
622  $this->assertEquals($uri->getSchema(), 'g+it');
623  $this->assertEquals($uri->getAuthority(), 'localhost1:10');
624  $this->assertEquals($uri->getHost(), 'localhost1');
625  $this->assertEquals($uri->getPort(), 10);
626  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
627  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
628  $this->assertEquals($uri->getFragment(), 'fragment');
629  }
630 
635  {
636  $this->expectException(\InvalidArgumentException::class);
637  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
638  $uri->withAuthority('-foo-.de');
639  }
640 
645  {
646  $this->expectException(\InvalidArgumentException::class);
647  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
648  $uri->withAuthority('-bar-.de:6060');
649  }
650 
651 
656  {
657  $this->expectException(\InvalidArgumentException::class);
658  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
659  $uri->withHost('ilias.de:');
660  }
661 
666  {
667  $this->expectException(\InvalidArgumentException::class);
668  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
669  $uri->withHost('ilias.de: ');
670  }
671 
676  {
677  $this->expectException(\InvalidArgumentException::class);
678  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
679  $uri->withHost('ilias.de:aaa');
680  }
681 
686  {
687  $this->expectException(\InvalidArgumentException::class);
688  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
689  $uri->withAuthority('foo.de&<script>');
690  }
691 
692 
697  {
698  $this->expectException(\InvalidArgumentException::class);
699  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
700  $uri->withAuthority('foo.de"><script>alert');
701  }
702 
703 
708  {
709  $this->expectException(\InvalidArgumentException::class);
710  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
711  $uri->withAuthority(' :80');
712  }
713 
717  public function test_with_path($uri)
718  {
719  $this->assertEquals($uri->getSchema(), 'g+it');
720  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
721  $this->assertEquals($uri->getHost(), 'github.com');
722  $this->assertEquals($uri->getPort(), '8080');
723  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
724  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
725  $this->assertEquals($uri->getFragment(), 'fragment');
726  $uri = $uri->withPath('a/b');
727  $this->assertEquals($uri->getSchema(), 'g+it');
728  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
729  $this->assertEquals($uri->getHost(), 'github.com');
730  $this->assertEquals($uri->getPort(), '8080');
731  $this->assertEquals($uri->getPath(), 'a/b');
732  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
733  $this->assertEquals($uri->getFragment(), 'fragment');
734  $uri = $uri->withPath();
735  $this->assertEquals($uri->getSchema(), 'g+it');
736  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
737  $this->assertEquals($uri->getHost(), 'github.com');
738  $this->assertEquals($uri->getPort(), '8080');
739  $this->assertNull($uri->getPath());
740  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
741  $this->assertEquals($uri->getFragment(), 'fragment');
742  }
743 
747  public function test_with_path_invalid_1()
748  {
749  $this->expectException(\InvalidArgumentException::class);
750  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
751  $uri->withPath('/<script>/a');
752  }
753 
757  public function test_with_path_invalid_2()
758  {
759  $this->expectException(\InvalidArgumentException::class);
760  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
761  $uri->withPath('//a/b');
762  }
763 
767  public function test_with_path_invalid_3()
768  {
769  $this->expectException(\InvalidArgumentException::class);
770  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
771  $uri->withPath(':a/b');
772  }
773 
777  public function test_with_query($uri)
778  {
779  $this->assertEquals($uri->getSchema(), 'g+it');
780  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
781  $this->assertEquals($uri->getHost(), 'github.com');
782  $this->assertEquals($uri->getPort(), '8080');
783  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
784  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
785  $this->assertEquals($uri->getFragment(), 'fragment');
786  $uri = $uri->withQuery('query_par_a1=val_a1');
787  $this->assertEquals($uri->getSchema(), 'g+it');
788  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
789  $this->assertEquals($uri->getHost(), 'github.com');
790  $this->assertEquals($uri->getPort(), '8080');
791  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
792  $this->assertEquals($uri->getQuery(), 'query_par_a1=val_a1');
793  $this->assertEquals($uri->getFragment(), 'fragment');
794  $uri = $uri->withQuery();
795  $this->assertEquals($uri->getSchema(), 'g+it');
796  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
797  $this->assertEquals($uri->getHost(), 'github.com');
798  $this->assertEquals($uri->getPort(), '8080');
799  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
800  $this->assertNull($uri->getQuery());
801  $this->assertEquals($uri->getFragment(), 'fragment');
802  }
803 
807  public function test_with_query_invalid_1()
808  {
809  $this->expectException(\InvalidArgumentException::class);
810  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
811  $uri->withQuery('<script>a');
812  }
813 
817  public function test_with_query_invalid_2()
818  {
819  $this->expectException(\InvalidArgumentException::class);
820  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
821  $uri->withQuery('aa[]');
822  }
823 
827  public function test_with_fragment($uri)
828  {
829  $this->assertEquals($uri->getSchema(), 'g+it');
830  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
831  $this->assertEquals($uri->getHost(), 'github.com');
832  $this->assertEquals($uri->getPort(), '8080');
833  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
834  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
835  $this->assertEquals($uri->getFragment(), 'fragment');
836  $uri = $uri->withFragment('someFragment');
837  $this->assertEquals($uri->getSchema(), 'g+it');
838  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
839  $this->assertEquals($uri->getHost(), 'github.com');
840  $this->assertEquals($uri->getPort(), '8080');
841  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
842  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
843  $this->assertEquals($uri->getFragment(), 'someFragment');
844  $uri = $uri->withFragment();
845  $this->assertEquals($uri->getSchema(), 'g+it');
846  $this->assertEquals($uri->getAuthority(), 'github.com:8080');
847  $this->assertEquals($uri->getHost(), 'github.com');
848  $this->assertEquals($uri->getPort(), '8080');
849  $this->assertEquals($uri->getPath(), 'someaccount/somerepo/somerepo.git');
850  $this->assertEquals($uri->getQuery(), 'query_par_1=val_1&query_par_2=val_2');
851  $this->assertNull($uri->getFragment());
852  }
853 
858  {
859  $this->expectException(\InvalidArgumentException::class);
860  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
861  $uri->withFragment('aaa[]');
862  }
863 
868  {
869  $this->expectException(\InvalidArgumentException::class);
870  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
871  $uri->withFragment('script>');
872  }
873 
874  public function testToString()
875  {
876  $uri = new ILIAS\Data\URI(self::URI_COMPLETE);
877  $this->assertEquals(
878  self::URI_COMPLETE,
879  $uri
880  );
881  }
882 
883  public function testGetParameters() : ILIAS\Data\URI
884  {
885  $url = self::URI_BASE . '?' . http_build_query(self::PARAMS);
886  $uri = new ILIAS\Data\URI($url);
887  $this->assertEquals(
888  self::PARAMS,
889  $uri->getParameters()
890  );
891  return $uri;
892  }
893 
897  public function testGetParameter(ILIAS\Data\URI $uri)
898  {
899  $k = array_keys(self::PARAMS)[0];
900  $this->assertEquals(
901  self::PARAMS[$k],
902  $uri->getParameter($k)
903  );
904  }
905 
909  public function testWithParameters(ILIAS\Data\URI $uri) : ILIAS\Data\URI
910  {
911  $params = ['x' => 1, 'y' => 2];
912  $uri = $uri->withParameters($params);
913  $this->assertEquals(
914  $params,
915  $uri->getParameters()
916  );
917  return $uri;
918  }
919 
923  public function testSubstituteParameter(ILIAS\Data\URI $uri)
924  {
925  $uri = $uri->withParameter('x', 5);
926  $this->assertEquals(
927  5,
928  $uri->getParameter('x')
929  );
930  }
934  public function testAppendParameter(ILIAS\Data\URI $uri)
935  {
936  $params = [
937  'x' => 1, 'y' => 2,
938  'z' => 5
939  ];
940  $uri = $uri->withParameter('z', 5);
941  $this->assertEquals(
942  $params,
943  $uri->getParameters()
944  );
945  }
946 
950  public function testWithArrayParameters(ILIAS\Data\URI $uri)
951  {
952  $params = ['x' => 1, 'y' => [10, 11, 12]];
953  $uri = $uri->withParameters($params);
954  $this->assertEquals(
955  $params,
956  $uri->getParameters()
957  );
958  $this->assertEquals(
959  'git://github.com:8080/someaccount/somerepo/somerepo.git?x=1&y%5B0%5D=10&y%5B1%5D=11&y%5B2%5D=12',
960  $uri
961  );
962  $this->assertEquals(
963  $params['y'],
964  $uri->getParameter('y')
965  );
966  }
967 
968  public function testWithOutParameters()
969  {
970  $uri = new ILIAS\Data\URI(self::URI_NO_QUERY_2);
971  $this->assertEquals(
972  [],
973  $uri->getParameters()
974  );
975 
976  $this->assertNull($uri->getParameter('y'));
977 
978  $this->assertEquals(
979  self::URI_NO_QUERY_2,
980  (string) $uri
981  );
982  }
983 }
test_with_authority_invalid_3()
test_with_authority
Definition: URITest.php:655
testWithArrayParameters(ILIAS\Data\URI $uri)
testGetParameters
Definition: URITest.php:950
const URI_HOST_ALPHADIG_START_2
Definition: URITest.php:55
test_with_path_invalid_3()
test_with_path
Definition: URITest.php:767
test_alphadigit_start_host_5()
test_init
Definition: URITest.php:401
const URI_COMPLETE_LOCALHOST
Definition: URITest.php:13
test_base_uri_idempotent($uri)
test_init
Definition: URITest.php:132
const URI_HOST_ALPHADIG_START_3
Definition: URITest.php:56
const URI_NO_QUERY_2
Definition: URITest.php:20
const URI_NO_SCHEMA
Definition: URITest.php:33
const const URI_HOST_ALPHADIG_START_1
Definition: URITest.php:54
test_with_authority_invalid_7()
test_with_authority
Definition: URITest.php:696
test_with_authority_invalid_6()
test_with_authority
Definition: URITest.php:685
test_authority_only()
test_init
Definition: URITest.php:276
withParameters(array $parameters)
Get URI with modified parameters.
Definition: URI.php:428
testWithOutParameters()
Definition: URITest.php:968
test_wrong_authority_in_schema_1()
test_init
Definition: URITest.php:319
test_with_authority_invalid_4()
test_with_authority
Definition: URITest.php:665
test_with_path_invalid_2()
test_with_path
Definition: URITest.php:757
test_with_fragment($uri)
test_init
Definition: URITest.php:827
test_realpctenc()
test_init
Definition: URITest.php:346
test_with_authority_invalid_2()
test_with_authority
Definition: URITest.php:644
const PARAMS_REALPCTENC
Definition: URITest.php:49
test_with_host_invalid_4()
test_with_host
Definition: URITest.php:546
test_alphadigit_start_host_4()
test_init
Definition: URITest.php:392
test_fakepcenc()
test_init
Definition: URITest.php:356
const URI_AUTHORITY_AND_FRAGMENT
Definition: URITest.php:25
Class ChatMainBarProvider .
const URI_PATH
Definition: URITest.php:29
const URI_WRONG_SCHEMA
Definition: URITest.php:37
const URI_HOST_ALPHADIG_START_5
Definition: URITest.php:58
test_with_authority_invalid_1()
test_with_authority
Definition: URITest.php:634
testAppendParameter(ILIAS\Data\URI $uri)
testWithParameters
Definition: URITest.php:934
test_no_authority()
test_init
Definition: URITest.php:301
testGetParameter(ILIAS\Data\URI $uri)
testGetParameters
Definition: URITest.php:897
test_with_host_invalid_1()
test_with_host
Definition: URITest.php:526
test_with_schema($uri)
test_init
Definition: URITest.php:410
const test_init()
Definition: URITest.php:70
const URI_REALPCTENC
Definition: URITest.php:47
const URI_INVALID
Definition: URITest.php:43
test_wrong_char_in_schema()
test_init
Definition: URITest.php:310
test_with_query_invalid_1()
test_with_query
Definition: URITest.php:807
const URI_WRONG_AUTHORITY_1
Definition: URITest.php:39
const URI_NO_PATH_1
Definition: URITest.php:16
test_with_fragment_invalid_1()
test_with_fragment
Definition: URITest.php:857
const URI_FAKEPCENC
Definition: URITest.php:45
test_no_path()
test_init
Definition: URITest.php:159
test_path()
test_init
Definition: URITest.php:260
test_with_query_invalid_2()
test_with_query
Definition: URITest.php:817
test_with_fragment_invalid_2()
test_with_fragment
Definition: URITest.php:867
testWithParameters(ILIAS\Data\URI $uri)
testGetParameters
Definition: URITest.php:909
const URI_HOST_ALPHADIG_START_4
Definition: URITest.php:57
const PARAMS
Definition: URITest.php:61
test_with_port_invalid_1()
test_with_port
Definition: URITest.php:483
const URI_AUTHORITY_ONLY
Definition: URITest.php:31
const URI_NO_PATH_2
Definition: URITest.php:17
const URI_COMPLETE
Definition: URITest.php:9
test_with_host_invalid_3()
test_with_host
Definition: URITest.php:536
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:17
test_with_query($uri)
test_init
Definition: URITest.php:777
test_with_authority_invalid_8()
test_with_authority
Definition: URITest.php:707
test_authority_path_fragment()
test_init
Definition: URITest.php:245
test_base_uri($uri)
test_init
Definition: URITest.php:124
test_with_host($uri)
test_init
Definition: URITest.php:503
test_with_path($uri)
test_init
Definition: URITest.php:717
test_authority_and_query()
test_init
Definition: URITest.php:207
const URI_AUTHORITY_AND_QUERY_2
Definition: URITest.php:23
test_with_port($uri)
test_init
Definition: URITest.php:452
testSubstituteParameter(ILIAS\Data\URI $uri)
testWithParameters
Definition: URITest.php:923
test_with_authority($uri)
test_init
Definition: URITest.php:556
const URI_COMPLETE_IPV4
Definition: URITest.php:11
test_alphadigit_start_host_3()
test_init
Definition: URITest.php:383
test_alphadigit_start_host_2()
test_init
Definition: URITest.php:374
test_with_authority_invalid_5()
test_with_authority
Definition: URITest.php:675
test_no_schema()
test_init
Definition: URITest.php:292
test_localhost()
test_init
Definition: URITest.php:94
test_with_schema_invalid_1()
test_with_schema
Definition: URITest.php:432
const URI_NO_QUERY_1
Definition: URITest.php:19
test_uri_invalid()
test_init
Definition: URITest.php:337
testGetParameters()
Definition: URITest.php:883
test_components($uri)
test_init
Definition: URITest.php:110
test_ipv4()
test_init
Definition: URITest.php:78
$url
test_with_port_invalid_2()
test_with_port
Definition: URITest.php:493
const URI_BASE
Definition: URITest.php:60
test_no_query()
test_init
Definition: URITest.php:183
const PATH_REALPCTENC
Definition: URITest.php:48
testToString()
Definition: URITest.php:874
test_authority_and_fragment()
test_init
Definition: URITest.php:231
const URI_AUTHORITY_PATH_FRAGMENT
Definition: URITest.php:27
test_wrong_authority_in_schema_2()
test_init
Definition: URITest.php:328
const URI_NO_AUTHORITY
Definition: URITest.php:35
const URI_AUTHORITY_AND_QUERY_1
Definition: URITest.php:22
test_alphadigit_start_host()
test_init
Definition: URITest.php:365
test_with_path_invalid_1()
test_with_path
Definition: URITest.php:747
test_with_schema_invalid_2()
test_with_schema
Definition: URITest.php:442
const URI_WRONG_AUTHORITY_2
Definition: URITest.php:40