function StatisticsLoggingTest::setUp

Same name in this branch
  1. 8.9.x core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
Same name 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. 10 core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php \Drupal\Tests\statistics\FunctionalJavascript\StatisticsLoggingTest::setUp()
  4. 10 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 52

Class

StatisticsLoggingTest
Tests request logging for cached and uncached pages.

Namespace

Drupal\Tests\statistics\Functional

Code

protected function setUp() {
    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->drupalPostForm('admin/config/regional/language/add', $this->language, t('Add custom language'));
    $this->drupalPostForm('admin/config/regional/language/detection', [
        'language_interface[enabled][language-url]' => 1,
    ], t('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();
}

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