You are here

public function ImageFieldValidateTest::testAJAXValidationMessage in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/tests/src/FunctionalJavascript/ImageFieldValidateTest.php \Drupal\Tests\image\FunctionalJavascript\ImageFieldValidateTest::testAJAXValidationMessage()
  2. 10 core/modules/image/tests/src/FunctionalJavascript/ImageFieldValidateTest.php \Drupal\Tests\image\FunctionalJavascript\ImageFieldValidateTest::testAJAXValidationMessage()

Tests the validation message is displayed only once for ajax uploads.

File

core/modules/image/tests/src/FunctionalJavascript/ImageFieldValidateTest.php, line 23

Class

ImageFieldValidateTest
Tests validation functions such as min/max resolution.

Namespace

Drupal\Tests\image\FunctionalJavascript

Code

public function testAJAXValidationMessage() {
  $field_name = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($field_name, 'article', [
    'cardinality' => -1,
  ]);
  $this
    ->drupalGet('node/add/article');

  /** @var \Drupal\file\FileInterface[] $text_files */
  $text_files = $this
    ->drupalGetTestFiles('text');
  $text_file = reset($text_files);
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('files[' . $field_name . '_0][]');
  $field
    ->attachFile($this->container
    ->get('file_system')
    ->realpath($text_file->uri));
  $this
    ->assertSession()
    ->waitForElement('css', '.messages--error');

  // Verify that Ajax validation messages are displayed only once.
  $this
    ->assertSession()
    ->elementsCount('xpath', '//div[contains(@class, "messages--error")]', 1);
}