function CasLoginRedirectionTestCase::testExistingUserLoginRedirection in CAS 7
Same name and namespace in other branches
- 6.3 cas.test \CasLoginRedirectionTestCase::testExistingUserLoginRedirection()
Verify login redirection for an existing user.
File
- ./
cas.test, line 540 - Tests for cas.module.
Class
- CasLoginRedirectionTestCase
- Test case to test user login behavior.
Code
function testExistingUserLoginRedirection() {
$node1 = $this
->drupalCreateNode();
$node2 = $this
->drupalCreateNode();
$node3 = $this
->drupalCreateNode();
// Create a CAS user.
$account = $this
->casCreateUser();
$cas_name = $account->cas_name;
$this
->setCasUser($cas_name);
// Test going to 'cas'
$this
->drupalGet('cas');
$this
->assertLoggedIn($account);
$this
->assertUrl('');
$this
->drupalLogout();
// Test going to 'cas?destination=node/$node1->nid'
$destination = "node/{$node1->nid}";
$this
->drupalGet('cas', array(
'query' => array(
'destination' => $destination,
),
));
$this
->assertLoggedIn($account);
$this
->assertUrl($destination);
$this
->drupalLogout();
// Use the login block on $node2.
$destination = "node/{$node2->nid}";
variable_set('cas_login_form', CAS_ADD_LINK);
$edit = array(
'cas_identifier' => TRUE,
);
$this
->drupalPost($destination, $edit, t('Log in'));
$this
->assertLoggedIn($account);
$this
->assertUrl($destination);
$this
->drupalLogout();
// Use the regular login page, without a destination.
$edit = array(
'cas_identifier' => TRUE,
);
$this
->drupalPost('user/login', $edit, t('Log in'));
$this
->assertLoggedIn($account);
$this
->assertUrl('user');
$this
->drupalLogout();
// Use the regular login page, with a destination.
$destination = "node/{$node3->nid}";
$edit = array(
'cas_identifier' => TRUE,
);
$this
->drupalPost('user/login', $edit, t('Log in'), array(
'query' => array(
'destination' => $destination,
),
));
$this
->assertLoggedIn($account);
$this
->assertUrl($destination);
$this
->drupalLogout();
// External destinations are not allowed.
$destination = '';
$this
->drupalGet('cas', array(
'query' => array(
'destination' => 'http://example.com/node/3',
),
));
$this
->assertLoggedIn($account);
$this
->assertUrl($destination);
$this
->drupalLogout();
}