Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / image / tests / src / Functional / ImageStyleDeleteTest.php
1 <?php
2
3 namespace Drupal\Tests\image\Functional;
4
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\Core\Entity\Entity\EntityViewDisplay;
7
8 /**
9  * Tests image style deletion using the UI.
10  *
11  * @group image
12  */
13 class ImageStyleDeleteTest extends ImageFieldTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setUp() {
19     parent::setUp();
20     // Create an image field 'foo' having the image style 'medium' as widget
21     // preview and as formatter.
22     $this->createImageField('foo', 'page', [], [], ['preview_image_style' => 'medium'], ['image_style' => 'medium']);
23   }
24
25   /**
26    * Tests image style deletion.
27    */
28   public function testDelete() {
29     $this->drupalGet('admin/config/media/image-styles/manage/medium/delete');
30     // Checks that the 'replacement' select element is displayed.
31     $this->assertFieldByName('replacement');
32     // Checks that UI messages are correct.
33     $this->assertRaw(t('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.'));
34     $this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
35
36     // Delete 'medium' image style but replace it with 'thumbnail'. This style
37     // is involved in 'node.page.default' display view and form.
38     $this->drupalPostForm(NULL, ['replacement' => 'thumbnail'], t('Delete'));
39
40     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
41     $view_display = EntityViewDisplay::load('node.page.default');
42     // Checks that the formatter setting is replaced.
43     if ($this->assertNotNull($component = $view_display->getComponent('foo'))) {
44       $this->assertIdentical($component['settings']['image_style'], 'thumbnail');
45     }
46     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
47     $form_display = EntityFormDisplay::load('node.page.default');
48     // Check that the widget setting is replaced.
49     if ($this->assertNotNull($component = $form_display->getComponent('foo'))) {
50       $this->assertIdentical($component['settings']['preview_image_style'], 'thumbnail');
51     }
52
53     $this->drupalGet('admin/config/media/image-styles/manage/thumbnail/delete');
54     // Checks that the 'replacement' select element is displayed.
55     $this->assertFieldByName('replacement');
56     // Checks that UI messages are correct.
57     $this->assertRaw(t('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.'));
58     $this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
59
60     // Delete 'thumbnail' image style. Provide no replacement.
61     $this->drupalPostForm(NULL, [], t('Delete'));
62
63     $view_display = EntityViewDisplay::load('node.page.default');
64     // Checks that the formatter setting is disabled.
65     $this->assertNull($view_display->getComponent('foo'));
66     $this->assertNotNull($view_display->get('hidden')['foo']);
67     // Checks that widget setting is preserved with the image preview disabled.
68     $form_display = EntityFormDisplay::load('node.page.default');
69     $this->assertNotNull($widget = $form_display->getComponent('foo'));
70     $this->assertIdentical($widget['settings']['preview_image_style'], '');
71
72     // Now, there's only one image style configured on the system: 'large'.
73     $this->drupalGet('admin/config/media/image-styles/manage/large/delete');
74     // Checks that the 'replacement' select element is not displayed.
75     $this->assertNoFieldByName('replacement');
76     // Checks that UI messages are correct.
77     $this->assertNoRaw(t('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.'));
78     $this->assertRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
79   }
80
81 }