scratch – Blame information for rev 126

Subversion Repositories:
Rev:
Rev Author Line No. Line
126 office 1 <?php
2 namespace Aura\Uri;
3  
4 use Aura\Uri\Url\Factory as UrlFactory;
5  
6 /**
7 * Test class for Url.
8 * Generated by PHPUnit on 2012-07-21 at 15:46:30.
9 */
10 class UrlTest extends \PHPUnit_Framework_TestCase
11 {
12 /**
13 * @var Url
14 */
15 protected $url;
16  
17 /**
18 * @var string Url spec
19 */
20 protected $spec = 'http://anonymous:guest@example.com/path/to/index.php/foo/bar.xml?baz=dib#anchor';
21  
22 /**
23 * @var PublicSuffixList Public Suffix List
24 */
25 protected $psl;
26  
27 /**
28 * Sets up the fixture, for example, opens a network connection.
29 * This method is called before a test is executed.
30 */
31 protected function setUp()
32 {
33 parent::setUp();
34 $file = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR
35 . 'data' . DIRECTORY_SEPARATOR
36 . 'public-suffix-list.php';
37 $this->psl = new PublicSuffixList(require $file);
38 $factory = new UrlFactory([], $this->psl);
39 $this->url = $factory->newInstance($this->spec);
40 }
41  
42 /**
43 * Tears down the fixture, for example, closes a network connection.
44 * This method is called after a test is executed.
45 */
46 protected function tearDown()
47 {
48 parent::tearDown();
49 }
50  
51 public function test__construct()
52 {
53 $url = new Url(
54 'http',
55 'username',
56 'password',
57 new Host(
58 $this->psl,
59 [
60 'subdomain' => null,
61 'registerableDomain' => 'example.com',
62 'publicSuffix' => 'com'
63 ]
64 ),
65 '80',
66 new Path(['foo', 'bar']),
67 new Query(['baz' => 'dib', 'zim' => 'gir']),
68 'fragment'
69 );
70  
71 $this->assertInstanceOf('Aura\Uri\Url', $url);
72 }
73  
74 /**
75 * @covers Aura\Uri\Url::__toString
76 */
77 public function test__toString()
78 {
79 $actual = $this->url->__toString();
80 $this->assertSame($this->spec, $actual);
81 }
82  
83 /**
84 * @covers Aura\Uri\Url::__get
85 */
86 public function test__get()
87 {
88 $expected = [
89 'scheme' => 'http',
90 'user' => 'anonymous',
91 'pass' => 'guest',
92 'host' => 'example.com',
93 'fragment' => 'anchor'
94 ];
95 $this->assertEquals($expected['scheme'], $this->url->scheme);
96 $this->assertEquals($expected['user'], $this->url->user);
97 $this->assertEquals($expected['pass'], $this->url->pass);
98 $this->assertEquals($expected['host'], $this->url->host);
99 $this->assertEquals($expected['fragment'], $this->url->fragment);
100 }
101  
102 /**
103 * @covers Aura\Uri\Url::get
104 */
105 public function testGet()
106 {
107 $actual = $this->url->get();
108 $expected = '/path/to/index.php/foo/bar.xml?baz=dib#anchor';
109 $this->assertSame($expected, $actual);
110 }
111  
112 /**
113 * @covers Aura\Uri\Url::getFull
114 */
115 public function testGetFull()
116 {
117 $actual = $this->url->getFull();
118 $this->assertSame($this->spec, $actual);
119 }
120  
121 /**
122 * @covers Aura\Uri\Url::getSchemeless
123 */
124 public function testGetSchemeless()
125 {
126 $schemeless = substr_replace($this->spec, '', 0, 5);
127 $actual = $this->url->getSchemeless();
128 $this->assertSame($schemeless, $actual);
129 }
130  
131 /**
132 * @covers Aura\Uri\Url::setScheme
133 */
134 public function testSetScheme()
135 {
136 $scheme = 'https';
137 $this->url->setScheme($scheme);
138 $this->assertSame($scheme, $this->url->scheme);
139 }
140  
141 /**
142 * @covers Aura\Uri\Url::setUser
143 */
144 public function testSetUser()
145 {
146 $guest = 'guest';
147 $this->url->setUser($guest);
148 $this->assertSame($guest, $this->url->user);
149 }
150  
151 /**
152 * @covers Aura\Uri\Url::setPass
153 */
154 public function testSetPass()
155 {
156 $password = 'password';
157 $this->url->setPass($password);
158 $this->assertSame($password, $this->url->pass);
159 }
160  
161 /**
162 * @covers Aura\Uri\Url::setHost
163 */
164 public function testSetHost()
165 {
166 $host = new Host($this->psl);
167 $this->url->setHost($host);
168 $this->assertSame($host, $this->url->host);
169 }
170  
171 /**
172 * @covers Aura\Uri\Url::setPort
173 */
174 public function testSetPort()
175 {
176 $port = '8000';
177 $this->url->setPort($port);
178 $this->assertSame($port, $this->url->port);
179 }
180  
181 /**
182 * @covers Aura\Uri\Url::setPath
183 */
184 public function testSetPath()
185 {
186 $path = new Path();
187 $this->url->setPath($path);
188 $this->assertSame($path, $this->url->path);
189 }
190  
191 /**
192 * @covers Aura\Uri\Url::setQuery
193 */
194 public function testSetQuery()
195 {
196 $query = new Query();
197 $this->url->setQuery($query);
198 $this->assertSame($query, $this->url->query);
199 }
200  
201 /**
202 * @covers Aura\Uri\Url::setFragment
203 */
204 public function testSetFragment()
205 {
206 $fragment = '#hello';
207 $this->url->setFragment($fragment);
208 $this->assertSame($fragment, $this->url->fragment);
209 }
210 }