scratch – Blame information for rev 126
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
126 | office | 1 | <?php |
2 | namespace Aura\Uri\Url; |
||
3 | |||
4 | use Aura\Uri\PublicSuffixList; |
||
5 | |||
6 | /** |
||
7 | * Test class for Factory. |
||
8 | * Generated by PHPUnit on 2012-07-21 at 17:13:55. |
||
9 | */ |
||
10 | class FactoryTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | protected function newFactory($server = []) |
||
13 | { |
||
14 | $psl = new PublicSuffixList([]); |
||
15 | return new Factory($server, $psl); |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * @covers Aura\Uri\Url\Factory::newInstance |
||
20 | */ |
||
21 | public function testNewInstance() |
||
22 | { |
||
23 | $factory = $this->newFactory([]); |
||
24 | $spec = 'http://anonymous:guest@example.com/path/to/index.php/foo/bar.xml?baz=dib#anchor'; |
||
25 | $url = $factory->newInstance($spec); |
||
26 | $this->assertTrue($url instanceof \Aura\Uri\Url); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @covers Aura\Uri\Url\Factory::newCurrent |
||
31 | */ |
||
32 | public function testNewCurrent() |
||
33 | { |
||
34 | $factory = $this->newFactory([ |
||
35 | 'HTTP_HOST' => 'example.com', |
||
36 | 'REQUEST_URI' => '/path/to/index.php/foo/bar.xml?baz=dib', |
||
37 | ]); |
||
38 | |||
39 | $url = $factory->newCurrent(); |
||
40 | $actual = $url->__toString(); |
||
41 | $expect = 'http://example.com/path/to/index.php/foo/bar.xml?baz=dib'; |
||
42 | $this->assertSame($expect, $actual); |
||
43 | } |
||
44 | |||
45 | public function testNewCurrent_https() |
||
46 | { |
||
47 | $factory = $this->newFactory([ |
||
48 | 'HTTPS' => 'on', |
||
49 | 'HTTP_HOST' => 'example.com', |
||
50 | 'REQUEST_URI' => '/path/to/index.php/foo/bar.xml?baz=dib', |
||
51 | ]); |
||
52 | |||
53 | $url = $factory->newCurrent(); |
||
54 | $actual = $url->__toString(); |
||
55 | $expect = 'https://example.com/path/to/index.php/foo/bar.xml?baz=dib'; |
||
56 | $this->assertSame($expect, $actual); |
||
57 | } |
||
58 | |||
59 | public function testNewCurrent_ssl() |
||
60 | { |
||
61 | $factory = $this->newFactory([ |
||
62 | 'SERVER_PORT' => '443', |
||
63 | 'HTTP_HOST' => 'example.com', |
||
64 | 'REQUEST_URI' => '/path/to/index.php/foo/bar.xml?baz=dib', |
||
65 | ]); |
||
66 | |||
67 | $url = $factory->newCurrent(); |
||
68 | $actual = $url->__toString(); |
||
69 | $expect = 'https://example.com/path/to/index.php/foo/bar.xml?baz=dib'; |
||
70 | $this->assertSame($expect, $actual); |
||
71 | } |
||
72 | |||
73 | public function testNewCurrent_noHttpHost() |
||
74 | { |
||
75 | $factory = $this->newFactory([ |
||
76 | 'REQUEST_URI' => '/path/to/index.php/foo/bar.xml?baz=dib', |
||
77 | ]); |
||
78 | |||
79 | $url = $factory->newCurrent(); |
||
80 | $actual = $url->__toString(); |
||
81 | $expect = ''; |
||
82 | $this->assertSame($expect, $actual); |
||
83 | } |
||
84 | |||
85 | public function testNewCurrent_noRequestUri() |
||
86 | { |
||
87 | $factory = $this->newFactory([ |
||
88 | 'HTTP_HOST' => 'example.com', |
||
89 | ]); |
||
90 | |||
91 | $url = $factory->newCurrent(); |
||
92 | $actual = $url->__toString(); |
||
93 | $expect = 'http://example.com'; |
||
94 | $this->assertSame($expect, $actual); |
||
95 | } |
||
96 | |||
97 | public function testIssue9() |
||
98 | { |
||
99 | $factory = $this->newFactory([ |
||
100 | 'HTTP_HOST' => 'example.com', |
||
101 | ]); |
||
102 | $string = 'http://localhost:8000/site/foo/bar'; |
||
103 | $url = $factory->newInstance($string); |
||
104 | $this->assertSame(array('site', 'foo', 'bar'), $url->path->getArrayCopy()); |
||
105 | } |
||
106 | |||
107 | public function testNewInstance_noScheme() |
||
108 | { |
||
109 | $factory = $this->newFactory([]); |
||
110 | $string = 'example.com'; |
||
111 | $url = $factory->newInstance($string); |
||
112 | $actual = $url->__toString(); |
||
113 | $expect = 'http://example.com'; |
||
114 | $this->assertSame($expect, $actual); |
||
115 | } |
||
116 | |||
117 | public function testNewInstance_schemeless() |
||
118 | { |
||
119 | $factory = $this->newFactory([]); |
||
120 | $string = '//example.com'; |
||
121 | $url = $factory->newInstance($string); |
||
122 | $actual = $url->__toString(); |
||
123 | $expect = 'http://example.com'; |
||
124 | $this->assertSame($expect, $actual); |
||
125 | } |
||
126 | |||
127 | public function testNewInstance_ftpUrl() |
||
128 | { |
||
129 | $factory = $this->newFactory([]); |
||
130 | $string = 'ftp://ftp.example.com'; |
||
131 | $url = $factory->newInstance($string); |
||
132 | $actual = $url->__toString(); |
||
133 | $this->assertSame($string, $actual); |
||
134 | } |
||
135 | } |