function FrontPageTest::testDrupalFrontPage
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()
- 10 core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()
- 9 core/modules/system/tests/src/Functional/System/FrontPageTest.php \Drupal\Tests\system\Functional\System\FrontPageTest::testDrupalFrontPage()
- 8.9.x 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 58
Class
- FrontPageTest
- Tests front page functionality and administration.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testDrupalFrontPage() : void {
// Test the front page displays correctly.
$this->drupalGet('');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('On front page.');
// Check that the direct path is also considered the front page.
$this->drupalGet($this->nodePath);
$this->assertSession()
->pageTextContains('On front page.');
// Test that other paths are not the front page.
$this->drupalGet('admin/structure');
$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 again 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 the empty path is the front page.
$this->drupalGet('');
$this->assertSession()
->pageTextContains('On front page.');
// Test that other paths are not the front page.
$this->drupalGet('admin');
$this->assertSession()
->pageTextNotContains('On front page.');
// Check that the direct path is also considered the front page.
$this->drupalGet($this->nodePath);
$this->assertSession()
->pageTextContains('On front page.');
// Test the form when page.front is null.
$this->config('system.site')
->clear('page.front')
->save();
$this->drupalGet('admin/config/system/site-information');
$this->assertSession()
->statusCodeEquals(200);
// Create a new piece of content with an alias and confirm that its aliased
// path can be set as the front page.
$this->drupalCreateNode([
'path' => '/what-a-twist',
'body' => 'Space, the final frontier.',
]);
$edit['site_frontpage'] = '/what-a-twist';
$this->submitForm($edit, 'Save configuration');
$assert_session = $this->assertSession();
$assert_session->pageTextContains('The configuration options have been saved.');
$assert_session->fieldValueEquals('site_frontpage', '/what-a-twist');
$this->drupalGet('<front>');
$this->assertSession()
->pageTextContains('On front page.');
$assert_session->pageTextContains('Space, the final frontier.');
$assert_session->addressEquals('/');
$this->assertSame('/what-a-twist', $this->config('system.site')
->get('page.front'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.