function ImageEffectsTest::testEffectFormValidationErrors

Same name in other branches
  1. 9 core/modules/image/tests/src/Kernel/ImageEffectsTest.php \Drupal\Tests\image\Kernel\ImageEffectsTest::testEffectFormValidationErrors()
  2. 8.9.x core/modules/image/tests/src/Functional/ImageEffectsTest.php \Drupal\Tests\image\Functional\ImageEffectsTest::testEffectFormValidationErrors()
  3. 11.x core/modules/image/tests/src/Kernel/ImageEffectsTest.php \Drupal\Tests\image\Kernel\ImageEffectsTest::testEffectFormValidationErrors()

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

File

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

Class

ImageEffectsTest
Tests image effects.

Namespace

Drupal\Tests\image\Kernel

Code

public function testEffectFormValidationErrors() : void {
    $form_builder = $this->container
        ->get('form_builder');
    
    /** @var \Drupal\image\ImageStyleInterface $image_style */
    $image_style = ImageStyle::create([
        'name' => 'foo',
        'label' => '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);
}

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