diff -r 07239de796bb -r e756a8c72c3d cms/drupal/modules/user/user.test
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cms/drupal/modules/user/user.test Fri Sep 08 12:04:06 2017 +0200
@@ -0,0 +1,2636 @@
+ 'User registration',
+ 'description' => 'Test registration of user under different configurations.',
+ 'group' => 'User'
+ );
+ }
+
+ function setUp() {
+ parent::setUp('field_test');
+ }
+
+ function testRegistrationWithEmailVerification() {
+ // Require e-mail verification.
+ variable_set('user_email_verification', TRUE);
+
+ // Set registration to administrator only.
+ variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
+ $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.
+ variable_set('user_register', USER_REGISTER_VISITORS);
+ $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 = 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.
+ variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
+ $edit = array();
+ $edit['name'] = $name = $this->randomName();
+ $edit['mail'] = $mail = $edit['name'] . '@example.com';
+ $this->drupalPost('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.');
+ }
+
+ function testRegistrationWithoutEmailVerification() {
+ // Don't require e-mail verification.
+ variable_set('user_email_verification', FALSE);
+
+ // Allow registration by site visitors without administrator approval.
+ variable_set('user_register', USER_REGISTER_VISITORS);
+ $edit = array();
+ $edit['name'] = $name = $this->randomName();
+ $edit['mail'] = $mail = $edit['name'] . '@example.com';
+
+ // Try entering a mismatching password.
+ $edit['pass[pass1]'] = '99999.0';
+ $edit['pass[pass2]'] = '99999';
+ $this->drupalPost('user/register', $edit, t('Create new account'));
+ $this->assertText(t('The specified passwords do not match.'), 'Typing mismatched passwords displays an error message.');
+
+ // Enter a correct password.
+ $edit['pass[pass1]'] = $new_pass = $this->randomName();
+ $edit['pass[pass2]'] = $new_pass;
+ $this->drupalPost('user/register', $edit, t('Create new account'));
+ $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
+ $new_user = reset($accounts);
+ $this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.');
+ $this->drupalLogout();
+
+ // Allow registration by site visitors, but require administrator approval.
+ variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
+ $edit = array();
+ $edit['name'] = $name = $this->randomName();
+ $edit['mail'] = $mail = $edit['name'] . '@example.com';
+ $edit['pass[pass1]'] = $pass = $this->randomName();
+ $edit['pass[pass2]'] = $pass;
+ $this->drupalPost('user/register', $edit, t('Create new account'));
+ $this->assertText(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'), 'Users are notified of pending approval');
+
+ // Try to login before administrator approval.
+ $auth = array(
+ 'name' => $name,
+ 'pass' => $pass,
+ );
+ $this->drupalPost('user/login', $auth, t('Log in'));
+ $this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), 'User cannot login yet.');
+
+ // Activate the new account.
+ $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
+ $new_user = reset($accounts);
+ $admin_user = $this->drupalCreateUser(array('administer users'));
+ $this->drupalLogin($admin_user);
+ $edit = array(
+ 'status' => 1,
+ );
+ $this->drupalPost('user/' . $new_user->uid . '/edit', $edit, t('Save'));
+ $this->drupalLogout();
+
+ // Login after administrator approval.
+ $this->drupalPost('user/login', $auth, t('Log in'));
+ $this->assertText(t('Member for'), 'User can log in after administrator approval.');
+ }
+
+ function testRegistrationEmailDuplicates() {
+ // Don't require e-mail verification.
+ variable_set('user_email_verification', FALSE);
+
+ // Allow registration by site visitors without administrator approval.
+ variable_set('user_register', USER_REGISTER_VISITORS);
+
+ // Set up a user to check for duplicates.
+ $duplicate_user = $this->drupalCreateUser();
+
+ $edit = array();
+ $edit['name'] = $this->randomName();
+ $edit['mail'] = $duplicate_user->mail;
+
+ // Attempt to create a new account using an existing e-mail address.
+ $this->drupalPost('user/register', $edit, t('Create new account'));
+ $this->assertText(t('The e-mail address @email is already registered.', array('@email' => $duplicate_user->mail)), 'Supplying an exact duplicate email address displays an error message');
+
+ // Attempt to bypass duplicate email registration validation by adding spaces.
+ $edit['mail'] = ' ' . $duplicate_user->mail . ' ';
+
+ $this->drupalPost('user/register', $edit, t('Create new account'));
+ $this->assertText(t('The e-mail address @email is already registered.', array('@email' => $duplicate_user->mail)), 'Supplying a duplicate email address with added whitespace displays an error message');
+ }
+
+ function testRegistrationDefaultValues() {
+ // Allow registration by site visitors without administrator approval.
+ variable_set('user_register', USER_REGISTER_VISITORS);
+
+ // Don't require e-mail verification.
+ variable_set('user_email_verification', FALSE);
+
+ // Set the default timezone to Brussels.
+ variable_set('configurable_timezones', 1);
+ variable_set('date_default_timezone', 'Europe/Brussels');
+
+ // Check that the account information fieldset's options are not displayed
+ // is a fieldset if there is not more than one fieldset in the form.
+ $this->drupalGet('user/register');
+ $this->assertNoRaw('