Skip to content
Snippets Groups Projects
Commit 12ca6ae6 authored by Andrey Postnikov's avatar Andrey Postnikov Committed by Andrey Postnikov
Browse files

Issue #3093666 by saidatom, andypost: Change the way how translation is made

parent e9d1b782
No related branches found
No related tags found
No related merge requests found
......@@ -81,18 +81,17 @@ class EmailRegistrationLogin extends Login {
$pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);
$login_with_username = $this->config->get('login_with_username');
$pane_form['returning_customer']['name']['#title'] = $login_with_username ? t('Email address or username') : t('Email address');
$pane_form['returning_customer']['name']['#description'] = $login_with_username ? t('Enter your email address or username.') : t('Enter your email address.');
$pane_form['returning_customer']['name']['#title'] = $login_with_username ? $this->t('Email address or username') : $this->t('Email address');
$pane_form['returning_customer']['name']['#description'] = $login_with_username ? $this->t('Enter your email address or username.') : $this->t('Enter your email address.');
$pane_form['returning_customer']['name']['#element_validate'][] = 'email_registration_user_login_validate';
$pane_form['returning_customer']['name']['#type'] = $login_with_username ? 'textfield' : 'email';
$pane_form['returning_customer']['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
$pane_form['returning_customer']['password']['#description'] = t('Enter the password that accompanies your email address.');
$pane_form['returning_customer']['password']['#description'] = $this->t('Enter the password that accompanies your email address.');
$complete_form['#cache']['tags'][] = 'config:email_registration.settings';
$pane_form['register']['name']['#type'] = 'value';
$pane_form['register']['name']['#value'] = 'email_registration_' . user_password();
$pane_form['register']['mail']['#title'] = t('Email');
$pane_form['register']['mail']['#title'] = $this->t('Email');
return $pane_form;
}
......@@ -155,7 +154,7 @@ class EmailRegistrationLogin extends Login {
$this->credentialsCheckFlood->register($this->clientIp, $username);
// Changing the wrong credentials error message.
if (!$this->config->get('login_with_username')) {
$form_state->setError($name_element, $this->t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [':url' => $password_url]));
$form_state->setError($name_element, $this->t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [':password' => $password_url]));
// Adding return to avoid the parent error when password is empty.
return;
}
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\email_registration\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
/**
* Tests the email registration module.
......@@ -19,6 +20,11 @@ class EmailRegistrationTestCase extends BrowserTestBase {
*/
public static $modules = ['email_registration'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Test various behaviors for anonymous users.
*/
......@@ -27,7 +33,7 @@ class EmailRegistrationTestCase extends BrowserTestBase {
$email_registration_config = $this->container->get('config.factory')->getEditable('email_registration.settings');
$user_config
->set('verify_mail', FALSE)
->set('register', USER_REGISTER_VISITORS)
->set('register', UserInterface::REGISTER_VISITORS)
->save();
// Try to register a user.
$name = $this->randomMachineName();
......@@ -37,41 +43,44 @@ class EmailRegistrationTestCase extends BrowserTestBase {
'pass[pass1]' => $pass,
'pass[pass2]' => $pass,
];
$this->drupalPostForm('/user/register', $register, t('Create new account'));
$this->drupalPostForm('/user/register', $register, 'Create new account');
$this->drupalLogout();
$login = [
'name' => $name . '@example.com',
'pass' => $pass,
];
$this->drupalPostForm('user/login', $login, t('Log in'));
$this->drupalPostForm('user/login', $login, 'Log in');
// Really basic confirmation that the user was created and logged in.
$this->assertRaw('<title>' . $name . ' | Drupal</title>', t('User properly created, logged in.'));
$this->assertSession()->responseContains('<title>' . $name . ' | Drupal</title>');
// Now try the immediate login.
$this->drupalLogout();
// Try to login with just username, should fail by default.
$this->drupalGet('user/login');
$this->assertText('Enter your email address.');
$this->assertText('Email');
$this->assertNoText('Email or username');
$this->assertSession()->responseContains('Enter your email address.');
$this->assertSession()->responseContains('Email');
$this->assertSession()->responseNotContains('Email or username');
$login = [
'name' => $name,
'pass' => $pass,
];
$this->drupalPostForm('user/login', $login, t('Log in'));
$error_message = $this->xpath('//div[contains(@class, "error")]');
$this->assertTrue(!empty($error_message), t('When login_with_username is false, a user cannot login with just their username.'));
$this->drupalPostForm('user/login', $login, 'Log in');
// When login_with_username is false, a user cannot login with just their
// username.
$this->assertSession()->responseContains('Unrecognized email address or password.');
// Set login_with_username to TRUE and try to login with just username.
$email_registration_config->set('login_with_username', TRUE)->save();
$this->drupalGet('user/login');
$this->assertText('Enter your email address or username.');
$this->assertText('Email or username');
$this->drupalPostForm('user/login', $login, t('Log in'));
$this->assertRaw('<title>' . $name . ' | Drupal</title>', t('When login_with_username is true, a user can login with just their username.'));
$this->assertSession()->responseContains('Enter your email address or username.');
$this->assertSession()->responseContains('Email or username');
$this->drupalPostForm('user/login', $login, 'Log in');
// When login_with_username is true, a user can login with just their
// username.
$this->assertSession()->responseContains('<title>' . $name . ' | Drupal</title>');
$this->drupalLogout();
$user_config
......@@ -84,14 +93,15 @@ class EmailRegistrationTestCase extends BrowserTestBase {
'pass[pass1]' => $pass,
'pass[pass2]' => $pass,
];
$this->drupalPostForm('/user/register', $register, t('Create new account'));
$this->assertRaw('Registration successful. You are now logged in.', t('User properly created, immediately logged in.'));
$this->drupalPostForm('/user/register', $register, 'Create new account');
// User properly created, immediately logged in.
$this->assertSession()->responseContains('Registration successful. You are now logged in.');
// Test email_registration_unique_username().
$this->drupalLogout();
$user_config
->set('verify_mail', FALSE)
->set('register', USER_REGISTER_VISITORS)
->set('register', UserInterface::REGISTER_VISITORS)
->save();
$name = $this->randomMachineName(32);
$pass = $this->randomString(10);
......@@ -104,9 +114,9 @@ class EmailRegistrationTestCase extends BrowserTestBase {
'pass[pass1]' => $pass,
'pass[pass2]' => $pass,
];
$this->drupalPostForm('/user/register', $register, t('Create new account'));
$this->drupalPostForm('/user/register', $register, 'Create new account');
$account = user_load_by_mail($register['mail']);
$this->assertTrue($next_unique_name === $account->getAccountName());
$this->assertSame($next_unique_name, $account->getAccountName());
$this->drupalLogout();
// Check if custom username stays the same when user is edited.
......@@ -115,8 +125,9 @@ class EmailRegistrationTestCase extends BrowserTestBase {
$this->drupalLogin($user);
$this->drupalPostForm('/user/' . $user->id() . '/edit', [], 'Save');
$this->assertEqual($name, User::load($user->id())->label(), 'Username should not change after empty edit.');
$this->drupalLogout($user);
$this->drupalLogout();
$this->drupalLogin($user);
$this->assertSame($next_unique_name, $account->getAccountName());
}
/**
......@@ -134,7 +145,7 @@ class EmailRegistrationTestCase extends BrowserTestBase {
$this->drupalGet('user/' . $user->id() . '/edit');
$this->assertSession()->fieldExists('edit-name');
$this->drupalLogout($user);
$this->drupalLogout();
$user = $this->createUser();
$username = $user->getAccountName();
......
......@@ -125,7 +125,7 @@ class EmailRegistrationLoginTest extends CommerceBrowserTestBase {
$this->assertSession()->pageTextContains('Email address or username');
$edit = [
'email_registration_login[returning_customer][name]' => $account->getUsername(),
'email_registration_login[returning_customer][name]' => $account->getAccountName(),
'email_registration_login[returning_customer][password]' => $account->passRaw,
];
$this->submitForm($edit, 'Log in');
......@@ -180,7 +180,7 @@ class EmailRegistrationLoginTest extends CommerceBrowserTestBase {
$this->assertSession()->pageTextContains('Enter your email address.');
$edit = [
'email_registration_login[returning_customer][name]' => $account->getUsername(),
'email_registration_login[returning_customer][name]' => $account->getAccountName(),
'email_registration_login[returning_customer][password]' => $account->passRaw,
];
$this->submitForm($edit, 'Log in');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment