function FrontPageTest::testDrupalFrontPage

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()
  2. 10 core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()
  3. 11.x core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()

Test front page functionality.

File

core/modules/system/tests/src/Functional/System/FrontPageTest.php, line 54

Class

FrontPageTest
Tests front page functionality and administration.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testDrupalFrontPage() {
    // Create a promoted node to test the <title> tag on the front page view.
    $settings = [
        'title' => $this->randomMachineName(8),
        'promote' => 1,
    ];
    $this->drupalCreateNode($settings);
    $this->drupalGet('');
    $this->assertTitle('Home | Drupal');
    $this->assertText(t('On front page.'), 'Path is the front page.');
    $this->drupalGet('node');
    $this->assertText(t('On front page.'), 'Path is the front page.');
    $this->drupalGet($this->nodePath);
    $this->assertNoText(t('On front page.'), 'Path is not the front page.');
    // Change the front page to an invalid path.
    $edit = [
        'site_frontpage' => '/kittens',
    ];
    $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
    $this->assertText(t("Either the path '@path' is invalid or you do not have access to it.", [
        '@path' => $edit['site_frontpage'],
    ]));
    // Change the front page to a path without a starting slash.
    $edit = [
        'site_frontpage' => $this->nodePath,
    ];
    $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
    $this->assertRaw(new FormattableMarkup("The path '%path' has to start with a slash.", [
        '%path' => $edit['site_frontpage'],
    ]));
    // Change the front page to a valid path.
    $edit['site_frontpage'] = '/' . $this->nodePath;
    $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
    $this->drupalGet('');
    $this->assertText(t('On front page.'), 'Path is the front page.');
    $this->drupalGet('node');
    $this->assertNoText(t('On front page.'), 'Path is not the front page.');
    $this->drupalGet($this->nodePath);
    $this->assertText(t('On front page.'), 'Path is the front page.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.