Issue #3015752 by alexpott, bnjmnm: Properly deprecate USERNAME_MAX_LENGTH and USER_REGISTER_* constants
parent
140e97ef29
commit
3cc8a612de
|
@ -9,6 +9,7 @@ use Drupal\Core\Locale\CountryManagerInterface;
|
|||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\user\UserStorageInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -178,7 +179,7 @@ class SiteConfigureForm extends ConfigFormBase {
|
|||
$form['admin_account']['account']['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username'),
|
||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
||||
'#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
|
||||
'#description' => $this->t("Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign."),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => ['class' => ['username']],
|
||||
|
|
|
@ -17,6 +17,7 @@ use Drupal\Core\Url;
|
|||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Comment manager contains common functions to manage comment fields.
|
||||
|
@ -174,7 +175,7 @@ class CommentManager implements CommentManagerInterface {
|
|||
$destination = ['destination' => $entity->toUrl('canonical', ['fragment' => 'comment-form'])->toString()];
|
||||
}
|
||||
|
||||
if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
if ($this->userConfig->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
|
||||
// Users can register themselves.
|
||||
return $this->t('<a href=":login">Log in</a> or <a href=":register">register</a> to post comments', [
|
||||
':login' => Url::fromRoute('user.login', [], ['query' => $destination])->toString(),
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Drupal\user\Access;
|
|||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Access check for user registration routes.
|
||||
|
@ -22,7 +23,7 @@ class RegisterAccessCheck implements AccessInterface {
|
|||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
$user_settings = \Drupal::config('user.settings');
|
||||
return AccessResult::allowedIf($account->isAnonymous() && $user_settings->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY)->cacheUntilConfigurationChanges($user_settings);
|
||||
return AccessResult::allowedIf($account->isAnonymous() && $user_settings->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY)->cacheUntilConfigurationChanges($user_settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$form['account']['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username'),
|
||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
||||
'#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
|
||||
'#description' => $this->t("Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign."),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => [
|
||||
|
@ -184,7 +184,7 @@ abstract class AccountForm extends ContentEntityForm {
|
|||
$status = $account->get('status')->value;
|
||||
}
|
||||
else {
|
||||
$status = $config->get('register') == USER_REGISTER_VISITORS ? 1 : 0;
|
||||
$status = $config->get('register') == UserInterface::REGISTER_VISITORS ? 1 : 0;
|
||||
}
|
||||
|
||||
$form['account']['status'] = [
|
||||
|
|
|
@ -151,9 +151,9 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
'#title' => $this->t('Who can register accounts?'),
|
||||
'#default_value' => $config->get('register'),
|
||||
'#options' => [
|
||||
USER_REGISTER_ADMINISTRATORS_ONLY => $this->t('Administrators only'),
|
||||
USER_REGISTER_VISITORS => $this->t('Visitors'),
|
||||
USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => $this->t('Visitors, but administrator approval is required'),
|
||||
UserInterface::REGISTER_ADMINISTRATORS_ONLY => $this->t('Administrators only'),
|
||||
UserInterface::REGISTER_VISITORS => $this->t('Visitors'),
|
||||
UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => $this->t('Visitors, but administrator approval is required'),
|
||||
],
|
||||
];
|
||||
$form['registration_cancellation']['user_email_verification'] = [
|
||||
|
@ -203,7 +203,7 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
$form['email_admin_created'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Welcome (new user created by administrator)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_ADMINISTRATORS_ONLY,
|
||||
'#open' => $config->get('register') == UserInterface::REGISTER_ADMINISTRATORS_ONLY,
|
||||
'#description' => $this->t('Edit the welcome email messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
];
|
||||
|
@ -223,7 +223,7 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
$form['email_pending_approval'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Welcome (awaiting approval)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
|
||||
'#open' => $config->get('register') == UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
|
||||
'#description' => $this->t('Edit the welcome email messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
];
|
||||
|
@ -243,7 +243,7 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
$form['email_pending_approval_admin'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Admin (user awaiting approval)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
|
||||
'#open' => $config->get('register') == UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
|
||||
'#description' => $this->t('Edit the email notifying the site administrator that there are new members awaiting administrative approval.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
];
|
||||
|
@ -263,7 +263,7 @@ class AccountSettingsForm extends ConfigFormBase {
|
|||
$form['email_no_approval_required'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Welcome (no approval required)'),
|
||||
'#open' => $config->get('register') == USER_REGISTER_VISITORS,
|
||||
'#open' => $config->get('register') == UserInterface::REGISTER_VISITORS,
|
||||
'#description' => $this->t('Edit the welcome email messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help,
|
||||
'#group' => 'email',
|
||||
];
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Form\FormBase;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\user\UserAuthInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
use Drupal\user\UserStorageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -94,7 +95,7 @@ class UserLoginForm extends FormBase {
|
|||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
||||
'#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
|
||||
'#description' => $this->t('Enter your @s username.', ['@s' => $config->get('name')]),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => [
|
||||
|
|
|
@ -6,6 +6,7 @@ use Drupal\Core\Form\FormBase;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\Render\Element\Email;
|
||||
use Drupal\user\UserInterface;
|
||||
use Drupal\user\UserStorageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -68,7 +69,7 @@ class UserPasswordForm extends FormBase {
|
|||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Username or email address'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => max(USERNAME_MAX_LENGTH, Email::EMAIL_MAX_LENGTH),
|
||||
'#maxlength' => max(UserInterface::USERNAME_MAX_LENGTH, Email::EMAIL_MAX_LENGTH),
|
||||
'#required' => TRUE,
|
||||
'#attributes' => [
|
||||
'autocorrect' => 'off',
|
||||
|
|
|
@ -9,6 +9,7 @@ use Drupal\Core\Routing\RouteMatchInterface;
|
|||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\user\UserInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -111,7 +112,7 @@ class UserLoginBlock extends BlockBase implements ContainerFactoryPluginInterfac
|
|||
|
||||
// Build action links.
|
||||
$items = [];
|
||||
if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
if (\Drupal::config('user.settings')->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
|
||||
$items['create_account'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Create new account'),
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\user\Plugin\Validation\Constraint;
|
||||
|
||||
use Drupal\user\UserInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
|
@ -52,8 +53,8 @@ class UserNameConstraintValidator extends ConstraintValidator {
|
|||
) {
|
||||
$this->context->addViolation($constraint->illegalMessage);
|
||||
}
|
||||
if (mb_strlen($name) > USERNAME_MAX_LENGTH) {
|
||||
$this->context->addViolation($constraint->tooLongMessage, ['%name' => $name, '%max' => USERNAME_MAX_LENGTH]);
|
||||
if (mb_strlen($name) > UserInterface::USERNAME_MAX_LENGTH) {
|
||||
$this->context->addViolation($constraint->tooLongMessage, ['%name' => $name, '%max' => UserInterface::USERNAME_MAX_LENGTH]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\Core\Password\PasswordInterface;
|
|||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\user\UserInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -167,8 +168,8 @@ class EntityUser extends EntityContentBase {
|
|||
if (is_array($name)) {
|
||||
$name = reset($name);
|
||||
}
|
||||
if (mb_strlen($name) > USERNAME_MAX_LENGTH) {
|
||||
$row->setDestinationProperty('name', mb_substr($name, 0, USERNAME_MAX_LENGTH));
|
||||
if (mb_strlen($name) > UserInterface::USERNAME_MAX_LENGTH) {
|
||||
$row->setDestinationProperty('name', mb_substr($name, 0, UserInterface::USERNAME_MAX_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class UserRegistrationResource extends ResourceBase {
|
|||
|
||||
// Only activate new users if visitors are allowed to register and no email
|
||||
// verification required.
|
||||
if ($this->userSettings->get('register') == USER_REGISTER_VISITORS && !$this->userSettings->get('verify_mail')) {
|
||||
if ($this->userSettings->get('register') == UserInterface::REGISTER_VISITORS && !$this->userSettings->get('verify_mail')) {
|
||||
$account->activate();
|
||||
}
|
||||
else {
|
||||
|
@ -147,7 +147,7 @@ class UserRegistrationResource extends ResourceBase {
|
|||
}
|
||||
|
||||
// Verify that the current user can register a user account.
|
||||
if ($this->userSettings->get('register') == USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
if ($this->userSettings->get('register') == UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
|
||||
throw new AccessDeniedHttpException('You cannot register a new user account.');
|
||||
}
|
||||
|
||||
|
@ -175,14 +175,14 @@ class UserRegistrationResource extends ResourceBase {
|
|||
protected function sendEmailNotifications(UserInterface $account) {
|
||||
$approval_settings = $this->userSettings->get('register');
|
||||
// No e-mail verification is required. Activating the user.
|
||||
if ($approval_settings == USER_REGISTER_VISITORS) {
|
||||
if ($approval_settings == UserInterface::REGISTER_VISITORS) {
|
||||
if ($this->userSettings->get('verify_mail')) {
|
||||
// No administrator approval required.
|
||||
_user_mail_notify('register_no_approval_required', $account);
|
||||
}
|
||||
}
|
||||
// Administrator approval required.
|
||||
elseif ($approval_settings == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
|
||||
elseif ($approval_settings == UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
|
||||
_user_mail_notify('register_pending_approval', $account);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class UserStorageSchema extends SqlContentEntityStorageSchema {
|
|||
$schema['fields'][$field_name]['not null'] = TRUE;
|
||||
// Make sure the field is no longer than 191 characters so we can
|
||||
// add a unique constraint in MySQL.
|
||||
$schema['fields'][$field_name]['length'] = USERNAME_MAX_LENGTH;
|
||||
$schema['fields'][$field_name]['length'] = UserInterface::USERNAME_MAX_LENGTH;
|
||||
break;
|
||||
|
||||
case 'mail':
|
||||
|
|
|
@ -5,8 +5,9 @@ namespace Drupal\Tests\user\Functional;
|
|||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\ResourceTestBase;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Drupal\Core\Test\AssertMailTrait;
|
||||
use Drupal\user\UserInterface;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
/**
|
||||
* Tests user registration via REST resource.
|
||||
|
@ -70,7 +71,7 @@ class RestRegisterUserTest extends ResourceTestBase {
|
|||
|
||||
// Test out different setting User Registration and Email Verification.
|
||||
// Allow visitors to register with no email verification.
|
||||
$config->set('register', USER_REGISTER_VISITORS);
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS);
|
||||
$config->set('verify_mail', 0);
|
||||
$config->save();
|
||||
$user = $this->registerUser('Palmer.Eldritch');
|
||||
|
@ -85,14 +86,14 @@ class RestRegisterUserTest extends ResourceTestBase {
|
|||
$this->assertResourceErrorResponse(422, "No password provided.", $response);
|
||||
|
||||
// Attempt to register with a password when e-mail verification is on.
|
||||
$config->set('register', USER_REGISTER_VISITORS);
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS);
|
||||
$config->set('verify_mail', 1);
|
||||
$config->save();
|
||||
$response = $this->registerRequest('Estraven', TRUE);
|
||||
$this->assertResourceErrorResponse(422, 'A Password cannot be specified. It will be generated on login.', $response);
|
||||
|
||||
// Allow visitors to register with email verification.
|
||||
$config->set('register', USER_REGISTER_VISITORS);
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS);
|
||||
$config->set('verify_mail', 1);
|
||||
$config->save();
|
||||
$name = 'Jason.Taverner';
|
||||
|
@ -104,7 +105,7 @@ class RestRegisterUserTest extends ResourceTestBase {
|
|||
$this->assertMailString('body', 'You may now log in by clicking this link', 1);
|
||||
|
||||
// Allow visitors to register with Admin approval and no email verification.
|
||||
$config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
|
||||
$config->set('verify_mail', 0);
|
||||
$config->save();
|
||||
$name = 'Argaven';
|
||||
|
@ -116,7 +117,7 @@ class RestRegisterUserTest extends ResourceTestBase {
|
|||
$this->assertMailString('body', 'Argaven has applied for an account', 2);
|
||||
|
||||
// Allow visitors to register with Admin approval and e-mail verification.
|
||||
$config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
|
||||
$config->set('verify_mail', 1);
|
||||
$config->save();
|
||||
$name = 'Bob.Arctor';
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Drupal\Tests\user\Functional;
|
|||
use Drupal\Core\Test\AssertMailTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Tests user administration page functionality.
|
||||
|
@ -167,7 +168,7 @@ class UserAdminTest extends BrowserTestBase {
|
|||
// Allow users to register with admin approval.
|
||||
$config
|
||||
->set('verify_mail', TRUE)
|
||||
->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
|
||||
->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
|
||||
->save();
|
||||
// Set the site and notification email addresses.
|
||||
$system = $this->config('system.site');
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\user\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Tests user edited own account can still log in.
|
||||
|
@ -14,7 +15,7 @@ class UserEditedOwnAccountTest extends BrowserTestBase {
|
|||
public function testUserEditedOwnAccount() {
|
||||
// Change account setting 'Who can register accounts?' to Administrators
|
||||
// only.
|
||||
$this->config('user.settings')->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save();
|
||||
$this->config('user.settings')->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)->save();
|
||||
|
||||
// Create a new user account and log in.
|
||||
$account = $this->drupalCreateUser(['change own username']);
|
||||
|
|
|
@ -8,6 +8,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
|||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Tests registration of user under different configurations.
|
||||
|
@ -29,12 +30,12 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
$config->set('verify_mail', TRUE)->save();
|
||||
|
||||
// Set registration to administrator only.
|
||||
$config->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save();
|
||||
$config->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)->save();
|
||||
$this->drupalGet('user/register');
|
||||
$this->assertResponse(403, 'Registration page is inaccessible when only administrators can create accounts.');
|
||||
|
||||
// Allow registration by site visitors without administrator approval.
|
||||
$config->set('register', USER_REGISTER_VISITORS)->save();
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS)->save();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
|
@ -51,7 +52,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
$this->assertTitle(t('Set password | Drupal'), 'Page title is "Set password".');
|
||||
|
||||
// Allow registration by site visitors, but require administrator approval.
|
||||
$config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
|
@ -68,7 +69,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
// without administrator approval.
|
||||
$config
|
||||
->set('verify_mail', FALSE)
|
||||
->set('register', USER_REGISTER_VISITORS)
|
||||
->set('register', UserInterface::REGISTER_VISITORS)
|
||||
->save();
|
||||
|
||||
$edit = [];
|
||||
|
@ -94,7 +95,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
$this->drupalLogout();
|
||||
|
||||
// Allow registration by site visitors, but require administrator approval.
|
||||
$config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
|
||||
$config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
|
||||
$edit = [];
|
||||
$edit['name'] = $name = $this->randomMachineName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
|
@ -133,7 +134,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
// without administrator approval.
|
||||
$this->config('user.settings')
|
||||
->set('verify_mail', FALSE)
|
||||
->set('register', USER_REGISTER_VISITORS)
|
||||
->set('register', UserInterface::REGISTER_VISITORS)
|
||||
->save();
|
||||
|
||||
// Set up a user to check for duplicates.
|
||||
|
@ -195,7 +196,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
// without administrator approval.
|
||||
$this->config('user.settings')
|
||||
->set('verify_mail', FALSE)
|
||||
->set('register', USER_REGISTER_VISITORS)
|
||||
->set('register', UserInterface::REGISTER_VISITORS)
|
||||
->save();
|
||||
|
||||
$edit = [];
|
||||
|
@ -228,7 +229,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
// without administrator approval.
|
||||
$config_user_settings = $this->config('user.settings')
|
||||
->set('verify_mail', FALSE)
|
||||
->set('register', USER_REGISTER_VISITORS)
|
||||
->set('register', UserInterface::REGISTER_VISITORS)
|
||||
->save();
|
||||
|
||||
// Set the default timezone to Brussels.
|
||||
|
@ -255,7 +256,7 @@ class UserRegistrationTest extends BrowserTestBase {
|
|||
$this->assertEqual($new_user->getAccountName(), $name, 'Username matches.');
|
||||
$this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.');
|
||||
$this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20), 'Correct creation time.');
|
||||
$this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
|
||||
$this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == UserInterface::REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
|
||||
$this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.');
|
||||
$this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct language field.');
|
||||
$this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct preferred language field.');
|
||||
|
|
|
@ -6,6 +6,7 @@ use Drupal\Tests\SchemaCheckTestTrait;
|
|||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\user\AccountSettingsForm;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Upgrade variables to user.*.yml.
|
||||
|
@ -63,9 +64,9 @@ class MigrateUserConfigsTest extends MigrateDrupal6TestBase {
|
|||
|
||||
// Map D6 value to D8 value
|
||||
$user_register_map = [
|
||||
[0, USER_REGISTER_ADMINISTRATORS_ONLY],
|
||||
[1, USER_REGISTER_VISITORS],
|
||||
[2, USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL],
|
||||
[0, UserInterface::REGISTER_ADMINISTRATORS_ONLY],
|
||||
[1, UserInterface::REGISTER_VISITORS],
|
||||
[2, UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL],
|
||||
];
|
||||
|
||||
foreach ($user_register_map as $map) {
|
||||
|
|
|
@ -8,6 +8,7 @@ use Drupal\Core\Render\Element\Email;
|
|||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Verify that user validity checks behave as designed.
|
||||
|
@ -63,7 +64,7 @@ class UserValidationTest extends KernelTestBase {
|
|||
'foo' . chr(0) . 'bar' => ['Invalid username containing chr(0)', 'assertNotNull'],
|
||||
// CR.
|
||||
'foo' . chr(13) . 'bar' => ['Invalid username containing chr(13)', 'assertNotNull'],
|
||||
str_repeat('x', USERNAME_MAX_LENGTH + 1) => ['Invalid excessively long username', 'assertNotNull'],
|
||||
str_repeat('x', UserInterface::USERNAME_MAX_LENGTH + 1) => ['Invalid excessively long username', 'assertNotNull'],
|
||||
];
|
||||
foreach ($test_cases as $name => $test_case) {
|
||||
list($description, $test) = $test_case;
|
||||
|
|
|
@ -7,32 +7,11 @@ use Drupal\Core\Session\AccountInterface;
|
|||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\Plugin\rest\resource\UserRegistrationResource;
|
||||
use Drupal\user\UserInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
/**
|
||||
* Only administrators can create user accounts.
|
||||
*/
|
||||
if (!defined('USER_REGISTER_ADMINISTRATORS_ONLY')) {
|
||||
define('USER_REGISTER_ADMINISTRATORS_ONLY', 'admin_only');
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitors can create their own accounts.
|
||||
*/
|
||||
if (!defined('USER_REGISTER_VISITORS')) {
|
||||
define('USER_REGISTER_VISITORS', 'visitors');
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitors can create accounts, but they don't become active without
|
||||
* administrative approval.
|
||||
*/
|
||||
if (!defined('USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL')) {
|
||||
define('USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL', 'visitors_admin_approval');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests User Registration REST resource.
|
||||
*
|
||||
|
@ -118,7 +97,7 @@ class UserRegistrationResourceTest extends UnitTestCase {
|
|||
*/
|
||||
public function testRegistrationAdminOnlyPost() {
|
||||
|
||||
$this->userSettings->get('register')->willReturn(USER_REGISTER_ADMINISTRATORS_ONLY);
|
||||
$this->userSettings->get('register')->willReturn(UserInterface::REGISTER_ADMINISTRATORS_ONLY);
|
||||
|
||||
$this->currentUser->isAnonymous()->willReturn(TRUE);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\minimal\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Tests Minimal installation profile expectations.
|
||||
|
@ -40,7 +41,7 @@ class MinimalTest extends BrowserTestBase {
|
|||
|
||||
// Ensure special configuration overrides are correct.
|
||||
$this->assertFalse($this->config('system.theme.global')->get('features.node_user_picture'), 'Configuration system.theme.global:features.node_user_picture is FALSE.');
|
||||
$this->assertEquals(USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, $this->config('user.settings')->get('register'));
|
||||
$this->assertEquals(UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, $this->config('user.settings')->get('register'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue