public function IntegrationTest::testNodeCounterIntegration in Drupal 9
Same name and namespace in other branches
- 8 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 77
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:');
}