You are here

public function AuthcacheFlagTest::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

modules/authcache_flag/authcache_flag.test, line 35
Test cases for the Authcache Flag module.

Class

AuthcacheFlagTest
Tests for markup substitution.

Code

public function setUp() {
  parent::setUp(array(
    'authcache_flag',
    'authcache_p13n_test',
  ));
  $node_flag_data = array(
    'entity_type' => 'node',
    'name' => 'test_node_flag',
    'title' => 'Test Flag',
    'global' => 0,
    'types' => array(
      0 => 'article',
    ),
    'flag_short' => 'Flag this item',
    'flag_long' => '',
    'flag_message' => '',
    'unflag_short' => 'Unflag this item',
    'unflag_long' => '',
    'unflag_message' => '',
    'unflag_denied_text' => 'You may not unflag this item',
    'link_type' => 'normal',
    'weight' => 0,
    'show_as_field' => 0,
    'show_on_form' => 0,
    'access_author' => '',
    'show_contextual_link' => 0,
    'show_in_links' => array(
      'full' => 1,
      'teaser' => 1,
    ),
    'i18n' => 0,
    'api_version' => 3,
  );
  $this->nodeFlag = $this
    ->createFlag($node_flag_data);
  $user_flag_data = array(
    'entity_type' => 'user',
    'name' => 'test_user_flag',
    'title' => 'Test Flag',
    'global' => 0,
    'types' => array(
      0 => 'user',
    ),
    'flag_short' => 'Flag this item',
    'flag_long' => '',
    'flag_message' => '',
    'unflag_short' => 'Unflag this item',
    'unflag_long' => '',
    'unflag_message' => '',
    'unflag_denied_text' => 'You may not unflag this item',
    'link_type' => 'normal',
    'weight' => 0,
    'show_as_field' => 0,
    'show_on_form' => 0,
    'show_on_profile' => 0,
    'access_author' => '',
    'show_contextual_link' => 0,
    'show_in_links' => array(
      'full' => 1,
      'teaser' => 1,
    ),
    'i18n' => 0,
    'api_version' => 3,
  );
  $this->userFlag = $this
    ->createFlag($user_flag_data);
  $taxonomy_term_flag_data = array(
    'entity_type' => 'taxonomy_term',
    'name' => 'test_taxonomy_term_flag',
    'title' => 'Test Flag',
    'global' => 0,
    'types' => array(
      0 => 'tags',
    ),
    'flag_short' => 'Flag this item',
    'flag_long' => '',
    'flag_message' => '',
    'unflag_short' => 'Unflag this item',
    'unflag_long' => '',
    'unflag_message' => '',
    'unflag_denied_text' => 'You may not unflag this item',
    'link_type' => 'normal',
    'weight' => 0,
    'show_as_field' => 0,
    'show_on_form' => 0,
    'access_author' => '',
    'show_contextual_link' => 0,
    'show_in_links' => array(
      'full' => 1,
      'teaser' => 1,
    ),
    'i18n' => 0,
    'api_version' => 3,
  );
  $this->termFlag = $this
    ->createFlag($taxonomy_term_flag_data);

  // Create test user who can flag and unflag.
  $this->member1 = $this
    ->drupalCreateUser(array(
    'flag test_node_flag',
    'flag test_user_flag',
    'flag test_taxonomy_term_flag',
    'access user profiles',
  ));
  $this->member2 = $this
    ->drupalCreateUser(array(
    'flag test_node_flag',
    'unflag test_node_flag',
    'flag test_user_flag',
    'unflag test_user_flag',
    'flag test_taxonomy_term_flag',
    'unflag test_taxonomy_term_flag',
    'access user profiles',
  ));
  $this->editor = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer flags',
  ));
  $this->node1 = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'promote' => 1,
    'uid' => $this->editor->uid,
  ));
  $this->node2 = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'promote' => 1,
    'uid' => $this->editor->uid,
  ));

  // Add taxonomy term.
  $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
  $this->term = $this
    ->createTerm($vocabulary);
  $authcache_roles = array(
    DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
    DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
  ) + $this->member1->roles + $this->member2->roles + $this->editor->roles;

  // Setup authcache.
  variable_set('authcache_roles', $authcache_roles);
  $pagecaching = _authcache_default_pagecaching();
  $pagecaching[0]['roles']['roles'] = $authcache_roles;
  $pagecaching[0]['pages'] = '';
  variable_set('authcache_pagecaching', $pagecaching);

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