function UserRegistrationTest::testRegistrationDefaultValues
Same name in other branches
- 9 core/modules/user/tests/src/Functional/UserRegistrationTest.php \Drupal\Tests\user\Functional\UserRegistrationTest::testRegistrationDefaultValues()
- 8.9.x core/modules/user/tests/src/Functional/UserRegistrationTest.php \Drupal\Tests\user\Functional\UserRegistrationTest::testRegistrationDefaultValues()
- 11.x core/modules/user/tests/src/Functional/UserRegistrationTest.php \Drupal\Tests\user\Functional\UserRegistrationTest::testRegistrationDefaultValues()
File
-
core/
modules/ user/ tests/ src/ Functional/ UserRegistrationTest.php, line 244
Class
- UserRegistrationTest
- Tests registration of user under different configurations.
Namespace
Drupal\Tests\user\FunctionalCode
public function testRegistrationDefaultValues() : void {
// Don't require email verification and allow registration by site visitors
// without administrator approval.
$config_user_settings = $this->config('user.settings')
->set('verify_mail', FALSE)
->set('register', UserInterface::REGISTER_VISITORS)
->save();
// Set the default timezone to Brussels.
$config_system_date = $this->config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
->save();
// Check the presence of expected cache tags.
$this->drupalGet('user/register');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config:user.settings');
$edit = [];
$edit['name'] = $name = $this->randomMachineName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$edit['pass[pass1]'] = $new_pass = $this->randomMachineName();
$edit['pass[pass2]'] = $new_pass;
$this->submitForm($edit, 'Create new account');
// Check user fields.
$accounts = $this->container
->get('entity_type.manager')
->getStorage('user')
->loadByProperties([
'name' => $name,
'mail' => $mail,
]);
$new_user = reset($accounts);
$this->assertEquals($name, $new_user->getAccountName(), 'Username matches.');
$this->assertEquals($mail, $new_user->getEmail(), 'Email address matches.');
// Verify that the creation time is correct.
$this->assertGreaterThan(\Drupal::time()->getRequestTime() - 20, $new_user->getCreatedTime());
$this->assertEquals($config_user_settings->get('register') == UserInterface::REGISTER_VISITORS ? 1 : 0, $new_user->isActive(), 'Correct status field.');
$this->assertEquals($config_system_date->get('timezone.default'), $new_user->getTimezone(), 'Correct time zone field.');
$this->assertEquals(\Drupal::languageManager()->getDefaultLanguage()
->getId(), $new_user->langcode->value, 'Correct language field.');
$this->assertEquals(\Drupal::languageManager()->getDefaultLanguage()
->getId(), $new_user->preferred_langcode->value, 'Correct preferred language field.');
$this->assertEquals($mail, $new_user->init->value, 'Correct init field.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.