1 filter.test FilterCRUDTestCase::testTextFormatCRUD()

Tests CRUD operations for text formats and filters.

File

core/modules/filter/tests/filter.test, line 18
Tests for filter.module.

Class

FilterCRUDTestCase
Tests for text format and filter CRUD operations.

Code

function testTextFormatCRUD() {
  // Add a text format with minimum data only.
  $format = new stdClass();
  $format->format = 'empty_format';
  $format->name = 'Empty format';
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Add another text format specifying all possible properties.
  $format = new stdClass();
  $format->format = 'custom_format';
  $format->name = 'Custom format';
  $format->filters = array(
    'filter_url' => array(
      'status' => 1,
      'settings' => array(
        'filter_url_length' => 30,
      ),
    ),
  );
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Alter some text format properties and save again.
  $format->name = 'Altered format';
  $format->filters['filter_url']->status = 0;
  $format->filters['filter_autop'] = (object) array(
    'status' => 1,
  );
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Add an uncacheable filter and save again.
  $format->filters['filter_test_uncacheable'] = (object) array(
    'status' => 1,
  );
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Disable the text format.
  filter_format_disable($format);

  $config_format = config_get('filter.format.' . $format->format);
  $this->assertFalse($config_format['status'], 'Disabled text format is marked as disabled in config.');
  $formats = filter_formats();
  $this->assertTrue(!isset($formats[$format->format]), 'filter_formats: Disabled text format no longer exists.');

  // Add a new format to check for XSS in format name.
  $format = new stdClass();
  $format->format = 'xss_format';
  $format->name = '<script>alert(123)</script>';
  filter_format_save($format);
  user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(filter_permission_name($format) => 1));
  $this->backdropGet('filter/tips');
  $this->assertNoRaw($format->name, 'Text format name contains no xss.');
}