PageNotFoundTest.php in Zircon Profile 8.0
File
core/modules/system/src/Tests/System/PageNotFoundTest.php
View source
<?php
namespace Drupal\system\Tests\System;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
class PageNotFoundTest extends WebTestBase {
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser(array(
'administer site configuration',
'link to any page',
));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array(
'access user profiles',
));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array(
'access user profiles',
));
}
function testPageNotFound() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->randomMachineName(10));
$this
->assertText(t('Page not found'), 'Found the default 404 page');
$edit = [
'site_404' => 'user/' . $this->adminUser
->id(),
];
$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_404'],
]));
$edit = array(
'site_404' => '/user/' . $this->adminUser
->id(),
);
$this
->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this
->drupalGet($this
->randomMachineName(10));
$this
->assertText($this->adminUser
->getUsername(), 'Found the custom 404 page');
}
}