public function PatternsShortcutTestCase::setUp in Patterns 7
Same name and namespace in other branches
- 7.2 tests/shortcut/shortcut.test \PatternsShortcutTestCase::setUp()
Setups the testing environment.
Loads the patterns and libraries modules plus all those that are passed as parameters; skips the Patterns splash screen.
Parameters
array $user_modules The array of modules to enable:
bool $first (optional) If TRUE, the Patterns splash: screen is not skipped.
Overrides PatternsTestCase::setUp
File
- tests/shortcut/ shortcut.test, line 20 
- SimpleTests for the Shortcut component of Patterns.
Class
- PatternsShortcutTestCase
- @file SimpleTests for the Shortcut component of Patterns.
Code
public function setUp($modules = array(), $first = FALSE) {
  $this->shortcut_tests_dir = $this
    ->getPatternsTestDir() . 'shortcut/';
  // Enable any modules required for the tests.
  $modules = array(
    'patterns_components',
    'patterns_yamlparser',
  );
  parent::setUp($modules);
  // Create a role with the given permission set, if any.
  $rid = FALSE;
  $permissions = array(
    'administer site configuration',
    'access administration pages',
    'administer patterns',
    'administer shortcuts',
    'switch shortcut sets',
    'customize shortcut links',
  );
  if ($permissions) {
    $rid = $this
      ->drupalCreateRole($permissions);
    if (!$rid) {
      return FALSE;
    }
  }
  // Create a user assigned to that role.
  $edit = array();
  $edit['name'] = 'someone';
  $edit['mail'] = $edit['name'] . '@example.com';
  $edit['pass'] = user_password();
  $edit['status'] = 1;
  if ($rid) {
    $edit['roles'] = array(
      $rid => $rid,
    );
  }
  $account = user_save(drupal_anonymous_user(), $edit);
  $this
    ->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array(
    '%name' => $edit['name'],
    '%pass' => $edit['pass'],
  )), t('User login'));
  if (empty($account->uid)) {
    return FALSE;
  }
  // Add the raw password so that we can log in as this user.
  $account->pass_raw = $edit['pass'];
  $this->admin_user = $account;
  // "someone" login
  $this
    ->drupalLogin($this->admin_user);
}