View source
<?php
namespace Drupal\system\Tests\System;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;
class FrontPageTest extends WebTestBase {
public static $modules = array(
'node',
'system_test',
'views',
);
protected $nodePath;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser(array(
'access content',
'administer site configuration',
)));
$this
->drupalCreateContentType(array(
'type' => 'page',
));
$this->nodePath = "node/" . $this
->drupalCreateNode(array(
'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 = array(
'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.');
$edit = array(
'site_frontpage' => '/kittens',
);
$this
->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this
->assertText(t("The path '@path' is either invalid or you do not have access to it.", array(
'@path' => $edit['site_frontpage'],
)));
$edit = [
'site_frontpage' => $this->nodePath,
];
$this
->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this
->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", [
'%path' => $edit['site_frontpage'],
]));
$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.');
}
}