You are here

public function AutoLoginUrlTest::testAluTokenGenerationCheck in Auto Login URL 2.x

Same name and namespace in other branches
  1. 8 src/Tests/AutoLoginUrlTest.php \Drupal\auto_login_url\Tests\AutoLoginUrlTest::testAluTokenGenerationCheck()

Test token generation.

File

src/Tests/AutoLoginUrlTest.php, line 49

Class

AutoLoginUrlTest
AutoLoginUrlTestCase Class.

Namespace

Drupal\auto_login_url\Tests

Code

public function testAluTokenGenerationCheck() {

  // Create user.
  $user = $this
    ->createUser([
    'use auto login url',
  ]);

  // Create an auto login url for this user.
  $url = auto_login_url_create($user
    ->get('uid')->value, 'user/' . $user
    ->get('uid')->value);

  // Access url.
  $this
    ->drupalGet($url);

  // Make assertions.
  $this
    ->assertResponse(200, t('User logged in successfully.'));
  $this
    ->assertText($user
    ->get('name')->value, t('User name is visible, hence user is logged in.'));

  // Create another user and login again.
  $user2 = $this
    ->createUser([
    'use auto login url',
  ]);

  // Create an auto login url for this user.
  $url = auto_login_url_create($user2
    ->get('uid')->value, 'user/' . $user2
    ->get('uid')->value);

  // Access url.
  $this
    ->drupalGet($url);

  // Make assertions.
  $this
    ->assertResponse(200, t('User 2 logged in successfully.'));
  $this
    ->assertText($user2
    ->get('name')->value, t('User 2 name is visible, hence user is logged in.'));
}