Chris@0: getCurrentLanguage(); Chris@0: Chris@0: // Create user and node. Chris@0: $user = $this->drupalCreateUser(['create page content']); Chris@0: $this->drupalLogin($user); Chris@0: $node = $this->drupalCreateNode(['type' => 'page', 'uid' => $user->id()]); Chris@0: Chris@0: // Hit the node. Chris@0: $this->drupalGet('node/' . $node->id()); Chris@0: // Manually calling statistics.php, simulating ajax behavior. Chris@0: $nid = $node->id(); Chris@0: $post = http_build_query(['nid' => $nid]); Chris@0: $headers = ['Content-Type' => 'application/x-www-form-urlencoded']; Chris@0: global $base_url; Chris@0: $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; Chris@0: $client = \Drupal::httpClient(); Chris@0: $client->post($stats_path, ['headers' => $headers, 'body' => $post]); Chris@0: $statistics = statistics_get($node->id()); Chris@0: Chris@0: // Generate and test tokens. Chris@0: $tests = []; Chris@0: $tests['[node:total-count]'] = 1; Chris@0: $tests['[node:day-count]'] = 1; Chris@18: /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */ Chris@18: $date_formatter = $this->container->get('date.formatter'); Chris@18: $tests['[node:last-view]'] = $date_formatter->format($statistics['timestamp']); Chris@18: $tests['[node:last-view:short]'] = $date_formatter->format($statistics['timestamp'], 'short'); Chris@0: Chris@0: // Test to make sure that we generated something for each token. Chris@0: $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); Chris@0: Chris@0: foreach ($tests as $input => $expected) { Chris@0: $output = \Drupal::token()->replace($input, ['node' => $node], ['langcode' => $language_interface->getId()]); Chris@0: $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', ['%token' => $input])); Chris@0: } Chris@0: } Chris@0: Chris@0: }