1 filter.test FilterSettingsTestCase::testFilterDefaults()

Tests explicit and implicit default settings for filters.

File

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

Class

FilterSettingsTestCase
Tests filter settings.

Code

function testFilterDefaults() {
  $filter_info = filter_filter_info();
  $filters = array_fill_keys(array_keys($filter_info), array());

  // Create text format using filter default settings.
  $filter_defaults_format = (object) array(
    'format' => 'filter_defaults',
    'name' => 'Filter defaults',
    'filters' => $filters,
  );
  filter_format_save($filter_defaults_format);

  // Verify that default weights defined in hook_filter_info() were applied.
  $saved_settings = array();
  foreach ($filter_defaults_format->filters as $name => $filter) {
    $expected_weight = (isset($filter_info[$name]['weight']) ? $filter_info[$name]['weight'] : 0);
    $this->assertEqual($filter->weight, $expected_weight, format_string('@name filter weight %saved equals %default', array(
      '@name' => $name,
      '%saved' => $filter->weight,
      '%default' => $expected_weight,
    )));
    $saved_settings[$name]['weight'] = $expected_weight;
  }

  // Re-save the text format.
  filter_format_save($filter_defaults_format);
  // Reload it from scratch.
  filter_formats_reset();
  $filter_defaults_format = filter_format_load($filter_defaults_format->format);

  // Verify that saved filter settings have not been changed.
  foreach ($filter_defaults_format->filters as $name => $filter) {
    $this->assertEqual($filter->weight, $saved_settings[$name]['weight'], format_string('@name filter weight %saved equals %previous', array(
      '@name' => $name,
      '%saved' => $filter->weight,
      '%previous' => $saved_settings[$name]['weight'],
    )));
  }
}