cdec5b905e736a0cf3c10de5dbb9fb2cee0d2c0a
[yaffs-website] / web / core / modules / image / tests / src / Functional / ImageFieldWidgetTest.php
1 <?php
2
3 namespace Drupal\Tests\image\Functional;
4
5 use Drupal\field\Entity\FieldConfig;
6
7 /**
8  * Tests the image field widget.
9  *
10  * @group image
11  */
12 class ImageFieldWidgetTest extends ImageFieldTestBase {
13
14   /**
15    * Tests file widget element.
16    */
17   public function testWidgetElement() {
18     // Check for image widget in add/node/article page
19     $field_name = strtolower($this->randomMachineName());
20     $min_resolution = 50;
21     $max_resolution = 100;
22     $field_settings = [
23       'max_resolution' => $max_resolution . 'x' . $max_resolution,
24       'min_resolution' => $min_resolution . 'x' . $min_resolution,
25       'alt_field' => 0,
26     ];
27     $this->createImageField($field_name, 'article', [], $field_settings, [], [], 'Image test on [site:name]');
28     $this->drupalGet('node/add/article');
29     $this->assertNotEqual(0, count($this->xpath('//div[contains(@class, "field--widget-image-image")]')), 'Image field widget found on add/node page', 'Browser');
30     $this->assertNotEqual(0, count($this->xpath('//input[contains(@accept, "image/*")]')), 'Image field widget limits accepted files.', 'Browser');
31     $this->assertNoText('Image test on [site:name]');
32
33     // Check for allowed image file extensions - default.
34     $this->assertText('Allowed types: png gif jpg jpeg.');
35
36     // Try adding to the field config an unsupported extension, should not
37     // appear in the allowed types.
38     $field_config = FieldConfig::loadByName('node', 'article', $field_name);
39     $field_config->setSetting('file_extensions', 'png gif jpg jpeg tiff')->save();
40     $this->drupalGet('node/add/article');
41     $this->assertText('Allowed types: png gif jpg jpeg.');
42
43     // Add a supported extension and remove some supported ones, we should see
44     // the intersect of those entered in field config with those supported.
45     $field_config->setSetting('file_extensions', 'png jpe tiff')->save();
46     $this->drupalGet('node/add/article');
47     $this->assertText('Allowed types: png jpe.');
48   }
49
50 }