Problem/Motivation

While working on #2505283: Handle import of private files a number of faults were discovered in Drupal\Tests\file\Kernel\Migrate\d7\MigrateFileTest. These faults are being corrected for MigratePrivateFileTest in that ticket, but the same corrections should be applied to MigrateFileTest. These faults include (but not limited to):

  • Use of \Drupal::service() rather than $this->container->get().
  • Redundant register of public stream wrapper.

Proposed resolution

Wait for #2505283: Handle import of private files to be fixed and then copy any improvements into MigrateFileTest.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jo Fitzgerald created an issue. See original summary.

jofitz’s picture

Assigned: jofitz » Unassigned
Status: Active » Needs review
FileSize
880 bytes

Here's a start point, but we'll wait until #2505283: Handle import of private files is in before doing any more.

jofitz’s picture

Status: Needs review » Postponed

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.

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

Status: Postponed » Needs work

No longer blocked.

jofitz’s picture

Status: Needs work » Needs review
FileSize
10.51 KB

Adapted the trait to apply to both file migration tests.

Status: Needs review » Needs work

The last submitted patch, 7: 2860760-7.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.63 KB
12.14 KB

Update other use of FileMigrationTrait.

Status: Needs review » Needs work

The last submitted patch, 9: 2860760-9.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review

Patch passed retest, setting back to Needs Review

heddn’s picture

Status: Needs review » Needs work
index 01fc464..501d9bb 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php

--- a/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationTrait.php

Contrib uses this trait. Moving it will break them. We need to add a BC layer, or don't rename.

jofitz’s picture

Status: Needs work » Needs review
FileSize
9.78 KB
10.94 KB

Reverted trait renaming.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

All feedback addressed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php
@@ -11,27 +11,88 @@
   /**
+   * The path of the file to be migrated.
+   *
+   * @var string
+   */
+  protected $path = 'public://sites/default/files/cube.jpeg';
+
+  /**
+   * The size of the file to be migrated.
+   *
+   * @var string
+   */
+  protected $size = '3620';
+
+  /**
+   * The base path of the file to be migrated.
+   *
+   * @var string
+   */
+  protected $base_path = 'public://';
+
+  /**
+   * The plugin ID of the migration to use.
+   *
+   * @var string
+   */
+  protected $plugin_id = 'd7_file';

I've stared at this for a while and what confuses me is why these default settings for the public are on the common trait. It doesn't really make sense. The trait could have abstract methods to get these things so that tests know they need to set them in order to use it.

jofitz’s picture

Status: Needs work » Needs review
FileSize
6.78 KB
12.88 KB

Addressed @alexpott's comment in #15.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

I thought about it for a second, but we could easily do something else during implementation to make the file paths, etc different if we have more than a single file in a test. That's an implementation detail. So, back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php
@@ -11,27 +11,92 @@
+  abstract protected function getPath();
...
+  abstract protected function getFileSize();
...
+  abstract protected function getBasePath();
...
+  abstract protected function getPluginId();

+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
@@ -72,6 +73,34 @@ protected function setUp() {
+  protected function getPath() {
...
+  protected function getBasePath() {
...
+  protected function getPluginId() {

Looking at how this has worked out. I think we need to add File to these names. I'm also tempted to suggest coalescing these methods into a getFileMigrationInfo() method that returns a keyed array of 'path', 'size', 'base_path', and 'plugin_id'. That way the trait is a little bit less "add-all-the-methods" and it is easier to grok that this is all related.

jofitz’s picture

Status: Needs work » Needs review
FileSize
6.66 KB
11.5 KB

I agree. Made changes according to #18.

alexpott’s picture

+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
@@ -22,51 +23,27 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
-    $this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', '3620', '1421727515', '1421727515', '1');
+    $info = $this->getFileMigrationInfo();
+    $this->assertEntity(1, basename($info['path']), $info['base_path'] . basename($info['path']), 'image/jpeg', $info['size'], '1421727515', '1421727515', '1');

+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php
@@ -53,46 +50,11 @@ public function register(ContainerBuilder $container) {
-    $this->assertEntity(3, 'Babylon5.txt', 'private://Babylon5.txt', 'text/plain', '3', '1486104045', '1486104045', '1');
+    $info = $this->getFileMigrationInfo();
+    $this->assertEntity(3, basename($info['path']), $info['base_path'] . basename($info['path']), 'text/plain', $info['size'], '1486104045', '1486104045', '1');

I think the old assertions are better. Being explicit makes it more readable and obvious what is being tested.

jofitz’s picture

Fair enough, I can understand the readability argument.

Put back the original assertions.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Looking good again.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2860760-21.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.14 KB
11.15 KB

Correct test failures.

quietone’s picture

Assigned: Unassigned » quietone

Assigning to self for review

quietone’s picture

Read through the issue, everything has been addressed. The most recent change was to correct a test failure that happened after the latest RTBC. So, retesting now to be sure it still passes tests.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

All good to go back to RTBC.

quietone’s picture

Assigned: quietone » Unassigned

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2860760-24.patch, failed testing. View results

jofitz’s picture

Kicked off retest.

jofitz’s picture

Status: Needs work » Reviewed & tested by the community

Appears to have been a testbot error, back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 4784ac3d0f to 8.6.x and 19100d948a to 8.5.x. Thanks!

  • alexpott committed 4784ac3 on 8.6.x
    Issue #2860760 by Jo Fitzgerald, heddn, quietone, alexpott: Match setup...

  • alexpott committed 19100d9 on 8.5.x
    Issue #2860760 by Jo Fitzgerald, heddn, quietone, alexpott: Match setup...

Status: Fixed » Closed (fixed)

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