You are here

function AutoassignroleUserPathTestCase::testPathMenuAssignment in Auto Assign Role 6

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

File

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

Class

AutoassignroleUserPathTestCase

Code

function testPathMenuAssignment() {

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

  // for each role we are going to create a path with Display Method of Tab
  // Items
  foreach ($this->roles as $rid => $role) {
    $edit["path_display_{$rid}"] = 0;
  }
  $this
    ->drupalPost('admin/user/autoassignrole', $edit, t('Save'));
  $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}"];

    // verify that our menu items are not showing up as tabs on the user page
    $regex = '/\\<ul class="tabs primary"\\>.+(\\/user\\/' . $path . '"\\>' . $title . ').+\\<\\/ul>/si';
    $this
      ->assertFalse(preg_match($regex, $user_page), 'A tab named ' . $title . ' pointing to user/' . $path . ' does not exist on the user page');

    // verify that our menu items are showing up as menu items on the user page
    $regex = '/\\<ul class="menu"\\>.+(\\/' . $path . '"\\>' . $title . ').+\\<\\/ul>/si';
    $this
      ->assertTrue(preg_match($regex, $user_page), 'A menu item named ' . $title . ' pointing to /' . $path . ' exists on the user page');

    // Create a new user at this page and load the user object
    $new_user = $this
      ->getNewUser();
    $this
      ->drupalPost($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');
  }
}