You are here

public function UserRegistrationPasswordMailNotifyTest::testUserRegistrationMailsSent in User registration password 8

Tests mails are sent.

@dataProvider userRegistrationMailsProvider

Parameters

string $op: The operation being performed on the account.

array $mail_keys: The mail keys to test for.

File

tests/src/Kernel/UserRegistrationPasswordMailNotifyTest.php, line 48

Class

UserRegistrationPasswordMailNotifyTest
Tests user_registrationpassword_mail_notify()

Namespace

Drupal\Tests\user_registrationpassword\Kernel

Code

public function testUserRegistrationMailsSent($op, array $mail_keys) {
  $this
    ->config('user_registrationpassword.settings')
    ->set('notify.' . $op, 1)
    ->save();
  $edit = [];
  $edit['name'] = $this
    ->randomMachineName();
  $edit['mail'] = $edit['name'] . '@example.com';
  $edit['pass'] = user_password();
  $edit['status'] = 0;

  /** @var \Drupal\user\UserInterface $account */
  $account = $this
    ->createUser($edit);
  $return = _user_registrationpassword_mail_notify($op, $account);
  $this
    ->assertTrue($return, '_user_registrationpassword_mail_notify() returns TRUE.');
  foreach ($mail_keys as $key) {
    $filter = [
      'key' => $key,
    ];
    $this
      ->assertNotEmpty($this
      ->getMails($filter), "Mails with {$key} exists.");
  }
  $this
    ->assertCount(count($mail_keys), $this
    ->getMails(), 'The expected number of emails sent.');
}