You are here

function CasUserTestCase::testCasAutoRegister in CAS 6.3

Same name and namespace in other branches
  1. 7 cas.test \CasUserTestCase::testCasAutoRegister()

Tests automatically registering a user on login.

File

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

Class

CasUserTestCase
Test case to test user editing behavior.

Code

function testCasAutoRegister() {
  $cas_name = $this
    ->randomName();
  $this
    ->setCasUser($cas_name);

  // Test that the user is not automatically registered.
  variable_set('cas_user_register', FALSE);
  $this
    ->drupalGet('cas');
  $this
    ->assertRaw(t('No account found for %cas_name.', array(
    '%cas_name' => $cas_name,
  )));

  // Test that the user is automatically registered.
  variable_set('cas_user_register', TRUE);
  $this
    ->drupalGet('cas');
  $this->loggedInUser = cas_user_load_by_name($cas_name, TRUE);
  $this
    ->assertRaw(t('Logged in via CAS as %cas_username.', array(
    '%cas_username' => $cas_name,
  )));
  $this
    ->drupalLogout();

  // Create a new user.
  $user2 = $this
    ->drupalCreateUser();
  $cas_name = $user2->name;
  $this
    ->setCasUser($cas_name);

  // Test that CAS does not hijack an existing username.
  $this
    ->drupalGet('cas');
  $this
    ->assertRaw(t('A new account could not be created for %cas_name. The username is already in use on this site.', array(
    '%cas_name' => $cas_name,
  )));
}