class UserLogoutTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Functional/UserLogoutTest.php \Drupal\Tests\user\Functional\UserLogoutTest
- 10 core/modules/user/tests/src/Functional/UserLogoutTest.php \Drupal\Tests\user\Functional\UserLogoutTest
Tests user logout.
Attributes
#[Group('user')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\user\Functional\UserLogoutTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of UserLogoutTest
File
-
core/
modules/ user/ tests/ src/ Functional/ UserLogoutTest.php, line 15
Namespace
Drupal\Tests\user\FunctionalView source
class UserLogoutTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'user',
'block',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->placeBlock('system_menu_block:account');
}
/**
* Tests user logout functionality.
*/
public function testLogout() : void {
$account = $this->createUser();
$this->drupalLogin($account);
// Test missing csrf token does not log the user out.
$logoutUrl = Url::fromRoute('user.logout');
$confirmUrl = Url::fromRoute('user.logout.confirm');
$this->drupalGet($logoutUrl);
$this->assertTrue($this->drupalUserIsLoggedIn($account));
$this->assertSession()
->addressEquals($confirmUrl);
// Test invalid csrf token does not log the user out.
$this->drupalGet($logoutUrl, [
'query' => [
'token' => '123',
],
]);
$this->assertTrue($this->drupalUserIsLoggedIn($account));
$this->assertSession()
->addressEquals($confirmUrl);
// Test to ensure the text 'This action cannot be undone.' is not
// present on the page.
$this->assertSession()
->pageTextNotContains('This action cannot be undone.');
// Submitting the confirmation form correctly logs the user out.
$this->submitForm([], 'Log out');
$this->assertFalse($this->drupalUserIsLoggedIn($account));
$this->drupalResetSession();
$this->drupalLogin($account);
// Test with valid logout link.
$this->drupalGet('user');
$this->getSession()
->getPage()
->clickLink('Log out');
$this->assertFalse($this->drupalUserIsLoggedIn($account));
// Test hitting the confirm form while logged out redirects to the
// frontpage.
$this->drupalGet($confirmUrl);
$this->assertSession()
->addressEquals(Url::fromRoute('<front>'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.