aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/HttpUtils/GetHttpUrlTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 00:34:53 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 22:47:48 +0100
commit51753e403fa69c0ce124ede27d300477e3e799ca (patch)
tree0afe2a84598648b49cc53bb3e8640569ac370240 /tests/http/HttpUtils/GetHttpUrlTest.php
parentfb1b182fbf0ee5afed586f77eec84d7a906831ef (diff)
downloadShaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.gz
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.zst
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.zip
namespacing: move HTTP utilities along \Shaarli\Http\ classes
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
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}