You are here

public function HtmlPurifierFilterTest::testConfigurationValidation in HTML Purifier 8

Test configuration validation for the filter settings form.

@dataProvider providerTestConfigurationValidation

Parameters

string $configuration: The HTMLPurifier configuration.

string[] $expected_errors: The expected errors.

File

tests/src/Kernel/HtmlPurifierFilterTest.php, line 72

Class

HtmlPurifierFilterTest
Tests htmlpurifier filter.

Namespace

Drupal\Tests\htmlpurifier\Kernel

Code

public function testConfigurationValidation(string $configuration, array $expected_errors) {
  $element = [
    '#parents' => [
      'filters',
      'htmlpurifier',
      'settings',
      'htmlpurifier_configuration',
    ],
  ];
  $form_state = new FormState();
  $filters['htmlpurifier']['settings']['htmlpurifier_configuration'] = $configuration;
  $form_state
    ->setValue('filters', $filters);
  $this->filter
    ->settingsFormConfigurationValidate($element, $form_state);
  $errors = $form_state
    ->getErrors();
  if (!empty($expected_errors)) {
    $this
      ->assertNotEmpty($errors);
    $this
      ->assertStringContainsString($expected_errors[0], array_values($errors)[0]);
  }
  else {
    $this
      ->assertSame($expected_errors, $errors);
  }
}