public function UserRegistrationTest::testUuidFormState in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/tests/src/Functional/UserRegistrationTest.php \Drupal\Tests\user\Functional\UserRegistrationTest::testUuidFormState()
Tests that UUID isn't cached in form state on register form.
This is a regression test for https://www.drupal.org/node/2500527 to ensure that the form is not cached on GET requests.
File
- core/
modules/ user/ tests/ src/ Functional/ UserRegistrationTest.php, line 170
Class
- UserRegistrationTest
- Tests registration of user under different configurations.
Namespace
Drupal\Tests\user\FunctionalCode
public function testUuidFormState() {
\Drupal::service('module_installer')
->install([
'image',
]);
\Drupal::service('router.builder')
->rebuild();
// Add a picture field in order to ensure that no form cache is written,
// which breaks registration of more than 1 user every 6 hours.
$field_storage = FieldStorageConfig::create([
'field_name' => 'user_picture',
'entity_type' => 'user',
'type' => 'image',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_name' => 'user_picture',
'entity_type' => 'user',
'bundle' => 'user',
]);
$field
->save();
$form_display = EntityFormDisplay::create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'default',
'status' => TRUE,
]);
$form_display
->setComponent('user_picture', [
'type' => 'image_image',
]);
$form_display
->save();
// Don't require email verification and allow registration by site visitors
// without administrator approval.
$this
->config('user.settings')
->set('verify_mail', FALSE)
->set('register', UserInterface::REGISTER_VISITORS)
->save();
$edit = [];
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$edit['pass[pass2]'] = $edit['pass[pass1]'] = $this
->randomMachineName();
// Create one account.
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertSession()
->statusCodeEquals(200);
$user_storage = \Drupal::entityTypeManager()
->getStorage('user');
$this
->assertNotEmpty($user_storage
->loadByProperties([
'name' => $edit['name'],
]));
$this
->drupalLogout();
// Create a second account.
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$edit['pass[pass2]'] = $edit['pass[pass1]'] = $this
->randomMachineName();
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertNotEmpty($user_storage
->loadByProperties([
'name' => $edit['name'],
]));
}