@@ -109,4 +109,70 @@ public function testEntityDisplayDependency() {
109109 $ this ->assertSame ('' , $ widget ['settings ' ]['preview_image_style ' ]);
110110 }
111111
112+ /**
113+ * Tests renaming the ImageStyle.
114+ */
115+ public function testEntityDisplayDependencyRename () {
116+ // Create an image style.
117+ /** @var \Drupal\image\ImageStyleInterface $style */
118+ $ style = ImageStyle::create (['name ' => 'main_style ' ]);
119+ $ style ->save ();
120+
121+ // Create a node-type, named 'note'.
122+ $ node_type = NodeType::create (['type ' => 'note ' ]);
123+ $ node_type ->save ();
124+
125+ // Create an image field and attach it to the 'note' node-type.
126+ FieldStorageConfig::create ([
127+ 'entity_type ' => 'node ' ,
128+ 'field_name ' => 'sticker ' ,
129+ 'type ' => 'image ' ,
130+ ])->save ();
131+ FieldConfig::create ([
132+ 'entity_type ' => 'node ' ,
133+ 'field_name ' => 'sticker ' ,
134+ 'bundle ' => 'note ' ,
135+ ])->save ();
136+
137+ // Create the default entity view display and set the 'sticker' field to use
138+ // the 'main_style' images style in formatter.
139+ /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
140+ $ view_display = EntityViewDisplay::create ([
141+ 'targetEntityType ' => 'node ' ,
142+ 'bundle ' => 'note ' ,
143+ 'mode ' => 'default ' ,
144+ 'status ' => TRUE ,
145+ ])->setComponent ('sticker ' , ['settings ' => ['image_style ' => 'main_style ' ]]);
146+ $ view_display ->save ();
147+
148+ // Create the default entity form display and set the 'sticker' field to use
149+ // the 'main_style' images style in the widget.
150+ /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
151+ $ form_display = EntityFormDisplay::create ([
152+ 'targetEntityType ' => 'node ' ,
153+ 'bundle ' => 'note ' ,
154+ 'mode ' => 'default ' ,
155+ 'status ' => TRUE ,
156+ ])->setComponent ('sticker ' , ['settings ' => ['preview_image_style ' => 'main_style ' ]]);
157+ $ form_display ->save ();
158+
159+ // Check that the entity displays exists before dependency renaming.
160+ $ this ->assertNotNull (EntityViewDisplay::load ($ view_display ->id ()));
161+ $ this ->assertNotNull (EntityFormDisplay::load ($ form_display ->id ()));
162+
163+ // Rename the 'main_style' image style.
164+ $ style ->setName ('main_style_renamed ' );
165+ $ style ->save ();
166+
167+ // Check that the entity displays exists after dependency renaming.
168+ $ this ->assertNotNull ($ view_display = EntityViewDisplay::load ($ view_display ->id ()));
169+ $ this ->assertNotNull ($ form_display = EntityFormDisplay::load ($ form_display ->id ()));
170+ // Check that the 'sticker' formatter component exists in both displays.
171+ $ this ->assertNotNull ($ formatter = $ view_display ->getComponent ('sticker ' ));
172+ $ this ->assertNotNull ($ widget = $ form_display ->getComponent ('sticker ' ));
173+ // Check that both displays are using now 'main_style_renamed' for images.
174+ $ this ->assertSame ('main_style_renamed ' , $ formatter ['settings ' ]['image_style ' ]);
175+ $ this ->assertSame ('main_style_renamed ' , $ widget ['settings ' ]['preview_image_style ' ]);
176+ }
177+
112178}
0 commit comments