Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\user\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Test\AssertMailTrait;
|
Chris@0
|
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests _user_mail_notify() use of user.settings.notify.*.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group user
|
Chris@0
|
12 */
|
Chris@0
|
13 class UserMailNotifyTest extends EntityKernelTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 use AssertMailTrait {
|
Chris@0
|
16 getMails as drupalGetMails;
|
Chris@0
|
17 }
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * Data provider for user mail testing.
|
Chris@0
|
21 *
|
Chris@0
|
22 * @return array
|
Chris@0
|
23 */
|
Chris@0
|
24 public function userMailsProvider() {
|
Chris@0
|
25 return [
|
Chris@0
|
26 ['cancel_confirm', ['cancel_confirm']],
|
Chris@0
|
27 ['password_reset', ['password_reset']],
|
Chris@0
|
28 ['status_activated', ['status_activated']],
|
Chris@0
|
29 ['status_blocked', ['status_blocked']],
|
Chris@0
|
30 ['status_canceled', ['status_canceled']],
|
Chris@0
|
31 ['register_admin_created', ['register_admin_created']],
|
Chris@0
|
32 ['register_no_approval_required', ['register_no_approval_required']],
|
Chris@17
|
33 ['register_pending_approval', ['register_pending_approval', 'register_pending_approval_admin']],
|
Chris@0
|
34 ];
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Tests mails are sent when notify.$op is TRUE.
|
Chris@0
|
39 *
|
Chris@0
|
40 * @param string $op
|
Chris@0
|
41 * The operation being performed on the account.
|
Chris@0
|
42 * @param array $mail_keys
|
Chris@0
|
43 * The mail keys to test for.
|
Chris@0
|
44 *
|
Chris@0
|
45 * @dataProvider userMailsProvider
|
Chris@0
|
46 */
|
Chris@0
|
47 public function testUserMailsSent($op, array $mail_keys) {
|
Chris@0
|
48 $this->config('user.settings')->set('notify.' . $op, TRUE)->save();
|
Chris@0
|
49 $return = _user_mail_notify($op, $this->createUser());
|
Chris@0
|
50 $this->assertTrue($return, '_user_mail_notify() returns TRUE.');
|
Chris@0
|
51 foreach ($mail_keys as $key) {
|
Chris@0
|
52 $filter = ['key' => $key];
|
Chris@0
|
53 $this->assertNotEmpty($this->getMails($filter), "Mails with $key exists.");
|
Chris@0
|
54 }
|
Chris@0
|
55 $this->assertCount(count($mail_keys), $this->getMails(), 'The expected number of emails sent.');
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * Tests mails are not sent when notify.$op is FALSE.
|
Chris@0
|
60 *
|
Chris@0
|
61 * @param string $op
|
Chris@0
|
62 * The operation being performed on the account.
|
Chris@0
|
63 * @param array $mail_keys
|
Chris@0
|
64 * The mail keys to test for. Ignored by this test because we assert that no
|
Chris@0
|
65 * mails at all are sent.
|
Chris@0
|
66 *
|
Chris@0
|
67 * @dataProvider userMailsProvider
|
Chris@0
|
68 */
|
Chris@0
|
69 public function testUserMailsNotSent($op, array $mail_keys) {
|
Chris@0
|
70 $this->config('user.settings')->set('notify.' . $op, FALSE)->save();
|
Chris@0
|
71 $return = _user_mail_notify($op, $this->createUser());
|
Chris@0
|
72 $this->assertFalse($return, '_user_mail_notify() returns FALSE.');
|
Chris@0
|
73 $this->assertEmpty($this->getMails(), 'No emails sent by _user_mail_notify().');
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 }
|