You are here

public function BlockUiTest::testBlockValidateErrors in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testBlockValidateErrors()

Tests if validation errors are passed plugin form to the parent form.

File

core/modules/block/tests/src/Functional/BlockUiTest.php, line 356

Class

BlockUiTest
Tests that the block configuration UI exists and stores data correctly.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockValidateErrors() {
  $this
    ->drupalGet('admin/structure/block/add/test_settings_validation/classy');
  $this
    ->submitForm([
    'region' => 'content',
    'settings[digits]' => 'abc',
  ], 'Save block');
  $arguments = [
    ':message' => 'Only digits are allowed',
  ];
  $pattern = '//div[contains(@class,"messages messages--error")]/div[contains(text()[2],:message)]';
  $elements = $this
    ->xpath($pattern, $arguments);
  $this
    ->assertNotEmpty($elements, 'Plugin error message found in parent form.');
  $error_class_pattern = '//div[contains(@class,"form-item-settings-digits")]/input[contains(@class,"error")]';
  $error_class = $this
    ->xpath($error_class_pattern);
  $this
    ->assertNotEmpty($error_class, 'Plugin error class found in parent form.');
}