You are here

public function IntegrationTest::testNodeCounterIntegration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/statistics/src/Tests/Views/IntegrationTest.php \Drupal\statistics\Tests\Views\IntegrationTest::testNodeCounterIntegration()

Tests the integration of the {node_counter} table in views.

File

core/modules/statistics/src/Tests/Views/IntegrationTest.php, line 73
Contains \Drupal\statistics\Tests\Views\IntegrationTest.

Class

IntegrationTest
Tests basic integration of views data from the statistics module.

Namespace

Drupal\statistics\Tests\Views

Code

public function testNodeCounterIntegration() {
  $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 . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
  $client = \Drupal::service('http_client_factory')
    ->fromOptions([
    'config/curl',
    array(
      CURLOPT_TIMEOUT => 10,
    ),
  ]);
  $client
    ->post($stats_path, array(
    'form_params' => array(
      'nid' => $this->node
        ->id(),
    ),
  ));
  $this
    ->drupalGet('test_statistics_integration');
  $expected = statistics_get($this->node
    ->id());

  // Convert the timestamp to year, to match the expected output of the date
  // handler.
  $expected['timestamp'] = date('Y', $expected['timestamp']);
  foreach ($expected as $field => $value) {
    $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']";
    $this
      ->assertFieldByXpath($xpath, $value, "The {$field} output matches the expected.");
  }
}