1<?php
2
3namespace OAuthTest\Unit\Common\Http\Uri;
4
5use OAuth\Common\Http\Uri\Uri;
6
7class UriTest extends \PHPUnit_Framework_TestCase
8{
9    /**
10     * @covers OAuth\Common\Http\Uri\Uri::__construct
11     */
12    public function testConstructCorrectInterfaceWithoutUri()
13    {
14        $uri = new Uri();
15
16        $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri);
17    }
18
19    /**
20     * @covers OAuth\Common\Http\Uri\Uri::__construct
21     * @covers OAuth\Common\Http\Uri\Uri::parseUri
22     */
23    public function testConstructThrowsExceptionOnInvalidUri()
24    {
25        $this->setExpectedException('\\InvalidArgumentException');
26
27        // http://lxr.php.net/xref/PHP_5_4/ext/standard/tests/url/urls.inc#92
28        $uri = new Uri('http://@:/');
29    }
30
31    /**
32     * @covers OAuth\Common\Http\Uri\Uri::__construct
33     * @covers OAuth\Common\Http\Uri\Uri::parseUri
34     */
35    public function testConstructThrowsExceptionOnUriWithoutScheme()
36    {
37        $this->setExpectedException('\\InvalidArgumentException');
38
39        $uri = new Uri('www.pieterhordijk.com');
40    }
41
42    /**
43     * @covers OAuth\Common\Http\Uri\Uri::__construct
44     * @covers OAuth\Common\Http\Uri\Uri::parseUri
45     * @covers OAuth\Common\Http\Uri\Uri::getScheme
46     */
47    public function testGetScheme()
48    {
49        $uri = new Uri('http://example.com');
50
51        $this->assertSame('http', $uri->getScheme());
52    }
53
54    /**
55     * @covers OAuth\Common\Http\Uri\Uri::__construct
56     * @covers OAuth\Common\Http\Uri\Uri::parseUri
57     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
58     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
59     * @covers OAuth\Common\Http\Uri\Uri::getUserInfo
60     */
61    public function testGetUserInfo()
62    {
63        $uri = new Uri('http://peehaa@example.com');
64
65        $this->assertSame('peehaa', $uri->getUserInfo());
66    }
67
68    /**
69     * @covers OAuth\Common\Http\Uri\Uri::__construct
70     * @covers OAuth\Common\Http\Uri\Uri::parseUri
71     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
72     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
73     * @covers OAuth\Common\Http\Uri\Uri::getUserInfo
74     */
75    public function testGetUserInfoWithPass()
76    {
77        $uri = new Uri('http://peehaa:pass@example.com');
78
79        $this->assertSame('peehaa:********', $uri->getUserInfo());
80    }
81
82    /**
83     * @covers OAuth\Common\Http\Uri\Uri::__construct
84     * @covers OAuth\Common\Http\Uri\Uri::parseUri
85     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
86     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
87     * @covers OAuth\Common\Http\Uri\Uri::getRawUserInfo
88     */
89    public function testGetRawUserInfo()
90    {
91        $uri = new Uri('http://peehaa@example.com');
92
93        $this->assertSame('peehaa', $uri->getRawUserInfo());
94    }
95
96    /**
97     * @covers OAuth\Common\Http\Uri\Uri::__construct
98     * @covers OAuth\Common\Http\Uri\Uri::parseUri
99     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
100     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
101     * @covers OAuth\Common\Http\Uri\Uri::getRawUserInfo
102     */
103    public function testGetRawUserInfoWithPass()
104    {
105        $uri = new Uri('http://peehaa:pass@example.com');
106
107        $this->assertSame('peehaa:pass', $uri->getRawUserInfo());
108    }
109
110    /**
111     * @covers OAuth\Common\Http\Uri\Uri::__construct
112     * @covers OAuth\Common\Http\Uri\Uri::parseUri
113     * @covers OAuth\Common\Http\Uri\Uri::getHost
114     */
115    public function testGetHost()
116    {
117        $uri = new Uri('http://example.com');
118
119        $this->assertSame('example.com', $uri->getHost());
120    }
121
122    /**
123     * @covers OAuth\Common\Http\Uri\Uri::__construct
124     * @covers OAuth\Common\Http\Uri\Uri::parseUri
125     * @covers OAuth\Common\Http\Uri\Uri::getPort
126     */
127    public function testGetPortImplicitHttp()
128    {
129        $uri = new Uri('http://example.com');
130
131        $this->assertSame(80, $uri->getPort());
132    }
133
134    /**
135     * @covers OAuth\Common\Http\Uri\Uri::__construct
136     * @covers OAuth\Common\Http\Uri\Uri::parseUri
137     * @covers OAuth\Common\Http\Uri\Uri::getPort
138     */
139    public function testGetPortImplicitHttps()
140    {
141        $uri = new Uri('https://example.com');
142
143        $this->assertSame(443, $uri->getPort());
144    }
145
146    /**
147     * @covers OAuth\Common\Http\Uri\Uri::__construct
148     * @covers OAuth\Common\Http\Uri\Uri::parseUri
149     * @covers OAuth\Common\Http\Uri\Uri::getPort
150     */
151    public function testGetPortExplicit()
152    {
153        $uri = new Uri('http://example.com:21');
154
155        $this->assertSame(21, $uri->getPort());
156    }
157
158    /**
159     * @covers OAuth\Common\Http\Uri\Uri::__construct
160     * @covers OAuth\Common\Http\Uri\Uri::parseUri
161     * @covers OAuth\Common\Http\Uri\Uri::getPath
162     */
163    public function testGetPathNotSupplied()
164    {
165        $uri = new Uri('http://example.com');
166
167        $this->assertSame('/', $uri->getPath());
168    }
169
170    /**
171     * @covers OAuth\Common\Http\Uri\Uri::__construct
172     * @covers OAuth\Common\Http\Uri\Uri::parseUri
173     * @covers OAuth\Common\Http\Uri\Uri::getPath
174     */
175    public function testGetPathSlash()
176    {
177        $uri = new Uri('http://example.com/');
178
179        $this->assertSame('/', $uri->getPath());
180    }
181
182    /**
183     * @covers OAuth\Common\Http\Uri\Uri::__construct
184     * @covers OAuth\Common\Http\Uri\Uri::parseUri
185     * @covers OAuth\Common\Http\Uri\Uri::getPath
186     */
187    public function testGetPath()
188    {
189        $uri = new Uri('http://example.com/foo');
190
191        $this->assertSame('/foo', $uri->getPath());
192    }
193
194    /**
195     * @covers OAuth\Common\Http\Uri\Uri::__construct
196     * @covers OAuth\Common\Http\Uri\Uri::parseUri
197     * @covers OAuth\Common\Http\Uri\Uri::getQuery
198     */
199    public function testGetQueryWithParams()
200    {
201        $uri = new Uri('http://example.com?param1=first&param2=second');
202
203        $this->assertSame('param1=first&param2=second', $uri->getQuery());
204    }
205
206    /**
207     * @covers OAuth\Common\Http\Uri\Uri::__construct
208     * @covers OAuth\Common\Http\Uri\Uri::parseUri
209     * @covers OAuth\Common\Http\Uri\Uri::getQuery
210     */
211    public function testGetQueryWithoutParams()
212    {
213        $uri = new Uri('http://example.com');
214
215        $this->assertSame('', $uri->getQuery());
216    }
217
218    /**
219     * @covers OAuth\Common\Http\Uri\Uri::__construct
220     * @covers OAuth\Common\Http\Uri\Uri::parseUri
221     * @covers OAuth\Common\Http\Uri\Uri::getFragment
222     */
223    public function testGetFragmentExists()
224    {
225        $uri = new Uri('http://example.com#foo');
226
227        $this->assertSame('foo', $uri->getFragment());
228    }
229
230    /**
231     * @covers OAuth\Common\Http\Uri\Uri::__construct
232     * @covers OAuth\Common\Http\Uri\Uri::parseUri
233     * @covers OAuth\Common\Http\Uri\Uri::getFragment
234     */
235    public function testGetFragmentNotExists()
236    {
237        $uri = new Uri('http://example.com');
238
239        $this->assertSame('', $uri->getFragment());
240    }
241
242    /**
243     * @covers OAuth\Common\Http\Uri\Uri::__construct
244     * @covers OAuth\Common\Http\Uri\Uri::parseUri
245     * @covers OAuth\Common\Http\Uri\Uri::getAuthority
246     */
247    public function testGetAuthorityWithoutUserInfo()
248    {
249        $uri = new Uri('http://example.com');
250
251        $this->assertSame('example.com', $uri->getAuthority());
252    }
253
254    /**
255     * @covers OAuth\Common\Http\Uri\Uri::__construct
256     * @covers OAuth\Common\Http\Uri\Uri::parseUri
257     * @covers OAuth\Common\Http\Uri\Uri::getAuthority
258     */
259    public function testGetAuthorityWithoutUserInfoWithExplicitPort()
260    {
261        $uri = new Uri('http://example.com:21');
262
263        $this->assertSame('example.com:21', $uri->getAuthority());
264    }
265
266    /**
267     * @covers OAuth\Common\Http\Uri\Uri::__construct
268     * @covers OAuth\Common\Http\Uri\Uri::parseUri
269     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
270     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
271     * @covers OAuth\Common\Http\Uri\Uri::getAuthority
272     */
273    public function testGetAuthorityWithUsernameWithExplicitPort()
274    {
275        $uri = new Uri('http://peehaa@example.com:21');
276
277        $this->assertSame('peehaa@example.com:21', $uri->getAuthority());
278    }
279
280    /**
281     * @covers OAuth\Common\Http\Uri\Uri::__construct
282     * @covers OAuth\Common\Http\Uri\Uri::parseUri
283     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
284     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
285     * @covers OAuth\Common\Http\Uri\Uri::getAuthority
286     */
287    public function testGetAuthorityWithUsernameAndPassWithExplicitPort()
288    {
289        $uri = new Uri('http://peehaa:pass@example.com:21');
290
291        $this->assertSame('peehaa:********@example.com:21', $uri->getAuthority());
292    }
293
294    /**
295     * @covers OAuth\Common\Http\Uri\Uri::__construct
296     * @covers OAuth\Common\Http\Uri\Uri::parseUri
297     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
298     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
299     * @covers OAuth\Common\Http\Uri\Uri::getAuthority
300     */
301    public function testGetAuthorityWithUsernameAndPassWithoutExplicitPort()
302    {
303        $uri = new Uri('http://peehaa:pass@example.com');
304
305        $this->assertSame('peehaa:********@example.com', $uri->getAuthority());
306    }
307
308    /**
309     * @covers OAuth\Common\Http\Uri\Uri::__construct
310     * @covers OAuth\Common\Http\Uri\Uri::parseUri
311     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
312     */
313    public function testGetRawAuthorityWithoutUserInfo()
314    {
315        $uri = new Uri('http://example.com');
316
317        $this->assertSame('example.com', $uri->getRawAuthority());
318    }
319
320    /**
321     * @covers OAuth\Common\Http\Uri\Uri::__construct
322     * @covers OAuth\Common\Http\Uri\Uri::parseUri
323     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
324     */
325    public function testGetRawAuthorityWithoutUserInfoWithExplicitPort()
326    {
327        $uri = new Uri('http://example.com:21');
328
329        $this->assertSame('example.com:21', $uri->getRawAuthority());
330    }
331
332    /**
333     * @covers OAuth\Common\Http\Uri\Uri::__construct
334     * @covers OAuth\Common\Http\Uri\Uri::parseUri
335     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
336     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
337     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
338     */
339    public function testGetRawAuthorityWithUsernameWithExplicitPort()
340    {
341        $uri = new Uri('http://peehaa@example.com:21');
342
343        $this->assertSame('peehaa@example.com:21', $uri->getRawAuthority());
344    }
345
346    /**
347     * @covers OAuth\Common\Http\Uri\Uri::__construct
348     * @covers OAuth\Common\Http\Uri\Uri::parseUri
349     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
350     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
351     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
352     */
353    public function testGetRawAuthorityWithUsernameAndPassWithExplicitPort()
354    {
355        $uri = new Uri('http://peehaa:pass@example.com:21');
356
357        $this->assertSame('peehaa:pass@example.com:21', $uri->getRawAuthority());
358    }
359
360    /**
361     * @covers OAuth\Common\Http\Uri\Uri::__construct
362     * @covers OAuth\Common\Http\Uri\Uri::parseUri
363     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
364     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
365     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
366     */
367    public function testGetRawAuthorityWithUsernameAndPassWithoutExplicitPort()
368    {
369        $uri = new Uri('http://peehaa:pass@example.com');
370
371        $this->assertSame('peehaa:pass@example.com', $uri->getRawAuthority());
372    }
373
374    /**
375     * @covers OAuth\Common\Http\Uri\Uri::__construct
376     * @covers OAuth\Common\Http\Uri\Uri::parseUri
377     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
378     */
379    public function testGetAbsoluteUriBare()
380    {
381        $uri = new Uri('http://example.com');
382
383        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
384    }
385
386    /**
387     * @covers OAuth\Common\Http\Uri\Uri::__construct
388     * @covers OAuth\Common\Http\Uri\Uri::parseUri
389     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
390     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
391     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
392     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
393     */
394    public function testGetAbsoluteUriWithAuthority()
395    {
396        $uri = new Uri('http://peehaa:pass@example.com');
397
398        $this->assertSame('http://peehaa:pass@example.com', $uri->getAbsoluteUri());
399    }
400
401    /**
402     * @covers OAuth\Common\Http\Uri\Uri::__construct
403     * @covers OAuth\Common\Http\Uri\Uri::parseUri
404     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
405     */
406    public function testGetAbsoluteUriWithPath()
407    {
408        $uri = new Uri('http://example.com/foo');
409
410        $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri());
411    }
412
413    /**
414     * @covers OAuth\Common\Http\Uri\Uri::__construct
415     * @covers OAuth\Common\Http\Uri\Uri::parseUri
416     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
417     */
418    public function testGetAbsoluteUriWithoutPath()
419    {
420        $uri = new Uri('http://example.com');
421
422        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
423    }
424
425    /**
426     * @covers OAuth\Common\Http\Uri\Uri::__construct
427     * @covers OAuth\Common\Http\Uri\Uri::parseUri
428     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
429     */
430    public function testGetAbsoluteUriWithoutPathExplicitTrailingSlash()
431    {
432        $uri = new Uri('http://example.com/');
433
434        $this->assertSame('http://example.com/', $uri->getAbsoluteUri());
435    }
436
437    /**
438     * @covers OAuth\Common\Http\Uri\Uri::__construct
439     * @covers OAuth\Common\Http\Uri\Uri::parseUri
440     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
441     */
442    public function testGetAbsoluteUriWithQuery()
443    {
444        $uri = new Uri('http://example.com?param1=value1');
445
446        $this->assertSame('http://example.com?param1=value1', $uri->getAbsoluteUri());
447    }
448
449    /**
450     * @covers OAuth\Common\Http\Uri\Uri::__construct
451     * @covers OAuth\Common\Http\Uri\Uri::parseUri
452     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
453     */
454    public function testGetAbsoluteUriWithFragment()
455    {
456        $uri = new Uri('http://example.com#foo');
457
458        $this->assertSame('http://example.com#foo', $uri->getAbsoluteUri());
459    }
460
461    /**
462     * @covers OAuth\Common\Http\Uri\Uri::__construct
463     * @covers OAuth\Common\Http\Uri\Uri::parseUri
464     * @covers OAuth\Common\Http\Uri\Uri::getRelativeUri
465     */
466    public function testGetRelativeUriWithoutPath()
467    {
468        $uri = new Uri('http://example.com');
469
470        $this->assertSame('', $uri->getRelativeUri());
471    }
472
473    /**
474     * @covers OAuth\Common\Http\Uri\Uri::__construct
475     * @covers OAuth\Common\Http\Uri\Uri::parseUri
476     * @covers OAuth\Common\Http\Uri\Uri::getRelativeUri
477     */
478    public function testGetRelativeUriWithPath()
479    {
480        $uri = new Uri('http://example.com/foo');
481
482        $this->assertSame('/foo', $uri->getRelativeUri());
483    }
484
485    /**
486     * @covers OAuth\Common\Http\Uri\Uri::__construct
487     * @covers OAuth\Common\Http\Uri\Uri::parseUri
488     * @covers OAuth\Common\Http\Uri\Uri::getRelativeUri
489     */
490    public function testGetRelativeUriWithExplicitTrailingSlash()
491    {
492        $uri = new Uri('http://example.com/');
493
494        $this->assertSame('/', $uri->getRelativeUri());
495    }
496
497    /**
498     * @covers OAuth\Common\Http\Uri\Uri::__construct
499     * @covers OAuth\Common\Http\Uri\Uri::parseUri
500     * @covers OAuth\Common\Http\Uri\Uri::__toString
501     */
502    public function testToStringBare()
503    {
504        $uri = new Uri('http://example.com');
505
506        $this->assertSame('http://example.com', (string) $uri);
507    }
508
509    /**
510     * @covers OAuth\Common\Http\Uri\Uri::__construct
511     * @covers OAuth\Common\Http\Uri\Uri::parseUri
512     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
513     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
514     * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority
515     * @covers OAuth\Common\Http\Uri\Uri::__toString
516     */
517    public function testToStringWithAuthority()
518    {
519        $uri = new Uri('http://peehaa:pass@example.com');
520
521        $this->assertSame('http://peehaa:********@example.com', (string) $uri);
522    }
523
524    /**
525     * @covers OAuth\Common\Http\Uri\Uri::__construct
526     * @covers OAuth\Common\Http\Uri\Uri::parseUri
527     * @covers OAuth\Common\Http\Uri\Uri::__toString
528     */
529    public function testToStringWithPath()
530    {
531        $uri = new Uri('http://example.com/foo');
532
533        $this->assertSame('http://example.com/foo', (string) $uri);
534    }
535
536    /**
537     * @covers OAuth\Common\Http\Uri\Uri::__construct
538     * @covers OAuth\Common\Http\Uri\Uri::parseUri
539     * @covers OAuth\Common\Http\Uri\Uri::__toString
540     */
541    public function testToStringWithoutPath()
542    {
543        $uri = new Uri('http://example.com');
544
545        $this->assertSame('http://example.com', (string) $uri);
546    }
547
548    /**
549     * @covers OAuth\Common\Http\Uri\Uri::__construct
550     * @covers OAuth\Common\Http\Uri\Uri::parseUri
551     * @covers OAuth\Common\Http\Uri\Uri::__toString
552     */
553    public function testToStringWithoutPathExplicitTrailingSlash()
554    {
555        $uri = new Uri('http://example.com/');
556
557        $this->assertSame('http://example.com/', (string) $uri);
558    }
559
560    /**
561     * @covers OAuth\Common\Http\Uri\Uri::__construct
562     * @covers OAuth\Common\Http\Uri\Uri::parseUri
563     * @covers OAuth\Common\Http\Uri\Uri::__toString
564     */
565    public function testToStringWithQuery()
566    {
567        $uri = new Uri('http://example.com?param1=value1');
568
569        $this->assertSame('http://example.com?param1=value1', (string) $uri);
570    }
571
572    /**
573     * @covers OAuth\Common\Http\Uri\Uri::__construct
574     * @covers OAuth\Common\Http\Uri\Uri::parseUri
575     * @covers OAuth\Common\Http\Uri\Uri::__toString
576     */
577    public function testToStringWithFragment()
578    {
579        $uri = new Uri('http://example.com#foo');
580
581        $this->assertSame('http://example.com#foo', (string) $uri);
582    }
583
584    /**
585     * @covers OAuth\Common\Http\Uri\Uri::__construct
586     * @covers OAuth\Common\Http\Uri\Uri::parseUri
587     * @covers OAuth\Common\Http\Uri\Uri::setPath
588     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
589     */
590    public function testSetPathEmpty()
591    {
592        $uri = new Uri('http://example.com');
593        $uri->setPath('');
594
595        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
596    }
597
598    /**
599     * @covers OAuth\Common\Http\Uri\Uri::__construct
600     * @covers OAuth\Common\Http\Uri\Uri::parseUri
601     * @covers OAuth\Common\Http\Uri\Uri::setPath
602     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
603     */
604    public function testSetPathWithPath()
605    {
606        $uri = new Uri('http://example.com');
607        $uri->setPath('/foo');
608
609        $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri());
610    }
611
612    /**
613     * @covers OAuth\Common\Http\Uri\Uri::__construct
614     * @covers OAuth\Common\Http\Uri\Uri::parseUri
615     * @covers OAuth\Common\Http\Uri\Uri::setPath
616     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
617     */
618    public function testSetPathWithOnlySlash()
619    {
620        $uri = new Uri('http://example.com');
621        $uri->setPath('/');
622
623        $this->assertSame('http://example.com/', $uri->getAbsoluteUri());
624    }
625
626    /**
627     * @covers OAuth\Common\Http\Uri\Uri::__construct
628     * @covers OAuth\Common\Http\Uri\Uri::parseUri
629     * @covers OAuth\Common\Http\Uri\Uri::setQuery
630     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
631     */
632    public function testSetQueryEmpty()
633    {
634        $uri = new Uri('http://example.com');
635        $uri->setQuery('');
636
637        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
638    }
639
640    /**
641     * @covers OAuth\Common\Http\Uri\Uri::__construct
642     * @covers OAuth\Common\Http\Uri\Uri::parseUri
643     * @covers OAuth\Common\Http\Uri\Uri::setQuery
644     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
645     */
646    public function testSetQueryFilled()
647    {
648        $uri = new Uri('http://example.com');
649        $uri->setQuery('param1=value1&param2=value2');
650
651        $this->assertSame('http://example.com?param1=value1&param2=value2', $uri->getAbsoluteUri());
652    }
653
654    /**
655     * @covers OAuth\Common\Http\Uri\Uri::__construct
656     * @covers OAuth\Common\Http\Uri\Uri::parseUri
657     * @covers OAuth\Common\Http\Uri\Uri::addToQuery
658     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
659     */
660    public function testAddToQueryAppend()
661    {
662        $uri = new Uri('http://example.com?param1=value1');
663        $uri->addToQuery('param2', 'value2');
664
665        $this->assertSame('http://example.com?param1=value1&param2=value2', $uri->getAbsoluteUri());
666    }
667
668    /**
669     * @covers OAuth\Common\Http\Uri\Uri::__construct
670     * @covers OAuth\Common\Http\Uri\Uri::parseUri
671     * @covers OAuth\Common\Http\Uri\Uri::addToQuery
672     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
673     */
674    public function testAddToQueryCreate()
675    {
676        $uri = new Uri('http://example.com');
677        $uri->addToQuery('param1', 'value1');
678
679        $this->assertSame('http://example.com?param1=value1', $uri->getAbsoluteUri());
680    }
681
682    /**
683     * @covers OAuth\Common\Http\Uri\Uri::__construct
684     * @covers OAuth\Common\Http\Uri\Uri::parseUri
685     * @covers OAuth\Common\Http\Uri\Uri::setFragment
686     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
687     */
688    public function testSetFragmentEmpty()
689    {
690        $uri = new Uri('http://example.com');
691        $uri->setFragment('');
692
693        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
694    }
695
696    /**
697     * @covers OAuth\Common\Http\Uri\Uri::__construct
698     * @covers OAuth\Common\Http\Uri\Uri::parseUri
699     * @covers OAuth\Common\Http\Uri\Uri::setFragment
700     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
701     */
702    public function testSetFragmentWithData()
703    {
704        $uri = new Uri('http://example.com');
705        $uri->setFragment('foo');
706
707        $this->assertSame('http://example.com#foo', $uri->getAbsoluteUri());
708    }
709
710    /**
711     * @covers OAuth\Common\Http\Uri\Uri::__construct
712     * @covers OAuth\Common\Http\Uri\Uri::parseUri
713     * @covers OAuth\Common\Http\Uri\Uri::setScheme
714     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
715     */
716    public function testSetSchemeWithEmpty()
717    {
718        $uri = new Uri('http://example.com');
719        $uri->setScheme('');
720
721        $this->assertSame('://example.com', $uri->getAbsoluteUri());
722    }
723
724    /**
725     * @covers OAuth\Common\Http\Uri\Uri::__construct
726     * @covers OAuth\Common\Http\Uri\Uri::parseUri
727     * @covers OAuth\Common\Http\Uri\Uri::setScheme
728     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
729     */
730    public function testSetSchemeWithData()
731    {
732        $uri = new Uri('http://example.com');
733        $uri->setScheme('foo');
734
735        $this->assertSame('foo://example.com', $uri->getAbsoluteUri());
736    }
737
738    /**
739     * @covers OAuth\Common\Http\Uri\Uri::__construct
740     * @covers OAuth\Common\Http\Uri\Uri::parseUri
741     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
742     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
743     */
744    public function testSetUserInfoEmpty()
745    {
746        $uri = new Uri('http://example.com');
747        $uri->setUserInfo('');
748
749        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
750    }
751
752    /**
753     * @covers OAuth\Common\Http\Uri\Uri::__construct
754     * @covers OAuth\Common\Http\Uri\Uri::parseUri
755     * @covers OAuth\Common\Http\Uri\Uri::setUserInfo
756     * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo
757     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
758     */
759    public function testSetUserInfoWithData()
760    {
761        $uri = new Uri('http://example.com');
762        $uri->setUserInfo('foo:bar');
763
764        $this->assertSame('http://foo:bar@example.com', $uri->getAbsoluteUri());
765    }
766
767    /**
768     * @covers OAuth\Common\Http\Uri\Uri::__construct
769     * @covers OAuth\Common\Http\Uri\Uri::parseUri
770     * @covers OAuth\Common\Http\Uri\Uri::setPort
771     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
772     */
773    public function testSetPortCustom()
774    {
775        $uri = new Uri('http://example.com');
776        $uri->setPort('21');
777
778        $this->assertSame('http://example.com:21', $uri->getAbsoluteUri());
779    }
780
781    /**
782     * @covers OAuth\Common\Http\Uri\Uri::__construct
783     * @covers OAuth\Common\Http\Uri\Uri::parseUri
784     * @covers OAuth\Common\Http\Uri\Uri::setPort
785     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
786     */
787    public function testSetPortHttpImplicit()
788    {
789        $uri = new Uri('http://example.com');
790        $uri->setPort(80);
791
792        $this->assertSame('http://example.com', $uri->getAbsoluteUri());
793    }
794
795    /**
796     * @covers OAuth\Common\Http\Uri\Uri::__construct
797     * @covers OAuth\Common\Http\Uri\Uri::parseUri
798     * @covers OAuth\Common\Http\Uri\Uri::setPort
799     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
800     */
801    public function testSetPortHttpsImplicit()
802    {
803        $uri = new Uri('https://example.com');
804        $uri->setPort(443);
805
806        $this->assertSame('https://example.com', $uri->getAbsoluteUri());
807    }
808
809    /**
810     * @covers OAuth\Common\Http\Uri\Uri::__construct
811     * @covers OAuth\Common\Http\Uri\Uri::parseUri
812     * @covers OAuth\Common\Http\Uri\Uri::setPort
813     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
814     */
815    public function testSetPortHttpExplicit()
816    {
817        $uri = new Uri('http://example.com');
818        $uri->setPort(443);
819
820        $this->assertSame('http://example.com:443', $uri->getAbsoluteUri());
821    }
822
823    /**
824     * @covers OAuth\Common\Http\Uri\Uri::__construct
825     * @covers OAuth\Common\Http\Uri\Uri::parseUri
826     * @covers OAuth\Common\Http\Uri\Uri::setPort
827     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
828     */
829    public function testSetPortHttpsExplicit()
830    {
831        $uri = new Uri('https://example.com');
832        $uri->setPort(80);
833
834        $this->assertSame('https://example.com:80', $uri->getAbsoluteUri());
835    }
836
837    /**
838     * @covers OAuth\Common\Http\Uri\Uri::__construct
839     * @covers OAuth\Common\Http\Uri\Uri::parseUri
840     * @covers OAuth\Common\Http\Uri\Uri::setHost
841     * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri
842     */
843    public function testSetHost()
844    {
845        $uri = new Uri('http://example.com');
846        $uri->setHost('pieterhordijk.com');
847
848        $this->assertSame('http://pieterhordijk.com', $uri->getAbsoluteUri());
849    }
850
851    /**
852     * @covers OAuth\Common\Http\Uri\Uri::__construct
853     * @covers OAuth\Common\Http\Uri\Uri::parseUri
854     * @covers OAuth\Common\Http\Uri\Uri::hasExplicitTrailingHostSlash
855     */
856    public function testHasExplicitTrailingHostSlashTrue()
857    {
858        $uri = new Uri('http://example.com/');
859
860        $this->assertTrue($uri->hasExplicitTrailingHostSlash());
861    }
862
863    /**
864     * @covers OAuth\Common\Http\Uri\Uri::__construct
865     * @covers OAuth\Common\Http\Uri\Uri::parseUri
866     * @covers OAuth\Common\Http\Uri\Uri::hasExplicitTrailingHostSlash
867     */
868    public function testHasExplicitTrailingHostSlashFalse()
869    {
870        $uri = new Uri('http://example.com/foo');
871
872        $this->assertFalse($uri->hasExplicitTrailingHostSlash());
873    }
874
875    /**
876     * @covers OAuth\Common\Http\Uri\Uri::__construct
877     * @covers OAuth\Common\Http\Uri\Uri::parseUri
878     * @covers OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified
879     */
880    public function testHasExplicitPortSpecifiedTrue()
881    {
882        $uri = new Uri('http://example.com:8080');
883
884        $this->assertTrue($uri->hasExplicitPortSpecified());
885    }
886
887    /**
888     * @covers OAuth\Common\Http\Uri\Uri::__construct
889     * @covers OAuth\Common\Http\Uri\Uri::parseUri
890     * @covers OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified
891     */
892    public function testHasExplicitPortSpecifiedFalse()
893    {
894        $uri = new Uri('http://example.com');
895
896        $this->assertFalse($uri->hasExplicitPortSpecified());
897    }
898}
899