function UserRegistrationTest::testRegistrationDefaultValues in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/user/src/Tests/UserRegistrationTest.php \Drupal\user\Tests\UserRegistrationTest::testRegistrationDefaultValues()
File
- core/
modules/ user/ src/ Tests/ UserRegistrationTest.php, line 226 - Contains \Drupal\user\Tests\UserRegistrationTest.
Class
- UserRegistrationTest
- Tests registration of user under different configurations.
Namespace
Drupal\user\TestsCode
function testRegistrationDefaultValues() {
// 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', USER_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 that the account information options are not displayed
// as a details element if there is not more than one details in the form.
$this
->drupalGet('user/register');
$this
->assertNoRaw('<details id="edit-account"><summary>Account information</summary>');
// Check the presence of expected cache tags.
$this
->assertCacheTag('config:user.settings');
$edit = array();
$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
->drupalPostForm(NULL, $edit, t('Create new account'));
// Check user fields.
$accounts = entity_load_multiple_by_properties('user', array(
'name' => $name,
'mail' => $mail,
));
$new_user = reset($accounts);
$this
->assertEqual($new_user
->getUsername(), $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
->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.');
$this
->assertEqual($new_user->init->value, $mail, 'Correct init field.');
}