You are here

public function NodeViewCountBaseFunctionalityTest::testExpiredLogs in Node view count 8

Tests that cron clears old nodeviewcount records.

File

src/Tests/NodeViewCountBaseFunctionalityTest.php, line 31

Class

NodeViewCountBaseFunctionalityTest
Tests the base functionality of nodeviewcount module.

Namespace

Drupal\nodeviewcount\Tests

Code

public function testExpiredLogs() {
  $this
    ->sendAjaxStatistics($this->firstTestTrackedNode
    ->id(), 0);
  $this
    ->sendAjaxStatistics($this->secondTestTrackedNode
    ->id(), 0);
  sleep(2);
  $this
    ->cronRun();
  $query = $this->connection
    ->select('nodeviewcount', 'nvc')
    ->fields('nvc', [
    'id',
  ]);
  $result = $query
    ->execute()
    ->fetchAll();
  $this
    ->assertEqual(count($result), 2, ' Nodeviewcount statistics is not deleted after cron run.');
  $node_view_count_settings = $this
    ->config('nodeviewcount.settings');
  $node_view_count_settings
    ->set('logs_life_time', 1)
    ->save();
  sleep(2);
  $this
    ->cronRun();
  $result = $query
    ->execute()
    ->fetchAll();
  $this
    ->assertEqual(count($result), 0, ' Nodeviewcount statistics is deleted after cron run.');
}