3 namespace Drupal\system\Tests\System;
5 use Drupal\Component\Utility\SafeMarkup;
6 use Drupal\simpletest\WebTestBase;
9 * Tests front page functionality and administration.
13 class FrontPageTest extends WebTestBase {
20 public static $modules = ['node', 'system_test', 'views'];
23 * The path to a node that is created for testing.
29 protected function setUp() {
32 // Create admin user, log in admin user, and create one node.
33 $this->drupalLogin ($this->drupalCreateUser([
35 'administer site configuration',
37 $this->drupalCreateContentType(['type' => 'page']);
38 $this->nodePath = "node/" . $this->drupalCreateNode(['promote' => 1])->id();
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);
47 * Test front page functionality.
49 public function testDrupalFrontPage() {
50 // Create a promoted node to test the <title> tag on the front page view.
52 'title' => $this->randomMachineName(8),
55 $this->drupalCreateNode($settings);
57 $this->assertTitle('Home | Drupal');
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.');
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']]));
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']]));
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.');
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.');