comparison core/modules/user/tests/src/Kernel/UserMailNotifyTest.php @ 18:af1871eacc83

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