diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:30:33 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:30:33 +0200 |
commit | 1b8ed48a0d3964186f4d66d443783f4d250e7147 (patch) | |
tree | 23597f312507ba0c1b461755b9aa086106374a4d /tests/http/HttpUtils/GetHttpUrlTest.php | |
parent | 1aa24ed8d2974cda98733f74b36844b02942cc11 (diff) | |
parent | ed3365325d231e044dedc32608fde87b1b39fa34 (diff) | |
download | Shaarli-1b8ed48a0d3964186f4d66d443783f4d250e7147.tar.gz Shaarli-1b8ed48a0d3964186f4d66d443783f4d250e7147.tar.zst Shaarli-1b8ed48a0d3964186f4d66d443783f4d250e7147.zip |
Merge tag 'v0.11.0' into latest
Release v0.11.0
Diffstat (limited to 'tests/http/HttpUtils/GetHttpUrlTest.php')
-rw-r--r-- | tests/http/HttpUtils/GetHttpUrlTest.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/http/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php new file mode 100644 index 00000000..3dc5bc9b --- /dev/null +++ b/tests/http/HttpUtils/GetHttpUrlTest.php | |||
@@ -0,0 +1,67 @@ | |||
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 | } | ||