Tests that cron clears day counts and expired access logs.
function testExpiredLogs() {
config('statistics.settings')
->set('access_log.enabled', 1)
->set('count_content_views', 1)
->set('access_log.max_lifetime', 1)
->save();
state()
->set('statistics.day_timestamp', 8640000);
$this
->drupalGet('node/' . $this->test_node->nid);
// Manually calling statistics.php, simulating ajax behavior.
$nid = $this->test_node->nid;
$post = http_build_query(array(
'nid' => $nid,
));
$headers = array(
'Content-Type' => 'application/x-www-form-urlencoded',
);
global $base_url;
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
drupal_http_request($stats_path, array(
'method' => 'POST',
'data' => $post,
'headers' => $headers,
'timeout' => 10000,
));
$this
->drupalGet('node/' . $this->test_node->nid);
drupal_http_request($stats_path, array(
'method' => 'POST',
'data' => $post,
'headers' => $headers,
'timeout' => 10000,
));
$this
->assertText('1 view', 'Node is viewed once.');
$this
->drupalGet('admin/reports/pages');
$this
->assertText('node/' . $this->test_node->nid, 'Hit URL found.');
// statistics_cron() will subtract
// statistics.settings:accesslog.max_lifetime config from REQUEST_TIME in
// the delete query, so wait two secs here to make sure the access log will
// be flushed for the node just hit.
sleep(2);
$this
->cronRun();
$this
->drupalGet('admin/reports/pages');
$this
->assertNoText('node/' . $this->test_node->nid, 'No hit URL found.');
$result = db_select('node_counter', 'nc')
->fields('nc', array(
'daycount',
))
->condition('nid', $this->test_node->nid, '=')
->execute()
->fetchField();
$this
->assertFalse($result, 'Daycounter is zero.');
}