function ImageFieldValidateTest::testAJAXValidationMessage

Same name in other branches
  1. 9 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()
  3. 11.x core/modules/image/tests/src/FunctionalJavascript/ImageFieldValidateTest.php \Drupal\Tests\image\FunctionalJavascript\ImageFieldValidateTest::testAJAXValidationMessage()

Test 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');
    $elements = $this->xpath('//div[contains(@class, :class)]', [
        ':class' => 'messages--error',
    ]);
    $this->assertCount(1, $elements, 'Ajax validation messages are displayed once.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.