You are here

public function LoginTest::testLogin in Legal 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/LoginTest.php \Drupal\Tests\legal\Functional\LoginTest::testLogin()

Test loging in with default Legal seetings.

File

tests/src/Functional/LoginTest.php, line 19

Class

LoginTest
Tests a user loging into an account and accepting new T&C.

Namespace

Drupal\Tests\legal\Functional

Code

public function testLogin() {

  // Test with default Legal settings.
  // Log user in.
  $this
    ->drupalPostForm('user/login', $this->loginDetails, 'Log in');

  // Check user is redirected to T&C acceptance page.
  $current_url = $this
    ->getUrl();
  $expected_url = substr($current_url, strlen($this->baseUrl), 20);
  $this
    ->assertEquals($expected_url, '/legal_accept?token=');
  $this
    ->assertResponse(200);

  // Accept T&Cs and submit form.
  $edit = [
    'edit-legal-accept' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Confirm', 'legal-login');

  // Check user is logged in.
  $account = User::load($this->uid);
  $this
    ->drupalUserIsLoggedIn($account);

  // Check user is redirected to their user page.
  $current_url = $this
    ->getUrl();
  $expected_url = $this->baseUrl . '/user/' . $this->uid;
  $this
    ->assertEquals($current_url, $expected_url);
}