You are here

public function ImageEffectsTest::testEffectFormValidationErrors in Drupal 9

Tests that validation errors are passed from the plugin to the parent form.

File

core/modules/image/tests/src/Kernel/ImageEffectsTest.php, line 222

Class

ImageEffectsTest
Tests image effects.

Namespace

Drupal\Tests\image\Kernel

Code

public function testEffectFormValidationErrors() {
  $form_builder = $this->container
    ->get('form_builder');

  /** @var \Drupal\image\ImageStyleInterface $image_style */
  $image_style = ImageStyle::create([
    'name' => 'foo',
  ]);
  $effect_id = $image_style
    ->addImageEffect([
    'id' => 'image_scale',
  ]);
  $image_style
    ->save();
  $form = new ImageEffectEditForm();
  $form_state = (new FormState())
    ->setValues([
    'data' => [
      'width' => '',
      'height' => '',
    ],
  ]);
  $form_builder
    ->submitForm($form, $form_state, $image_style, $effect_id);
  $errors = $form_state
    ->getErrors();
  $this
    ->assertCount(1, $errors);
  $error = reset($errors);
  $this
    ->assertEquals('Width and height can not both be blank.', $error);
}