2015-09-01 21:45:06 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* HttpUtils' tests
|
|
|
|
*/
|
|
|
|
|
2018-12-03 00:34:53 +01:00
|
|
|
namespace Shaarli\Http;
|
|
|
|
|
|
|
|
require_once 'application/http/HttpUtils.php';
|
2015-09-01 21:45:06 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-04 10:45:54 +01:00
|
|
|
* Unitary tests for get_http_response()
|
2015-09-01 21:45:06 +02:00
|
|
|
*/
|
2018-12-03 00:34:53 +01:00
|
|
|
class GetHttpUrlTest extends \PHPUnit\Framework\TestCase
|
2015-09-01 21:45:06 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get an invalid local URL
|
|
|
|
*/
|
|
|
|
public function testGetInvalidLocalUrl()
|
|
|
|
{
|
2016-01-04 10:45:54 +01:00
|
|
|
// Local
|
|
|
|
list($headers, $content) = get_http_response('/non/existent', 1);
|
2018-12-03 00:34:53 +01:00
|
|
|
$this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
|
2016-01-04 10:45:54 +01:00
|
|
|
$this->assertFalse($content);
|
|
|
|
|
|
|
|
// Non HTTP
|
|
|
|
list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
|
2018-12-03 00:34:53 +01:00
|
|
|
$this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
|
2016-01-04 10:45:54 +01:00
|
|
|
$this->assertFalse($content);
|
2015-09-01 21:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an invalid remote URL
|
|
|
|
*/
|
|
|
|
public function testGetInvalidRemoteUrl()
|
|
|
|
{
|
2016-01-04 10:45:54 +01:00
|
|
|
list($headers, $content) = @get_http_response('http://non.existent', 1);
|
|
|
|
$this->assertFalse($headers);
|
|
|
|
$this->assertFalse($content);
|
2015-09-01 21:45:06 +02:00
|
|
|
}
|
2016-04-06 22:00:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getAbsoluteUrl with relative target URL.
|
|
|
|
*/
|
|
|
|
public function testGetAbsoluteUrlWithRelative()
|
|
|
|
{
|
|
|
|
$origin = 'http://non.existent/blabla/?test';
|
|
|
|
$target = '/stuff.php';
|
|
|
|
|
|
|
|
$expected = 'http://non.existent/stuff.php';
|
|
|
|
$this->assertEquals($expected, getAbsoluteUrl($origin, $target));
|
|
|
|
|
|
|
|
$target = 'stuff.php';
|
|
|
|
$expected = 'http://non.existent/blabla/stuff.php';
|
|
|
|
$this->assertEquals($expected, getAbsoluteUrl($origin, $target));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getAbsoluteUrl with absolute target URL.
|
|
|
|
*/
|
|
|
|
public function testGetAbsoluteUrlWithAbsolute()
|
|
|
|
{
|
|
|
|
$origin = 'http://non.existent/blabla/?test';
|
|
|
|
$target = 'http://other.url/stuff.php';
|
|
|
|
|
|
|
|
$this->assertEquals($target, getAbsoluteUrl($origin, $target));
|
|
|
|
}
|
2015-09-01 21:45:06 +02:00
|
|
|
}
|