function StatisticsLoggingTest::setUp

Same name in this branch
  1. 10 core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
Same name and namespace in other branches
  1. 9 core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
  2. 9 core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php \Drupal\Tests\statistics\Functional\StatisticsLoggingTest::setUp()
  3. 8.9.x core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
  4. 8.9.x core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php \Drupal\Tests\statistics\Functional\StatisticsLoggingTest::setUp()
  5. 11.x core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
  6. 11.x 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 64

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();
  $this->client = \Drupal::httpClient();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.