annotate core/modules/image/tests/src/Functional/ImageFieldWidgetTest.php @ 19:fa3358dc1485 tip

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