You are here

public function AuthcacheWebTestCase::setUp in Authenticated User Page Caching (Authcache) 7.2

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

./authcache.test, line 22
Tests for system.module.

Class

AuthcacheWebTestCase
Helper class for module test cases.

Code

public function setUp() {
  parent::setUp('authcache', 'authcache_test', 'authcache_backend_test');
  if ($this->profile !== 'standard') {
    $this
      ->drupalCreateContentType(array(
      'type' => 'page',
      'name' => 'Basic page',
    ));
  }

  // Plain user only has the authenticated user role.
  $this->plainUser = $this
    ->drupalCreateUser();

  // Web user has one additional role.
  $this->webUser = $this
    ->drupalCreateUser(array(
    'edit own page content',
    'create page content',
  ));

  // Admin user also has one additional role.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'bypass node access',
    'administer nodes',
  ));

  // Update uid 1's name and password to we know it.
  $password = user_password();
  require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
  $account = array(
    'name' => 'user1',
    'pass' => user_hash_password(trim($password)),
  );

  // We cannot use user_save() here or the password would be hashed again.
  db_update('users')
    ->fields($account)
    ->condition('uid', 1)
    ->execute();

  // Store.
  $this->superUser = user_load(1, TRUE);
  $this->superUser->pass_raw = $password;

  // HookStub.
  $this->stubmod = new ModuleStub('authcache_test');
  $this->stubbackend = new ModuleStub('authcache_backend_test');
}