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

CommentFileSizeAuthor
#125 2578263-125.patch35.27 KBjofitz
#125 interdiff-2578263-123-125.txt2.74 KBjofitz
#123 2578263-123.patch35.28 KBimalabya
#119 2578263-119.patch34.78 KBjofitz
#119 interdiff-2578263-117-119.txt1.24 KBjofitz
#117 2578263-117.patch35.12 KBjofitz
#117 interdiff-2578263-116-117.txt1.46 KBjofitz
#116 2578263-116.patch34.9 KBjofitz
#112 2578263-112.patch34.68 KBquietone
#105 interdiff-2578263-101-105.txt1.07 KByogeshmpawar
#105 2578263-105.patch34.65 KByogeshmpawar
#101 2578263-101.patch34.43 KBjofitz
#101 interdiff-99-101.txt10.53 KBjofitz
#99 2578263-99.patch30.5 KBjofitz
#99 interdiff-94-99.txt700 bytesjofitz
#94 2578263-94.patch30.17 KBjofitz
#92 2578263-92.patch30.17 KBjofitz
#92 interdiff-90-92.txt1.37 KBjofitz
#90 2578263-90.patch29.84 KBjofitz
#90 interdiff-87-90.txt2.81 KBjofitz
#87 2578263-87.patch29.88 KBjofitz
#87 interdiff-80-87.txt10.22 KBjofitz
#83 2578263-80.patch19.66 KBneerajsingh
#80 2578263-80.patch19.66 KBjofitz
#77 2578263-77.patch17.98 KBpk188
#64 2578263-64.patch17.95 KBjofitz
#64 interdiff-62-64.txt13.04 KBjofitz
#62 2578263-62.patch18.94 KBquietone
#59 2578263-59.patch19.51 KBjofitz
#59 interdiff-57-59.txt545 bytesjofitz
#57 2578263-57.patch19.52 KBjofitz
#57 interdiff-54-57.txt13.29 KBjofitz
#54 add_helper_functions_to-2578263-54.patch15.65 KByogeshmpawar
#48 add_helper_functions_to-2578263-48.patch15.52 KBManuel Garcia
#41 add_helper_functions_to-2578263-41.patch15.21 KBdeepakaryan1988
#39 2578263-39.patch13.73 KBsvendecabooter
#35 2578263-35.patch15.19 KBneerajsingh
#32 2578263-32.patch90.81 KBSonal.Sangale
#26 2578263-25-and-2569805-14.patch103.26 KBquietone
#25 2578263-25.patch22.4 KBquietone
#25 interdiff-2578263-21-25.txt8.56 KBquietone
#21 interdiff-2578263-17-21.txt1.45 KBquietone
#21 2578263-21.patch15.52 KBquietone
#17 2578263-17.patch15.49 KBsvendecabooter
#11 2578263-11.patch15.47 KBphenaproxima
#9 2578263-9.patch14.41 KBphenaproxima
#6 add_helper_functions_to-2578263-6.patch14.1 KBsvendecabooter
#4 add_helper_functions_to-2578263-4.patch14.15 KBsvendecabooter
#2 add_helper_functions_to-2578263-2.patch3.13 KBsvendecabooter
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

svendecabooter created an issue. See original summary.

svendecabooter’s picture

phenaproxima’s picture

Status: Needs review » Needs work

Looks perfect, but please alter the existing Drupal 7 tests to use these methods.

svendecabooter’s picture

Here 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.

phenaproxima’s picture

Status: Needs review » Needs work

Looking better and better. Few things --

  1. +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
    @@ -17,10 +18,109 @@
    +      $this->installEntitySchema('file');
    +      $this->executeMigrations([
    +        'user_picture_field',
    +        'user_picture_field_instance',
    +        'user_picture_entity_display',
    +        'user_picture_entity_form_display',
    +      ]);
    

    d7_file also needs to be executed.

  2. +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
    @@ -17,10 +18,109 @@
    +      // These are optional dependencies of d7_user, but we don't need them if
    +      // we're not migrating user pictures.
    +      Migration::load('user_picture_entity_display')->delete();
    +      Migration::load('user_picture_entity_form_display')->delete();
    

    If pictures are not needed, we don't need user_picture_field or user_picture_field_instance either.

  3. +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
    @@ -17,10 +18,109 @@
    +      'd7_upload_field',
    +      'd7_upload_field_instance',
    

    These don't exist :)

  4. +++ b/core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php
    @@ -36,22 +36,13 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
    +    $this->migrateContent(TRUE);
    

    Is it necessary to migrate the revisions in this test?

  5. +++ b/core/modules/user/src/Tests/Migrate/d7/MigrateUserTest.php
    @@ -29,15 +29,7 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
    +    $this->migrateUsers(TRUE);
    

    Likewise, is it necessary to migrate pictures in this test? Unless the test is asserting on the pictures themselves, there's no need to.

