Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\simpletest\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests User related helper methods of WebTestBase.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group simpletest
|
Chris@0
|
11 */
|
Chris@0
|
12 class UserHelpersTest extends BrowserTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Tests WebTestBase::drupalUserIsLoggedIn().
|
Chris@0
|
16 */
|
Chris@0
|
17 public function testDrupalUserIsLoggedIn() {
|
Chris@0
|
18 $first_user = $this->drupalCreateUser();
|
Chris@0
|
19 $second_user = $this->drupalCreateUser();
|
Chris@0
|
20
|
Chris@0
|
21 // After logging in, the first user should be logged in, the second not.
|
Chris@0
|
22 $this->drupalLogin($first_user);
|
Chris@0
|
23 $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
|
Chris@0
|
24 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
|
Chris@0
|
25
|
Chris@0
|
26 // Verify that logged in state is retained across pages.
|
Chris@0
|
27 $this->drupalGet('');
|
Chris@0
|
28 $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
|
Chris@0
|
29 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
|
Chris@0
|
30
|
Chris@0
|
31 // After logging out, both users should be logged out.
|
Chris@0
|
32 $this->drupalLogout();
|
Chris@0
|
33 $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
|
Chris@0
|
34 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
|
Chris@0
|
35
|
Chris@0
|
36 // After logging back in, the second user should still be logged out.
|
Chris@0
|
37 $this->drupalLogin($first_user);
|
Chris@0
|
38 $this->assertTrue($this->drupalUserIsLoggedIn($first_user));
|
Chris@0
|
39 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
|
Chris@0
|
40
|
Chris@0
|
41 // After logging in the second user, the first one should be logged out.
|
Chris@0
|
42 $this->drupalLogin($second_user);
|
Chris@0
|
43 $this->assertTrue($this->drupalUserIsLoggedIn($second_user));
|
Chris@0
|
44 $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
|
Chris@0
|
45
|
Chris@0
|
46 // After logging out, both should be logged out.
|
Chris@0
|
47 $this->drupalLogout();
|
Chris@0
|
48 $this->assertFalse($this->drupalUserIsLoggedIn($first_user));
|
Chris@0
|
49 $this->assertFalse($this->drupalUserIsLoggedIn($second_user));
|
Chris@0
|
50 }
|
Chris@0
|
51
|
Chris@0
|
52 }
|