function DrupalHTTPRequestTestCase::testDrupalHTTPRequestRedirect in SimpleTest 7
File
- tests/
common.test, line 810 - Tests for common.inc functionality.
Class
Code
function testDrupalHTTPRequestRedirect() {
$redirect_301 = drupal_http_request(url('system-test/redirect/301', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 1,
));
$this
->assertEqual($redirect_301->redirect_code, 301, t('drupal_http_request follows the 301 redirect.'));
$redirect_301 = drupal_http_request(url('system-test/redirect/301', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 0,
));
$this
->assertFalse(isset($redirect_301->redirect_code), t('drupal_http_request does not follow 301 redirect if max_redirects = 0.'));
$redirect_invalid = drupal_http_request(url('system-test/redirect-noscheme', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 1,
));
$this
->assertEqual($redirect_invalid->code, -1002, t('301 redirect to invalid URL returned with error code !error.', array(
'!error' => $redirect_invalid->error,
)));
$this
->assertEqual($redirect_invalid->error, 'missing schema', t('301 redirect to invalid URL returned with error message "!error".', array(
'!error' => $redirect_invalid->error,
)));
$redirect_invalid = drupal_http_request(url('system-test/redirect-noparse', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 1,
));
$this
->assertEqual($redirect_invalid->code, -1001, t('301 redirect to invalid URL returned with error message code "!error".', array(
'!error' => $redirect_invalid->error,
)));
$this
->assertEqual($redirect_invalid->error, 'unable to parse URL', t('301 redirect to invalid URL returned with error message "!error".', array(
'!error' => $redirect_invalid->error,
)));
$redirect_invalid = drupal_http_request(url('system-test/redirect-invalid-scheme', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 1,
));
$this
->assertEqual($redirect_invalid->code, -1003, t('301 redirect to invalid URL returned with error code !error.', array(
'!error' => $redirect_invalid->error,
)));
$this
->assertEqual($redirect_invalid->error, 'invalid schema ftp', t('301 redirect to invalid URL returned with error message "!error".', array(
'!error' => $redirect_invalid->error,
)));
$redirect_302 = drupal_http_request(url('system-test/redirect/302', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 1,
));
$this
->assertEqual($redirect_302->redirect_code, 302, t('drupal_http_request follows the 302 redirect.'));
$redirect_302 = drupal_http_request(url('system-test/redirect/302', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 0,
));
$this
->assertFalse(isset($redirect_302->redirect_code), t('drupal_http_request does not follow 302 redirect if $retry = 0.'));
$redirect_307 = drupal_http_request(url('system-test/redirect/307', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 1,
));
$this
->assertEqual($redirect_307->redirect_code, 307, t('drupal_http_request follows the 307 redirect.'));
$redirect_307 = drupal_http_request(url('system-test/redirect/307', array(
'absolute' => TRUE,
)), array(
'max_redirects' => 0,
));
$this
->assertFalse(isset($redirect_307->redirect_code), t('drupal_http_request does not follow 307 redirect if max_redirects = 0.'));
}