a15d49e76107cd15b184bdbca02ea95337e3e71c
[yaffs-website] / web / core / modules / image / tests / src / Kernel / Migrate / d7 / MigrateImageStylesTest.php
1 <?php
2
3 namespace Drupal\Tests\image\Kernel\Migrate\d7;
4
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;
9
10 /**
11  * Test image styles migration to config entities.
12  *
13  * @group image
14  */
15 class MigrateImageStylesTest extends MigrateDrupal7TestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['image'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27     $this->installConfig(static::$modules);
28     $this->executeMigration('d7_image_styles');
29   }
30
31   /**
32    * Test the image styles migration.
33    */
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']]);
38   }
39
40   /**
41    * Asserts various aspects of an ImageStyle entity.
42    *
43    * @param string $id
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
51    */
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());
58
59     // Check the number of effects associated with the style.
60     $effects = $style->getEffects();
61     $this->assertIdentical(count($effects), count($expected_effect_plugins));
62
63     $index = 0;
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']);
69       $index++;
70     }
71   }
72
73 }