Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Issue #2554321: Clean up Migrate's test suite introduces helper methods in MigrateDrupal6TestBase, that allow to perform bundled migrations in tests, such as migrateUsers(), migrateContentTypes(), migrateFields(), ...
Proposed Resolution
Add D7 variants of these helper methods to MigrateDrupal7TestBase
Comment | File | Size | Author |
---|---|---|---|
#125 | 2578263-125.patch | 35.27 KB | jofitz |
#125 | interdiff-2578263-123-125.txt | 2.74 KB | jofitz |
#123 | 2578263-123.patch | 35.28 KB | imalabya |
#119 | 2578263-119.patch | 34.78 KB | jofitz |
#119 | interdiff-2578263-117-119.txt | 1.24 KB | jofitz |
Comments
Comment #2
svendecabooterLet's see if this works...
Comment #3
phenaproximaLooks perfect, but please alter the existing Drupal 7 tests to use these methods.
Comment #4
svendecabooterHere is an updated patch where all of the added helper functions get used in the various D7 test cases, where they are appropriate.
This cleans up repetition in the setUp() method of various tests.
Comment #5
phenaproximaLooking better and better. Few things --
d7_file also needs to be executed.
If pictures are not needed, we don't need user_picture_field or user_picture_field_instance either.
These don't exist :)
Is it necessary to migrate the revisions in this test?
Likewise, is it necessary to migrate pictures in this test? Unless the test is asserting on the pictures themselves, there's no need to.
Comment #6
svendecabooterUpdated based on feedback.
Issues:
2.: When I add
I get errors:
Fatal error: Call to a member function delete() on a non-object
Any idea what's causing this? Can't seem to figure out what's going on.
This code was just copied from the D6 version. Should I add those delete() calls there too then?
4.: Removed the revision migration. I assumed it was needed because of assertRevision() in MigrateNodeTest, but tests pass even without it.
5.: If I remove the boolean, I get
Undefined index: source_base_path Drupal\file\Plugin\migrate\source\d7\File->prepareRow()
:(Comment #7
svendecabooterComment #9
phenaproximaOkay, fixed MigrateCommentTest. Fly, baby, fly!
Comment #11
phenaproximaSigh. No? How 'bout...
Comment #12
benjy CreditAttribution: benjy at PreviousNext commentedI think these helpers are really good for testing, they handle a lot of setUp that can be difficult to get right.
I read the backscroll on IRC, chx mentioned his concerns with the large amount of $modules we're enabling on the base. I do see his point, couldn't we move any module setUp into the helpers methods?
Eg, migrateContent() would install the node module etc. The field modules, we should probably just move those into their relevant tests, surely there can't be many tests depending on the datetime module?
Comment #13
svendecabooterI tried changing the helper functions, so the dependent modules get loaded in the helper function itself, not through __construct().
The problem I encounter is when a module gets enabled later on in the process, their migration_templates aren't available.
This works until call to executeMigration(). This tries to call
Migration::load('d7_node_type');
but fails, since the migration template for node module hasn't been created.I tried changing it to:
But this fails also, since it tries to create Migration config entities that were already created.
Not sure how to proceed.... Only the migration templates for the enabled module should be created, but that functionality doesn't seem to exist, and is probably out of scope of this issue.
Comment #14
mikeryanThis looks like a non-sequitor?
I guess that schema addition above has something to do with this?
Comment #15
quietone CreditAttribution: quietone commented@svendecabooter, thx for your analysis. I came to the same conclusion and retired before posting.
Comment #16
svendecabooter@mikeryan that's probably related to the last paragraph in comment #6. Perhaps phenaproxima can elaborate on it?
With regards to the concern raised by chx: also keep in mind that these helper functions are also already in core for D6 MigrateDrupal6TestBase, so if the performance impact outweighs the usefulness, they should probably be removed from D6 as well, to stay consistent.
Comment #17
svendecabooterAttached a reroll of this last patch.
Comment #18
quietone CreditAttribution: quietone commentedLooks like this issue is to create helper functions in MigrateDrupal7TestBase just like in MigrateDrupal6TestBase. And that that work has been competed and reviewed. But this is held up on the concern about the large of $modules being enabled on the base. That doesn't seem to have a simple solutions (#13) and it effects both D6 and D7, which is outside the scope of this issue. So that is being moved to a new issue.
That will also help #2409435: Upgrade path for Book 6.x and 7.x, which is postponed on this issue.
The new issue is #2623280: Minimize enabled modules in D6 and D7 test base
Comment #19
quietone CreditAttribution: quietone commentedRe mikeryan's comment about source_base_path. That was added in patch #11 by phenaproxima. I've just asked him about it on IRC, he is AFK now but will look later.
I presume that was to fix this error from patch #9,
Comment #20
phenaproximaRegarding #14 -- @quietone is correct. The source_base_path fix was added to address the exceptions @svendecabooter was encountering in #6.
With these minor nits fixed, RTBC from me, although I can't officially RTBC this since I had a hand in writing it ;-)
Nit: The FALSE is unnecessary -- the parameter is FALSE by default.
The presence of d7_comment_type here is understandable, but jarring for people who don't know the system. Can a comment be added explaining that?
No need for TRUE here -- TRUE is the default for the parameter.
Comment #21
quietone CreditAttribution: quietone commentedFixes for all of phenaproxima's nits.
Comment #22
andypostMaybe better to make this methods with trait? like
\Drupal\comment\Tests\CommentTestTrait
Comment #23
phenaproxima@andypost, there's no real point in putting those methods in a trait -- the Drupal 6 and Drupal 7 versions are subtly different, and all tests which use them will extend from either MigrateDrupal6TestBase or MigrateDrupal7TestBase already. So putting them in a trait wouldn't add anything -- additionally, the trait would not be able to specify modules to enable for the test (as far as I know, SimpleTest doesn't scan for $modules properties imported from traits).
The patch looks good to me.
Comment #24
xjmOverall, this is a really great patch that should make writing migrate tests cleaner and more reliable.
One thing stood out for me though when I did a code review.
I have a lot of concern about all these modules being enabled in every Migrate test. There are two non-trivial problems with this:
I see this was also discussed earlier on the issue and that #2623280: Minimize enabled modules in D6 and D7 test base was filed to address it. At a minimum, this hunk of code should have an @todo referencing that issue. However, for me, my initial reaction is that it needs to be blocking rather than a followup, because it does have a negative impact on the whole Migrate test suite.
I see also in #13:
Maybe the solution to this is to also add functionality to the base class to ensure this gets done? Alternately, we could add support in
setUp()
(so then the child classes have to do two things, opt in to the correct installed modules in their setup, and then execute the migrations).If we could solve that in this issue and close #2623280: Minimize enabled modules in D6 and D7 test base as a duplicate that would be excellent. For me it is an important part of the scope of this improvement.
Thanks @svendecabooter and @quietone for working through much of this already!
Comment #25
quietone CreditAttribution: quietone commented#13
I agree with that and have used the provider property from #2569805: For Drupal migration, identify the source module to achieve it. There is a new method, findTemplatesByInstalledModule, which scans all templates and returns only those templates where the value of the provider property matches the name of an installed module.
Also, a check is added in installMigrations to prevent the saving of an already saved migration because when that happens, an exception is thrown. There is probably a better way to do this?
Comment #26
quietone CreditAttribution: quietone commentedI'm curious to see what the testbot says with a combination of 2578263-25.patch and the current patch from #2569805: For Drupal migration, identify the source module.
Comment #28
quietone CreditAttribution: quietone as a volunteer commentedComment #30
mikeryanComment #31
Sonal.Sangale CreditAttribution: Sonal.Sangale at Blisstering Solutions commentedComment #32
Sonal.Sangale CreditAttribution: Sonal.Sangale at Blisstering Solutions commentedRerolling patch against branch 8.1.x-dev.
Comment #34
quietone CreditAttribution: quietone as a volunteer commented@Sonal.Sangale, thanks for working on this. It looks like this is a reroll of the patch in #26. That was just a test which combined patch #25 with one from another issue. I think you'll need to start from the patch in #25. It is unfortunate that I didn't run tests on it, that was an oversight.
Comment #35
neerajsinghRe-rolling the patch from #25.
Comment #37
svendecabooterI was just rerolling this as well, but seems you beat me to it :)
The logic in MigrateDrupal7TestBase should be updated however, because we moved from Migration config entities to plugins.
It should probably act more like MigrateDrupal6TestBase, which has already been refactored for this change.
Comment #38
neerajsingh@svendecabooter, Please re-roll your patch..
Comment #39
svendecabooterWork in progress patch - this still fails some tests...
Comment #40
deepakaryan1988Comment #41
deepakaryan1988Re-rolled the patch.
Comment #44
iMiksu#41 needs reroll and investigate why tests failed (if still applicable).
Comment #45
iMiksuLets see if we can get this checked out today.
Comment #46
Jānis Bebrītis CreditAttribution: Jānis Bebrītis at Wunder commentedComment #47
Jānis Bebrītis CreditAttribution: Jānis Bebrītis at Wunder commentedComment #48
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedRerroll of #41
Comment #51
heddnComment #52
mikeryanStill needs reroll, methinks.
Comment #53
yogeshmpawarComment #54
yogeshmpawarHere's the updated patch for this issue.
Comment #55
yogeshmpawarComment #57
jofitz CreditAttribution: jofitz at ComputerMinds commentedBring this patch up-to-date.
Comment #59
jofitz CreditAttribution: jofitz at ComputerMinds commentedFix test failure.
Comment #60
phenaproximaSelf-assigning for review.
Comment #61
quietone CreditAttribution: quietone as a volunteer commentedNeeds a reroll.
Comment #62
quietone CreditAttribution: quietone as a volunteer commentedRerolled
Comment #63
phenaproximaI don't think we need this if there's not going to be anything in it.
IMHO, unless there's a compelling reason not to, this one method should also migrate the field instances as well. It doesn't seem too likely that we'll want to migrate field storages but not field instances, and if that case arises, we can just execute those migrations manually.
This gives me pause. Shouldn't we simply migrate the node and comment types for real instead?
Same here -- would it not be better to simply migrate the taxonomy vocabularies from D7?
This should probably also install schema and config for comments too.
Nit: No need for $modules to be its own variable.
migrateContent() already calls migrateContentTypes(), which in turn already installs node's config. No need to do it twice.
Comment #64
jofitz CreditAttribution: jofitz at ComputerMinds commented$this->executeMigration('d7_field');
in there.Comment #65
jofitz CreditAttribution: jofitz at ComputerMinds commentedComment #68
phenaproximaWell, it's not performance I'm worried about -- I'm wondering why we are creating node types manually in a functional migration test, and whether that might have repercussions down the line. Setting up pre-migration state directly undermines the reliability of migration tests, and we have been burned by that kind of thing before (and our tests used to be rife with it, but I worked hard in 2015 to correct that). What is the advantage of creating node types directly, rather than migrating them?
Comment #69
jofitz CreditAttribution: jofitz at ComputerMinds commentedSorry, re-reading what I wrote I didn't make it clear that I totally agree and have removed any creation of nodes etc and replaced it with migrations.
Comment #70
phenaproximaIt might help to attach the latest patch ;-)
Comment #71
jofitz CreditAttribution: jofitz at ComputerMinds commentedNo new patch, that's all in #64.
My communication/typing skills need work!
s/have removed/had removed
Comment #72
yogeshmpawarAny Update on this issue ?
Comment #73
heddnAssigning to myself to see what else is left on this.
Comment #75
heddnNeeds a re-roll.
Comment #76
heddnComment #77
pk188 CreditAttribution: pk188 at OpenSense Labs commentedRe rolled.
Comment #80
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-roll based on the patch in #64.
Comment #82
heddnPatch still applies cleanly. What is left here to review?
Comment #83
neerajsinghYes, the patch at #80 still applies cleanly to 8.6.x
Attaching the same patch here again for the bot to re-review.
Comment #84
quietone CreditAttribution: quietone as a volunteer commentedAssigning to myself for review.
Comment #85
quietone CreditAttribution: quietone as a volunteer commentedStarted to review this and so far I have read through the issue and had a brief look at the patch, focusing on the more recent request for changes in #63. There was some concern about the performance and loading of lots of modules in the TestBase. That has been resolved by enabling modules in the individual tests and none in the TestBase, which is the right way to go. There is also the change from creating content to actually migrating it which is was should happen in these test. There are no coding standards errors either. All up, this looks really good and much praise to all for getting it this far.
I'm inclined to RTBC except for two things, 1) I want to read through the patch tomorrow (too late now) and 2) I've written a few patches.
Comment #86
quietone CreditAttribution: quietone as a volunteer commentedOK read through the patch and found a few things;
Comment #87
jofitz CreditAttribution: jofitz at ComputerMinds commentedI have addressed points 1 & 2 from #86 (there is one instance of d7_taxonomy_term remaining in *Test.php because that uses CreateTestContentEntitiesTrait and a whole different approach).
Then I ran out of time...
Points 3 & 4 from #86 still need to be addressed, but here's my work in progress.
Comment #88
jofitz CreditAttribution: jofitz at ComputerMinds commentedHaving re-read #86 (when not rushing), I see that points 3 & 4 discuss follow-ups so I will set this to Needs Review.
Comment #89
quietone CreditAttribution: quietone as a volunteer commented@Jo Fitzgerald, awesome.
I found several occurrences where executeMigrations can be executeMigration.
Can be executeMigration.
Comment #90
jofitz CreditAttribution: jofitz at ComputerMinds commentedCorrected the 5 instances of
executeMigrations()
that could be replaced withexecuteMigration()
. Also found one instance ofexecuteMigration()
that should beexecuteMigrations()
.Comment #92
jofitz CreditAttribution: jofitz at ComputerMinds commentedAha, so there is a difference between
executeMigrations(['migration_id'])
andexecuteMigration('migration_id')
. The first runscreateInstances()
which will return migration derivatives, e.g. d7_taxonomy_term:tags.I have made the necessary corrections and added a comment.
Comment #94
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled.
Comment #95
quietone CreditAttribution: quietone as a volunteer commented@Jo Fitzgerald, oh yes, I too forgot that one of those will create the derivatives. The docs on executeMigrations should be improved to make the obvious.
Although I haven't posted I have been reviewing that changes made due to #89. Everything looks good to go. This is really amazing to sort this out.
The remaining items I found are these, and they are from me!
Not something for this patch but it would be good to also remove the module list from MigrateTestBase and update all the d6 and d7 test accordingly.Made an issue #2974445: [Meta] Refactor Migrate Drupal UI Functional testsDo the others need a follow up?
Comment #96
heddnLet's add two follow-ups 95.1 and 95.3 and this could be pretty close to ready.
Comment #97
jofitz CreditAttribution: jofitz at ComputerMinds commentedCreated follow-ups in response to:
95.1. #2978287: Add documentation to helper functions in MigrateDrupal7TestBase
95.3. #2978288: Improve the documentation on executeMigrations
I think this is ready for RTBC...
Comment #98
quietone CreditAttribution: quietone as a volunteer commented@jo Fitzgerald, thanks for making the followups.
Found one more thing,
The test reports coding standard errors. There are unused use statements to remove in MigrateNodeTaxonomtyTest.
Comment #99
jofitz CreditAttribution: jofitz at ComputerMinds commentedCorrected coding standards errors.
I can't believe I missed them! I hang my head in shame.
Comment #100
quietone CreditAttribution: quietone as a volunteer commentedThank you!
Notice this wee thing this time.
I think this can go inside the following if block.
Then I grepped for all the migrations in the new helper test functions and only found one thing, where it looks like MigrateUsers() can be used in 3 more tests.
Can use MigrateUsers() ? Also, I think MigrateShortcutSetUsersTest.php can as well.
Thats it, almost done!
Comment #101
jofitz CreditAttribution: jofitz at ComputerMinds commentedAddressed the @quietone's comments in #100 and, following a quick review, removed some redundant lines from:
Comment #102
jofitz CreditAttribution: jofitz at ComputerMinds commentedimo, it would be nice to have a follow-up that handled the $modules variable because the contents are related to the helper functions, so I've created #2978862: Add set-up helper functions to MigrateDrupal7TestBase.
Comment #103
phenaproximaTwo small things, then I think we're ready.
Needs (optional) before the description, and let's add "defaults to TRUE".
Needs (optional), and let's add "defaults to FALSE".
Comment #104
yogeshmpawarComment #105
yogeshmpawarAddressed @phenaproxima comments in #103, also added an interdiff.
Comment #106
phenaproximaThanks, @yogeshmpawar! RTBC once all backends pass tests.
Comment #108
phenaproximaI think this is some random Nightwatch BS. Back to RTBC.
Comment #111
phenaproximaComment #112
quietone CreditAttribution: quietone as a volunteer commentedA reroll.
Comment #113
quietone CreditAttribution: quietone as a volunteer commentedAdded tests for PostgreSQl and SQLite
Comment #114
phenaproximaThanks for the reroll! Restoring RTBC.
Comment #115
alexpottLet's deprecate this and tell people to use the new methods and only remove in Drupal 9. That way we won't break contrib or custom tests that use this.
Comment #116
jofitz CreditAttribution: jofitz at ComputerMinds commentedPatch from #112 no longer applies, re-rolled.
Comment #117
jofitz CreditAttribution: jofitz at ComputerMinds commentedDeprecated NodeCommentCombinationTrait.
Comment #118
heddnUnless I'm reading that interdiff wrong, it looks like we also removed the code in the trait? I don't think that is what was intended.
Comment #119
jofitz CreditAttribution: jofitz at ComputerMinds commentedYou're absolutely right, @heddn. I was kinda fumbling in the dark with that one. How about this.
Comment #120
heddnThat seems more right. Let's wait for tests to pass.
Comment #121
heddnFeedback from #115 addressed. Back to RTBC.
Comment #122
catchPatch looks good to me now, but needs a re-roll.
Comment #123
imalabyaRerolled patch.
Comment #125
jofitz CreditAttribution: jofitz commentedRe-rolled patch from #119 (included interdiff against #123, for reference).
Comment #126
jofitz CreditAttribution: jofitz at jofitz commentedComment #127
quietone CreditAttribution: quietone as a volunteer commentedI looked at this last night and even started to make a patch when I noticed the time and went to bed. Jo Fitzgerald has implemented what I started for taxonomy and he has done better and fixed all the tests. I like the removal of these lines as well. Don't think I would have spotted that there were not needed last night.
Back to RTBC
Comment #128
catchCommitted 4b9af62 and pushed to 8.7.x. Thanks!