aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HttpUtilsTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-09-01 21:45:06 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-09-06 19:30:26 +0200
commit451314eb48c7d922264adc6eada8a0273b12344c (patch)
treefddc1a6d7a92728d0dfdcbb676f113a09325b1c2 /tests/HttpUtilsTest.php
parentf5d6b19b73cd026cb1d937aab16d48b43e412c77 (diff)
downloadShaarli-451314eb48c7d922264adc6eada8a0273b12344c.tar.gz
Shaarli-451314eb48c7d922264adc6eada8a0273b12344c.tar.zst
Shaarli-451314eb48c7d922264adc6eada8a0273b12344c.zip
HTTP: move utils to a proper file, add tests
Relates to #333 Modifications: - move HTTP utils to 'application/HttpUtils.php' - simplify logic - replace 'http_parse_headers_shaarli' by built-in 'get_headers()' - remove superfluous '$status' parameter (provided by the HTTP headers) - apply coding conventions - add test coverage (unitary only) Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/HttpUtilsTest.php')
-rw-r--r--tests/HttpUtilsTest.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/HttpUtilsTest.php b/tests/HttpUtilsTest.php
new file mode 100644
index 00000000..76092b80
--- /dev/null
+++ b/tests/HttpUtilsTest.php
@@ -0,0 +1,38 @@
1<?php
2/**
3 * HttpUtils' tests
4 */
5
6require_once 'application/HttpUtils.php';
7
8/**
9 * Unitary tests for get_http_url()
10 */
11class GetHttpUrlTest extends PHPUnit_Framework_TestCase
12{
13 /**
14 * Get an invalid local URL
15 */
16 public function testGetInvalidLocalUrl()
17 {
18 list($headers, $content) = get_http_url('/non/existent', 1);
19 $this->assertEquals('HTTP Error', $headers[0]);
20 $this->assertRegexp(
21 '/failed to open stream: No such file or directory/',
22 $content
23 );
24 }
25
26 /**
27 * Get an invalid remote URL
28 */
29 public function testGetInvalidRemoteUrl()
30 {
31 list($headers, $content) = get_http_url('http://non.existent', 1);
32 $this->assertEquals('HTTP Error', $headers[0]);
33 $this->assertRegexp(
34 '/Name or service not known/',
35 $content
36 );
37 }
38}