From 98889d33d16163a252ea5bb182615256082a8a0e Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Mon, 15 Aug 2016 08:39:21 +0100 Subject: [PATCH] Issue #2765437 by gambry, alexpott: _user_mail_notify() always sends emails even if is FALSE --- .../user/src/Tests/UserMailNotifyTest.php | 76 +++++++++++++++++++ core/modules/user/user.module | 4 +- 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 core/modules/user/src/Tests/UserMailNotifyTest.php diff --git a/core/modules/user/src/Tests/UserMailNotifyTest.php b/core/modules/user/src/Tests/UserMailNotifyTest.php new file mode 100644 index 00000000000..9943c5b73de --- /dev/null +++ b/core/modules/user/src/Tests/UserMailNotifyTest.php @@ -0,0 +1,76 @@ +config('user.settings')->set('notify.' . $op, TRUE)->save(); + $return = _user_mail_notify($op, $this->createUser()); + $this->assertTrue($return, '_user_mail_notify() returns TRUE.'); + foreach ($mail_keys as $key) { + $filter = array('key' => $key); + $this->assertNotEmpty($this->getMails($filter), "Mails with $key exists."); + } + $this->assertCount(count($mail_keys), $this->getMails(), 'The expected number of emails sent.'); + } + + /** + * Tests mails are not sent when notify.$op is FALSE. + * + * @param string $op + * The operation being performed on the account. + * @param array $mail_keys + * The mail keys to test for. Ignored by this test because we assert that no + * mails at all are sent. + * + * @dataProvider userMailsProvider + */ + public function testUserMailsNotSent($op, array $mail_keys) { + $this->config('user.settings')->set('notify.' . $op, FALSE)->save(); + $return = _user_mail_notify($op, $this->createUser()); + $this->assertFalse($return, '_user_mail_notify() returns FALSE.'); + $this->assertEmpty($this->getMails(), 'No emails sent by _user_mail_notify().'); + } + +} diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 1adfc9b5bac..c530547387c 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1197,9 +1197,7 @@ function user_role_revoke_permissions($rid, array $permissions = array()) { * @see user_mail_tokens() */ function _user_mail_notify($op, $account, $langcode = NULL) { - // By default, we always notify except for canceled and blocked. - $notify = \Drupal::config('user.settings')->get('notify.' . $op); - if ($notify || ($op != 'status_canceled' && $op != 'status_blocked')) { + if (\Drupal::config('user.settings')->get('notify.' . $op)) { $params['account'] = $account; $langcode = $langcode ? $langcode : $account->getPreferredLangcode(); // Get the custom site notification email to use as the from email address