comparison core/modules/system/src/Tests/System/FrontPageTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\system\Tests\System;
4
5 use Drupal\Component\Utility\SafeMarkup;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9 * Tests front page functionality and administration.
10 *
11 * @group system
12 */
13 class FrontPageTest extends WebTestBase {
14
15 /**
16 * Modules to enable.
17 *
18 * @var array
19 */
20 public static $modules = ['node', 'system_test', 'views'];
21
22 /**
23 * The path to a node that is created for testing.
24 *
25 * @var string
26 */
27 protected $nodePath;
28
29 protected function setUp() {
30 parent::setUp();
31
32 // Create admin user, log in admin user, and create one node.
33 $this->drupalLogin($this->drupalCreateUser([
34 'access content',
35 'administer site configuration',
36 ]));
37 $this->drupalCreateContentType(['type' => 'page']);
38 $this->nodePath = "node/" . $this->drupalCreateNode(['promote' => 1])->id();
39
40 // Configure 'node' as front page.
41 $this->config('system.site')->set('page.front', '/node')->save();
42 // Enable front page logging in system_test.module.
43 \Drupal::state()->set('system_test.front_page_output', 1);
44 }
45
46 /**
47 * Test front page functionality.
48 */
49 public function testDrupalFrontPage() {
50 // Create a promoted node to test the <title> tag on the front page view.
51 $settings = [
52 'title' => $this->randomMachineName(8),
53 'promote' => 1,
54 ];
55 $this->drupalCreateNode($settings);
56 $this->drupalGet('');
57 $this->assertTitle('Home | Drupal');
58
59 $this->assertText(t('On front page.'), 'Path is the front page.');
60 $this->drupalGet('node');
61 $this->assertText(t('On front page.'), 'Path is the front page.');
62 $this->drupalGet($this->nodePath);
63 $this->assertNoText(t('On front page.'), 'Path is not the front page.');
64
65 // Change the front page to an invalid path.
66 $edit = ['site_frontpage' => '/kittens'];
67 $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
68 $this->assertText(t("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage']]));
69
70 // Change the front page to a path without a starting slash.
71 $edit = ['site_frontpage' => $this->nodePath];
72 $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
73 $this->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", ['%path' => $edit['site_frontpage']]));
74
75 // Change the front page to a valid path.
76 $edit['site_frontpage'] = '/' . $this->nodePath;
77 $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
78 $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
79
80 $this->drupalGet('');
81 $this->assertText(t('On front page.'), 'Path is the front page.');
82 $this->drupalGet('node');
83 $this->assertNoText(t('On front page.'), 'Path is not the front page.');
84 $this->drupalGet($this->nodePath);
85 $this->assertText(t('On front page.'), 'Path is the front page.');
86 }
87
88 }