X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fstatistics%2Ftests%2Fsrc%2FFunctional%2FViews%2FIntegrationTest.php;fp=web%2Fcore%2Fmodules%2Fstatistics%2Ftests%2Fsrc%2FFunctional%2FViews%2FIntegrationTest.php;h=56e18eefad4bbef28667e4435d12ed248d05ceca;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php b/web/core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php new file mode 100644 index 000000000..56e18eefa --- /dev/null +++ b/web/core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php @@ -0,0 +1,103 @@ +webUser = $this->drupalCreateUser(['access content', 'view post access counter']); + + // Create a new user for viewing nodes only. + $this->deniedUser = $this->drupalCreateUser(['access content']); + + $this->drupalCreateContentType(['type' => 'page']); + $this->node = $this->drupalCreateNode(['type' => 'page']); + + // Enable counting of content views. + $this->config('statistics.settings') + ->set('count_content_views', 1) + ->save(); + + } + + /** + * Tests the integration of the {node_counter} table in views. + */ + public function testNodeCounterIntegration() { + $this->drupalLogin($this->webUser); + + $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 = $this->getHttpClient(); + $client->post($stats_path, ['form_params' => ['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."); + } + + $this->drupalLogout(); + $this->drupalLogin($this->deniedUser); + $this->drupalGet('test_statistics_integration'); + $this->assertResponse(200); + + foreach ($expected as $field => $value) { + $xpath = "//div[contains(@class, views-field-$field)]/span[@class = 'field-content']"; + $this->assertNoFieldByXpath($xpath, $value, "The $field output is not displayed."); + } + + } + +}