6 require_once 'application/HttpUtils.php';
9 * Unitary tests for get_http_response()
11 class GetHttpUrlTest
extends PHPUnit_Framework_TestCase
14 * Get an invalid local URL
16 public function testGetInvalidLocalUrl()
19 list($headers, $content) = get_http_response('/non/existent', 1);
20 $this->assertEquals('Invalid HTTP Url', $headers[0]);
21 $this->assertFalse($content);
24 list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
25 $this->assertEquals('Invalid HTTP Url', $headers[0]);
26 $this->assertFalse($content);
30 * Get an invalid remote URL
32 public function testGetInvalidRemoteUrl()
34 list($headers, $content) = @get_http_response('http://non.existent', 1);
35 $this->assertFalse($headers);
36 $this->assertFalse($content);
40 * Test getAbsoluteUrl with relative target URL.
42 public function testGetAbsoluteUrlWithRelative()
44 $origin = 'http://non.existent/blabla/?test';
45 $target = '/stuff.php';
47 $expected = 'http://non.existent/stuff.php';
48 $this->assertEquals($expected, getAbsoluteUrl($origin, $target));
50 $target = 'stuff.php';
51 $expected = 'http://non.existent/blabla/stuff.php';
52 $this->assertEquals($expected, getAbsoluteUrl($origin, $target));
56 * Test getAbsoluteUrl with absolute target URL.
58 public function testGetAbsoluteUrlWithAbsolute()
60 $origin = 'http://non.existent/blabla/?test';
61 $target = 'http://other.url/stuff.php';
63 $this->assertEquals($target, getAbsoluteUrl($origin, $target));