function UserPasswordResetTest::testUserPasswordResetPreferredLanguage

Same name in other branches
  1. 10 core/modules/user/tests/src/Functional/UserPasswordResetTest.php \Drupal\Tests\user\Functional\UserPasswordResetTest::testUserPasswordResetPreferredLanguage()
  2. 11.x core/modules/user/tests/src/Functional/UserPasswordResetTest.php \Drupal\Tests\user\Functional\UserPasswordResetTest::testUserPasswordResetPreferredLanguage()

Tests password reset functionality when user has set preferred language.

@dataProvider languagePrefixTestProvider

File

core/modules/user/tests/src/Functional/UserPasswordResetTest.php, line 243

Class

UserPasswordResetTest
Ensure that password reset methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserPasswordResetPreferredLanguage($setPreferredLangcode, $activeLangcode, $prefix, $visitingUrl, $expectedResetUrl, $unexpectedResetUrl) {
    // Set two new languages.
    ConfigurableLanguage::createFromLangcode('fr')->save();
    ConfigurableLanguage::createFromLangcode('zh-hant')->save();
    $this->languageManager = \Drupal::languageManager();
    // Set language prefixes.
    $config = $this->config('language.negotiation');
    $config->set('url.prefixes', [
        'en' => '',
        'fr' => 'fr',
        'zh-hant' => 'zh',
    ])
        ->save();
    $this->rebuildContainer();
    $this->account->preferred_langcode = $setPreferredLangcode;
    $this->account
        ->save();
    $this->assertSame($setPreferredLangcode, $this->account
        ->getPreferredLangcode(FALSE));
    // Test Default langcode is different from active langcode when visiting different.
    if ($setPreferredLangcode !== 'en') {
        $this->drupalGet($prefix . '/user/password');
        $this->assertSame($activeLangcode, $this->getSession()
            ->getResponseHeader('Content-language'));
        $this->assertSame('en', $this->languageManager
            ->getDefaultLanguage()
            ->getId());
    }
    // Test password reset with language prefixes.
    $this->drupalGet($visitingUrl);
    $edit = [
        'name' => $this->account
            ->getAccountName(),
    ];
    $this->submitForm($edit, 'Submit');
    $this->assertValidPasswordReset($edit['name']);
    $resetURL = $this->getResetURL();
    $this->assertStringContainsString($expectedResetUrl, $resetURL);
    $this->assertStringNotContainsString($unexpectedResetUrl, $resetURL);
}

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