function StatisticsTestCase::setUp

7.x statistics.test StatisticsTestCase::setUp()

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

drupal-7.x/modules/statistics/statistics.test, line 13
Tests for the Statistics module.

Class

StatisticsTestCase
Defines a base class for testing the Statistics module.

Code

function setUp() {
  parent::setUp('statistics');

  // Create user.
  $this->blocking_user = $this->drupalCreateUser(array(
    'access administration pages',
    'access site reports',
    'access statistics',
    'block IP addresses',
    'administer blocks',
    'administer statistics',
    'administer users',
  ));
  $this->drupalLogin($this->blocking_user);

  // Enable access logging.
  variable_set('statistics_enable_access_log', 1);
  variable_set('statistics_count_content_views', 1);

  // Insert dummy access by anonymous user into access log.
  db_insert('accesslog')
    ->fields(array(
      'title' => 'test',
      'path' => 'node/1',
      'url' => 'http://example.com',
      'hostname' => '192.168.1.1',
      'uid' => 0,
      'sid' => 10,
      'timer' => 10,
      'timestamp' => REQUEST_TIME,
    ))
    ->execute();
}