protected function GlobalRedirectTestCase::_globalredirect_batch_test in Global Redirect 7
Same name and namespace in other branches
- 6 globalredirect.test \GlobalRedirectTestCase::_globalredirect_batch_test()
4 calls to GlobalRedirectTestCase::_globalredirect_batch_test()
- GlobalRedirectTestCaseConfigAlpha::testGlobalRedirect in ./globalredirect.test
- GlobalRedirectTestCaseConfigBeta::testGlobalRedirect in ./globalredirect.test
- GlobalRedirectTestCaseConfigLanguages::testGlobalRedirect in ./globalredirect.test
- GlobalRedirectTestCaseDefault::testGlobalRedirect in ./globalredirect.test
File
- ./globalredirect.test, line 227
- Global Redirect functionality tests
Class
- GlobalRedirectTestCase
- @file
Global Redirect functionality tests
Code
protected function _globalredirect_batch_test() {
$path_defaults = array(
'options' => array(),
);
$path_options_defaults = array(
'base_url' => $GLOBALS['base_url'] . base_path(),
'absolute' => TRUE,
'alias' => TRUE,
'external' => TRUE,
);
$test_paths = $this
->_globalredirect_test_paths();
$this
->assert('pass', '<pre>' . print_r($test_paths, TRUE) . '</pre>');
foreach ($test_paths as $id => $path) {
$path += $path_defaults;
$path['options'] += $path_options_defaults;
$request_path = $path['options']['external'] ? $path['options']['base_url'] . $path['request'] : $path['request'];
$request_path = url($request_path, $path['options']);
$info = array(
'!id' => $id,
'!path' => '<pre>' . print_r($path, TRUE) . '</pre>',
'!url' => $request_path,
);
$this
->pass(t(INFO_MESSAGE, $info), 'GlobalRedirect');
$this
->drupalHead($request_path, array(
'alias' => TRUE,
));
$headers = $this
->drupalGetHeaders(TRUE);
$result = array(
'!expected_status' => $path['return-code'],
'!location' => isset($headers[0]['location']) ? $headers[0]['location'] : 'N/A',
'!status' => $headers[0][':status'],
);
if ($path['return-code'] != 301) {
$result['!expected_path'] = 'N/A';
}
else {
$url_options = array(
'absolute' => TRUE,
);
if (isset($path['expected-path'])) {
$expected = $path['expected-path'];
$url_options['alias'] = TRUE;
}
else {
$expected = $path['request'];
}
$result['!expected_path'] = url($expected, $url_options);
}
if (strpos($result['!status'], (string) $result['!expected_status']) !== FALSE) {
if ($result['!expected_status'] == 301 && $result['!location'] == $result['!expected_path']) {
$this
->pass(t(SUCCESS_MESSAGE, $result), 'GlobalRedirect');
}
elseif ($result['!expected_status'] != 301) {
$this
->pass(t(SUCCESS_MESSAGE, $result), 'GlobalRedirect');
}
else {
$this
->fail(t(ERROR_MESSAGE, $result), 'GlobalRedirect');
$this
->fail('<pre>' . print_r($headers, TRUE) . '</pre>');
}
}
else {
$this
->fail(t(ERROR_MESSAGE, $result), 'GlobalRedirect');
$this
->fail('<pre>' . print_r($headers, TRUE) . '</pre>');
}
}
}