diff core/modules/statistics/tests/src/Functional/StatisticsAttachedTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/modules/statistics/tests/src/Functional/StatisticsAttachedTest.php	Wed Nov 29 16:09:58 2017 +0000
@@ -0,0 +1,57 @@
+<?php
+
+namespace Drupal\Tests\statistics\Functional;
+
+use Drupal\Tests\BrowserTestBase;
+use Drupal\node\Entity\Node;
+
+/**
+ * Tests if statistics.js is loaded when content is not printed.
+ *
+ * @group statistics
+ */
+class StatisticsAttachedTest extends BrowserTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['node', 'statistics'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->drupalCreateContentType(['type' => 'page']);
+
+    // Install "statistics_test_attached" and set it as the default theme.
+    $theme = 'statistics_test_attached';
+    \Drupal::service('theme_handler')->install([$theme]);
+    $this->config('system.theme')
+      ->set('default', $theme)
+      ->save();
+    // Installing a theme will cause the kernel terminate event to rebuild the
+    // router. Simulate that here.
+    \Drupal::service('router.builder')->rebuildIfNeeded();
+  }
+
+  /**
+   * Tests if statistics.js is loaded when content is not printed.
+   */
+  public function testAttached() {
+
+    $node = Node::create([
+      'type' => 'page',
+      'title' => 'Page node',
+      'body' => 'body text'
+    ]);
+    $node->save();
+    $this->drupalGet('node/' . $node->id());
+
+    $this->assertRaw('core/modules/statistics/statistics.js', 'Statistics library is available');
+  }
+
+}