When creating a new user, the message telling that the new user has been e-mailed is always displayed, even if it's not true.
How to reproduce it:
In a Drupal instance unable to send e-mails:
1. Go to the page to create new users (admin/people/create)
2. Optional: check the option 'Notify user of new account'
3. Create a new user
Two contradictory messages will be displayed (see screenshot). The messages are:
Unable to send e-mail. Contact the site administrator if the problem persists.
A welcome message with further instructions has been e-mailed to the new user $username.
We should backport the fix to 7.
Comments
Comment #1
Pere OrgaThe following patch fixes the issue.
Comment #2
Pere OrgaI don't know if it's possible to create a test to reproduce the failure.
This second patch is shorter.
Comment #3
Pere OrgaComment #3.0
Pere Orgaadded the text of the messages
Comment #3.1
Pere OrgaIt's not a message, it's a notification.
Comment #4
wesleydv CreditAttribution: wesleydv commentedTested and all seems to work fine.
Comment #5
xjmLet's add an automated test for this. Also tagging for the backport.
Comment #6
Pere Orga@xjm, do yo mean a test that creates a new user, fails to send an e-mail to the new user, and checks the displayed message? Seems strange to do.
Anyways, I think it's quite obvious that the return value of _user_mail_notify() should be checked before printing a success message.
Comment #7
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedI am trying to come up with a test case and found it is difficult to stop mail function with code.
Comment #8
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedHere is the test patch (It should fail before applying patch at #2). I am also put test patch together with the patch in #2.
Comment #9
disasm CreditAttribution: disasm commentedThe patch overall functionally looks great wuinfo! I would like a little better naming though, can't figure out what Mal is supposed to be. Also, the variable_get/variable_set function you are using should be converted to CMI. We don't want to introduce new old style variable functions after a conversion.
What is Mal?
this should be CMI since mail system is converted. Use: config('system.mail')->get('interface'); instead of variable_get('mail_system);
This should be CMI as well.
Comment #10
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commented"Mal" in "MalPhpMail is same as "Mal" in word "Malfunction".
In order to let mail function fail intentionally, I put the MalPhpMail there. Would love the change the name if you have one for it.
Meanwhile, I will convert variable_get/variable_set function to CMI.
Comment #11
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedvariable_get/variable_set function were converted to CMI.
Comment #12
xjmThanks @wuinfo! That test should provide the needed coverage. I like the solution of defining a "broken" mail service.
First, one note about file locations and namespacing for classes that are used only for testing:
I'm with @disasm that "MalPHPMail" is a bit confusing--generally, we prefer whole words in class names, functions, etc. rather than abbreviations. I'd suggest
TestPhpMailFailure
or something like that.Since this class is purely for testing purposes, we should instead move it to the test namespace (including creating a test module to house it if appropriate).
Since the bug we're testing is in the user module, the place to create a test module would be in something like:
We'd create an empty module file in that directory, and then move the test mail sender to the appropriate PSR-0 directory within that module. So, the namespace for the test class will then be:
Drupal\user_mail_failure_test
; and we'll need to add ause
statement forDrupal\Core\Mail\PhpMail
.Make sense? :)
Aside from that, there's just a couple minor cleanups to make:
Minor thing, but the standards for these docblocks since last summer are that they should start with "Contains" instead of "Definition of" and have a preceding slash on the namespace, so:
(A lot of core isn't actually updated to the standard yet, but we should use it here.)
Minor docblock style note: The docblocks should be a single line of 80 characters or fewer and start with an indicative verb, e.g. "Tests."
For inline comments, we normally use the imperative, e.g.:
(Also make sure that they are complete sentences with capitalization, periods, articles, etc.)
TRUE
should be in all caps except in JS.We can probably remove the assertion messages from these two assertions--the default assertion will be even more specific.
Each test method gets its own fresh test installation, so AFAIK we don't need to do this. (Might be worth testing just to make sure it doesn't leak into the parent environment -- remove the line, run the test, and then see if the parent site's setting is affected.)
Adding the novice tag; all these changes should be fairly simple to make. If you do update @wuinfo's patch, please be sure to upload the failing patch as well as the combined patch again, and also provide an interdiff showing your changes. Thanks!
Comment #13
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedThanks xjm, that makes a lot sense.
Changes are done according to @xjm's review.
Tested mail function after running test. Testing did not leak into the parent environment.
1) Installed a new Drupal8 site.
2) Enabled the test module.
3) Tested the user part of tests tasks.
4) Tested the really mail function by sending a notification.(mail was sent.*)
Another patch in #2 is combined with test patch. The combined patch should pass the test. The test patch itself should fail.
Comment #15
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedComment #16
xjmThanks @wuinfo! Note that if you put the test-only patch first and the passing patch second, the testbot won't mark it needs work. :)
I think this is pretty much ready. I just noticed a couple small things re-reading it:
Tests, not test. :) http://drupal.org/node/1354#functions
Ah, sorry if I was unclear: These should be one line only, but they should still be docblocks: http://drupal.org/node/1354#functions
Also, "Tests". :)
Maybe just add an inline comment here as well to explicitly say:
(Above the return but inside the function.)
Let's also add an opening
<?php
tag and an@file
docblock for the module file: http://drupal.org/node/1354#fileTagging novice for those cleanups--removing the "Needs tests" tag because the current tests are exactly what we need.
Comment #17
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedHi @xjm, thanks for the quick review.
Changes are done.
Comment #18
xjmOops, one more thing -- This still needs to be a docblock as well. (Otherwise
api.drupal.org
and IDEs won't be able to parse it to list it as a member for the class.)I really want to RTBC this, so I just fixed this myself. :) (In general one wouldn't RTBC one's own patch, but this is super minor and doesn't change any functional code.)
Comment #19
xjm#18: user-mail-1843380-18.patch queued for re-testing.
Comment #20
xjmComment #21
alexpottThe new user_mail_failure_test module is nice functionality... that should be used elsewhere so lets move it to system/tests and change it's name to system_mail_failure_test.
Minor nits...
The description can be improved to something like
'Provides a malfunctioning mail service for testing purposes.'
We should improve the class's doc block to say how to use it... something along the lines of
Normally this is:
There is no dependency on the user module.
Comment #22
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedThanks @alexpott,
Since I have changed the location of the module, the interdiff.txt file is large. So, I think it is not necessarily to include it.
Comment #23
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedSame as #22. Upload patch again for test.
Comment #24
disasm CreditAttribution: disasm commented@wuinfo You don't need to re-upload the patch to call testbot. Just change the status to needs review, and it will run the tests on any patches that haven't had tests ran on them.
Comment #25
xjmIt's still useful for the other changes, to make it easier for reviewers to check your changes against the committer's review in #21. :) Also, you can make moved/renamed files appear as just one line so long as you didn't also change a majority of the code in the file. You'll want to add this to your
.gitconfig
:(See http://drupal.org/documentation/git/configure for more information.)
For this patch, I just re-read the whole thing and checked it against @alexpott's review.
"Modules to enable" is IMO less useful in general than what we're enabling and why. ;) (However, the missing
@var
was a bug). It's fine to leave it as it is now, though; just wanted to point this out for future reference. :)Typo here: "return" should be "returns".
The config() line should be indented by two spaces here.
Typo: "purpose" should be "purposes." Also, maybe "Disables email sending functionality for testing purposes" would be clearer?
Looks great to me other than those small things. The rest of @alexpott's feedback seems to be covered.
Comment #26
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commented@disasm, yes, I realized it soon after I changed the status on second comment.
Comment #27
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedinterdiff between this and #23. Thanks @xjm, My English is getting better now :)
Comment #29
alexpottRequesting a retest as failure is unrelated...
Comment #30
alexpott#27: contradictory-messages-creating-new-user-include-fix-1843380-27.patch queued for re-testing.
Comment #31
xjmThanks!
Comment #32
alexpottCommitted 42bfe92 and pushed to 8.x. Thanks!
Comment #32.0
alexpottbetter written steps to reproduce
Comment #35
nileshleve CreditAttribution: nileshleve as a volunteer commentedI am working on the backport!!
Comment #36
nileshleve CreditAttribution: nileshleve as a volunteer commentedComment #37
nileshleve CreditAttribution: nileshleve as a volunteer commentedHello, absolute beginner here!
I applied the patch using
patch -p2 < path/you/saved/patch/in.patch
which didn't work because of the various directory name changes and filename changes between D7 and D8.
So, I have manually tried to locate the code that needed changing and created a patch
Applied the patch on my local repo where it works but not sure how those test file works.
Please review and provide me the required suggestions!
Comment #38
darius.restivan CreditAttribution: darius.restivan as a volunteer commentedTested:
"A welcome message with further instructions has been e-mailed to the new user asdasd". Problem seems to be solved.
Comment #39
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commented@nileshleve : Please add Test case for the suggested patch .
Cheers
SwapS
Comment #40
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commented