diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php index 6207dc6..a4924a2 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityImageStyle.php @@ -34,7 +34,7 @@ public function import(Row $row, array $old_destination_id_values = array()) { // is created, this prevents improper effect plugin initialization. if ($row->getDestinationProperty('effects')) { $effects = $row->getDestinationProperty('effects'); - $row->setDestinationProperty('effects', NULL); + $row->setDestinationProperty('effects', array()); } $style = $this->getEntity($row, $old_destination_id_values); @@ -52,6 +52,6 @@ public function import(Row $row, array $old_destination_id_values = array()) { $style->save(); - return array($style->id); + return array($style->id()); } } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php index 779bbfd..f651acb 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/ImageCacheActions.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\process\d6; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; @@ -20,13 +21,28 @@ class ImageCacheActions extends ProcessPluginBase { /** * {@inheritdoc} + * + * @throws \Drupal\migrate\MigrateSkipRowException. */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $effects = array(); - foreach ($row->getSourceProperty('actions') as $action) { + foreach($row->getSourceProperty('actions') as $action) { + $id = preg_replace('/^imagecache/', 'image', $action['action']); + + if($id === 'image_crop') { + $action['data']['anchor'] = $action['data']['xoffset'] . '-' . $action['data']['yoffset']; + + if(!preg_match('/^[a-z]*\-[a-z]*/', $action['data']['anchor'])) { + throw new MigrateSkipRowException('The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.'); + } + + unset($action['data']['xoffset']); + unset($action['data']['yoffset']); + } + $effects[] = array( - 'id' => preg_replace('/^imagecache/', 'image', $action['action']), + 'id' => $id, 'weight' => $action['weight'], 'data' => $action['data'], ); diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php index 55f3bef..194cc93 100644 --- a/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction.php @@ -71,13 +71,6 @@ public function load() { 'data', )) ->values(array( - 'actionid' => '2', - 'presetid' => '1', - 'weight' => '0', - 'module' => 'imagecache', - 'action' => 'imagecache_deprecated_scale', - 'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}', - ))->values(array( 'actionid' => '3', 'presetid' => '1', 'weight' => '0', @@ -109,4 +102,4 @@ public function load() { } } -#79a19aa7a4e9c76e439882490c8c9bdb +#90267fd3a92bd722208f016a23ab5f97 diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction_fail.php b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction_fail.php new file mode 100644 index 0000000..ea12418 --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/ImagecacheAction_fail.php @@ -0,0 +1,112 @@ +createTable("imagecache_action", array( + 'primary key' => array( + 'actionid', + ), + 'fields' => array( + 'actionid' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'length' => '10', + 'unsigned' => TRUE, + ), + 'presetid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'length' => '10', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'weight' => array( + 'type' => 'int', + 'not null' => TRUE, + 'length' => '11', + 'default' => '0', + ), + 'module' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '255', + ), + 'action' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '255', + ), + 'data' => array( + 'type' => 'text', + 'not null' => TRUE, + 'length' => 100, + ), + ), + 'mysql_character_set' => 'utf8', + )); + $this->database->insert("imagecache_action")->fields(array( + 'actionid', + 'presetid', + 'weight', + 'module', + 'action', + 'data', + )) + ->values(array( + 'actionid' => '2', + 'presetid' => '1', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_deprecated_scale', + 'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}', + ))->values(array( + 'actionid' => '3', + 'presetid' => '1', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_scale_and_crop', + 'data' => 'a:2:{s:5:"width";s:4:"100%";s:6:"height";s:4:"100%";}', + ))->values(array( + 'actionid' => '4', + 'presetid' => '2', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_crop', + 'data' => 'a:4:{s:5:"width";s:3:"555";s:6:"height";s:4:"5555";s:7:"xoffset";s:6:"center";s:7:"yoffset";s:6:"center";}', + ))->values(array( + 'actionid' => '5', + 'presetid' => '2', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_resize', + 'data' => 'a:2:{s:5:"width";s:3:"55%";s:6:"height";s:3:"55%";}', + ))->values(array( + 'actionid' => '6', + 'presetid' => '2', + 'weight' => '0', + 'module' => 'imagecache', + 'action' => 'imagecache_rotate', + 'data' => 'a:3:{s:7:"degrees";s:2:"55";s:6:"random";i:0;s:7:"bgcolor";s:0:"";}', + ))->execute(); + } + +} +#2adcbd67f3f7113bca46e1804ab1d99a diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index ecba4c8..d5c90fa 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -95,7 +95,6 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_file', 'd6_filter_format', 'd6_forum_settings', - 'd6_imagecache_presets', 'd6_locale_settings', 'd6_menu_settings', 'd6_menu', @@ -227,8 +226,6 @@ protected function getDumps() { 'Files.php', 'FilterFormats.php', 'Filters.php', - 'ImagecacheAction.php', - 'ImagecachePreset.php', 'MenuCustom.php', 'MenuLinks.php', 'Node.php', @@ -285,7 +282,6 @@ protected function getTestClassesList() { __NAMESPACE__ . '\MigrateFileTest', __NAMESPACE__ . '\MigrateFilterFormatTest', __NAMESPACE__ . '\MigrateForumConfigsTest', - __NAMESPACE__ . '\MigrateImageCacheTest', __NAMESPACE__ . '\MigrateLocaleConfigsTest', __NAMESPACE__ . '\MigrateMenuConfigsTest', __NAMESPACE__ . '\MigrateMenuLinkTest', diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php index 7f9ae90..f9fc95e 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateImageCacheTest.php @@ -8,8 +8,8 @@ namespace Drupal\migrate_drupal\Tests\d6; use Drupal\image\Entity\ImageStyle; -use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; -use Drupal\migrate\MigrateExecutable; +use \Drupal\image\ConfigurableImageEffectBase; +use Drupal\migrate\MigrateException; /** * Migrate ImageCache presets to Image styles @@ -30,46 +30,89 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase { */ public function setUp() { parent::setUp(); - + $this->prepareMigrations(array( + 'd6_imagecache_presets' => [], + )); $this->installConfig(array('image')); - $migration = entity_load('migration', 'd6_imagecache_presets'); - - $dumps = array( - $this->getDumpDirectory() . '/ImagecachePreset.php', - $this->getDumpDirectory() . '/ImagecacheAction.php', - ); - - $this->prepare($migration, $dumps); - $executable = new MigrateExecutable($migration, $this); - $executable->import(); } - public function testImageCache() { + /** + * + */ + public function testPassingMigration() { + $this->loadDumps(['ImagecacheAction.php', 'ImagecachePreset.php']); + $this->executeMigration('d6_imagecache_presets'); + + /** @var \Drupal\migrate\Entity\Migration $migration */ $migration = entity_load('migration', 'd6_imagecache_presets'); - $style = ImageStyle::load('big_blue_cheese'); - //check for failed style creation due to missing plugin - $this->assertNull(ImageStyle::load('slackjaw_boys')); + /** @var \Drupal\image\Entity\ImageStyle $style */ + $style = ImageStyle::load('big_blue_cheese'); //check basic Style info $this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly'); $this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly'); + //test effects + $effects = $style->getEffects(); + //check crop effect - $image_crop = $style->getEffect('image_crop')->getConfiguration(); - $this->assertIdentical('555',$image_crop['data']['width'], 'ImageEffect crop Width set correctly'); - $this->assertIdentical('5555', $image_crop['data']['height'], 'ImageEffect crop Height set correctly'); - $this->assertIdentical('center-center', $image_crop['data']['anchor'], 'ImageEffect crop Anchor set correctly'); + $this->assertImageEffect('image_crop', $effects, [ + 'width' => 555, + 'height' => 5555, + 'anchor' => 'center-center', + ]); //check resize effect - $image_resize = $style->getEffect('image_resize')->getConfiguration(); - $this->assertIdentical('55', $image_resize['data']['width'], 'ImageEffect resize Width set correctly'); - $this->assertIdentical('55', $image_resize['data']['height'], 'ImageEffect resize Height set correctly'); + $this->assertImageEffect('image_resize', $effects, [ + 'width' => 55, + 'height' => 55, + ]); //check rotate effect - $image_rotate = $style->getEffect('image_rotate')->getConfiguration(); - $this->assertIdentical('55', $image_rotate['data']['degrees'], 'ImageEffect rotate Degrees set correctly'); - $this->assertIdentical('0', $image_rotate['data']['random'], 'ImageEffect rotate Random set correctly'); - $this->assertIdentical('0', $image_resize['data']['bgcolor'], 'ImageEffect rotate color set correctly'); + $this->assertImageEffect('image_rotate', $effects, [ + 'degrees' => 55, + 'random' => FALSE, + 'bgcolor' => '', + ]); + } + + /** + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage The "image_deprecated_scale" plugin does not exist. + * + * @todo This test will not work because exceptions can not be caught + */ +/* public function testMissingEffectPlugin() { + $this->loadDumps(['ImagecacheAction_fail.php', 'ImagecachePreset.php']); + + try { + $this->executeMigration('d6_imagecache_presets'); + $this->fail('fail'); + } + catch (MigrateException $e) { + $this->pass('Nonexistent plugin exception caught') + } + }*/ + + /** + * + * + * @param $id + * @param $collection + * @param $config + * @return bool + */ + protected function assertImageEffect($id, $collection, $config) { + /** @var \Drupal\image\ConfigurableImageEffectBase $effect */ + foreach ($collection as $key => $effect) { + $effect_config = $effect->getConfiguration(); + + if ($effect_config['id'] == $id && $effect_config['data'] == $config) { + return $this->pass('Effect ' . $id . ' imported correctly'); + } + } + return $this->fail('Effect ' . $id . ' did not import correctly'); } }