You are here

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

@covers ::form @covers ::flagViolations

Overrides FormWidgetBrowserTestBase::testValidation

File

tests/src/Functional/TypedDataFormWidget/SelectWidgetTest.php, line 93

Class

SelectWidgetTest
Class SelectWidgetTest.

Namespace

Drupal\Tests\typed_data\Functional\TypedDataFormWidget

Code

public function testValidation() {
  $context_definition = ContextDefinition::create('filter_format')
    ->setLabel('Filter format')
    ->setDescription('Some example selection.')
    ->setRequired(TRUE);
  $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);

  // Set the empty option and make sure it results in a violation.
  $this
    ->fillField('data[value]', '');
  $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());
}