function testRegistrationWithEmailVerification() {
$config = config('user.settings');
// Require e-mail verification.
$config
->set('verify_mail', TRUE)
->save();
// Set registration to administrator only.
$config
->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)
->save();
$this
->drupalGet('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('register', USER_REGISTER_VISITORS)
->save();
$edit = array();
$edit['name'] = $name = $this
->randomName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this
->drupalPost('user/register', $edit, t('Create new account'));
$this
->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), 'User registered successfully.');
$accounts = entity_load_multiple_by_properties('user', 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('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
->save();
$edit = array();
$edit['name'] = $name = $this
->randomName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this
->drupalPost('user/register', $edit, t('Create new account'));
entity_get_controller('user')
->resetCache();
$accounts = entity_load_multiple_by_properties('user', array(
'name' => $name,
'mail' => $mail,
));
$new_user = reset($accounts);
$this
->assertFalse($new_user->status, 'New account is blocked until approved by an administrator.');
}