You are here

protected function WidgetTestTrait::assertWidgetSettingsForm in The CodeMirror Editor 8

Asserts widget settings form.

1 call to WidgetTestTrait::assertWidgetSettingsForm()
WidgetTestTrait::testWidgetEditor in tests/src/FunctionalJavascript/WidgetTestTrait.php
Test callback.

File

tests/src/FunctionalJavascript/WidgetTestTrait.php, line 157

Class

WidgetTestTrait
Provides a helper methods to for testing widgets.

Namespace

Drupal\Tests\codemirror_editor\FunctionalJavascript

Code

protected function assertWidgetSettingsForm(array $widget_settings) {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $settings_wrapper = $assert_session
    ->waitForElementVisible('xpath', '//div[@data-drupal-selector = "edit-fields-' . Html::getClass($this->fieldName) . '-settings-edit-form"]');
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][rows]" and @value = %d]';
  $xpath = sprintf($xpath, $widget_settings['rows']);
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][placeholder]" and @value = "%s"]';
  $xpath = sprintf($xpath, $widget_settings['placeholder']);
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//select[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][mode]"]/optgroup/option[@value = "%s" and @selected]';
  $xpath = sprintf($xpath, $widget_settings['mode']);
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][toolbar]" and %s]';
  $xpath = sprintf($xpath, $widget_settings['toolbar'] ? '@checked = "checked"' : 'not(@checked)');
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $element = $page
    ->find('xpath', "//select[@name='fields[{$this->fieldName}][settings_edit_form][settings][buttons][]']");
  $this
    ->assertNotEmpty($element);
  self::assertSame($widget_settings['buttons'], $element
    ->getValue());
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][lineWrapping]" and %s]';
  $xpath = sprintf($xpath, $widget_settings['lineWrapping'] ? '@checked = "checked"' : 'not(@checked)');
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][lineNumbers]" and %s]';
  $xpath = sprintf($xpath, $widget_settings['lineNumbers'] ? '@checked = "checked"' : 'not(@checked)');
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][foldGutter]" and %s]';
  $xpath = sprintf($xpath, $widget_settings['foldGutter'] ? '@checked = "checked"' : 'not(@checked)');
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][autoCloseTags]" and %s]';
  $xpath = sprintf($xpath, $widget_settings['autoCloseTags'] ? '@checked = "checked"' : 'not(@checked)');
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
  $xpath = '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][styleActiveLine]" and %s]';
  $xpath = sprintf($xpath, $widget_settings['styleActiveLine'] ? '@checked = "checked"' : 'not(@checked)');
  $assert_session
    ->elementExists('xpath', $xpath, $settings_wrapper);
}