ImageStyleDeleteTest.php in Drupal 10
File
core/modules/image/tests/src/Functional/ImageStyleDeleteTest.php
View source
<?php
namespace Drupal\Tests\image\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
class ImageStyleDeleteTest extends ImageFieldTestBase {
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->createImageField('foo', 'page', [], [], [
'preview_image_style' => 'medium',
], [
'image_style' => 'medium',
]);
}
public function testDelete() {
$this
->drupalGet('admin/config/media/image-styles/manage/medium/delete');
$this
->assertSession()
->fieldExists('replacement');
$this
->assertSession()
->pageTextContains("If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.");
$this
->assertSession()
->pageTextNotContains("All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.");
$this
->submitForm([
'replacement' => 'thumbnail',
], 'Delete');
$view_display = EntityViewDisplay::load('node.page.default');
$this
->assertNotNull($component = $view_display
->getComponent('foo'));
$this
->assertSame('thumbnail', $component['settings']['image_style']);
$form_display = EntityFormDisplay::load('node.page.default');
$this
->assertNotNull($component = $form_display
->getComponent('foo'));
$this
->assertSame('thumbnail', $component['settings']['preview_image_style']);
$this
->drupalGet('admin/config/media/image-styles/manage/thumbnail/delete');
$this
->assertSession()
->fieldExists('replacement');
$this
->assertSession()
->pageTextContains("If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.");
$this
->assertSession()
->pageTextNotContains("All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.");
$this
->submitForm([], 'Delete');
$view_display = EntityViewDisplay::load('node.page.default');
$this
->assertNull($view_display
->getComponent('foo'));
$this
->assertNotNull($view_display
->get('hidden')['foo']);
$form_display = EntityFormDisplay::load('node.page.default');
$this
->assertNotNull($widget = $form_display
->getComponent('foo'));
$this
->assertSame('', $widget['settings']['preview_image_style']);
$this
->drupalGet('admin/config/media/image-styles/manage/wide/delete');
$this
->assertSession()
->fieldExists('replacement');
$this
->assertSession()
->pageTextContains("If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.");
$this
->assertSession()
->pageTextNotContains("All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.");
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/config/media/image-styles/manage/large/delete');
$this
->assertSession()
->fieldNotExists('replacement');
$this
->assertSession()
->pageTextNotContains("If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.");
$this
->assertSession()
->pageTextContains("All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.");
}
}