You are here

autoassignrole.test in Auto Assign Role 7.2

Same filename and directory in other branches
  1. 7 autoassignrole.test

Creates tests for auto assign role module.

File

autoassignrole.test
View source
<?php

/**
 * @file
 * Creates tests for auto assign role module.
 */

/**
 * Extend the DrupalWebTestCase.
 */
class AutoassignroleAdminAutoTestCase extends DrupalWebTestCase {
  protected $admin_user;
  protected $roles;
  public static function getInfo() {
    return array(
      'name' => 'Admin auto',
      'description' => 'Tests the administrative setting for auto assign role automatic assignment',
      'group' => 'Auto assign role',
    );
  }
  function setUp() {
    parent::setUp('autoassignrole');
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer autoassignrole',
      'access administration pages',
    ));
    $permissions = array(
      'access content',
    );
    $this
      ->drupalCreateRole($permissions);
    $this->roles = user_roles(TRUE);
    unset($this->roles[DRUPAL_AUTHENTICATED_RID]);
  }

  /**
   * Validate that the block for this functionality exists on
   * admin/config.
   */
  function testAutoConfigBlock() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see a link to the auto settings.
    $this
      ->drupalGet('admin/config/people');
    $this
      ->assertLink('Auto assign role', 0, 'Auto role assignment link exists on admin/config/people');
  }

  /**
   * Validate that the block for this functionality exists on
   * admin/config/people/autoassignrole.
   */
  function testAutoConfigAarBlock() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see a link to the auto settings.
    $this
      ->drupalGet('admin/config/people/autoassignrole');
    $this
      ->assertLink('Automatic', 0, 'Automatic link exists on admin/config/people/autoassignrole');
  }

  /**
   * Test admin setting functionality for autoassignrole_auto_active.
   * @see http://drupal.org/node/937468
   */
  function testAutoActiveSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/auto');
    $this
      ->assertField('autoassignrole_auto_active', 'The autoassignrole_auto_active field is accessible.');

    // Enable autoassignrole_auto_active.
    $edit['autoassignrole_auto_active'] = 1;
    $this
      ->drupalPost('admin/config/people/autoassignrole/auto', $edit, t('Save configuration'));

    // Verify autoassignrole_auto_active has been enabled.
    $this
      ->assertEqual(variable_get('autoassignrole_auto_active', 0), 1, 'autoassignrole_auto_active has been enabled');

    // Disable autoassignrole_auto_active
    $edit['autoassignrole_auto_active'] = 0;
    $this
      ->drupalPost('admin/config/people/autoassignrole/auto', $edit, t('Save configuration'));

    // Verify autoassignrole_auto_active has been disabled.
    $this
      ->assertEqual(variable_get('autoassignrole_auto_active', 1), 0, 'autoassignrole_auto_active has been disabled');
  }

  /**
   * Test admin setting functionality for autoassignrole_admin_active.
   * @see http://drupal.org/node/937666
   */
  function testAdminActiveSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/auto');
    $this
      ->assertField('autoassignrole_admin_active', 'The autoassignrole_admin_active field is accessible.');

    // Enable autoassignrole_admin_active
    $edit['autoassignrole_admin_active'] = 1;
    $this
      ->drupalPost('admin/config/people/autoassignrole/auto', $edit, t('Save configuration'));

    // Verify autoassignrole_admin_active has been enabled.
    $this
      ->assertEqual(variable_get('autoassignrole_admin_active', 0), 1, 'autoassignrole_admin_active has been enabled');

    // Disable autoassignrole_admin_active
    $edit['autoassignrole_admin_active'] = 0;
    $this
      ->drupalPost('admin/config/people/autoassignrole/auto', $edit, t('Save configuration'));

    // Verify autoassignrole_admin_active has been disabled.
    $this
      ->assertEqual(variable_get('autoassignrole_admin_active', 1), 0, 'autoassignrole_admin_active has been disabled');
  }

  /**
   * Test admin setting functionality for autoassignrole_auto_roles.
   * @see http://drupal.org/node/937678
   */
  function testAutoRolesSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/auto');

    // Verify that there are roles exposed.
    $this
      ->assertField('autoassignrole_auto_roles[' . $this->roles[3] . ']', 'Looking for the autoassignrole_auto_roles checkboxes.');

    // Verify that a checkbox for each of our valid roles shows on the page.
    foreach ($this->roles as $role) {
      $edit["autoassignrole_auto_roles[{$role}]"] = $role;
    }

    // Check each of our roles and submit the form.
    $this
      ->drupalPost('admin/config/people/autoassignrole/auto', $edit, t('Save configuration'));

    // Verify the checked value was saved for each of our roles.
    $roles = variable_get("autoassignrole_auto_roles", array());
    foreach ($this->roles as $role) {
      $this
        ->assertEqual(TRUE, array_key_exists($role, $roles), sprintf('Verifying that role %s was activated.', $role));
    }
  }

}

