MDL-47646 CURL redirect unit test: handle broken servers
authorTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 13 Oct 2014 14:00:46 +0000 (15:00 +0100)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 13 Oct 2014 14:52:04 +0000 (15:52 +0100)
lib/tests/filelib_test.php

index aa07dc5..004dc8b 100644 (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);