Chris@18
|
1 <?php
|
Chris@18
|
2
|
Chris@18
|
3 namespace Drupal\Tests\user\Kernel;
|
Chris@18
|
4
|
Chris@18
|
5 use Drupal\Core\Test\AssertMailTrait;
|
Chris@18
|
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
Chris@18
|
7
|
Chris@18
|
8 /**
|
Chris@18
|
9 * Tests _user_mail_notify() use of user.settings.notify.*.
|
Chris@18
|
10 *
|
Chris@18
|
11 * @group user
|
Chris@18
|
12 */
|
Chris@18
|
13 class UserMailNotifyTest extends EntityKernelTestBase {
|
Chris@18
|
14
|
Chris@18
|
15 use AssertMailTrait {
|
Chris@18
|
16 getMails as drupalGetMails;
|
Chris@18
|
17 }
|
Chris@18
|
18
|
Chris@18
|
19 /**
|
Chris@18
|
20 * Data provider for user mail testing.
|
Chris@18
|
21 *
|
Chris@18
|
22 * @return array
|
Chris@18
|
23 */
|
Chris@18
|
24 public function userMailsProvider() {
|
Chris@18
|
25 return [
|
Chris@18
|
26 'cancel confirm notification' => [
|
Chris@18
|
27 'cancel_confirm',
|
Chris@18
|
28 ['cancel_confirm'],
|
Chris@18
|
29 ],
|
Chris@18
|
30 'password reset notification' => [
|
Chris@18
|
31 'password_reset',
|
Chris@18
|
32 ['password_reset'],
|
Chris@18
|
33 ],
|
Chris@18
|
34 'status activated notification' => [
|
Chris@18
|
35 'status_activated',
|
Chris@18
|
36 ['status_activated'],
|
Chris@18
|
37 ],
|
Chris@18
|
38 'status blocked notification' => [
|
Chris@18
|
39 'status_blocked',
|
Chris@18
|
40 ['status_blocked'],
|
Chris@18
|
41 ],
|
Chris@18
|
42 'status canceled notification' => [
|
Chris@18
|
43 'status_canceled',
|
Chris@18
|
44 ['status_canceled'],
|
Chris@18
|
45 ],
|
Chris@18
|
46 'register admin created notification' => [
|
Chris@18
|
47 'register_admin_created',
|
Chris@18
|
48 ['register_admin_created'],
|
Chris@18
|
49 ],
|
Chris@18
|
50 'register no approval required notification' => [
|
Chris@18
|
51 'register_no_approval_required',
|
Chris@18
|
52 ['register_no_approval_required'],
|
Chris@18
|
53 ],
|
Chris@18
|
54 'register pending approval notification' => [
|
Chris@18
|
55 'register_pending_approval',
|
Chris@18
|
56 ['register_pending_approval', 'register_pending_approval_admin'],
|
Chris@18
|
57 ],
|
Chris@18
|
58 ];
|
Chris@18
|
59 }
|
Chris@18
|
60
|
Chris@18
|
61 /**
|
Chris@18
|
62 * Tests mails are sent when notify.$op is TRUE.
|
Chris@18
|
63 *
|
Chris@18
|
64 * @param string $op
|
Chris@18
|
65 * The operation being performed on the account.
|
Chris@18
|
66 * @param array $mail_keys
|
Chris@18
|
67 * The mail keys to test for.
|
Chris@18
|
68 *
|
Chris@18
|
69 * @dataProvider userMailsProvider
|
Chris@18
|
70 */
|
Chris@18
|
71 public function testUserMailsSent($op, array $mail_keys) {
|
Chris@18
|
72 $this->config('user.settings')->set('notify.' . $op, TRUE)->save();
|
Chris@18
|
73 $return = _user_mail_notify($op, $this->createUser());
|
Chris@18
|
74 $this->assertTrue($return);
|
Chris@18
|
75 foreach ($mail_keys as $key) {
|
Chris@18
|
76 $filter = ['key' => $key];
|
Chris@18
|
77 $this->assertNotEmpty($this->getMails($filter));
|
Chris@18
|
78 }
|
Chris@18
|
79 $this->assertCount(count($mail_keys), $this->getMails());
|
Chris@18
|
80 }
|
Chris@18
|
81
|
Chris@18
|
82 /**
|
Chris@18
|
83 * Tests mails are not sent when notify.$op is FALSE.
|
Chris@18
|
84 *
|
Chris@18
|
85 * @param string $op
|
Chris@18
|
86 * The operation being performed on the account.
|
Chris@18
|
87 *
|
Chris@18
|
88 * @dataProvider userMailsProvider
|
Chris@18
|
89 */
|
Chris@18
|
90 public function testUserMailsNotSent($op) {
|
Chris@18
|
91 $this->config('user.settings')->set('notify.' . $op, FALSE)->save();
|
Chris@18
|
92 $return = _user_mail_notify($op, $this->createUser());
|
Chris@18
|
93 $this->assertFalse($return);
|
Chris@18
|
94 $this->assertEmpty($this->getMails());
|
Chris@18
|
95 }
|
Chris@18
|
96
|
Chris@18
|
97 }
|