/**
 * Extend the DrupalWebTestCase.
 */
class AutoassignroleAdminUserTestCase extends DrupalWebTestCase {
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'Admin user',
      'description' => 'Tests the administrative setting for auto assign role user selection',
      'group' => 'Auto assign role',
    );
  }
  function setUp() {
    parent::setUp('autoassignrole');
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer autoassignrole',
      'access administration pages',
    ));
    $permissions = array(
      'access content',
    );
    $this
      ->drupalCreateRole($permissions);
    $this->roles = user_roles(TRUE);
    unset($this->roles[DRUPAL_AUTHENTICATED_RID]);
  }

  /**
   * Validate that the block for this functionality exists on admin/config.
   */
  function testAutoConfigBlock() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see a link to the auto settings.
    $this
      ->drupalGet('admin/config/people');
    $this
      ->assertLink('Auto assign role', 0, 'Auto assign role link exists on admin/config/people');
  }

  /**
   * Validate that the block for this functionality exists on
   * admin/config/people/autoassignrole.
   */
  function testAutoConfigAarBlock() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see a link to the auto settings.
    $this
      ->drupalGet('admin/config/people/autoassignrole');
    $this
      ->assertLink('User choice', 0, 'Allow user to choose link exists on admin/config/people/autoassignrole');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_active.
   * @see http://drupal.org/node/944880
   */
  function testAdminUserSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_active', 'The autoassignrole_user_active field is accessible.');

    // Enable autoassignrole_user_active.
    $edit['autoassignrole_user_active'] = 1;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_active has been enabled.
    $this
      ->assertEqual(variable_get('autoassignrole_user_active', 0), 1, 'autoassignrole_user_active has been enabled');

    // Disable autoassignrole_user_active
    $edit['autoassignrole_user_active'] = 0;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_active has been disabled.
    $this
      ->assertEqual(variable_get('autoassignrole_user_active', 1), 0, 'autoassignrole_user_active has been disabled');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_roles.
   * @see http://drupal.org/node/944922
   */
  function testAdminUserRolesSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');

    // Verify that there are roles exposed.
    $this
      ->assertField('autoassignrole_user_roles[' . $this->roles[3] . ']', 'Looking for the autoassignrole_user_roles checkboxes.');

    // Verify that a checkbox for each of our valid roles shows on the page.
    foreach ($this->roles as $rid => $role) {
      $edit["autoassignrole_user_roles[{$role}]"] = $role;
    }

    // Check each of our roles and submit the form.
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify the checked value was saved for each of our roles.
    $roles = variable_get("autoassignrole_user_roles", array());
    foreach ($this->roles as $rid => $role) {
      $this
        ->assertEqual(TRUE, array_key_exists($role, $roles), 'Verifying that role "' . $role . '" was activated.');
    }
  }

  /**
   * Test admin setting functionality for autoassignrole_user_multiple.
   * @see http://drupal.org/node/944944
   */
  function testAdminUserMultipleSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_multiple', 'The autoassignrole_user_multiple field is accessible.');

    // Enable autoassignrole_user_multiple.
    $edit['autoassignrole_user_multiple'] = 1;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_multiple has been enabled.
    $this
      ->assertEqual(variable_get('autoassignrole_user_multiple', 0), 1, 'autoassignrole_user_multiple has been enabled');

    // Disable autoassignrole_user_multiple.
    $edit['autoassignrole_user_multiple'] = 0;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_multiple has been disabled.
    $this
      ->assertEqual(variable_get('autoassignrole_user_multiple', 1), 0, 'autoassignrole_user_multiple has been disabled');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_selection.
   * @see http://drupal.org/node/944974
   */
  function testAdminUserSelectionSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_selection', 'The autoassignrole_user_selection field is accessible.');

    // Set autoassignrole_user_selection to radio inputs.
    $edit['autoassignrole_user_selection'] = 0;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_selection has set to radio.
    $this
      ->assertEqual(variable_get('autoassignrole_user_selection', -1), 0, 'autoassignrole_user_selection has been set to radio/ checkbox');

    // Set autoassignrole_user_selection to select box.
    $edit['autoassignrole_user_selection'] = 1;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_selection has been set to select box.
    $this
      ->assertEqual(variable_get('autoassignrole_user_selection', -1), 1, 'autoassignrole_user_selection has been set to select box');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_selection.
   * @see http://drupal.org/node/944978
   */
  function testAdminUserSelectionRequired() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_required', 'The autoassignrole_user_required field is accessible.');

    // Set autoassignrole_user_required to no.
    $edit['autoassignrole_user_required'] = 0;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_required has set to no.
    $this
      ->assertEqual(variable_get('autoassignrole_user_required', -1), 0, 'autoassignrole_user_required has been set to radio');

    // Set autoassignrole_user_required to yes.
    $edit['autoassignrole_user_required'] = 1;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_required has been set to yes.
    $this
      ->assertEqual(variable_get('autoassignrole_user_required', -1), 1, 'autoassignrole_user_required has been set to select box');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_selection.
   * @see http://drupal.org/node/944988
   */
  function testAdminUserSortSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_sort', 'The autoassignrole_user_sort field is accessible.');

    // Set autoassignrole_user_sort to radio SORT_ASC.
    $edit['autoassignrole_user_sort'] = 'SORT_ASC';
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_sort has set to SORT_ASC
    $this
      ->assertEqual(variable_get('autoassignrole_user_sort', -1), 'SORT_ASC', 'autoassignrole_user_selection has been set to SORT_ASC');

    // Set autoassignrole_user_sort to SORT_DESC.
    $edit['autoassignrole_user_sort'] = 'SORT_DESC';
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_sort has been set to 'SORT_DESC'
    $this
      ->assertEqual(variable_get('autoassignrole_user_sort', -1), 'SORT_DESC', 'autoassignrole_user_sort has been set to SORT_DESC');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_description.
   * @see http://drupal.org/node/945024
   */
  function testAdminUserDescriptionSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_description[value]', 'The autoassignrole_user_description field is accessible.');

    // Set autoassignrole_user_description to a random string.
    $random_string = $this
      ->randomName();
    $edit['autoassignrole_user_description[value]'] = $random_string;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_fieldset_title has been saved.
    $autoassignrole_user_description = _autoassignrole_get_user_description();
    $this
      ->assertEqual($autoassignrole_user_description['value'], $random_string, 'autoassignrole_user_description has been set to random string');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_selection.
   * @see http://drupal.org/node/945010
   */
  function testAdminUserFieldsetTitleSettings() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_fieldset_title', 'The autoassignrole_user_fieldset_title field is accessible.');

    // Set autoassignrole_user_fieldset_title to a random string.
    $random_string = $this
      ->randomName();
    $edit['autoassignrole_user_fieldset_title'] = $random_string;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_fieldset_title has been saved.
    $this
      ->assertEqual(variable_get('autoassignrole_user_fieldset_title', -1), $random_string, 'autoassignrole_user_fieldset_title has been set to random string');
  }

  /**
   * Test admin setting functionality for autoassignrole_user_title.
   * @see http://drupal.org/node/945016
   */
  function testAdminUserTitle() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin settings page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/user');
    $this
      ->assertField('autoassignrole_user_title', 'The autoassignrole_user_title field is accessible.');

    // Set autoassignrole_user_title to a random string.
    $random_string = $this
      ->randomName();
    $edit['autoassignrole_user_title'] = $random_string;
    $this
      ->drupalPost('admin/config/people/autoassignrole/user', $edit, t('Save configuration'));

    // Verify autoassignrole_user_title has been saved.
    $this
      ->assertEqual(variable_get('autoassignrole_user_title', -1), $random_string, 'autoassignrole_user_title has been set to random string');
  }

}
class AuthassignroleRolePerPathTestCase extends DrupalWebTestCase {
  protected $page_title;
  protected $page_path;

