3 namespace Drupal\Tests\image\Kernel\Migrate\d7;
5 use Drupal\image\Entity\ImageStyle;
6 use Drupal\image\ImageStyleInterface;
7 use Drupal\image\ImageEffectBase;
8 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
11 * Test image styles migration to config entities.
15 class MigrateImageStylesTest extends MigrateDrupal7TestBase {
20 public static $modules = ['image'];
25 protected function setUp() {
27 $this->installConfig(static::$modules);
28 $this->executeMigration('d7_image_styles');
32 * Test the image styles migration.
34 public function testImageStylesMigration() {
35 $this->assertEntity('custom_image_style_1', "Custom image style 1", ['image_scale_and_crop', 'image_desaturate'], [['width' => 55, 'height' => 55, 'anchor' => 'center-center'], []]);
36 $this->assertEntity('custom_image_style_2', "Custom image style 2", ['image_resize', 'image_rotate'], [['width' => 55, 'height' => 100], ['degrees' => 45, 'bgcolor' => '#FFFFFF', 'random' => FALSE]]);
37 $this->assertEntity('custom_image_style_3', "Custom image style 3", ['image_scale', 'image_crop'], [['width' => 150, 'height' => NULL, 'upscale' => FALSE], ['width' => 50, 'height' => 50, 'anchor' => 'left-top']]);
41 * Asserts various aspects of an ImageStyle entity.
44 * The expected image style ID.
45 * @param string $label
46 * The expected image style label.
47 * @param array $expected_effect_plugins
48 * An array of expected plugins attached to the image style entity
49 * @param array $expected_effect_config
50 * An array of expected configuration for each effect in the image style
52 protected function assertEntity($id, $label, array $expected_effect_plugins, array $expected_effect_config) {
53 $style = ImageStyle::load($id);
54 $this->assertTrue($style instanceof ImageStyleInterface);
55 /** @var \Drupal\image\ImageStyleInterface $style */
56 $this->assertIdentical($id, $style->id());
57 $this->assertIdentical($label, $style->label());
59 // Check the number of effects associated with the style.
60 $effects = $style->getEffects();
61 $this->assertIdentical(count($effects), count($expected_effect_plugins));
64 foreach ($effects as $effect) {
65 $this->assertTrue($effect instanceof ImageEffectBase);
66 $this->assertIdentical($expected_effect_plugins[$index], $effect->getPluginId());
67 $config = $effect->getConfiguration();
68 $this->assertIdentical($expected_effect_config[$index], $config['data']);