You are here

public function TextInputWidgetTest::testValidation in Typed Data API enhancements 8

@covers ::form @covers ::flagViolations

Overrides FormWidgetBrowserTestBase::testValidation

File

tests/src/Functional/TypedDataFormWidget/TextInputWidgetTest.php, line 86

Class

TextInputWidgetTest
Class TextInputWidgetTest.

Namespace

Drupal\Tests\typed_data\Functional\TypedDataFormWidget

Code

public function testValidation() {
  $context_definition = ContextDefinition::create('string')
    ->setLabel('Example string')
    ->setDescription('Some example string')
    ->setDefaultValue('default1')
    ->addConstraint('Length', [
    'max' => 3,
  ]);
  $this->container
    ->get('state')
    ->set('typed_data_widgets.definition', $context_definition);
  $this
    ->drupalLogin($this
    ->createUser([], NULL, TRUE));
  $path = 'admin/config/user-interface/typed-data-widgets/' . $this->widget
    ->getPluginId();
  $this
    ->drupalGet($path);
  $this
    ->fillField('data[value]', 'too-long');
  $this
    ->pressButton('Submit');

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $assert
    ->fieldExists('data[value]')
    ->hasClass('error');

  // Make sure the changes have not been saved also.
  $this
    ->drupalGet($path);
  $assert
    ->fieldValueEquals('data[value]', $context_definition
    ->getDefaultValue());
}