  /**
   * Helper method for creating a random AutoAssignRole page.
   */
  protected function createAarPage($specificRid = NULL) {

    // Check that the user can see the admin add page.
    $this
      ->drupalGet('admin/config/people/autoassignrole/pages/add');

    // Verify that there are roles exposed.
    $role_keys = array_values($this->roles);
    $this
      ->assertField('roles[' . $role_keys[0] . ']', 'Looking for the autoassignrole_auto_roles checkboxes.');

    // Verify that a checkbox for each of our valid roles shows on the page.
    foreach ($this->roles as $rid => $role) {

      // Only assign the specific rid to this page.
      if (!is_null($specificRid)) {
        if ($specificRid != $rid) {
          continue;
        }
      }
      $edit["roles[{$role}]"] = $role;
    }

    // Set the title.
    $this->page_title = $this
      ->randomName();
    $edit['title'] = $this->page_title;
    $edit['name'] = drupal_strtolower($this
      ->randomName());

    // Set the path.
    $edit['path'] = $this->page_path = 'test/register/' . $this->page_title;

    // Check each of our roles and submit the form.
    $this
      ->drupalPost('admin/config/people/autoassignrole/pages/add', $edit, t('Add'));

    // Verify the path has been saved.
    $this
      ->assertText('Successfully created page ' . $this->page_title . '.', 'Verified that path has been created.');
  }

}

