You are here

function AutoassignroleUserPathTestCase::testPathTabAssignment in Auto Assign Role 6

Same name and namespace in other branches
  1. 6.2 tests/autoassignrole.test \AutoassignroleUserPathTestCase::testPathTabAssignment()

File

tests/autoassignrole.test, line 326
Autoassignrole functionality tests.

Class

AutoassignroleUserPathTestCase

Code

function testPathTabAssignment() {

  // Create a new user who can access the administration settings
  $this
    ->drupalLogin($this->admin_user);
  $edit = $this
    ->getEditValues('assign_from_path');
  $this
    ->drupalPost('admin/user/autoassignrole', $edit, t('Save'));

  //Create a new user normally and verify that no additional roles are added
  $new_user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($new_user);

  // check the user after login to make sure they have not been assigned our
  // roles
  foreach ($this->roles as $rid => $role) {
    $this
      ->assertFalse(array_key_exists($rid, $this->loggedInUser->roles), "New User has not been assigned the role {$role}");
  }
  $this
    ->drupalLogout();
  $user_page = $this
    ->drupalGet('user');
  foreach ($this->roles as $rid => $role) {
    $this
      ->drupalLogout();
    $path = $edit["path_{$rid}"];
    $title = $edit["path_title_{$rid}"];
    $description = $edit["path_description_{$rid}"];

    // Make sure all tabs are on the user page with the correct titles
    $regex = '/\\<ul class="tabs primary"\\>.+(\\/user\\/' . $path . '"\\>' . $title . ').+\\<\\/ul>/si';
    $this
      ->assertTrue(preg_match($regex, $user_page), 'A tab named ' . $title . ' is pointing to user/' . $path);
    $role_page = $this
      ->drupalGet('user/' . $path);

    // Verify our description is on the page
    $regex = '/\\<p\\>(' . $description . ')\\<\\/p>/si';
    $this
      ->assertTrue(preg_match($regex, $role_page), 'The description ' . $description . ' is on the page at user/' . $path);

    // Create a new user at this page and load the user object
    $new_user = $this
      ->getNewUser();
    $this
      ->drupalPost('user/' . $path, $new_user, t('Create new account'));
    $user = user_load(array(
      'name' => $new_user['name'],
      'mail' => $new_user['mail'],
    ));

    // verify the user has been assigned only this path based and authenticated
    // user roles
    $this
      ->assertEqual(count($user->roles), 2, 'The roles array for user ' . $new_user['name'] . ' is the correct size');
    $this
      ->assertTrue(array_key_exists($rid, $user->roles), 'The user ' . $new_user['name'] . ' has been assigned the correct path based role');
  }
}