You are here

public function ImageFieldValidateTest::testFriendlyAjaxValidation in Drupal 8

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

Tests that image field validation works with other form submit handlers.

File

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

Class

ImageFieldValidateTest
Tests validation functions such as min/max resolution.

Namespace

Drupal\Tests\image\FunctionalJavascript

Code

public function testFriendlyAjaxValidation() {

  // Add a custom field to the Article content type that contains an AJAX
  // handler on a select field.
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'field_dummy_select',
    'type' => 'image_module_test_dummy_ajax',
    'entity_type' => 'node',
    'cardinality' => 1,
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'entity_type' => 'node',
    'bundle' => 'article',
    'field_name' => 'field_dummy_select',
    'label' => t('Dummy select'),
  ])
    ->save();
  \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load('node.article.default')
    ->setComponent('field_dummy_select', [
    'type' => 'image_module_test_dummy_ajax_widget',
    'weight' => 1,
  ])
    ->save();

  // Then, add an image field.
  $this
    ->createImageField('field_dummy_image', 'article');

  // Open an article and trigger the AJAX handler.
  $this
    ->drupalGet('node/add/article');
  $id = $this
    ->getSession()
    ->getPage()
    ->find('css', '[name="form_build_id"]')
    ->getValue();
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('field_dummy_select[select_widget]');
  $field
    ->setValue('bam');

  // Make sure that the operation did not end with an exception.
  $this
    ->assertSession()
    ->waitForElement('css', "[name='form_build_id']:not([value='{$id}'])");
}