From 451314eb48c7d922264adc6eada8a0273b12344c Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Tue, 1 Sep 2015 21:45:06 +0200 Subject: 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 --- tests/HttpUtilsTest.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/HttpUtilsTest.php (limited to 'tests/HttpUtilsTest.php') 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 @@ +assertEquals('HTTP Error', $headers[0]); + $this->assertRegexp( + '/failed to open stream: No such file or directory/', + $content + ); + } + + /** + * Get an invalid remote URL + */ + public function testGetInvalidRemoteUrl() + { + list($headers, $content) = get_http_url('http://non.existent', 1); + $this->assertEquals('HTTP Error', $headers[0]); + $this->assertRegexp( + '/Name or service not known/', + $content + ); + } +} -- cgit v1.2.3