aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/HttpUtils/GetHttpUrlTest.php
diff options
context:
space:
mode:
authorAurélien Tamisier <virtualtam+github@flibidi.net>2019-01-18 21:26:03 +0100
committerGitHub <noreply@github.com>2019-01-18 21:26:03 +0100
commitff3b5dc5542ec150f0d9b447394364a15e9156d0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092 /tests/http/HttpUtils/GetHttpUrlTest.php
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
parentdea72c711ff740b3b829d238fcf85648465143a0 (diff)
downloadShaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.gz
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.zst
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.zip
Merge pull request #1248 from virtualtam/refactor/namespacing
Ensure all PHP classes are properly namespaced
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}