function UserLoginTest::testLoginCacheTagsAndDestination

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testLoginCacheTagsAndDestination()
  2. 10 core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testLoginCacheTagsAndDestination()
  3. 11.x core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testLoginCacheTagsAndDestination()

Tests login with destination.

File

core/modules/user/tests/src/Functional/UserLoginTest.php, line 24

Class

UserLoginTest
Ensure that login works as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testLoginCacheTagsAndDestination() {
    $this->drupalGet('user/login');
    // The user login form says "Enter your <site name> username.", hence it
    // depends on config:system.site, and its cache tags should be present.
    $this->assertCacheTag('config:system.site');
    $user = $this->drupalCreateUser([]);
    $this->drupalGet('user/login', [
        'query' => [
            'destination' => 'foo',
        ],
    ]);
    $edit = [
        'name' => $user->getAccountName(),
        'pass' => $user->passRaw,
    ];
    $this->drupalPostForm(NULL, $edit, t('Log in'));
    $this->assertUrl('foo', [], 'Redirected to the correct URL');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.