You are here

function UserAdminTest::testNotificationEmailAddress in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/user/src/Tests/UserAdminTest.php \Drupal\user\Tests\UserAdminTest::testNotificationEmailAddress()

Tests the alternate notification email address for user mails.

File

core/modules/user/src/Tests/UserAdminTest.php, line 151
Contains \Drupal\user\Tests\UserAdminTest.

Class

UserAdminTest
Tests user administration page functionality.

Namespace

Drupal\user\Tests

Code

function testNotificationEmailAddress() {

  // Test that the Notification Email address field is on the config page.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer users',
    'administer account settings',
  ));
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('admin/config/people/accounts');
  $this
    ->assertRaw('id="edit-mail-notification-address"', 'Notification Email address field exists');
  $this
    ->drupalLogout();

  // Test custom user registration approval email address(es).
  $config = $this
    ->config('user.settings');

  // Allow users to register with admin approval.
  $config
    ->set('verify_mail', TRUE)
    ->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
    ->save();

  // Set the site and notification email addresses.
  $system = $this
    ->config('system.site');
  $server_address = $this
    ->randomMachineName() . '@example.com';
  $notify_address = $this
    ->randomMachineName() . '@example.com';
  $system
    ->set('mail', $server_address)
    ->set('mail_notification', $notify_address)
    ->save();

  // Register a new user account.
  $edit = array();
  $edit['name'] = $name = $this
    ->randomMachineName();
  $edit['mail'] = $mail = $edit['name'] . '@example.com';
  $this
    ->drupalPostForm('user/register', $edit, t('Create new account'));
  $subject = 'Account details for ' . $edit['name'] . ' at ' . $system
    ->get('name') . ' (pending admin approval)';

  // Ensure that admin notification mail is sent to the configured
  // Notification Email address.
  $admin_mail = $this
    ->drupalGetMails(array(
    'to' => $notify_address,
    'from' => $server_address,
    'subject' => $subject,
  ));
  $this
    ->assertTrue(count($admin_mail), 'New user mail to admin is sent to configured Notification Email address');

  // Ensure that user notification mail is sent from the configured
  // Notification Email address.
  $user_mail = $this
    ->drupalGetMails(array(
    'to' => $edit['mail'],
    'from' => $server_address,
    'reply-to' => $notify_address,
    'subject' => $subject,
  ));
  $this
    ->assertTrue(count($user_mail), 'New user mail to user is sent from configured Notification Email address');
}