1 user.test | UserRegistrationTestCase::testRegistrationWithEmailVerification() |
File
- core/
modules/ user/ tests/ user.test, line 88 - Tests for user.module.
Class
Code
function testRegistrationWithEmailVerification() {
$config = config('system.core');
// Require email verification.
$config->set('user_email_verification', TRUE);
// Set registration to administrator only.
$config->set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
$config->save();
$this->backdropGet('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('user_register', USER_REGISTER_VISITORS)->save();
$edit = array();
$edit['name'] = $name = $this->randomName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this->backdropPost('user/register', $edit, t('Create new account'));
$this->assertText(t('A welcome message with further instructions has been sent to your email address.'), 'User registered successfully.');
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$this->assertTrue($new_user->status, 'New account is active after registration.');
// Allow registration by site visitors, but require administrator approval.
$config->set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
$edit = array();
$edit['name'] = $name = $this->randomName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this->backdropPost('user/register', $edit, t('Create new account'));
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
$new_user = reset($accounts);
$this->assertFalse($new_user->status, 'New account is blocked until approved by an administrator.');
}