aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/HttpUtils/GetHttpUrlTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-13 12:07:13 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 12:07:13 +0200
commitd9f6275ebca035fec8331652c677981056793ccc (patch)
tree37a64baf4f0eba6b781040605965383d8aded2cc /tests/http/HttpUtils/GetHttpUrlTest.php
parent38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff)
parentd63ff87a009313141ae684ec447b902562ff6ee7 (diff)
downloadShaarli-stable.tar.gz
Shaarli-stable.tar.zst
Shaarli-stable.zip
Merge branch 'v0.11' into stablestable
Diffstat (limited to 'tests/http/HttpUtils/GetHttpUrlTest.php')
-rw-r--r--tests/http/HttpUtils/GetHttpUrlTest.php67
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
6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
9
10/**
11 * Unitary tests for get_http_response()
12 */
13class 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}