Chris@0: webUser = $this->drupalCreateUser(['access content', 'view post access counter']); Chris@0: Chris@0: // Create a new user for viewing nodes only. Chris@0: $this->deniedUser = $this->drupalCreateUser(['access content']); Chris@0: Chris@0: $this->drupalCreateContentType(['type' => 'page']); Chris@0: $this->node = $this->drupalCreateNode(['type' => 'page']); Chris@0: Chris@0: // Enable counting of content views. Chris@0: $this->config('statistics.settings') Chris@0: ->set('count_content_views', 1) Chris@0: ->save(); Chris@0: Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the integration of the {node_counter} table in views. Chris@0: */ Chris@0: public function testNodeCounterIntegration() { Chris@0: $this->drupalLogin($this->webUser); Chris@0: Chris@0: $this->drupalGet('node/' . $this->node->id()); Chris@0: // Manually calling statistics.php, simulating ajax behavior. Chris@0: // @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging(). 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, ['form_params' => ['nid' => $this->node->id()]]); Chris@0: $this->drupalGet('test_statistics_integration'); Chris@0: Chris@0: $expected = statistics_get($this->node->id()); Chris@0: // Convert the timestamp to year, to match the expected output of the date Chris@0: // handler. Chris@0: $expected['timestamp'] = date('Y', $expected['timestamp']); Chris@0: Chris@0: foreach ($expected as $field => $value) { Chris@0: $xpath = "//div[contains(@class, views-field-$field)]/span[@class = 'field-content']"; Chris@0: $this->assertFieldByXpath($xpath, $value, "The $field output matches the expected."); Chris@0: } Chris@0: Chris@0: $this->drupalLogout(); Chris@0: $this->drupalLogin($this->deniedUser); Chris@0: $this->drupalGet('test_statistics_integration'); Chris@0: $this->assertResponse(200); Chris@0: Chris@0: foreach ($expected as $field => $value) { Chris@0: $xpath = "//div[contains(@class, views-field-$field)]/span[@class = 'field-content']"; Chris@0: $this->assertNoFieldByXpath($xpath, $value, "The $field output is not displayed."); Chris@0: } Chris@0: Chris@0: } Chris@0: Chris@0: }