public function FrontPageTest::testDrupalFrontPage in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()
Tests front page functionality.
File
- core/
modules/ system/ tests/ src/ Functional/ System/ FrontPageTest.php, line 53
Class
- FrontPageTest
- Tests front page functionality and administration.
Namespace
Drupal\Tests\system\Functional\SystemCode
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
->assertSession()
->titleEquals('Home | Drupal');
// Check that path is the front page.
$this
->assertSession()
->pageTextContains('On front page.');
$this
->drupalGet('node');
$this
->assertSession()
->pageTextContains('On front page.');
$this
->drupalGet($this->nodePath);
$this
->assertSession()
->pageTextNotContains('On front page.');
// Change the front page to an invalid path.
$edit = [
'site_frontpage' => '/kittens',
];
$this
->drupalGet('admin/config/system/site-information');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->pageTextContains("Either the path '" . $edit['site_frontpage'] . "' is invalid or you do not have access to it.");
// Change the front page to a path without a starting slash.
$edit = [
'site_frontpage' => $this->nodePath,
];
$this
->drupalGet('admin/config/system/site-information');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->pageTextContains("The path '{$edit['site_frontpage']}' has to start with a slash.");
// Change the front page to a valid path.
$edit['site_frontpage'] = '/' . $this->nodePath;
$this
->drupalGet('admin/config/system/site-information');
$this
->submitForm($edit, 'Save configuration');
// Check that the front page path has been saved.
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
// Check that path is the front page.
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains('On front page.');
$this
->drupalGet('node');
$this
->assertSession()
->pageTextNotContains('On front page.');
$this
->drupalGet($this->nodePath);
$this
->assertSession()
->pageTextContains('On front page.');
}