Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
98889d33
Commit
98889d33
authored
Aug 15, 2016
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2765437
by gambry, alexpott: _user_mail_notify() always sends emails even if is FALSE
parent
24343f97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
3 deletions
+77
-3
core/modules/user/src/Tests/UserMailNotifyTest.php
core/modules/user/src/Tests/UserMailNotifyTest.php
+76
-0
core/modules/user/user.module
core/modules/user/user.module
+1
-3
No files found.
core/modules/user/src/Tests/UserMailNotifyTest.php
0 → 100644
View file @
98889d33
<?php
namespace
Drupal\user\Tests
;
use
Drupal\Core\Test\AssertMailTrait
;
use
Drupal\KernelTests\Core\Entity\EntityKernelTestBase
;
/**
* Tests _user_mail_notify() use of user.settings.notify.*.
*
* @group user
*/
class
UserMailNotifyTest
extends
EntityKernelTestBase
{
use
AssertMailTrait
{
getMails
as
drupalGetMails
;
}
/**
* Data provider for user mail testing.
*
* @return array
*/
public
function
userMailsProvider
()
{
return
[
[
'cancel_confirm'
,
[
'cancel_confirm'
]],
[
'password_reset'
,
[
'password_reset'
]],
[
'status_activated'
,
[
'status_activated'
]],
[
'status_blocked'
,
[
'status_blocked'
]],
[
'status_canceled'
,
[
'status_canceled'
]],
[
'register_admin_created'
,
[
'register_admin_created'
]],
[
'register_no_approval_required'
,
[
'register_no_approval_required'
]],
[
'register_pending_approval'
,
[
'register_pending_approval'
,
'register_pending_approval_admin'
]]
];
}
/**
* Tests mails are sent when notify.$op is TRUE.
*
* @param string $op
* The operation being performed on the account.
* @param array $mail_keys
* The mail keys to test for.
*
* @dataProvider userMailsProvider
*/
public
function
testUserMailsSent
(
$op
,
array
$mail_keys
)
{
$this
->
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().'
);
}
}
core/modules/user/user.module
View file @
98889d33
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment