summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-03-01 12:02:54 (GMT)
committerAlex Pott2018-03-01 12:02:54 (GMT)
commit544740df31da953bdb38c632f861d3a995f3c584 (patch)
tree5f7e0e551d92d798633fdc1b9d17c137e47b6764
parentcf94492ee8673f2d0f62b760130ac8f1c623ae00 (diff)
Issue #2934145 by quietone, heddn, Jo Fitzgerald, David Hernández, alexpott, joelpittet, phenaproxima, Gábor Hojtsy: Image field migration plugin in wrong module
-rw-r--r--core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php38
-rw-r--r--core/modules/file/src/Plugin/migrate/field/d6/ImageField.php18
-rw-r--r--core/modules/file/src/Plugin/migrate/field/d7/ImageField.php39
-rw-r--r--core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php60
-rw-r--r--core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php2
-rw-r--r--core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php43
-rw-r--r--core/modules/image/src/Plugin/migrate/field/d6/ImageField.php15
-rw-r--r--core/modules/image/src/Plugin/migrate/field/d7/ImageField.php36
-rw-r--r--core/modules/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php51
-rw-r--r--core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php65
-rw-r--r--core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php4
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php6
-rw-r--r--core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php2
13 files changed, 305 insertions, 74 deletions
diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php
index 7cb2048..dc3b9cd 100644
--- a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php
+++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php
@@ -2,42 +2,16 @@
namespace Drupal\file\Plugin\migrate\cckfield\d7;
-@trigger_error('ImageField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\field\d7\ImageField instead.', E_USER_DEPRECATED);
+@trigger_error('ImageField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED);
-use Drupal\migrate\Plugin\MigrationInterface;
-use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
+use Drupal\image\Plugin\migrate\cckfield\d7\ImageField as LegacyImageField;
/**
- * @MigrateCckField(
- * id = "image",
- * core = {7},
- * source_module = "image",
- * destination_module = "file"
- * )
+ * CCK plugin for image fields.
*
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
- * \Drupal\file\Plugin\migrate\field\d7\ImageField instead.
+ * \Drupal\image\Plugin\migrate\field\d7\ImageField instead.
*
- * @see https://www.drupal.org/node/2751897
+ * @see https://www.drupal.org/node/2936061
*/
-class ImageField extends CckFieldPluginBase {
-
- /**
- * {@inheritdoc}
- */
- public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
- $process = [
- 'plugin' => 'sub_process',
- 'source' => $field_name,
- 'process' => [
- 'target_id' => 'fid',
- 'alt' => 'alt',
- 'title' => 'title',
- 'width' => 'width',
- 'height' => 'height',
- ],
- ];
- $migration->mergeProcessOfProperty($field_name, $process);
- }
-
-}
+class ImageField extends LegacyImageField {}
diff --git a/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php
index 3ec65dd..c05d8c3 100644
--- a/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php
+++ b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php
@@ -2,12 +2,16 @@
namespace Drupal\file\Plugin\migrate\field\d6;
+@trigger_error('ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d6\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED);
+
+use Drupal\image\Plugin\migrate\field\d6\ImageField as NonLegacyImageField;
+
/**
- * @MigrateField(
- * id = "imagefield",
- * core = {6},
- * source_module = "imagefield",
- * destination_module = "file"
- * )
+ * Field plugin for image fields.
+ *
+ * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.x. Use
+ * \Drupal\image\Plugin\migrate\field\d6\ImageField instead.
+ *
+ * @see https://www.drupal.org/node/2936061
*/
-class ImageField extends FileField {}
+class ImageField extends NonLegacyImageField {}
diff --git a/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php
index ea2005e..29da4d2 100644
--- a/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php
+++ b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php
@@ -2,35 +2,16 @@
namespace Drupal\file\Plugin\migrate\field\d7;
-use Drupal\migrate\Plugin\MigrationInterface;
-use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
+@trigger_error('ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED);
+
+use Drupal\image\Plugin\migrate\field\d7\ImageField as NonLegacyImageField;
/**
- * @MigrateField(
- * id = "image",
- * core = {7},
- * source_module = "image",
- * destination_module = "file"
- * )
+ * Field plugin for image fields.
+ *
+ * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.x. Use
+ * \Drupal\image\Plugin\migrate\field\d7\ImageField instead.
+ *
+ * @see https://www.drupal.org/node/2936061
*/
-class ImageField extends FieldPluginBase {
-
- /**
- * {@inheritdoc}
- */
- public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
- $process = [
- 'plugin' => 'sub_process',
- 'source' => $field_name,
- 'process' => [
- 'target_id' => 'fid',
- 'alt' => 'alt',
- 'title' => 'title',
- 'width' => 'width',
- 'height' => 'height',
- ],
- ];
- $migration->mergeProcessOfProperty($field_name, $process);
- }
-
-}
+class ImageField extends NonLegacyImageField {}
diff --git a/core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php
new file mode 100644
index 0000000..c84bc6e
--- /dev/null
+++ b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d6;
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\Tests\UnitTestCase;
+use Drupal\file\Plugin\migrate\field\d6\ImageField;
+use Prophecy\Argument;
+
+/**
+ * @coversDefaultClass \Drupal\file\Plugin\migrate\field\d6\ImageField
+ * @group file
+ * @group legacy
+ */
+class ImageFieldTest extends UnitTestCase {
+
+ /**
+ * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
+ */
+ protected $plugin;
+
+ /**
+ * @var \Drupal\migrate\Plugin\MigrationInterface
+ */
+ protected $migration;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ $this->plugin = new ImageField([], 'image', []);
+
+ $migration = $this->prophesize(MigrationInterface::class);
+
+ // The plugin's processFieldValues() method will call
+ // mergeProcessOfProperty() and return nothing. So, in order to examine the
+ // process pipeline created by the plugin, we need to ensure that
+ // getProcess() always returns the last input to mergeProcessOfProperty().
+ $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
+ ->will(function ($arguments) use ($migration) {
+ $migration->getProcess()->willReturn($arguments[1]);
+ });
+ $this->migration = $migration->reveal();
+ }
+
+ /**
+ * @covers ::processFieldValues
+ * @expectedDeprecation ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d6\ImageField instead. See https://www.drupal.org/node/2936061.
+ */
+ public function testProcessFieldValues() {
+ $this->plugin->processFieldValues($this->migration, 'somefieldname', []);
+
+ $expected = [
+ 'plugin' => 'd6_field_file',
+ 'source' => 'somefieldname',
+ ];
+ $this->assertSame($expected, $this->migration->getProcess());
+ }
+
+}
diff --git a/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php
index 3cab353..9e9c3fa 100644
--- a/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php
+++ b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php
@@ -10,6 +10,7 @@ use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\ImageField
* @group file
+ * @group legacy
*/
class ImageFieldTest extends UnitTestCase {
@@ -44,6 +45,7 @@ class ImageFieldTest extends UnitTestCase {
/**
* @covers ::processFieldValues
+ * @expectedDeprecation ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.
*/
public function testProcessFieldValues() {
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
diff --git a/core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php
new file mode 100644
index 0000000..081ff05
--- /dev/null
+++ b/core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Drupal\image\Plugin\migrate\cckfield\d7;
+
+@trigger_error('ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead.', E_USER_DEPRECATED);
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
+
+/**
+ * @MigrateCckField(
+ * id = "image",
+ * core = {7},
+ * source_module = "image",
+ * destination_module = "file"
+ * )
+ *
+ * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.x. Use
+ * \Drupal\image\Plugin\migrate\field\d7\ImageField instead.
+ *
+ * @see https://www.drupal.org/node/2751897
+ */
+class ImageField extends CckFieldPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
+ $process = [
+ 'plugin' => 'sub_process',
+ 'source' => $field_name,
+ 'process' => [
+ 'target_id' => 'fid',
+ 'alt' => 'alt',
+ 'title' => 'title',
+ 'width' => 'width',
+ 'height' => 'height',
+ ],
+ ];
+ $migration->mergeProcessOfProperty($field_name, $process);
+ }
+
+}
diff --git a/core/modules/image/src/Plugin/migrate/field/d6/ImageField.php b/core/modules/image/src/Plugin/migrate/field/d6/ImageField.php
new file mode 100644
index 0000000..072c4c2
--- /dev/null
+++ b/core/modules/image/src/Plugin/migrate/field/d6/ImageField.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Drupal\image\Plugin\migrate\field\d6;
+
+use Drupal\file\Plugin\migrate\field\d6\FileField;
+
+/**
+ * @MigrateField(
+ * id = "imagefield",
+ * core = {6},
+ * source_module = "imagefield",
+ * destination_module = "image"
+ * )
+ */
+class ImageField extends FileField {}
diff --git a/core/modules/image/src/Plugin/migrate/field/d7/ImageField.php b/core/modules/image/src/Plugin/migrate/field/d7/ImageField.php
new file mode 100644
index 0000000..4336c15
--- /dev/null
+++ b/core/modules/image/src/Plugin/migrate/field/d7/ImageField.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\image\Plugin\migrate\field\d7;
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
+
+/**
+ * @MigrateField(
+ * id = "image",
+ * core = {7},
+ * source_module = "image",
+ * destination_module = "image"
+ * )
+ */
+class ImageField extends FieldPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
+ $process = [
+ 'plugin' => 'sub_process',
+ 'source' => $field_name,
+ 'process' => [
+ 'target_id' => 'fid',
+ 'alt' => 'alt',
+ 'title' => 'title',
+ 'width' => 'width',
+ 'height' => 'height',
+ ],
+ ];
+ $migration->mergeProcessOfProperty($field_name, $process);
+ }
+
+}
diff --git a/core/modules/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php b/core/modules/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php
new file mode 100644
index 0000000..7fc0b0b
--- /dev/null
+++ b/core/modules/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Drupal\Tests\image\Kernel\Migrate\d6;
+
+use Drupal\node\Entity\Node;
+use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
+use Drupal\Tests\file\Kernel\Migrate\d6\FileMigrationTestTrait;
+
+/**
+ * Image migration test.
+ *
+ * This extends the node test, because the D6 fixture has images; they just
+ * need to be migrated into D8.
+ *
+ * @group migrate_drupal_6
+ */
+class MigrateImageTest extends MigrateNodeTestBase {
+
+ use FileMigrationTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['menu_ui'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ $this->setUpMigratedFiles();
+ $this->installSchema('file', ['file_usage']);
+ $this->executeMigrations([
+ 'd6_node',
+ ]);
+ }
+
+ /**
+ * Test image migration from Drupal 6 to 8.
+ */
+ public function testNode() {
+ $node = Node::load(9);
+ // Test the image field sub fields.
+ $this->assertSame('2', $node->field_test_imagefield->target_id);
+ $this->assertSame('Test alt', $node->field_test_imagefield->alt);
+ $this->assertSame('Test title', $node->field_test_imagefield->title);
+ $this->assertSame('80', $node->field_test_imagefield->width);
+ $this->assertSame('60', $node->field_test_imagefield->height);
+ }
+
+}
diff --git a/core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php b/core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php
new file mode 100644
index 0000000..198aa9d
--- /dev/null
+++ b/core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Drupal\Tests\image\Unit\Plugin\migrate\field\d7;
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\Tests\UnitTestCase;
+use Drupal\image\Plugin\migrate\field\d7\ImageField;
+use Prophecy\Argument;
+
+/**
+ * @coversDefaultClass \Drupal\image\Plugin\migrate\field\d7\ImageField
+ * @group image
+ */
+class ImageFieldTest extends UnitTestCase {
+
+ /**
+ * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
+ */
+ protected $plugin;
+
+ /**
+ * @var \Drupal\migrate\Plugin\MigrationInterface
+ */
+ protected $migration;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ $this->plugin = new ImageField([], 'image', []);
+
+ $migration = $this->prophesize(MigrationInterface::class);
+
+ // The plugin's processFieldValues() method will call
+ // mergeProcessOfProperty() and return nothing. So, in order to examine the
+ // process pipeline created by the plugin, we need to ensure that
+ // getProcess() always returns the last input to mergeProcessOfProperty().
+ $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
+ ->will(function ($arguments) use ($migration) {
+ $migration->getProcess()->willReturn($arguments[1]);
+ });
+ $this->migration = $migration->reveal();
+ }
+
+ /**
+ * @covers ::processFieldValues
+ */
+ public function testProcessFieldValues() {
+ $this->plugin->processFieldValues($this->migration, 'somefieldname', []);
+
+ $expected = [
+ 'plugin' => 'sub_process',
+ 'source' => 'somefieldname',
+ 'process' => [
+ 'target_id' => 'fid',
+ 'alt' => 'alt',
+ 'title' => 'title',
+ 'width' => 'width',
+ 'height' => 'height',
+ ],
+ ];
+ $this->assertSame($expected, $this->migration->getProcess());
+ }
+
+}
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php
index 9f4873a..efb8312 100644
--- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php
@@ -87,7 +87,7 @@ class MigrationProvidersExistTest extends MigrateDrupalTestBase {
],
'imagefield' => [
'source_module' => 'imagefield',
- 'destination_module' => 'file',
+ 'destination_module' => 'image',
],
'file' => [
'source_module' => 'file',
@@ -95,7 +95,7 @@ class MigrationProvidersExistTest extends MigrateDrupalTestBase {
],
'image' => [
'source_module' => 'image',
- 'destination_module' => 'file',
+ 'destination_module' => 'image',
],
'phone' => [
'source_module' => 'phone',
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index 1c8a875..059ba78 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -3780,9 +3780,9 @@ $connection->insert('content_type_story')
'field_test_phone_value' => NULL,
'field_test_exclude_unset_value' => 'text for default value',
'field_test_exclude_unset_format' => '1',
- 'field_test_imagefield_fid' => NULL,
- 'field_test_imagefield_list' => NULL,
- 'field_test_imagefield_data' => NULL,
+ 'field_test_imagefield_fid' => '2',
+ 'field_test_imagefield_list' => '1',
+ 'field_test_imagefield_data' => 'a:2:{s:3:"alt";s:8:"Test alt";s:5:"title";s:10:"Test title";}',
'field_test_text_single_checkbox2_value' => 'Off',
'field_test_datestamp_value2' => '1391357160',
'field_test_datetime_value2' => '2015-03-04 06:07:00',
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php b/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php
index 7e36364e..284a267 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php
@@ -14,7 +14,7 @@ class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase {
/**
* {@inheritdoc}
*/
- public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'link', 'migrate_field_plugin_manager_test'];
+ public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'image', 'text', 'link', 'migrate_field_plugin_manager_test'];
/**
* Tests that the correct MigrateField plugins are used.