function IntegrationTest::testNodeCounterIntegration
Same name in other branches
- 9 core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php \Drupal\Tests\statistics\Functional\Views\IntegrationTest::testNodeCounterIntegration()
- 8.9.x core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php \Drupal\Tests\statistics\Functional\Views\IntegrationTest::testNodeCounterIntegration()
- 10 core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php \Drupal\Tests\statistics\Functional\Views\IntegrationTest::testNodeCounterIntegration()
Tests the integration of the {node_counter} table in views.
File
-
core/
modules/ statistics/ tests/ src/ Functional/ Views/ IntegrationTest.php, line 87
Class
- IntegrationTest
- Tests basic integration of views data from the statistics module.
Namespace
Drupal\Tests\statistics\Functional\ViewsCode
public function testNodeCounterIntegration() {
$this->drupalLogin($this->webUser);
$this->drupalGet('node/' . $this->node
->id());
// Manually calling statistics.php, simulating ajax behavior.
// @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging().
global $base_url;
$stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
$client = $this->getHttpClient();
$client->post($stats_path, [
'form_params' => [
'nid' => $this->node
->id(),
],
]);
$this->drupalGet('test_statistics_integration');
/** @var \Drupal\statistics\StatisticsViewsResult $statistics */
$statistics = \Drupal::service('statistics.storage.node')->fetchView($this->node
->id());
$this->assertSession()
->pageTextContains('Total views: 1');
$this->assertSession()
->pageTextContains('Views today: 1');
$this->assertSession()
->pageTextContains('Most recent view: ' . date('Y', $statistics->getTimestamp()));
$this->drupalLogout();
$this->drupalLogin($this->deniedUser);
$this->drupalGet('test_statistics_integration');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextNotContains('Total views:');
$this->assertSession()
->pageTextNotContains('Views today:');
$this->assertSession()
->pageTextNotContains('Most recent view:');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.