Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/user/tests/src/Functional/UserRegistrationTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
6 use Drupal\Core\Entity\Entity\EntityFormDisplay; | 6 use Drupal\Core\Entity\Entity\EntityFormDisplay; |
7 use Drupal\Core\Field\FieldStorageDefinitionInterface; | 7 use Drupal\Core\Field\FieldStorageDefinitionInterface; |
8 use Drupal\field\Entity\FieldConfig; | 8 use Drupal\field\Entity\FieldConfig; |
9 use Drupal\field\Entity\FieldStorageConfig; | 9 use Drupal\field\Entity\FieldStorageConfig; |
10 use Drupal\Tests\BrowserTestBase; | 10 use Drupal\Tests\BrowserTestBase; |
11 use Drupal\user\UserInterface; | |
11 | 12 |
12 /** | 13 /** |
13 * Tests registration of user under different configurations. | 14 * Tests registration of user under different configurations. |
14 * | 15 * |
15 * @group user | 16 * @group user |
27 $config = $this->config('user.settings'); | 28 $config = $this->config('user.settings'); |
28 // Require email verification. | 29 // Require email verification. |
29 $config->set('verify_mail', TRUE)->save(); | 30 $config->set('verify_mail', TRUE)->save(); |
30 | 31 |
31 // Set registration to administrator only. | 32 // Set registration to administrator only. |
32 $config->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save(); | 33 $config->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)->save(); |
33 $this->drupalGet('user/register'); | 34 $this->drupalGet('user/register'); |
34 $this->assertResponse(403, 'Registration page is inaccessible when only administrators can create accounts.'); | 35 $this->assertResponse(403, 'Registration page is inaccessible when only administrators can create accounts.'); |
35 | 36 |
36 // Allow registration by site visitors without administrator approval. | 37 // Allow registration by site visitors without administrator approval. |
37 $config->set('register', USER_REGISTER_VISITORS)->save(); | 38 $config->set('register', UserInterface::REGISTER_VISITORS)->save(); |
38 $edit = []; | 39 $edit = []; |
39 $edit['name'] = $name = $this->randomMachineName(); | 40 $edit['name'] = $name = $this->randomMachineName(); |
40 $edit['mail'] = $mail = $edit['name'] . '@example.com'; | 41 $edit['mail'] = $mail = $edit['name'] . '@example.com'; |
41 $this->drupalPostForm('user/register', $edit, t('Create new account')); | 42 $this->drupalPostForm('user/register', $edit, t('Create new account')); |
42 $this->assertText(t('A welcome message with further instructions has been sent to your email address.'), 'User registered successfully.'); | 43 $this->assertText(t('A welcome message with further instructions has been sent to your email address.'), 'User registered successfully.'); |
49 $resetURL = user_pass_reset_url($new_user); | 50 $resetURL = user_pass_reset_url($new_user); |
50 $this->drupalGet($resetURL); | 51 $this->drupalGet($resetURL); |
51 $this->assertTitle(t('Set password | Drupal'), 'Page title is "Set password".'); | 52 $this->assertTitle(t('Set password | Drupal'), 'Page title is "Set password".'); |
52 | 53 |
53 // Allow registration by site visitors, but require administrator approval. | 54 // Allow registration by site visitors, but require administrator approval. |
54 $config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(); | 55 $config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(); |
55 $edit = []; | 56 $edit = []; |
56 $edit['name'] = $name = $this->randomMachineName(); | 57 $edit['name'] = $name = $this->randomMachineName(); |
57 $edit['mail'] = $mail = $edit['name'] . '@example.com'; | 58 $edit['mail'] = $mail = $edit['name'] . '@example.com'; |
58 $this->drupalPostForm('user/register', $edit, t('Create new account')); | 59 $this->drupalPostForm('user/register', $edit, t('Create new account')); |
59 $this->container->get('entity.manager')->getStorage('user')->resetCache(); | 60 $this->container->get('entity.manager')->getStorage('user')->resetCache(); |
66 $config = $this->config('user.settings'); | 67 $config = $this->config('user.settings'); |
67 // Don't require email verification and allow registration by site visitors | 68 // Don't require email verification and allow registration by site visitors |
68 // without administrator approval. | 69 // without administrator approval. |
69 $config | 70 $config |
70 ->set('verify_mail', FALSE) | 71 ->set('verify_mail', FALSE) |
71 ->set('register', USER_REGISTER_VISITORS) | 72 ->set('register', UserInterface::REGISTER_VISITORS) |
72 ->save(); | 73 ->save(); |
73 | 74 |
74 $edit = []; | 75 $edit = []; |
75 $edit['name'] = $name = $this->randomMachineName(); | 76 $edit['name'] = $name = $this->randomMachineName(); |
76 $edit['mail'] = $mail = $edit['name'] . '@example.com'; | 77 $edit['mail'] = $mail = $edit['name'] . '@example.com'; |
92 $this->assertNotNull($new_user, 'New account successfully created with matching passwords.'); | 93 $this->assertNotNull($new_user, 'New account successfully created with matching passwords.'); |
93 $this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.'); | 94 $this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.'); |
94 $this->drupalLogout(); | 95 $this->drupalLogout(); |
95 | 96 |
96 // Allow registration by site visitors, but require administrator approval. | 97 // Allow registration by site visitors, but require administrator approval. |
97 $config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(); | 98 $config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(); |
98 $edit = []; | 99 $edit = []; |
99 $edit['name'] = $name = $this->randomMachineName(); | 100 $edit['name'] = $name = $this->randomMachineName(); |
100 $edit['mail'] = $mail = $edit['name'] . '@example.com'; | 101 $edit['mail'] = $mail = $edit['name'] . '@example.com'; |
101 $edit['pass[pass1]'] = $pass = $this->randomMachineName(); | 102 $edit['pass[pass1]'] = $pass = $this->randomMachineName(); |
102 $edit['pass[pass2]'] = $pass; | 103 $edit['pass[pass2]'] = $pass; |
131 public function testRegistrationEmailDuplicates() { | 132 public function testRegistrationEmailDuplicates() { |
132 // Don't require email verification and allow registration by site visitors | 133 // Don't require email verification and allow registration by site visitors |
133 // without administrator approval. | 134 // without administrator approval. |
134 $this->config('user.settings') | 135 $this->config('user.settings') |
135 ->set('verify_mail', FALSE) | 136 ->set('verify_mail', FALSE) |
136 ->set('register', USER_REGISTER_VISITORS) | 137 ->set('register', UserInterface::REGISTER_VISITORS) |
137 ->save(); | 138 ->save(); |
138 | 139 |
139 // Set up a user to check for duplicates. | 140 // Set up a user to check for duplicates. |
140 $duplicate_user = $this->drupalCreateUser(); | 141 $duplicate_user = $this->drupalCreateUser(); |
141 | 142 |
193 | 194 |
194 // Don't require email verification and allow registration by site visitors | 195 // Don't require email verification and allow registration by site visitors |
195 // without administrator approval. | 196 // without administrator approval. |
196 $this->config('user.settings') | 197 $this->config('user.settings') |
197 ->set('verify_mail', FALSE) | 198 ->set('verify_mail', FALSE) |
198 ->set('register', USER_REGISTER_VISITORS) | 199 ->set('register', UserInterface::REGISTER_VISITORS) |
199 ->save(); | 200 ->save(); |
200 | 201 |
201 $edit = []; | 202 $edit = []; |
202 $edit['name'] = $this->randomMachineName(); | 203 $edit['name'] = $this->randomMachineName(); |
203 $edit['mail'] = $edit['name'] . '@example.com'; | 204 $edit['mail'] = $edit['name'] . '@example.com'; |
226 public function testRegistrationDefaultValues() { | 227 public function testRegistrationDefaultValues() { |
227 // Don't require email verification and allow registration by site visitors | 228 // Don't require email verification and allow registration by site visitors |
228 // without administrator approval. | 229 // without administrator approval. |
229 $config_user_settings = $this->config('user.settings') | 230 $config_user_settings = $this->config('user.settings') |
230 ->set('verify_mail', FALSE) | 231 ->set('verify_mail', FALSE) |
231 ->set('register', USER_REGISTER_VISITORS) | 232 ->set('register', UserInterface::REGISTER_VISITORS) |
232 ->save(); | 233 ->save(); |
233 | 234 |
234 // Set the default timezone to Brussels. | 235 // Set the default timezone to Brussels. |
235 $config_system_date = $this->config('system.date') | 236 $config_system_date = $this->config('system.date') |
236 ->set('timezone.user.configurable', 1) | 237 ->set('timezone.user.configurable', 1) |
250 | 251 |
251 // Check user fields. | 252 // Check user fields. |
252 $accounts = $this->container->get('entity_type.manager')->getStorage('user') | 253 $accounts = $this->container->get('entity_type.manager')->getStorage('user') |
253 ->loadByProperties(['name' => $name, 'mail' => $mail]); | 254 ->loadByProperties(['name' => $name, 'mail' => $mail]); |
254 $new_user = reset($accounts); | 255 $new_user = reset($accounts); |
255 $this->assertEqual($new_user->getUsername(), $name, 'Username matches.'); | 256 $this->assertEqual($new_user->getAccountName(), $name, 'Username matches.'); |
256 $this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.'); | 257 $this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.'); |
257 $this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20), 'Correct creation time.'); | 258 $this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20), 'Correct creation time.'); |
258 $this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); | 259 $this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == UserInterface::REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); |
259 $this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.'); | 260 $this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.'); |
260 $this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct language field.'); | 261 $this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct language field.'); |
261 $this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct preferred language field.'); | 262 $this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct preferred language field.'); |
262 $this->assertEqual($new_user->init->value, $mail, 'Correct init field.'); | 263 $this->assertEqual($new_user->init->value, $mail, 'Correct init field.'); |
263 } | 264 } |
269 * @see \Drupal\user\Plugin\Validation\Constraint\UserMailUnique | 270 * @see \Drupal\user\Plugin\Validation\Constraint\UserMailUnique |
270 */ | 271 */ |
271 public function testUniqueFields() { | 272 public function testUniqueFields() { |
272 $account = $this->drupalCreateUser(); | 273 $account = $this->drupalCreateUser(); |
273 | 274 |
274 $edit = ['mail' => 'test@example.com', 'name' => $account->getUsername()]; | 275 $edit = ['mail' => 'test@example.com', 'name' => $account->getAccountName()]; |
275 $this->drupalPostForm('user/register', $edit, t('Create new account')); | 276 $this->drupalPostForm('user/register', $edit, t('Create new account')); |
276 $this->assertRaw(new FormattableMarkup('The username %value is already taken.', ['%value' => $account->getUsername()])); | 277 $this->assertRaw(new FormattableMarkup('The username %value is already taken.', ['%value' => $account->getAccountName()])); |
277 | 278 |
278 $edit = ['mail' => $account->getEmail(), 'name' => $this->randomString()]; | 279 $edit = ['mail' => $account->getEmail(), 'name' => $this->randomString()]; |
279 $this->drupalPostForm('user/register', $edit, t('Create new account')); | 280 $this->drupalPostForm('user/register', $edit, t('Create new account')); |
280 $this->assertRaw(new FormattableMarkup('The email address %value is already taken.', ['%value' => $account->getEmail()])); | 281 $this->assertRaw(new FormattableMarkup('The email address %value is already taken.', ['%value' => $account->getEmail()])); |
281 } | 282 } |