/**
 * Extend the DrupalWebTestCase.
 */
class AutoassignroleAdminRolePerPageTestCase extends AuthassignroleRolePerPathTestCase {
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'Admin role by path',
      'description' => 'Tests the administrative setting for auto assign role role per page',
      'group' => 'Auto assign role',
    );
  }
  function setUp() {
    parent::setUp('autoassignrole');
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer autoassignrole',
      'access administration pages',
    ));
    $permissions = array(
      'access content',
    );
    $this
      ->drupalCreateRole($permissions);
    $this->roles = user_roles(TRUE);
    unset($this->roles[DRUPAL_AUTHENTICATED_RID]);
  }

  /**
   * Validate that the block for this functionality exists on
   * admin/config/people/autoassignrole.
   */
  function testAutoConfigAarBlock() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see a link to the auto settings.
    $this
      ->drupalGet('admin/config/people/autoassignrole');
    $this
      ->assertLink('Per Role Pages', 0, 'Allow user to define registration path to be assigned role(s) on admin/config/people/autoassignrole');
  }

  /**
   * Test admin functionality of creating a role per path.
   * @see https://www.drupal.org/node/971320
   */
  function testAutoRolePerPageAdd() {

    // Create a new user who can access the administration settings.
    $this
      ->drupalLogin($this->admin_user);

    // Check that the user can see the admin add page.
    $this
      ->createAarPage();

    // Click to edit this new path.
    $this
      ->clickLink(t('Edit'));

    // Verify the title has been saved correctly.
    $this
      ->assertFieldByName('title', $this->page_title, 'Role per path title has random string');
    $this
      ->assertFieldByName('path', 'test/register/' . $this->page_title, 'Role per path path is correct');

    // Go back to the list of AAR pages.
    $this
      ->drupalGet('admin/config/people/autoassignrole/pages');

    // Click to delete link.
    $this
      ->clickLink(t('Delete'));

    // Verify the delete confirmation message.
    $this
      ->assertText('Are you sure you want to delete the page ' . $this->page_title);
  }

}

/**
 * Extend the DrupalWebTestCase.
 */
class AutoassignroleUserCreationTestCase extends DrupalWebTestCase {
  protected $admin_user;
  protected $rid;
  protected $roles;
  protected $role;
  public static function getInfo() {
    return array(
      'name' => 'User creation',
      'description' => 'Tests the user creation functionality for auto assign role automatic assignment',
      'group' => 'Auto assign role',
    );
  }
  function setUp() {
    parent::setUp('autoassignrole');

    // Create a random role.
    $this->rid = $this
      ->drupalCreateRole(array(), $this
      ->randomName());
    $this->roles = user_roles(TRUE);
    $this->role = $this->roles[$this->rid];
    unset($this->roles[DRUPAL_AUTHENTICATED_RID]);
  }

  /**
   * Test functionality for programmatic user creation.
   * @see http://drupal.org/node/944864
   */
  function testUserCreateAPI() {

    // Enable auto role assignment.
    variable_set('autoassignrole_auto_active', 1);

    // Enable auto assignment for admin users.
    variable_set('autoassignrole_admin_active', 1);

    // Configure to assign our random role.
    variable_set('autoassignrole_auto_roles', array(
      $this->role => $this->role,
    ));

    // Create a test user.
    $this->test_user = $this
      ->drupalCreateUser();

    // Verify test user has been assigned role.
    $this
      ->assertTRUE(array_key_exists($this->rid, $this->test_user->roles), 'Programmatic creation of user is automatically assigned role');
  }

