Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\statistics\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6 use Drupal\node\Entity\Node;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests if statistics.js is loaded when content is not printed.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group statistics
|
Chris@0
|
12 */
|
Chris@0
|
13 class StatisticsAttachedTest extends BrowserTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Modules to enable.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var array
|
Chris@0
|
19 */
|
Chris@0
|
20 public static $modules = ['node', 'statistics'];
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * {@inheritdoc}
|
Chris@0
|
24 */
|
Chris@0
|
25 protected function setUp() {
|
Chris@0
|
26 parent::setUp();
|
Chris@0
|
27
|
Chris@0
|
28 $this->drupalCreateContentType(['type' => 'page']);
|
Chris@0
|
29
|
Chris@0
|
30 // Install "statistics_test_attached" and set it as the default theme.
|
Chris@0
|
31 $theme = 'statistics_test_attached';
|
Chris@0
|
32 \Drupal::service('theme_handler')->install([$theme]);
|
Chris@0
|
33 $this->config('system.theme')
|
Chris@0
|
34 ->set('default', $theme)
|
Chris@0
|
35 ->save();
|
Chris@0
|
36 // Installing a theme will cause the kernel terminate event to rebuild the
|
Chris@0
|
37 // router. Simulate that here.
|
Chris@0
|
38 \Drupal::service('router.builder')->rebuildIfNeeded();
|
Chris@0
|
39 }
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * Tests if statistics.js is loaded when content is not printed.
|
Chris@0
|
43 */
|
Chris@0
|
44 public function testAttached() {
|
Chris@0
|
45
|
Chris@0
|
46 $node = Node::create([
|
Chris@0
|
47 'type' => 'page',
|
Chris@0
|
48 'title' => 'Page node',
|
Chris@0
|
49 'body' => 'body text'
|
Chris@0
|
50 ]);
|
Chris@0
|
51 $node->save();
|
Chris@0
|
52 $this->drupalGet('node/' . $node->id());
|
Chris@0
|
53
|
Chris@0
|
54 $this->assertRaw('core/modules/statistics/statistics.js', 'Statistics library is available');
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 }
|