You are here

protected function StatisticsLoggingTest::setUp in Drupal 9

Same name in this branch
  1. 9 core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php \Drupal\Tests\statistics\Functional\StatisticsLoggingTest::setUp()
  2. 9 core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php \Drupal\Tests\statistics\Functional\StatisticsLoggingTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php, line 52

Class

StatisticsLoggingTest
Tests request logging for cached and uncached pages.

Namespace

Drupal\Tests\statistics\Functional

Code

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

  // Create Basic page node type.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType([
      'type' => 'page',
      'name' => 'Basic page',
    ]);
  }
  $this->authUser = $this
    ->drupalCreateUser([
    // For node creation.
    'access content',
    'create page content',
    'edit own page content',
    // For language negotiation administration.
    'administer languages',
    'access administration pages',
  ]);

  // Ensure we have a node page to access.
  $this->node = $this
    ->drupalCreateNode([
    'title' => $this
      ->randomMachineName(255),
    'uid' => $this->authUser
      ->id(),
  ]);

  // Add a custom language and enable path-based language negotiation.
  $this
    ->drupalLogin($this->authUser);
  $this->language = [
    'predefined_langcode' => 'custom',
    'langcode' => 'xx',
    'label' => $this
      ->randomMachineName(16),
    'direction' => 'ltr',
  ];
  $this
    ->drupalGet('admin/config/regional/language/add');
  $this
    ->submitForm($this->language, 'Add custom language');
  $this
    ->drupalGet('admin/config/regional/language/detection');
  $this
    ->submitForm([
    'language_interface[enabled][language-url]' => 1,
  ], 'Save settings');
  $this
    ->drupalLogout();

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

  // Clear the logs.
  Database::getConnection()
    ->truncate('node_counter');
  $this->client = \Drupal::httpClient();
}