Problem/Motivation
It was discovered in #84883: Unicode::mimeHeaderEncode() doesn't correctly follow RFC 2047 that two migration tests, DoubleSlashTest and Upgrade7Test, were sending emails, such as this one.
From: The Site Name <joseph@flattandsons.com>
MIME-Version: 1.0
Reply-to: joseph@flattandsons.com
Return-Path: <joseph@flattandsons.com>
Sender: joseph@flattandsons.com
Subject: Your account is approved!
To: odo@local.host
X-Mailer: DrupalYour account was activated, and there was much rejoicing.
Credit to alexpott for the following (summarized from a Slack conversation).
alexpott pointed out that migrate tests shouldn’t result in the test mailer being replaced and questioned why is a migration sending activation emails. "We’re sending an email because user 2 which is created by \Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait::createContent() is created as a blocked user. And in the drupal7.php user 2 exists and is active. So the migration activates that user and then User::postSave() sends the email. \Drupal\Core\Test\FunctionalTestSetupTrait::initConfig() is being undone by the migration"
This issue is to fix this so the tests use the test mail collector.
Steps to reproduce
N/A
Proposed resolution
Removed the d7_system_mail migration from the migration store before clicking 'Perform upgrade'.
Update migrate drupal functional tests to capture email and test the results. The D6 upgrade does not generate mail but D7 does.
Remaining tasks
Patch
Write Tests
Review
Commit
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 3207907-28.patch | 3.74 KB | quietone |
| #28 | interdiff-26-28.txt | 1.24 KB | quietone |
| #26 | 3207907-20_0.patch | 4.05 KB | quietone |
| #20 | 3207907-20.patch | 4.05 KB | quietone |
| #20 | interdiff-18-20.txt | 831 bytes | quietone |
Comments
Comment #2
quietone commentedComment #3
quietone commentedComment #5
quietone commentedAdd tests to confirm emails were not captured for D6 upgrade and were captured for D7 upgrade.
Comment #7
quietone commentedRetest and tests passing again.
Comment #8
quietone commentedComment #9
quietone commented@benjifisher prompted me on Slack to fix the typo in the title. :-)
Comment #10
berdirAlternative idea: Use settings.php config overrides to ensure the test mail handler is set, so even *if* config is changed and we'd want to change that, we would not actually use that configuration?
Comment #11
berdirThat is how \Drupal\KernelTests\KernelTestBase::bootKernel() for example works, but it only puts it into $GLOBALS. For functional tests, we need to write it out into the generated settings.php.
I'm doing that with redis in https://git.drupalcode.org/project/redis/-/blob/8.x-1.x/tests/src/Functi... for example.
Comment #12
berdirI suppose you could question whether a migration should send such a mail at all, I've had problems with that too in the past where I had to disable e.g. content notifications.
Could imagine a migrate_mail_alter() that prevents all mails from being sent, configurable maybe.
But it's actually useful in this case to make sure that we _do_ collect mails. Maybe we could be even more explicit, also in the D6 test to make sure that the runtime config really uses the correct mail configuration. Although that wouldn't catch the config during web requests either.
Comment #13
quietone commented@Berdir, Thanks for the reply. I don't understand. Are you suggesting that this will work if $settings are changed, like this, before running the test?
Comment #14
berdirNo, that only works in-memory in the current process, not in web requests.
I'm talking about the stuff around line 90 in the redis test, where the override is written out into settings.php of that test.
No strong feeling on which option is better, the advantage of that would be that you don't need to make runtime changes to what is being migrated.
Comment #15
quietone commentedAh, I see, I get it now.
I do prefer to not make runtime changes. Let's see if this works.
Comment #17
berdirHm, that's an interesting fail. So suddenly we _are_ catching that a mail was sent and before we weren't?
The previous logic only specifically removed the d7 migration, are you sure there's no d6 equivalent that we are now actually catching too?
Comment #18
quietone commentedYes, I didn't look closely enough at the d6 migration. It doesn't have a migration for 'system_mail' like the d7 migration but like the d7 migration a user activation email is sent.
Since the 3 lines of code for checking the email is the same for d6 and d7 I made a helper function.
Comment #19
berdirnitpick: onE user activation email.
that is kinda weird though. If there is no migration for that setting then why did it still try to send a real mail before? I tried to look a bit, but I don't know those tests or the migrations too well
Comment #20
quietone commentedI don't have a complete answer either. Both Upgrade6Test and Upgrade7Test test the 'complete' migration as run from /upgrade. And both of those will migrate users and as we have seen that results in an activation email. I didn't know the source dbs were setup that way but it is nice to know that activation email can be tested.
But none that explains why for the Drupal 6 migration that the activation email is only caught when the settings.php file is altered and for the Drupal 7 that is not necessary. I've poked around the migrations in the system module but nothing seems relevant. And I don't know enough about the mail system to spend time searching there. Do you think this question prevent this fix from being committed?
Comment #22
quietone commentedI was thinking about why the patch in #5 passed tests so I came back and re-applied that patch. I then ran Upgrade6Test.php and it failed, like it should have! I don't know what the difference is between #5 and #15 that caused that but it is good to know it was not something in the patches here.
Comment #23
mikelutzAnd rerunning #5 here now fails as well, so the pass in #5 must have been some kind of testbot hiccup. Which is slightly bothersome, but not relevant to this patch..
Comment #25
spokjeBack to RTBC per #23 after #3255836: Test fails due to Composer 2.2 solved the unrelated test failure.
Comment #26
quietone commented@Spokje, thanks.
Re-uploading the patch so it is tested with 9.4.x
Comment #27
alexpottThis should do:
instead... less complexity and relying on the existing API in tests to do this.
Comment #28
quietone commentedYes, of course.
Comment #29
mikelutzI must confess I didn't know about that one.
Comment #30
alexpottCommitted and pushed 4f043a2ecc9 to 10.0.x and f7c9202be9d to 9.4.x and ee025067d5c to 9.3.x. Thanks!