function StatisticsLoggingTest::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 Drupal\simpletest\WebTestBase::$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 WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php, line 43
Definition of Drupal\statistics\Tests\StatisticsLoggingTest.

Class

StatisticsLoggingTest
Tests that logging via statistics_exit() works for all pages.

Namespace

Drupal\statistics\Tests

Code

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

  // Create Basic page node type.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType(array(
      'type' => 'page',
      'name' => 'Basic page',
    ));
  }
  $this->auth_user = $this
    ->drupalCreateUser(array(
    'access content',
    'create page content',
    'edit own page content',
  ));

  // Ensure we have a node page to access.
  $this->node = $this
    ->drupalCreateNode(array(
    'title' => $this
      ->randomName(255),
    'uid' => $this->auth_user->uid,
  ));

  // Enable page caching.
  $config = config('system.performance');
  $config
    ->set('cache.page.use_internal', 1);
  $config
    ->set('cache.page.max_age', 300);
  $config
    ->save();

  // Enable access logging.
  config('statistics.settings')
    ->set('count_content_views', 1)
    ->save();

  // Clear the logs.
  db_truncate('node_counter');
  $this->client = \Drupal::httpClient();
  $this->client
    ->setConfig(array(
    'curl.options' => array(
      CURLOPT_TIMEOUT => 10,
    ),
  ));
}