You are here

public function ConfigurationUiTest::testValidationWhenEditing in Entity Embed 8

Test integration with Filter and Text Editor form validation.

@dataProvider providerTestValidations @dataProvider providerTestValidationWhenEditing

Parameters

bool $filter_html_status: Whether to enable filter_html.

bool $entity_embed_status: Whether to enabled entity_embed.

string $allowed_html: The allowed HTML to set. Set to 'default' to test 'drupal-entity' is present or FALSE to leave the properly alone.

string $expected_error_message: The error message that should display.

File

tests/src/FunctionalJavascript/ConfigurationUiTest.php, line 169

Class

ConfigurationUiTest
Tests text format & text editor configuration UI validation.

Namespace

Drupal\Tests\entity_embed\FunctionalJavascript

Code

public function testValidationWhenEditing($filter_html_status, $entity_embed_status, $allowed_html, $expected_error_message) {
  $this
    ->drupalGet('admin/config/content/formats/manage/embed_test');

  // Enable the `filter_html` and `entity_embed` filters, and select CKEditor
  // as the text editor.
  $page = $this
    ->getSession()
    ->getPage();
  if ($filter_html_status) {
    $page
      ->checkField('filters[filter_html][status]');
  }
  if ($entity_embed_status) {
    $page
      ->checkField('filters[entity_embed][status]');
  }
  $page
    ->selectFieldOption('editor[editor]', 'ckeditor');

  // Verify that after dragging the Entity Embed CKEditor plugin button into
  // the active toolbar, the <drupal-entity> tag is allowed, as well as some
  // attributes.
  $item = 'li[data-drupal-ckeditor-button-name="test_media_entity_embed"]';
  $from = "ul {$item}";
  $target = 'ul.ckeditor-toolbar-group-buttons';
  $this
    ->assertSession()
    ->waitForElementVisible('css', $target);
  $this
    ->sortableTo($item, $from, $target);
  if ($allowed_html == 'default' && $entity_embed_status) {
    $allowed_html = $this
      ->assertSession()
      ->fieldExists('filters[filter_html][settings][allowed_html]')
      ->getValue();
    $this
      ->assertStringContainsString('drupal-entity', $allowed_html);
  }
  elseif (!empty($allowed_html)) {
    $page
      ->fillField('filters[filter_html][settings][allowed_html]', $allowed_html);
  }
  $this
    ->assertSession()
    ->buttonExists('Save configuration')
    ->press();
  if ($expected_error_message) {
    $this
      ->assertSession()
      ->pageTextNotContains('The text format Embed format has been updated.');
    $this
      ->assertSession()
      ->pageTextContains($expected_error_message);
  }
  else {
    $this
      ->assertSession()
      ->pageTextContains('The text format Embed format has been updated.');
  }
}