3 namespace Drupal\Tests\image\Kernel\Migrate\d6;
5 use Drupal\Core\Database\Database;
6 use Drupal\image\Entity\ImageStyle;
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate\Exception\RequirementsException;
9 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
12 * Tests migration of ImageCache presets to image styles.
16 class MigrateImageCacheTest extends MigrateDrupal6TestBase {
21 protected function setUp() {
23 $this->installConfig(['image']);
27 * Tests that an exception is thrown when ImageCache is not installed.
29 public function testMissingTable() {
30 $this->sourceDatabase->update('system')
34 ->condition('name', 'imagecache')
35 ->condition('type', 'module')
39 $this->getMigration('d6_imagecache_presets')
41 ->checkRequirements();
42 $this->fail('Did not catch expected RequirementsException.');
44 catch (RequirementsException $e) {
45 $this->pass('Caught expected RequirementsException: ' . $e->getMessage());
50 * Test basic passing migrations.
52 public function testPassingMigration() {
53 $this->executeMigration('d6_imagecache_presets');
55 /** @var \Drupal\image\Entity\ImageStyle $style */
56 $style = ImageStyle::load('big_blue_cheese');
58 // Check basic Style info.
59 $this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly');
60 $this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly');
63 $effects = $style->getEffects();
66 $this->assertImageEffect($effects, 'image_crop', [
69 'anchor' => 'center-center',
72 // Check resize effect.
73 $this->assertImageEffect($effects, 'image_resize', [
78 // Check rotate effect.
79 $this->assertImageEffect($effects, 'image_rotate', [
87 * Test that missing actions causes failures.
89 public function testMissingEffectPlugin() {
90 Database::getConnection('default', 'migrate')->insert("imagecache_action")
101 'module' => 'imagecache',
102 'action' => 'imagecache_deprecated_scale',
103 'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}',
106 $this->startCollectingMessages();
107 $this->executeMigration('d6_imagecache_presets');
108 $messages = $this->migration->getIdMap()->getMessageIterator();
110 foreach ($messages as $message) {
112 $this->assertEqual($message->message, 'The "image_deprecated_scale" plugin does not exist.');
113 $this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR);
115 // There should be only the one message.
116 $this->assertEqual($count, 1);
120 * Test that missing action's causes failures.
122 public function testInvalidCropValues() {
123 Database::getConnection('default', 'migrate')->insert("imagecache_action")
134 'module' => 'imagecache',
135 'action' => 'imagecache_crop',
136 'data' => serialize([
142 $this->startCollectingMessages();
143 $this->executeMigration('d6_imagecache_presets');
146 'The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.',
148 ], $this->migrateMessages);
152 * Assert that a given image effect is migrated.
154 * @param array $collection
155 * Collection of effects
157 * Id that should exist in the collection.
159 * Expected configuration for the collection.
163 protected function assertImageEffect($collection, $id, $config) {
164 /** @var \Drupal\image\ConfigurableImageEffectBase $effect */
165 foreach ($collection as $key => $effect) {
166 $effect_config = $effect->getConfiguration();
168 if ($effect_config['id'] == $id && $effect_config['data'] == $config) {
169 // We found this effect so succeed and return.
170 return $this->pass('Effect ' . $id . ' imported correctly');
173 // The loop did not find the effect so we it was not imported correctly.
174 return $this->fail('Effect ' . $id . ' did not import correctly');