/**
  * Verifies node hit counter logging and script placement.
  */
 function testLogging()
 {
     global $base_url;
     $path = 'node/' . $this->node->id();
     $module_path = drupal_get_path('module', 'statistics');
     $stats_path = $base_url . '/' . $module_path . '/statistics.php';
     $expected_library = $module_path . '/statistics.js';
     $expected_settings = '"statistics":{"data":{"nid":"' . $this->node->id() . '"}';
     // Verify that logging scripts are not found on a non-node page.
     $this->drupalGet('node');
     $this->assertNoRaw($expected_library, 'Statistics library JS not found on node page.');
     $this->assertNoRaw($expected_settings, 'Statistics settings not found on node page.');
     // Verify that logging scripts are not found on a non-existent node page.
     $this->drupalGet('node/9999');
     $this->assertNoRaw($expected_library, 'Statistics library JS not found on non-existent node page.');
     $this->assertNoRaw($expected_settings, 'Statistics settings not found on non-existent node page.');
     // Verify that logging scripts are found on a valid node page.
     $this->drupalGet($path);
     $this->assertRaw($expected_library, 'Found statistics library JS on node page.');
     $this->assertRaw($expected_settings, 'Found statistics settings on node page.');
     // Manually call statistics.php to simulate ajax data collection behavior.
     $nid = $this->node->id();
     $post = array('nid' => $nid);
     $this->client->post($stats_path, array('form_params' => $post));
     $node_counter = statistics_get($this->node->id());
     $this->assertIdentical($node_counter['totalcount'], '1');
 }
Beispiel #2
0
 public function post(RequestEntityInterface $entity)
 {
     try {
         $response = $this->client->post($this->buildUrl($entity), ['headers' => $entity->getHeaders(), 'body' => $entity->getBody()]);
     } catch (ClientException $e) {
         $response = $e->getResponse();
     }
     return $this->handleResponse($response);
 }
 /**
  * Verifies node hit counter logging and script placement.
  */
 function testLogging()
 {
     $path = 'node/' . $this->node->id();
     $module_path = drupal_get_path('module', 'statistics');
     $stats_path = base_path() . $module_path . '/statistics.php';
     $lib_path = base_path() . $module_path . '/statistics.js';
     $expected_library = '/<script src=".*?' . preg_quote($lib_path, '/.') . '.*?">/is';
     // Verify that logging scripts are not found on a non-node page.
     $this->drupalGet('node');
     $settings = $this->getDrupalSettings();
     $this->assertNoPattern($expected_library, 'Statistics library JS not found on node page.');
     $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.');
     // Verify that logging scripts are not found on a non-existent node page.
     $this->drupalGet('node/9999');
     $settings = $this->getDrupalSettings();
     $this->assertNoPattern($expected_library, 'Statistics library JS not found on non-existent node page.');
     $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.');
     // Verify that logging scripts are found on a valid node page.
     $this->drupalGet($path);
     $settings = $this->getDrupalSettings();
     $this->assertPattern($expected_library, 'Found statistics library JS on node page.');
     $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on node page.');
     // Verify the same when loading the site in a non-default language.
     $this->drupalGet($this->language['langcode'] . '/' . $path);
     $settings = $this->getDrupalSettings();
     $this->assertPattern($expected_library, 'Found statistics library JS on a valid node page in a non-default language.');
     $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on valid node page in a non-default language.');
     // Manually call statistics.php to simulate ajax data collection behavior.
     global $base_root;
     $post = array('nid' => $this->node->id());
     $this->client->post($base_root . $stats_path, array('form_params' => $post));
     $node_counter = statistics_get($this->node->id());
     $this->assertIdentical($node_counter['totalcount'], '1');
 }
Beispiel #4
0
 /**
  * Tests that cron clears day counts and expired access logs.
  */
 function testExpiredLogs()
 {
     $this->config('statistics.settings')->set('count_content_views', 1)->save();
     \Drupal::state()->set('statistics.day_timestamp', 8640000);
     $this->drupalGet('node/' . $this->testNode->id());
     // Manually calling statistics.php, simulating ajax behavior.
     $nid = $this->testNode->id();
     $post = array('nid' => $nid);
     global $base_url;
     $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
     $this->client->post($stats_path, array('form_params' => $post));
     $this->drupalGet('node/' . $this->testNode->id());
     $this->client->post($stats_path, array('form_params' => $post));
     $this->assertText('1 view', 'Node is viewed once.');
     // 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->testNode->id(), 'No hit URL found.');
     $result = db_select('node_counter', 'nc')->fields('nc', array('daycount'))->condition('nid', $this->testNode->id(), '=')->execute()->fetchField();
     $this->assertFalse($result, 'Daycounter is zero.');
 }