class ImageFieldWidgetValidationTest
Tests the image field widget validation.
@group image
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait
- class \Drupal\Tests\image\Functional\ImageFieldTestBase extends \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\image\Kernel\ImageFieldCreationTrait
- class \Drupal\Tests\image\Functional\ImageFieldWidgetValidationTest extends \Drupal\Tests\image\Functional\ImageFieldTestBase
- class \Drupal\Tests\image\Functional\ImageFieldTestBase extends \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\image\Kernel\ImageFieldCreationTrait
Expanded class hierarchy of ImageFieldWidgetValidationTest
File
-
core/
modules/ image/ tests/ src/ Functional/ ImageFieldWidgetValidationTest.php, line 12
Namespace
Drupal\Tests\image\FunctionalView source
class ImageFieldWidgetValidationTest extends ImageFieldTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'image_field_property_constraint_validation',
];
/**
* Tests file widget element.
*/
public function testWidgetElementValidation() : void {
$page = $this->getSession()
->getPage();
// Check for image widget in add/node/article page
$field_name = 'field_image';
$field_settings = [
'description' => 'Image test description',
'alt_field' => 1,
'alt_field_required' => 0,
'title_field' => 1,
'title_field_required' => 0,
];
$this->createImageField($field_name, 'node', 'article', [], $field_settings, [], [], 'Image');
$this->drupalGet('node/add/article');
// Verify that the image field widget is found on add/node page.
$this->assertSession()
->elementExists('xpath', '//div[contains(@class, "field--widget-image-image")]');
// Attach an image.
$image_media_name = 'example_1.jpeg';
$page->attachFileToField('files[field_image_0]', $this->root . '/core/modules/image/tests/fixtures/' . $image_media_name);
$page->pressButton('Save');
// Alt is marked as errored.
$altElement = $this->assertSession()
->elementExists('css', 'input[data-drupal-selector="edit-field-image-0-alt"]');
$this->assertTrue(str_contains($altElement->getAttribute('class'), 'error'));
// Title is not marked as errored
$titleElement = $this->assertSession()
->elementExists('css', 'input[data-drupal-selector="edit-field-image-0-title"]');
$this->assertFalse(str_contains($titleElement->getAttribute('class'), 'error'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.