1 | <?php |
||
58 | class UrlTest extends AbstractTest |
||
59 | { |
||
60 | /** |
||
61 | * Example query fragment |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | const QUERY_FRAGMENT = '?param=value#fragment'; |
||
66 | /** |
||
67 | * Repository URL |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | const REPOSITORY_URL = '/repo'; |
||
72 | /** |
||
73 | * Example path |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | const PATH = '/2015/10/01/36704.event/36704-1'; |
||
78 | /** |
||
79 | * Example URL |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | const URL = self::REPOSITORY_URL . self::PATH . self::QUERY_FRAGMENT; |
||
84 | /** |
||
85 | * Example remote repository URL |
||
86 | * |
||
87 | * @var string |
||
88 | */ |
||
89 | const REMOTE_REPOSITORY_URL = 'http://apparat:[email protected]:80'; |
||
90 | /** |
||
91 | * Example remote URL |
||
92 | * |
||
93 | * @var string |
||
94 | */ |
||
95 | const REMOTE_URL = self::REMOTE_REPOSITORY_URL . self::PATH . self::QUERY_FRAGMENT; |
||
96 | /** |
||
97 | * Example apparat URL |
||
98 | * |
||
99 | * @var string |
||
100 | */ |
||
101 | const APPARAT_URL = 'aprts://apparat:[email protected]:80' . self::PATH . self::QUERY_FRAGMENT; |
||
102 | |||
103 | /** |
||
104 | * Test disabling of repository auto-connection |
||
105 | */ |
||
106 | public function testUseAutoconnect() |
||
107 | { |
||
108 | $this->assertFalse(Kernel::create(Service::class)->useAutoConnect(false)); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Test an URL |
||
113 | * |
||
114 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
115 | * @expectedExceptionCode 1451515385 |
||
116 | */ |
||
117 | public function testInvalidRemoteUrl() |
||
118 | { |
||
119 | new ObjectUrl(self::REMOTE_URL); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Test an URL |
||
124 | */ |
||
125 | public function testRemoteUrl() |
||
126 | { |
||
127 | $url = new ObjectUrl(self::REMOTE_URL, true); |
||
128 | $this->assertInstanceOf(ObjectUrl::class, $url); |
||
129 | $this->assertEquals(self::REMOTE_URL, strval($url)); |
||
130 | $this->assertEquals('http', $url->getScheme()); |
||
131 | $this->assertEquals('apparat', $url->getUser()); |
||
132 | $this->assertEquals('tools', $url->getPassword()); |
||
133 | $this->assertEquals('apparat.tools', $url->getHost()); |
||
134 | $this->assertEquals(80, $url->getPort()); |
||
135 | $this->assertEquals('', $url->getPath()); |
||
136 | $this->assertEquals(['param' => 'value'], $url->getQuery()); |
||
137 | $this->assertEquals('fragment', $url->getFragment()); |
||
138 | $this->assertInstanceOf(\DateTimeImmutable::class, $url->getCreationDate()); |
||
139 | $this->assertEquals('2015-10-01', $url->getCreationDate()->format('Y-m-d')); |
||
140 | $this->assertInstanceOf(Id::class, $url->getId()); |
||
141 | $this->assertEquals(new Id(36704), $url->getId()); |
||
142 | $this->assertInstanceOf(Type::class, $url->getType()); |
||
143 | $this->assertEquals(new Type('event'), $url->getType()); |
||
144 | $this->assertInstanceOf(Revision::class, $url->getRevision()); |
||
145 | $this->assertEquals(new Revision(1), $url->getRevision()); |
||
146 | $this->assertEquals(self::REMOTE_REPOSITORY_URL, Service::normalizeRepositoryUrl($url)); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Test a local URL with path prefix |
||
151 | */ |
||
152 | public function testLeadedLocalUrl() |
||
159 | |||
160 | /** |
||
161 | * Test an invalid URL |
||
162 | * |
||
163 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
164 | * @expectedExceptionCode 1449873819 |
||
165 | */ |
||
166 | public function testInvalidUrl() |
||
170 | |||
171 | /** |
||
172 | * Test an invalid URL path |
||
173 | * |
||
174 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
175 | * @expectedExceptionCode 1449874494 |
||
176 | */ |
||
177 | public function testInvalidUrlPath() |
||
181 | |||
182 | /** |
||
183 | * Test the scheme setter |
||
184 | * |
||
185 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
186 | * @expectedExceptionCode 1449924914 |
||
187 | */ |
||
188 | public function testUrlSchemeSetter() |
||
194 | |||
195 | /** |
||
196 | * Test the host setter |
||
197 | * |
||
198 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
199 | * @expectedExceptionCode 1449925567 |
||
200 | */ |
||
201 | public function testUrlHostSetter() |
||
207 | |||
208 | /** |
||
209 | * Test the port setter |
||
210 | * |
||
211 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
212 | * @expectedExceptionCode 1449925885 |
||
213 | */ |
||
214 | public function testUrlPortSetter() |
||
220 | |||
221 | /** |
||
222 | * Test the remaining setter methods |
||
223 | */ |
||
224 | public function testUrlSetters() |
||
246 | |||
247 | /** |
||
248 | * Test the override functionality when getting the URL path |
||
249 | */ |
||
250 | public function testUrlPathOverride() |
||
258 | |||
259 | /** |
||
260 | * Test absolute URL |
||
261 | */ |
||
262 | public function testUrlAbsolute() |
||
268 | |||
269 | /** |
||
270 | * Test absolute URL |
||
271 | */ |
||
272 | public function testUrlAbsoluteLocal() |
||
277 | |||
278 | /** |
||
279 | * Test relative URL |
||
280 | */ |
||
281 | public function testUrlRelative() |
||
282 | { |
||
283 | $url = new ObjectUrl(self::PATH . self::QUERY_FRAGMENT); |
||
284 | $this->assertEquals(false, $url->isAbsolute()); |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Test URL comparison |
||
289 | */ |
||
290 | public function testUrlComparison() |
||
304 | |||
305 | /** |
||
306 | * Test object URL comparison |
||
307 | */ |
||
308 | public function testObjectUrlComparison() |
||
352 | |||
353 | /** |
||
354 | * Test an invalid apparat URL |
||
355 | * |
||
356 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
357 | * @expectedExceptionCode 1451435429 |
||
358 | */ |
||
359 | public function testInvalidApparatUrl() |
||
363 | |||
364 | /** |
||
365 | * Test an absolute apparat URL |
||
366 | */ |
||
367 | public function testAbsoluteApparatUrl() |
||
373 | |||
374 | /** |
||
375 | * Test an unknown relative apparat URL |
||
376 | * |
||
377 | * @expectedException \Apparat\Object\Domain\Model\Path\ApparatInvalidArgumentException |
||
378 | * @expectedExceptionCode 1452695654 |
||
379 | */ |
||
380 | public function testUnknownRelativeApparatUrl() |
||
384 | |||
385 | /** |
||
386 | * Test a relative apparat URL |
||
387 | */ |
||
388 | public function testRelativeApparatUrl() |
||
401 | |||
402 | /** |
||
403 | * Test invalid date precision |
||
404 | * |
||
405 | * @expectedException \Apparat\Object\Domain\Model\Path\InvalidArgumentException |
||
406 | * @expectedExceptionCode 1451514114 |
||
407 | */ |
||
408 | public function testInvalidDatePrecision() |
||
412 | |||
413 | /** |
||
414 | * Test arbitrary date precision |
||
415 | */ |
||
416 | public function testArbitraryDatePrecision() |
||
421 | |||
422 | /** |
||
423 | * Test the normalization of an invalid repository URL |
||
424 | * |
||
425 | * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
||
426 | * @expectedExceptionCode 1453097878 |
||
427 | */ |
||
428 | public function testInvalidRepositoryUrlNormalization() { |
||
431 | } |
||
432 |