diff --git a/core/modules/user/src/Tests/UserLoginTest.php b/core/modules/user/src/Tests/UserLoginTest.php index 46a5c99..324fe26 100644 --- a/core/modules/user/src/Tests/UserLoginTest.php +++ b/core/modules/user/src/Tests/UserLoginTest.php @@ -4,6 +4,7 @@ use Drupal\simpletest\WebTestBase; use Drupal\user\Entity\User; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Ensure that login works as expected. @@ -12,6 +13,8 @@ */ class UserLoginTest extends WebTestBase { + use StringTranslationTrait; + /** * Tests login with destination. */ @@ -24,7 +27,7 @@ function testLoginCacheTagsAndDestination() { $user = $this->drupalCreateUser(array()); $this->drupalGet('user/login', array('query' => array('destination' => 'foo'))); $edit = array('name' => $user->getUserName(), 'pass' => $user->pass_raw); - $this->drupalPostForm(NULL, $edit, t('Log in')); + $this->drupalPostForm(NULL, $edit, $this->t('Log in')); $this->assertUrl('foo', [], 'Redirected to the correct URL'); } @@ -67,7 +70,9 @@ function testGlobalLoginFloodControl() { $this->drupalLogout(); // Try to login as user 1, it should be successful. $this->drupalLogin($user1); - $this->assertNoRaw(t('Too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', array(':url' => \Drupal::url('user.pass')))); + $this->assertNoRaw($this->t('Too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', [ + ':url' => \Drupal::url('user.pass'), + ])); } /** @@ -112,7 +117,12 @@ function testPerUserLoginFloodControl() { $this->drupalLogout(); // Try to login as user 1, it should be successful. $this->drupalLogin($user1); - $this->assertNoRaw(\Drupal::translation()->formatPlural($this->config('user.flood')->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or request a new password.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.', array(':url' => \Drupal::url('user.pass')))); + $this->assertNoRaw($this->formatPlural( + $this->config('user.flood')->get('user_limit'), + 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or request a new password.', + 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.', + [':url' => \Drupal::url('user.pass')] + )); } /** @@ -169,19 +179,26 @@ function assertFailedLogin($account, $flood_trigger = NULL) { 'name' => $account->getUsername(), 'pass' => $account->pass_raw, ); - $this->drupalPostForm('user/login', $edit, t('Log in')); + $this->drupalPostForm('user/login', $edit, $this->t('Log in')); $this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.'); if (isset($flood_trigger)) { if ($flood_trigger == 'user') { - $this->assertRaw(\Drupal::translation()->formatPlural($this->config('user.flood')->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or request a new password.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.', array(':url' => \Drupal::url('user.pass')))); + $this->assertRaw($this->formatPlural( + $this->config('user.flood')->get('user_limit'), + 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or request a new password.', + 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.', + [':url' => \Drupal::url('user.pass')] + )); } else { // No uid, so the limit is IP-based. - $this->assertRaw(t('Too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', array(':url' => \Drupal::url('user.pass')))); + $this->assertRaw($this->t('Too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', [ + ':url' => \Drupal::url('user.pass'), + ])); } } else { - $this->assertText(t('Unrecognized username or password. Forgot your password?')); + $this->assertText($this->t('Unrecognized username or password. Forgot your password?')); } } @@ -194,14 +211,14 @@ function assertFailedLogin($account, $flood_trigger = NULL) { public function resetUserPassword($user) { $this->drupalGet('user/password'); $edit['name'] = $user->getUsername(); - $this->drupalPostForm(NULL, $edit, t('Submit')); + $this->drupalPostForm(NULL, $edit, $this->t('Submit')); $_emails = $this->drupalGetMails(); $email = end($_emails); $urls = array(); preg_match('#.+user/reset/.+#', $email['body'], $urls); $resetURL = $urls[0]; $this->drupalGet($resetURL); - $this->drupalPostForm(NULL, NULL, t('Log in')); + $this->drupalPostForm(NULL, NULL, $this->t('Log in')); } }