3 namespace Drupal\Tests\user\Functional;
5 use Drupal\Core\Test\AssertMailTrait;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
9 * Tests _user_mail_notify() use of user.settings.notify.*.
13 class UserMailNotifyTest extends EntityKernelTestBase {
16 getMails as drupalGetMails;
20 * Data provider for user mail testing.
24 public function userMailsProvider() {
26 ['cancel_confirm', ['cancel_confirm']],
27 ['password_reset', ['password_reset']],
28 ['status_activated', ['status_activated']],
29 ['status_blocked', ['status_blocked']],
30 ['status_canceled', ['status_canceled']],
31 ['register_admin_created', ['register_admin_created']],
32 ['register_no_approval_required', ['register_no_approval_required']],
33 ['register_pending_approval', ['register_pending_approval', 'register_pending_approval_admin']],
38 * Tests mails are sent when notify.$op is TRUE.
41 * The operation being performed on the account.
42 * @param array $mail_keys
43 * The mail keys to test for.
45 * @dataProvider userMailsProvider
47 public function testUserMailsSent($op, array $mail_keys) {
48 $this->config('user.settings')->set('notify.' . $op, TRUE)->save();
49 $return = _user_mail_notify($op, $this->createUser());
50 $this->assertTrue($return, '_user_mail_notify() returns TRUE.');
51 foreach ($mail_keys as $key) {
52 $filter = ['key' => $key];
53 $this->assertNotEmpty($this->getMails($filter), "Mails with $key exists.");
55 $this->assertCount(count($mail_keys), $this->getMails(), 'The expected number of emails sent.');
59 * Tests mails are not sent when notify.$op is FALSE.
62 * The operation being performed on the account.
63 * @param array $mail_keys
64 * The mail keys to test for. Ignored by this test because we assert that no
65 * mails at all are sent.
67 * @dataProvider userMailsProvider
69 public function testUserMailsNotSent($op, array $mail_keys) {
70 $this->config('user.settings')->set('notify.' . $op, FALSE)->save();
71 $return = _user_mail_notify($op, $this->createUser());
72 $this->assertFalse($return, '_user_mail_notify() returns FALSE.');
73 $this->assertEmpty($this->getMails(), 'No emails sent by _user_mail_notify().');