  /**
   * Test that auto roles are only assigned when they are enabled.
   * @see http://drupal.org/node/971622
   */
  function testUserAutoActiveAPI() {

    // Enable auto role assignment.
    variable_set('autoassignrole_auto_active', 0);

    // Configure to assign our random role.
    variable_set('autoassignrole_auto_roles', array(
      $this->role => $this->role,
    ));

    // Create a test user.
    $this->test_user = $this
      ->drupalCreateUser();

    // Verify test user has been assigned role.
    $this
      ->assertFALSE(array_key_exists($this->rid, $this->test_user->roles), 'User is not automatically assigned role when autoassignrole_auto_active is set to 0');
  }

}

/**
 * Extend the DrupalWebTestCase.
 */
class AutoassignroleUserCreationRolePerPathTestCase extends AuthassignroleRolePerPathTestCase {
  protected $rid;
  protected $roleName;
  protected $roles;
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'User creation by path',
      'description' => 'Tests the user creation functionality for auto assign role automatic assignment based upon a path',
      'group' => 'Auto assign role',
    );
  }
  function setUp() {
    parent::setUp('autoassignrole');
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer permissions',
      'administer users',
      'administer autoassignrole',
      'access administration pages',
    ));

    // Create a random role.
    $this->roleName = $this
      ->randomName();
    $this->rid = $this
      ->drupalCreateRole(array(), $this->roleName);
    $this->roles = user_roles(TRUE);
    unset($this->roles[DRUPAL_AUTHENTICATED_RID]);
  }

  /**
   * Test the user registration based on a path.
   * @see https://www.drupal.org/node/971320
   */
  function testUserAutoRegistrationByPath() {

    // enable clean urls.
    variable_set('clean_url', 1);

    // Login as the admin user.
    $this
      ->drupalLogin($this->admin_user);

    // Create the AAR registration page to assign to the new role.
    $this
      ->createAarPage($this->rid);

    // Logout as an admin.
    $this
      ->drupalLogout();

    // Register as a new user with the new path.
    $this
      ->drupalGet($this->page_path);

    // Fill in the register form.
    $testUserName = 'testUser-' . $this
      ->randomName();
    $form['name'] = $testUserName;
    $form['mail'] = 'test@test.com';

    // Check each of our roles and submit the form.
    $this
      ->drupalPost($this->page_path, $form, t('Create new account'));

    // Logout as user registered user.
    $this
      ->drupalLogout();

    // Login as admin user to check new users role.
    $this
      ->drupalLogin($this->admin_user);

    // Get the list of users.
    $this
      ->drupalGet('admin/people');

    // Get the user span details.
    $userSpans = $this
      ->xpath('//span[@class="username"]');
    $userUrl = '';
    foreach ($userSpans as $user) {
      if ($user[0] == $testUserName) {
        foreach ($user[0]
          ->attributes() as $key => $value) {
          if ($key == 'about') {
            $userUrl = $value;
            break;
          }
        }
      }
    }

    // Load the user to check their roles.
    preg_match('/\\/user\\/([0-9]+)/', $userUrl, $matches);
    $userId = $matches[1];
    $user = user_load($userId);
    $this
      ->assertTrue(isset($user->roles[$this->rid]), t('The user [@userId] has been assigned role: \'@roleName\' [@rid] (roles [@roles]).', array(
      '@userId' => $userId,
      '@roleName' => $this->roleName,
      '@rid' => $this->rid,
      '@roles' => print_r($user->roles, true),
    )));
  }

}

Classes

Namesort descending Description
AuthassignroleRolePerPathTestCase
AutoassignroleAdminAutoTestCase Extend the DrupalWebTestCase.
AutoassignroleAdminRolePerPageTestCase Extend the DrupalWebTestCase.
AutoassignroleAdminUserTestCase Extend the DrupalWebTestCase.
AutoassignroleUserCreationRolePerPathTestCase Extend the DrupalWebTestCase.
AutoassignroleUserCreationTestCase Extend the DrupalWebTestCase.