FrontPageTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/System/FrontPageTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\System;
use Drupal\Tests\BrowserTestBase;
class FrontPageTest extends BrowserTestBase {
protected static $modules = [
'node',
'system_test',
'views',
];
protected $defaultTheme = 'stark';
protected $nodePath;
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'access content',
'administer site configuration',
]));
$this
->drupalCreateContentType([
'type' => 'page',
]);
$this->nodePath = "node/" . $this
->drupalCreateNode([
'promote' => 1,
])
->id();
$this
->config('system.site')
->set('page.front', '/node')
->save();
\Drupal::state()
->set('system_test.front_page_output', 1);
}
public function testDrupalFrontPage() {
$settings = [
'title' => $this
->randomMachineName(8),
'promote' => 1,
];
$this
->drupalCreateNode($settings);
$this
->drupalGet('');
$this
->assertSession()
->titleEquals('Home | Drupal');
$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.');
$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.");
$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.");
$edit['site_frontpage'] = '/' . $this->nodePath;
$this
->drupalGet('admin/config/system/site-information');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$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.');
}
}