Commit 544740df authored by alexpott's avatar alexpott

Issue #2934145 by quietone, heddn, Jo Fitzgerald, David Hernández, alexpott,...

Issue #2934145 by quietone, heddn, Jo Fitzgerald, David Hernández, alexpott, joelpittet, phenaproxima, Gábor Hojtsy: Image field migration plugin in wrong module
parent cf94492e
......@@ -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 {}
......@@ -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 {}
......@@ -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 {}
<?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());
}
}
......@@ -10,6 +10,7 @@
/**
* @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\ImageField
* @group file
* @group legacy
*/
class ImageFieldTest extends UnitTestCase {
......@@ -44,6 +45,7 @@ protected function setUp() {
/**
* @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', []);
......
<?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);
}
}
<?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 {}
<?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);
}
}
<?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);
}
}
<?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());
}
}
......@@ -87,7 +87,7 @@ public function testFieldProvidersExist() {
],
'imagefield' => [
'source_module' => 'imagefield',
'destination_module' => 'file',
'destination_module' => 'image',
],
'file' => [
'source_module' => 'file',
......@@ -95,7 +95,7 @@ public function testFieldProvidersExist() {
],
'image' => [
'source_module' => 'image',
'destination_module' => 'file',
'destination_module' => 'image',
],
'phone' => [
'source_module' => 'phone',
......
......@@ -3780,9 +3780,9 @@
'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',
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment