You are here

function DrupalTestCase::drupalCreateUserRolePerm in SimpleTest 5

Same name and namespace in other branches
  1. 6 drupal_test_case.php \DrupalTestCase::drupalCreateUserRolePerm()

Creates a user / role / permissions combination specified by permissions

Parameters

array $permissions Array of the permission strings:

Return value

array/boolean false if fails. fully loaded user object with added pass_raw property

11 calls to DrupalTestCase::drupalCreateUserRolePerm()
DrupalTestCase::drupalLoginUser in ./drupal_test_case.php
Logs in a user with the internal browser
ImageModuleTest::testImageNode in tests/image_module.test
PageCreationTest::testPageCreation in tests/page_creation.test
PageViewTest::testPageView in tests/page_view.test
TaxonomyTestNodeApi::testTaxonomyNode in tests/taxonomy.module.test

... See full list

File

./drupal_test_case.php, line 280

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function drupalCreateUserRolePerm($permissions = NULL) {

  /* Create role */
  $rid = $this
    ->drupalCreateRolePerm($permissions);
  if (!$rid) {
    return FALSE;
  }

  /* Create user */
  $ua = array();
  $ua['name'] = $this
    ->randomName();
  $ua['mail'] = $ua['name'] . '@example.com';
  $ua['roles'] = array(
    $rid => $rid,
  );
  $ua['pass'] = user_password();
  $ua['status'] = 1;
  $u = user_save('', $ua);
  $this
    ->assertTrue(!empty($u->uid), " [user] name: {$ua['name']} pass: {$ua['pass']} created");
  if (empty($u->uid)) {
    return FALSE;
  }

  /* Add to cleanup list */
  $this->_cleanupUsers[] = $u->uid;

  /* Add the raw password */
  $u->pass_raw = $ua['pass'];
  return $u;
}