Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/tests/src/Functional/UserMailNotifyTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\user\Functional; | |
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', ['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']] | |
34 ]; | |
35 } | |
36 | |
37 /** | |
38 * Tests mails are sent when notify.$op is TRUE. | |
39 * | |
40 * @param string $op | |
41 * The operation being performed on the account. | |
42 * @param array $mail_keys | |
43 * The mail keys to test for. | |
44 * | |
45 * @dataProvider userMailsProvider | |
46 */ | |
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."); | |
54 } | |
55 $this->assertCount(count($mail_keys), $this->getMails(), 'The expected number of emails sent.'); | |
56 } | |
57 | |
58 /** | |
59 * Tests mails are not sent when notify.$op is FALSE. | |
60 * | |
61 * @param string $op | |
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. | |
66 * | |
67 * @dataProvider userMailsProvider | |
68 */ | |
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().'); | |
74 } | |
75 | |
76 } |