MDL-47646 CURL redirect unit test: handle broken servers

This commit is contained in:
Tim Hunt 2014-10-13 15:00:46 +01:00
parent d3ff82257e
commit 90048c7cfa

View File

@ -241,10 +241,20 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame(2, $curl->info['redirect_count']);
$this->assertSame('done', $contents);
// This test was failing for people behind Squid proxies. Squid does not
// fully support HTTP 1.1, so converts things to HTTP 1.0, where the name
// of the status code is different.
reset($response);
if (key($response) === 'HTTP/1.0') {
$responsecode302 = '302 Moved Temporarily';
} else {
$responsecode302 = '302 Found';
}
$curl = new curl();
$contents = $curl->get("$testurl?redir=3", array(), array('CURLOPT_FOLLOWLOCATION'=>0));
$response = $curl->getResponse();
$this->assertSame('302 Found', reset($response));
$this->assertSame($responsecode302, reset($response));
$this->assertSame(0, $curl->get_errno());
$this->assertSame(302, $curl->info['http_code']);
$this->assertSame('', $contents);
@ -253,7 +263,7 @@ class core_filelib_testcase extends advanced_testcase {
$curl->emulateredirects = true;
$contents = $curl->get("$testurl?redir=3", array(), array('CURLOPT_FOLLOWLOCATION'=>0));
$response = $curl->getResponse();
$this->assertSame('302 Found', reset($response));
$this->assertSame($responsecode302, reset($response));
$this->assertSame(0, $curl->get_errno());
$this->assertSame(302, $curl->info['http_code']);
$this->assertSame('', $contents);