]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | /** | |
3 | * HttpUtils' tests | |
4 | */ | |
5 | ||
6 | namespace Shaarli\Http; | |
7 | ||
8 | require_once 'application/http/HttpUtils.php'; | |
9 | ||
10 | /** | |
11 | * Unitary tests for get_http_response() | |
12 | */ | |
13 | class GetHttpUrlTest extends \PHPUnit\Framework\TestCase | |
14 | { | |
15 | /** | |
16 | * Get an invalid local URL | |
17 | */ | |
18 | public function testGetInvalidLocalUrl() | |
19 | { | |
20 | // Local | |
21 | list($headers, $content) = get_http_response('/non/existent', 1); | |
22 | $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]); | |
23 | $this->assertFalse($content); | |
24 | ||
25 | // Non HTTP | |
26 | list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1); | |
27 | $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]); | |
28 | $this->assertFalse($content); | |
29 | } | |
30 | ||
31 | /** | |
32 | * Get an invalid remote URL | |
33 | */ | |
34 | public function testGetInvalidRemoteUrl() | |
35 | { | |
36 | list($headers, $content) = @get_http_response('http://non.existent', 1); | |
37 | $this->assertFalse($headers); | |
38 | $this->assertFalse($content); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Test getAbsoluteUrl with relative target URL. | |
43 | */ | |
44 | public function testGetAbsoluteUrlWithRelative() | |
45 | { | |
46 | $origin = 'http://non.existent/blabla/?test'; | |
47 | $target = '/stuff.php'; | |
48 | ||
49 | $expected = 'http://non.existent/stuff.php'; | |
50 | $this->assertEquals($expected, getAbsoluteUrl($origin, $target)); | |
51 | ||
52 | $target = 'stuff.php'; | |
53 | $expected = 'http://non.existent/blabla/stuff.php'; | |
54 | $this->assertEquals($expected, getAbsoluteUrl($origin, $target)); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Test getAbsoluteUrl with absolute target URL. | |
59 | */ | |
60 | public function testGetAbsoluteUrlWithAbsolute() | |
61 | { | |
62 | $origin = 'http://non.existent/blabla/?test'; | |
63 | $target = 'http://other.url/stuff.php'; | |
64 | ||
65 | $this->assertEquals($target, getAbsoluteUrl($origin, $target)); | |
66 | } | |
67 | } |