StatisticsTestBase.php

Definition of Drupal\statistics\Tests\StatisticsTestBase.

Namespace

Drupal\statistics\Tests

File

drupal/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php
View source
<?php

/**
 * @file
 * Definition of Drupal\statistics\Tests\StatisticsTestBase.
 */
namespace Drupal\statistics\Tests;

use Drupal\simpletest\WebTestBase;

/**
 * Defines a base class for testing the Statistics module.
 */
abstract class StatisticsTestBase extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array(
    'node',
    'block',
    'ban',
    'statistics',
  );
  function setUp() {
    parent::setUp();

    // Create Basic page node type.
    if ($this->profile != 'standard') {
      $this
        ->drupalCreateContentType(array(
        'type' => 'page',
        'name' => 'Basic page',
      ));
    }

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

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

    // 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();
  }

}

Classes

Namesort descending Description
StatisticsTestBase Defines a base class for testing the Statistics module.