You are here

protected function FilterFormTest::doFilterFormTestAsAdmin in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/filter/tests/src/Functional/FilterFormTest.php \Drupal\Tests\filter\Functional\FilterFormTest::doFilterFormTestAsAdmin()

Tests the behavior of the 'text_format' element as an administrator.

1 call to FilterFormTest::doFilterFormTestAsAdmin()
FilterFormTest::testFilterForm in core/modules/filter/tests/src/Functional/FilterFormTest.php
Tests various different configurations of the 'text_format' element.

File

core/modules/filter/tests/src/Functional/FilterFormTest.php, line 83

Class

FilterFormTest
Tests form elements with associated text formats.

Namespace

Drupal\Tests\filter\Functional

Code

protected function doFilterFormTestAsAdmin() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('filter-test/text-format');

  // Test a text format element with all formats.
  $formats = [
    'filtered_html',
    'full_html',
    'filter_test',
  ];
  $this
    ->assertEnabledTextarea('edit-all-formats-no-default-value');

  // If no default is given, the format with the lowest weight becomes the
  // default.
  $this
    ->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html');
  $this
    ->assertEnabledTextarea('edit-all-formats-default-value');

  // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses
  // 'filter_test' as the default value in this case.
  $this
    ->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test');
  $this
    ->assertEnabledTextarea('edit-all-formats-default-missing-value');

  // If a missing format is set as the default, administrators must select a
  // valid replacement format.
  $this
    ->assertRequiredSelectAndOptions('edit-all-formats-default-missing-format--2', $formats);

  // Test a text format element with a predefined list of formats.
  $formats = [
    'full_html',
    'filter_test',
  ];
  $this
    ->assertEnabledTextarea('edit-restricted-formats-no-default-value');
  $this
    ->assertOptions('edit-restricted-formats-no-default-format--2', $formats, 'full_html');
  $this
    ->assertEnabledTextarea('edit-restricted-formats-default-value');
  $this
    ->assertOptions('edit-restricted-formats-default-format--2', $formats, 'full_html');
  $this
    ->assertEnabledTextarea('edit-restricted-formats-default-missing-value');
  $this
    ->assertRequiredSelectAndOptions('edit-restricted-formats-default-missing-format--2', $formats);
  $this
    ->assertEnabledTextarea('edit-restricted-formats-default-disallowed-value');
  $this
    ->assertRequiredSelectAndOptions('edit-restricted-formats-default-disallowed-format--2', $formats);

  // Test a text format element with a fixed format.
  $formats = [
    'filter_test',
  ];

  // When there is only a single option there is no point in choosing.
  $this
    ->assertEnabledTextarea('edit-single-format-no-default-value');
  $this
    ->assertNoSelect('edit-single-format-no-default-format--2');
  $this
    ->assertEnabledTextarea('edit-single-format-default-value');
  $this
    ->assertNoSelect('edit-single-format-default-format--2');

  // If the select has a missing or disallowed format, administrators must
  // explicitly choose the format.
  $this
    ->assertEnabledTextarea('edit-single-format-default-missing-value');
  $this
    ->assertRequiredSelectAndOptions('edit-single-format-default-missing-format--2', $formats);
  $this
    ->assertEnabledTextarea('edit-single-format-default-disallowed-value');
  $this
    ->assertRequiredSelectAndOptions('edit-single-format-default-disallowed-format--2', $formats);
}