You are here

function CasLogoutRedirectionTestCase::testLogoutRedirection in CAS 7

Same name and namespace in other branches
  1. 6.3 cas.test \CasLogoutRedirectionTestCase::testLogoutRedirection()

Test redirection on user logout.

File

./cas.test, line 479
Tests for cas.module.

Class

CasLogoutRedirectionTestCase
Test case to test user logout behavior.

Code

function testLogoutRedirection() {
  $account = $this
    ->casCreateUser();
  $this
    ->casLogin($account);
  $this
    ->drupalGet('caslogout');
  $this
    ->assertText('Logged out. No redirection provided.');
  $this
    ->assertLoggedOut();

  // Verify the destination parameter may be passed on logout, i.e.,
  // caslogout?destination=node
  $destination = 'node';
  $this
    ->casLogin($account);
  $this
    ->drupalGet('caslogout', array(
    'query' => array(
      'destination' => $destination,
    ),
  ));
  $this
    ->assertText(t('Logged out. Continue to @url.', array(
    '@url' => url($destination, array(
      'absolute' => TRUE,
    )),
  )));
  $this
    ->assertLoggedOut();

  // Verify that remote destination parameters are not allowed.
  $destination = 'http://example.com/?query=yes#fragment';
  $this
    ->casLogin($account);
  $this
    ->drupalGet('caslogout', array(
    'query' => array(
      'destination' => $destination,
    ),
  ));
  $this
    ->assertText(t('Logged out. No redirection provided.'));
  $this
    ->assertLoggedOut();

  // Verify 'cas_logout_destination' works for a variety of destinations,
  // including remote destinations.
  $destinations = array(
    '<front>',
    'http://example.com/?query=yes#fragment',
    'node/1',
  );
  foreach ($destinations as $destination) {
    variable_set('cas_logout_destination', $destination);
    $this
      ->casLogin($account);
    $this
      ->drupalGet('caslogout');
    $this
      ->assertText(t('Logged out. Continue to @url.', array(
      '@url' => url($destination, array(
        'absolute' => TRUE,
      )),
    )));
    $this
      ->assertLoggedOut();
  }

  // Verify 'cas_logout_destination' can be overwritten by passing the
  // destination query string.
  variable_set('cas_logout_destination', 'http://example.com/');
  $destination = 'node/1';
  $this
    ->casLogin($account);
  $this
    ->drupalGet('caslogout', array(
    'query' => array(
      'destination' => $destination,
    ),
  ));
  $this
    ->assertText(t('Logged out. Continue to @url.', array(
    '@url' => url($destination, array(
      'absolute' => TRUE,
    )),
  )));
  $this
    ->assertLoggedOut();
}