3 namespace Drupal\Tests\simpletest\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests User related helper methods of WebTestBase.
12 class UserHelpersTest extends BrowserTestBase {
15 * Tests WebTestBase::drupalUserIsLoggedIn().
17 public function testDrupalUserIsLoggedIn() {
18 $first_user = $this->drupalCreateUser();
19 $second_user = $this->drupalCreateUser();
21 // After logging in, the first user should be logged in, the second not.
22 $this->drupalLogin($first_user);
23 $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
24 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
26 // Verify that logged in state is retained across pages.
28 $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
29 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
31 // After logging out, both users should be logged out.
32 $this->drupalLogout();
33 $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
34 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
36 // After logging back in, the second user should still be logged out.
37 $this->drupalLogin($first_user);
38 $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
39 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
41 // After logging in the second user, the first one should be logged out.
42 $this->drupalLogin($second_user);
43 $this->assertTrue($this->drupalUserIsLoggedIn($second_user));
44 $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
46 // After logging out, both should be logged out.
47 $this->drupalLogout();
48 $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
49 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));