Updated: Comment #N
Problem/Motivation
if (!$message->isPersonal()) {
watchdog('contact', '%sender-name (@sender-from) sent an e-mail regarding %category.', array(
'%sender-name' => $sender->name,
'@sender-from' => $sender->getEmail(),
'%category' => $category->label(),
));
}
else {
watchdog('contact', '%sender-name (@sender-from) sent %recipient-name an e-mail.', array(
'%sender-name' => $sender->name,
'@sender-from' => $sender->getEmail(),
'%recipient-name' => $message->recipient->name,
));
}
To reproduce the error: Send a contact mail, go the recent log messages page, you will see php warnings. If you have devel enabled, it will fail with a recoverable fatal error.
Proposed resolution
That should use getUsername() instead of getName().
For tests, make sure that dblog is enabled, and after the contact message is sent, go to admin/reports/dblog (make sure the user has the necessary permission), and verify that the correct message is shown.
Remaining tasks
Needs tests
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | smells_like_random_fail.png | 28.71 KB | berdir |
| #28 | interdiff-2223611-23.txt | 1.16 KB | cs_shadow |
| #28 | contact-php_notices_raised_due_to_incorrect_username-2223611-23.patch | 3.43 KB | cs_shadow |
| #19 | contact-php_notices_raised_due_to_incorrect_username-2223611-19.patch | 3.34 KB | visabhishek |
| #19 | interdiff-2223611-15-19.txt | 1016 bytes | visabhishek |
Comments
Comment #1
vintorezxxi commentedChanged $sender->name, to $sender->getUsername(),
Were thinking about changing to $sender->name->value, but previous solution seems more convenient.
Comment #2
vintorezxxi commentedComment #3
vintorezxxi commentedComment #4
vintorezxxi commentedComment #5
leex commentedTested, works fine.
Comment #6
dman commentedUpdate summary to : "needs tests" to complete this task. As in the OP, it's not ready until tests exist.
Comment #7
berdirYep, which means it needs work.
Also, I think $message->recipient->name needs to be updated too.
Comment #8
jonathan_hunt commentedAlso tested, works for me. However tests are a mess: ContactSitewideTest gives 164 passes, 216 fails.
Comment #9
dman commentedYep. We were sprinting ( #Drupal8NZ) so I took the opportunity to do a short in-person introduction to what it means to write tests before batting it back immediately with a terse "Needs Work". We are up to speed with that now. In progress.
Comment #10
dman commentedFollowing up from @vintorezxxi's work here...
Here is what a TEST that replicates the described error looks like.
This TEST ONLY patch is expected to return red, as it highlights the fact that : visiting the reports page after sending a message triggers a PHP warning.
Comment #11
dman commentedAnd here is the re-roll of #1, with the patch included. This is expected to run green again, as it proves the problem, AND fixes it at the same time.
(@vintorezxxi : Note the patch naming conventions we looked at on Monday.)
Comment #12
dman commentedIn related testing here, I noticed that it's now legal to create a user with no email. For reasons.
Yet there is no check for this when sending a mail to that user through the contact form - which triggers an error.
If I can't find an existing issue for that, I guess I'll open a new one.
Comment #14
berdirThe comment only makes sense in the context of this patch, as soon as it is committed, it is no longer clear what "was enough ..." refers to.
Instead I would add simple assertText() assertion and look for the message that we expect, including the correctly displayed username. Then we also have test coverage for what the code is actually doing, this would also pass if we would remove the watchdog() call completely.
Then add a comment that explains what we do ("Verify that the correct watchdog message has been logged." ?).
Comment #15
ACF commentedComment #16
ACF commentedMade the change to the test suggested. In the process I spotted that the recipient name wasn't being passed to watchdog so i've made that change.
Comment #18
berdirThis should use String::format('@username (@mail)....', $placeholders). Looks good otherwise.
Comment #19
visabhishek commentedi am updating patch as per #18
Comment #21
vastav commented19: contact-php_notices_raised_due_to_incorrect_username-2223611-19.patch queued for re-testing.
Comment #23
berdirThat is not what I meant, you should pass a single string to String::format() with multiple placeholders.
Comment #24
ACF commentedSuggested change made to contact test.
Comment #25
cs_shadow commentedDid changes to the patch in #16 as suggested in #18.
Comment #28
cs_shadow commentedAttaching files in #24 as they were overwritten somehow since I was also updating at the same time.
Comment #29
cs_shadow commentedComment #30
berdirLooks good, thanks all.
Comment #32
berdirYeah right testbot. looking for current timestamp fail *has* to be a random fail :)
Comment #33
berdir28: contact-php_notices_raised_due_to_incorrect_username-2223611-23.patch queued for re-testing.
Comment #34
dman commented@Berdir - could be worse, over here today is a test that asserts that 4 things really have been sorted 'randomly'. :-?
Comment #36
alexpottCommitted 1c11d16 and pushed to 8.x. Thanks!