diff --git a/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php b/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php new file mode 100644 index 0000000..128d2db --- /dev/null +++ b/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php @@ -0,0 +1,77 @@ +config('statistics.settings') + ->set('count_content_views', 1) + ->save(); + + Role::load(AccountInterface::ANONYMOUS_ROLE) + ->grantPermission('view post access counter') + ->save(); + + $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); + $this->node = $this->drupalCreateNode(['title' => 'test']); + } + + /** + * Tests that statistics with/without "index.php" prefix. + * + * @dataProvider providerTestLoggingPage + */ + public function testLoggingPage($path) { + $page = $this->getSession()->getPage(); + + $this->drupalGet($path); + // During the first load there are no statistics yet. + $this->assertNotContains('1 view', $page->getContent()); + // Wait while statistics module send ajax request. + $this->assertSession()->assertWaitOnAjaxRequest(); + // Resaving the node to call the hook_node_links_alter(), which is used to + // update information on the page. See statistics_node_links_alter(). + $this->node->save(); + + $this->drupalGet($path); + $this->assertContains('1 view', $page->getContent()); + } + + /** + * Data provider for testLoggingPage(). + */ + public function providerTestLoggingPage() { + return [ + ["node/1"], + ["index.php/node/1"], + ]; + } + +}