Expected Path: !expected_path
Expected Status Code: !expected_status
Location: !location
Status: !status');
define('SUCCESS_MESSAGE', 'SUCCESS
Expected Path: !expected_path
Expected Status Code: !expected_status
Location: !location
Status: !status');
/**
* @file
* Global Redirect functionality tests
*/
class GlobalRedirectTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('path', 'globalredirect', 'taxonomy', 'forum');
// Create a user
$user = $this->drupalCreateUser(array(
'access content',
'create page content',
'create url aliases',
));
$this->drupalLogin($user);
// Create a dummy node
$node = array(
'type' => 'page',
'title' => 'Test Page Node',
'path' => array('alias' => 'test-node'),
);
// Save the node
$node = $this->drupalCreateNode($node);
// Create an alias for the create story path - this is used in the "redirect with permissions testing" test.
$path = array('source' => 'node/add/article', 'alias' => 'node-add-artice');
path_save($path);
// The forum vocab should already be created - should be term 1?
$forum_term = (object)array(
'vid' => variable_get('forum_nav_vocabulary', 0),
'name' => 'Test Forum Term',
);
taxonomy_term_save($forum_term);
// Create another test vocab (with a default module) - should be vocab 2?
$vocab = (object)array(
'name' => 'test vocab',
'multiple' => 0,
'required' => 0,
'hierarchy' => 0,
'module' => 'taxonomy',
'nodes' => array('page', 'story'),
);
taxonomy_vocabulary_save($vocab);
$vocab = taxonomy_vocabulary_load($vocab->vid, TRUE);
// Create a test term - Should be term 2?
$term = (object)array(
'vid' => $vocab->vid,
'name' => 'Test Term',
'path' => array('alias' => 'test-term'),
);
taxonomy_term_save($term);
$term = taxonomy_term_load($term->tid);
}
protected function _globalredirect_batch_test() {
// Get the settings
$settings = _globalredirect_get_settings();
$this->assert('pass', '
' . print_r($settings, TRUE) . ''); // Array of request => "array of expected data" pairs. // The array must have a return-code key (with a numeric HTTP code as a value (eg 301 or 200). // The array may also have an expected-path key with a value representing the expected path. If this is ommitted, the request is passed through url(). $test_paths = array( // "" is the frontpage. Should NOT redirect. -- Test for normal requests array( 'request' => '', 'return-code' => 200, 'expected-path' => '', ), // "node" is the default frontpage. Should redirect to base path. --- Test for frontpage redirect array( 'request' => 'node', 'return-code' => 301, 'expected-path' => '', ), // "node/1" has been defined above as having an alias ("test-node"). Should 301 redirect to the alias. --- Test for source path request on aliased path array( 'request' => 'node/1', 'return-code' => 301, ), // "node/add/article" has an alias, however the redirect depends on the menu_check setting --- Test for access request to secured url array( 'request' => 'node/add/article', 'return-code' => $settings['menu_check'] ? 403 : 301, ), // "user/[uid]/" has no alias, but the redirect depends on the $deslash_check setting --- Test for deslashing redirect array( 'request' => 'user/' . $this->loggedInUser->uid . '/', 'return-code' => $settings['deslash'] ? 301 : 200, 'expected-path' => 'user/' . $this->loggedInUser->uid, ), // NonClean to Clean check 1 --- This should always redirect as we're requesting an aliased path in unaliased form (albeit also unclean) array( 'request' => url('
' . print_r($headers, TRUE) . ''); } } else { // The status either wasn't present or was not as expected $this->fail(t(ERROR_MESSAGE, $result), 'GlobalRedirect'); $this->fail('
' . print_r($headers, TRUE) . ''); } } } } class GlobalRedirectTestCaseDefault extends GlobalRedirectTestCase { public static function getInfo() { return array( 'name' => '1. Global Redirect - Default Settings', 'description' => 'Ensure that Global Redirect functions correctly', 'group' => 'Global Redirect', ); } function testGlobalRedirect() { variable_set('globalredirect_settings', array( 'deslash' => 1, 'menu_check' => 0, 'nonclean_to_clean' => 1, 'case_sensitive_urls' => 1, 'term_path_handler' => 0, )); $this->_globalredirect_batch_test(); } } class GlobalRedirectTestCaseConfigAlpha extends GlobalRedirectTestCase { public static function getInfo() { return array( 'name' => '2. Global Redirect - Config Alpha', 'description' => 'Ensure that Global Redirect functions correctly', 'group' => 'Global Redirect', ); } function testGlobalRedirect() { variable_set('globalredirect_settings', array( 'deslash' => 0, 'menu_check' => 1, 'nonclean_to_clean' => 0, 'case_sensitive_urls' => 0, 'term_path_handler' => 1, )); $this->_globalredirect_batch_test(); } }