3 namespace Drupal\Tests\image\Functional;
5 use Drupal\field\Entity\FieldConfig;
8 * Tests the image field widget.
12 class ImageFieldWidgetTest extends ImageFieldTestBase {
15 * Tests file widget element.
17 public function testWidgetElement() {
18 // Check for image widget in add/node/article page
19 $field_name = strtolower($this->randomMachineName());
21 $max_resolution = 100;
23 'max_resolution' => $max_resolution . 'x' . $max_resolution,
24 'min_resolution' => $min_resolution . 'x' . $min_resolution,
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]');
33 // Check for allowed image file extensions - default.
34 $this->assertText('Allowed types: png gif jpg jpeg.');
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.');
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.');