svendecabooter’s picture

Updated based on feedback.

Issues:

2.: When I add

Migration::load('user_picture_field')->delete();
Migration::load('user_picture_field_instance')->delete();

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() :(

svendecabooter’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: add_helper_functions_to-2578263-6.patch, failed testing.

phenaproxima’s picture

Status: Needs review » Needs work

The last submitted patch, 9: 2578263-9.patch, failed testing.

phenaproxima’s picture

benjy’s picture

+++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
@@ -17,10 +18,121 @@
+  protected function migrateUsers($include_pictures = TRUE) {
...
+  protected function migrateContentTypes() {
...
+  protected function migrateFields() {

I 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?

svendecabooter’s picture

I 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.

  /**
   * Migrates node types.
   */
  protected function migrateContentTypes() {
    $this->enableModules(['node', 'text']);
    $this->installEntitySchema('node');
    $this->installConfig(['node']);
    $this->executeMigration('d7_node_type');
  }

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:

  /**
   * Migrates node types.
   */
  protected function migrateContentTypes() {
    $this->enableModules(['node', 'text']);
    $this->installEntitySchema('node');
    $this->installConfig(['node']);
    $this->installMigrations('Drupal 7');
    $this->executeMigration('d7_node_type');
  }

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.

mikeryan’s picture

  1. +++ b/core/modules/file/config/schema/file.destination.schema.yml
    @@ -5,3 +5,6 @@ migrate.destination.entity:file:
    +    source_base_path:
    +      type: string
    +      label: 'Source base path'
    

    This looks like a non-sequitor?

  2. +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
    @@ -17,10 +18,121 @@
    +      $destination['source_base_path'] = $this->siteDirectory;
    

    I guess that schema addition above has something to do with this?

quietone’s picture

@svendecabooter, thx for your analysis. I came to the same conclusion and retired before posting.

svendecabooter’s picture

@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.

svendecabooter’s picture

Attached a reroll of this last patch.

quietone’s picture

Looks 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

quietone’s picture

Re 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,

exception: [Notice] Line 94 of core/modules/file/src/Plugin/migrate/source/d7/File.php:
Undefined index: source_base_pathDrupal\file\Plugin\migrate\source\d7\File->prepareRow(Object)
Drupal\migrate\Plugin\migrate\source\SourcePluginBase->next()
Drupal\migrate\Plugin\migrate\source\SourcePluginBase->rewind()
Drupal\migrate\MigrateExecutable->import()
Drupal\migrate\Tests\MigrateTestBase->executeMigration(Object, 'd7_file')
array_walk(Array, Array)
Drupal\migrate\Tests\MigrateTestBase->executeMigrations(Array)
Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase->migrateUsers(1)
Drupal\user\Tests\Migrate\d7\MigrateUserTest->setUp()
Drupal\simpletest\TestBase->run(Array)
simpletest_script_run_one_test('1764', 'Drupal\user\Tests\Migrate\d7\MigrateUserTest')
phenaproxima’s picture

Regarding #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 ;-)

  1. +++ b/core/modules/comment/src/Tests/Migrate/d7/MigrateCommentTest.php
    @@ -19,36 +19,14 @@
    +    $this->migrateContent(FALSE);
    

    Nit: The FALSE is unnecessary -- the parameter is FALSE by default.

  2. +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
    @@ -17,10 +18,121 @@
    +    $this->executeMigrations([
    +      'd7_comment_type',
    

    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?

  3. +++ b/core/modules/user/src/Tests/Migrate/d7/MigrateUserTest.php
    @@ -29,15 +29,7 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
    +    $this->migrateUsers(TRUE);
    

    No need for TRUE here -- TRUE is the default for the parameter.

andypost’s picture

+++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
@@ -17,10 +18,122 @@
+  protected function migrateUsers($include_pictures = TRUE) {
...
+  protected function migrateContentTypes() {
...
+  protected function migrateFields() {
...
+  protected function migrateContent($include_revisions = FALSE) {
...
+  protected function migrateTaxonomy() {

Maybe better to make this methods with trait? like \Drupal\comment\Tests\CommentTestTrait

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

@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.

xjm’s picture

Category: Feature request » Task
Status: Reviewed & tested by the community » Needs work

Overall, 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.

+++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php
@@ -17,10 +18,122 @@
+  public static $modules = [
+    'comment',
+    'datetime',
+    'entity_reference',
+    'filter',
+    'image',
+    'link',
+    'node',
+    'taxonomy',
+    'telephone',
+    'text',
+  ];
...
+    $this->installEntitySchema('comment');
+    $this->installEntitySchema('file');
+    $this->installEntitySchema('node');
+    $this->installEntitySchema('taxonomy_term');

I have a lot of concern about all these modules being enabled in every Migrate test. There are two non-trivial problems with this:

  • Adding a lot of overhead to the test.
  • The test being inappropriately coupled and the test environment being polluted by data and code that is not part of the test.

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:

The problem I encounter is when a module gets enabled later on in the process, their migration_templates aren't available.

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!

quietone’s picture

#13

Only the migration templates for the enabled module should be created,

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?

quietone’s picture

Status: Needs work » Needs review
FileSize
103.26 KB

I'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.

Status: Needs review » Needs work

The last submitted patch, 26: 2578263-25-and-2569805-14.patch, failed testing.

quietone’s picture

Issue tags: +migrate-d7-d8

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikeryan’s picture

Issue tags: +Needs reroll
Sonal.Sangale’s picture

Assigned: Unassigned » Sonal.Sangale
Sonal.Sangale’s picture

Assigned: Sonal.Sangale » Unassigned
Status: Needs work » Needs review
FileSize
90.81 KB

Rerolling patch against branch 8.1.x-dev.

Status: Needs review » Needs work

The last submitted patch, 32: 2578263-32.patch, failed testing.

quietone’s picture

@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.

neerajsingh’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs work » Needs review
FileSize
15.19 KB

Re-rolling the patch from #25.

Status: Needs review » Needs work

The last submitted patch, 35: 2578263-35.patch, failed testing.

svendecabooter’s picture

I 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.

neerajsingh’s picture

@svendecabooter, Please re-roll your patch..

svendecabooter’s picture

Work in progress patch - this still fails some tests...

deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
FileSize
15.21 KB

Re-rolled the patch.

Status: Needs review » Needs work

The last submitted patch, 41: add_helper_functions_to-2578263-41.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

iMiksu’s picture

#41 needs reroll and investigate why tests failed (if still applicable).

Your branch is up-to-date with 'origin/8.3.x'.
nothing to commit, working directory clean
$ curl https://www.drupal.org/files/issues/add_helper_functions_to-2578263-41.patch | patch -p1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15576  100 15576    0     0  25729      0 --:--:-- --:--:-- --:--:-- 25702
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php
Hunk #1 FAILED at 14.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php.rej
patching file core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php
patching file core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php
Hunk #1 succeeded at 148 (offset 3 lines).
patching file core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php
Hunk #1 FAILED at 42.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php.rej
patching file core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
patching file core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTypeTest.php
patching file core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
patching file core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateTrackerNodeTest.php
Hunk #1 FAILED at 32.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateTrackerNodeTest.php.rej
patching file core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateTrackerUserTest.php
Hunk #1 FAILED at 32.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateTrackerUserTest.php.rej
patching file core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php
Hunk #1 FAILED at 25.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php.rej
iMiksu’s picture

Issue tags: +DCampBaltics

Lets see if we can get this checked out today.

Jānis Bebrītis’s picture

Assigned: Unassigned » Jānis Bebrītis
Jānis Bebrītis’s picture

Assigned: Jānis Bebrītis » Unassigned
Manuel Garcia’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
15.52 KB

Rerroll of #41

Status: Needs review » Needs work

The last submitted patch, 48: add_helper_functions_to-2578263-48.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

Issue tags: +Needs reroll
mikeryan’s picture

Still needs reroll, methinks.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
15.65 KB

Here's the updated patch for this issue.

yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned

Status: Needs review » Needs work

The last submitted patch, 54: add_helper_functions_to-2578263-54.patch, failed testing.

jofitz’s picture

Status: Needs work » Needs review
FileSize
13.29 KB
19.52 KB

Bring this patch up-to-date.

Status: Needs review » Needs work

The last submitted patch, 57: 2578263-57.patch, failed testing.

jofitz’s picture

Status: Needs work » Needs review
FileSize
545 bytes
19.51 KB

Fix test failure.

phenaproxima’s picture

Assigned: Unassigned » phenaproxima

Self-assigning for review.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs a reroll.

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
18.94 KB

Rerolled

phenaproxima’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -9,6 +12,8 @@
    +  public static $modules = [];
    +
    

    I don't think we need this if there's not going to be anything in it.

  2. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +29,124 @@ protected function getFixtureFilePath() {
    +  /**
    +   * Executes all field migrations.
    +   */
    +  protected function migrateFields() {
    +    $this->executeMigration('d7_field');
    +  }
    

    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.

  3. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +29,124 @@ protected function getFixtureFilePath() {
    +    $this->createType('page');
    +    $this->createType('article');
    +    $this->createType('blog');
    +    $this->createType('book');
    +    $this->createType('forum');
    +    $this->createType('test_content_type');
    

    This gives me pause. Shouldn't we simply migrate the node and comment types for real instead?

  4. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +29,124 @@ protected function getFixtureFilePath() {
    +    Vocabulary::create(['vid' => 'test_vocabulary'])->save();
    

    Same here -- would it not be better to simply migrate the taxonomy vocabularies from D7?

  5. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +29,124 @@ protected function getFixtureFilePath() {
    +  protected function migrateContentTypes() {
    +    $this->installConfig(['node']);
    +    $this->executeMigration('d7_node_type');
    +  }
    

    This should probably also install schema and config for comments too.

  6. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +29,124 @@ protected function getFixtureFilePath() {
    +    $modules = [
    +      'comment',
    +      'datetime',
    +      'image',
    +      'link',
    +      'node',
    +      'taxonomy',
    +      'telephone',
    +      'text',
    +    ];
    +    $this->enableModules($modules);
    

    Nit: No need for $modules to be its own variable.

  7. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +29,124 @@ protected function migrateContent() {
    +    $this->installConfig('node');
    

    migrateContent() already calls migrateContentTypes(), which in turn already installs node's config. No need to do it twice.

jofitz’s picture

  1. Removed.
  2. The only place that does not require the migration of field instances along with fields is MigrateFieldTest (so I have simply used $this->executeMigration('d7_field'); in there.
  3. In my mind the intention was to save time, but a couple of non-scientific local tests suggested the difference is about half a second which is likely to be even less for the testbot.
  4. See 3.
  5. This can't install schema and config for comments because not all tests calling it have the comment module enabled. So I have created migrateCommentTypes() which calls migrateContentTypes() and then executes the d7_comment_type migration.
  6. I'm not a big fan of inline multi-line arrays, but that's just a personal preference so happy to make the change.
  7. I have done this and a lot of other refactoring of migrateContent() because this method was beginning to go down a completely different line, including enabling modules which is not done in the D6 version and just gets complicated!
jofitz’s picture

Status: Needs work » Needs review

The last submitted patch, 25: 2578263-25.patch, failed testing.

The last submitted patch, 39: 2578263-39.patch, failed testing.

phenaproxima’s picture

In my mind the intention was to save time, but a couple of non-scientific local tests suggested the difference is about half a second which is likely to be even less for the testbot.

Well, 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?

jofitz’s picture

+++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
@@ -12,8 +9,6 @@
@@ -34,43 +29,12 @@ protected function getFixtureFilePath() {

@@ -34,43 +29,12 @@ protected function getFixtureFilePath() {
    */
   protected function migrateFields() {
     $this->executeMigration('d7_field');
-  }
-
-  /**
-   * Executes all field instance migrations.
-   */
-  protected function migrateFieldInstances() {
-    $this->createType('page');
-    $this->createType('article');
-    $this->createType('blog');
-    $this->createType('book');
-    $this->createType('forum');
-    $this->createType('test_content_type');
-    Vocabulary::create(['vid' => 'test_vocabulary'])->save();
-    $this->migrateFields();
+    $this->migrateCommentTypes();
+    $this->executeMigration('d7_taxonomy_vocabulary');
     $this->executeMigration('d7_field_instance');
   }
 
   /**
-   * Creates a node type with a corresponding comment type.
-   *
-   * @param string $id
-   *   The node type ID.
-   */
-  protected function createType($id) {
-    NodeType::create([
-      'type' => $id,
-      'label' => $this->randomString(),
-    ])->save();
-
-    CommentType::create([
-      'id' => 'comment_node_' . $id,
-      'label' => $this->randomString(),
-      'target_entity_type_id' => 'node',
-    ])->save();
-  }
-
-  /**
    * Executes all user migrations.
    *
    * @param bool $include_pictures

Sorry, 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.

phenaproxima’s picture

Status: Needs review » Needs work

It might help to attach the latest patch ;-)

jofitz’s picture

Status: Needs work » Needs review

No new patch, that's all in #64.

My communication/typing skills need work!
s/have removed/had removed

yogeshmpawar’s picture

Any Update on this issue ?

heddn’s picture

Assigned: phenaproxima » heddn

Assigning to myself to see what else is left on this.

Status: Needs review » Needs work

The last submitted patch, 64: 2578263-64.patch, failed testing.

heddn’s picture

Issue tags: +Needs reroll

Needs a re-roll.

heddn’s picture

Assigned: heddn » Unassigned
pk188’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
17.98 KB

Re rolled.

Status: Needs review » Needs work

The last submitted patch, 77: 2578263-77.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

Status: Needs work » Needs review
FileSize
19.66 KB

Re-roll based on the patch in #64.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

Patch still applies cleanly. What is left here to review?

neerajsingh’s picture

Yes, the patch at #80 still applies cleanly to 8.6.x

Attaching the same patch here again for the bot to re-review.

quietone’s picture

Assigned: Unassigned » quietone

Assigning to myself for review.

quietone’s picture

Started 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.

quietone’s picture

Assigned: quietone » Unassigned
Status: Needs review » Needs work

OK read through the patch and found a few things;

  1. I grepped for 'd7_comment_type' and found it being used in MigrateNodeTest which is not modified by this patch. Shouldn't MigrateNodeTest use the new helper functions? It was in the patch way back in #25 but got lost after some rerolling.
  2. grep also turned up usages of d7_node_type and d7_taxonomy_term in d7 Migrate tests. Is there a reason for this? If so, does this need documentation to explain when to use the helpers and when not to use them? I didn't look further than the grep output so maybe it is obvious?
  3. I'd like to see documentation on the helper functions stating what modules need to be installed. It is a nice to have and should not hold this up. If someone thinks it is worth doing, a follow up is fine.
  4. 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.
jofitz’s picture

FileSize
10.22 KB
29.88 KB

I 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.

jofitz’s picture

Status: Needs work » Needs review

Having re-read #86 (when not rushing), I see that points 3 & 4 discuss follow-ups so I will set this to Needs Review.

quietone’s picture

Status: Needs review » Needs work

@Jo Fitzgerald, awesome.

I found several occurrences where executeMigrations can be executeMigration.

  1. +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php
    @@ -23,11 +23,8 @@ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase
    +    $this->executeMigrations(['d7_comment_entity_form_display_subject']);
    
    +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php
    @@ -23,11 +23,8 @@ class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
    +    $this->executeMigrations(['d7_comment_field']);
    
    +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +24,80 @@ protected function getFixtureFilePath() {
    +    $this->executeMigrations(['d7_node']);
    ...
    +      $this->executeMigrations(['d7_node_revision']);
    ...
    +    $this->executeMigrations(['d7_taxonomy_term']);
    

    Can be executeMigration.

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.81 KB
29.84 KB

Corrected the 5 instances of executeMigrations() that could be replaced with executeMigration(). Also found one instance of executeMigration() that should be executeMigrations().

Status: Needs review » Needs work

The last submitted patch, 90: 2578263-90.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.37 KB
30.17 KB

Aha, so there is a difference between executeMigrations(['migration_id']) and executeMigration('migration_id'). The first runs createInstances() which will return migration derivatives, e.g. d7_taxonomy_term:tags.

I have made the necessary corrections and added a comment.

Status: Needs review » Needs work

The last submitted patch, 92: 2578263-92.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
FileSize
30.17 KB

Re-rolled.

quietone’s picture

@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!

  1. I'd like to see documentation on the helper functions stating what modules need to be installed. It is a nice to have and should not hold this up. If someone thinks it is worth doing, a follow up is fine.
  2. 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 tests
  3. A follow up to improve/correct the documentation on executeMigrations to explain that it will create the derivations.

Do the others need a follow up?

heddn’s picture

Status: Needs review » Needs work

Let's add two follow-ups 95.1 and 95.3 and this could be pretty close to ready.

jofitz’s picture

Status: Needs work » Needs review
quietone’s picture

Status: Needs review » Needs work

@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.

jofitz’s picture

Status: Needs work » Needs review
FileSize
700 bytes
30.5 KB

Corrected coding standards errors.

I can't believe I missed them! I hang my head in shame.

quietone’s picture

Status: Needs review » Needs work

Thank you!

Notice this wee thing this time.

  1. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +24,85 @@ protected function getFixtureFilePath() {
    +    $this->installEntitySchema('file');
    
  2. I think this can go inside the following if block.

  3. 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.

    +++ b/core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateTrackerNodeTest.php
    @@ -33,10 +33,10 @@ protected function setUp() {
           'd7_user_role',
           'd7_user',
    
    +++ b/core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateTrackerUserTest.php
    @@ -33,10 +33,10 @@ protected function setUp() {
           'd7_user_role',
           'd7_user',
    

Can use MigrateUsers() ? Also, I think MigrateShortcutSetUsersTest.php can as well.

Thats it, almost done!

jofitz’s picture

Status: Needs work » Needs review
FileSize
10.53 KB
34.43 KB

Addressed the @quietone's comments in #100 and, following a quick review, removed some redundant lines from:

  • FollowUpMigrationsTest
  • MigrateFieldFormatterSettingsTest
  • MigrateFieldInstanceTest
  • MigrateFieldInstanceWidgetSettingsTest
  • MigrateNodeTaxonomyTest
  • MigrateNodeTest
  • MigrateUserTest
jofitz’s picture

imo, 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.

phenaproxima’s picture

Status: Needs review » Needs work

Two small things, then I think we're ready.

  1. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +24,85 @@ protected function getFixtureFilePath() {
    +   * @param bool $include_pictures
    +   *   If TRUE, migrates user pictures.
    

    Needs (optional) before the description, and let's add "defaults to TRUE".

  2. +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
    @@ -24,4 +24,85 @@ protected function getFixtureFilePath() {
    +   * @param bool $include_revisions
    +   *   If TRUE, migrates node revisions.
    

    Needs (optional), and let's add "defaults to FALSE".

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Addressed @phenaproxima comments in #103, also added an interdiff.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, @yogeshmpawar! RTBC once all backends pass tests.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 105: 2578263-105.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Reviewed & tested by the community

I think this is some random Nightwatch BS. Back to RTBC.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 105: 2578263-105.patch, failed testing. View results

phenaproxima’s picture

Issue tags: +Needs reroll
quietone’s picture

quietone’s picture

Issue tags: -Needs reroll

Added tests for PostgreSQl and SQLite

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the reroll! Restoring RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-namespace Drupal\Tests\migrate\Kernel;
-
-use Drupal\comment\Entity\CommentType;
-use Drupal\node\Entity\NodeType;
-
-/**
- * Provides methods for testing node and comment combinations.
- */
-trait NodeCommentCombinationTrait {

Let'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.

jofitz’s picture

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.46 KB
35.12 KB

Deprecated NodeCommentCombinationTrait.

heddn’s picture

Status: Needs review » Needs work

Unless 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.

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.24 KB
34.78 KB

You're absolutely right, @heddn. I was kinda fumbling in the dark with that one. How about this.

heddn’s picture

That seems more right. Let's wait for tests to pass.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Feedback from #115 addressed. Back to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Patch looks good to me now, but needs a re-roll.

imalabya’s picture

Status: Needs work » Needs review
FileSize
35.28 KB

Rerolled patch.

Status: Needs review » Needs work

The last submitted patch, 123: 2578263-123.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.74 KB
35.27 KB

Re-rolled patch from #119 (included interdiff against #123, for reference).

jofitz’s picture

quietone’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

+++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php
@@ -24,7 +24,6 @@
-    $this->installConfig(['node']);

+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
@@ -42,8 +42,16 @@
-    $this->installEntitySchema('node');

Back to RTBC

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 4b9af62 and pushed to 8.7.x. Thanks!

  • catch committed ae6c744 on 8.7.x
    Issue #2578263 by Jo Fitzgerald, quietone, svendecabooter, yogeshmpawar...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.