MyShaarli/tests/HttpUtils/GetHttpUrlTest.php
ArthurHoaro 1557cefbd7 Fixes #410 - Retrieve title fails in multiple cases
* `get_http_url()` renamed to `get_http_response()`.
  * Use the same HTTP context to retrieve response headers and content.
  * Follow HTTP 301 and 302 redirections to retrieve the title (default max 3 redirections).
  * Add `LinkUtils` to extract titles and charset.
  * Try to retrieve charset from HTTP headers first (new), then HTML content.
  * Use mb_string to re-encode title if necessary.
2016-01-11 21:19:31 +01:00

39 lines
951 B
PHP

<?php
/**
* HttpUtils' tests
*/
require_once 'application/HttpUtils.php';
/**
* Unitary tests for get_http_response()
*/
class GetHttpUrlTest extends PHPUnit_Framework_TestCase
{
/**
* Get an invalid local URL
*/
public function testGetInvalidLocalUrl()
{
// Local
list($headers, $content) = get_http_response('/non/existent', 1);
$this->assertEquals('Invalid HTTP Url', $headers[0]);
$this->assertFalse($content);
// Non HTTP
list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
$this->assertEquals('Invalid HTTP Url', $headers[0]);
$this->assertFalse($content);
}
/**
* Get an invalid remote URL
*/
public function testGetInvalidRemoteUrl()
{
list($headers, $content) = @get_http_response('http://non.existent', 1);
$this->assertFalse($headers);
$this->assertFalse($content);
}
}