Commit eab48b59 authored by catch's avatar catch

Issue #312458 by Heine, sun: Fixed HTML filter is not run first by default, despite default weight.

parent 17269ee9
......@@ -215,9 +215,11 @@ function filter_format_save($format) {
}
$filter_info = filter_get_filters();
foreach ($filter_info as $name => $filter) {
// Add new filters without weight to the bottom.
// If the format does not specify an explicit weight for a filter, assign
// a default weight, either defined in hook_filter_info(), or the default of
// 0 by filter_get_filters().
if (!isset($format->filters[$name]['weight'])) {
$format->filters[$name]['weight'] = 10;
$format->filters[$name]['weight'] = $filter['weight'];
}
$format->filters[$name]['status'] = isset($format->filters[$name]['status']) ? $format->filters[$name]['status'] : 0;
$format->filters[$name]['module'] = $filter['module'];
......
......@@ -1842,3 +1842,62 @@ class FilterHooksTestCase extends DrupalWebTestCase {
}
}
/**
* Tests filter settings.
*/
class FilterSettingsTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'Filter settings',
'description' => 'Tests filter settings.',
'group' => 'Filter',
);
}
/**
* Tests explicit and implicit default settings for filters.
*/
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 => $settings) {
$expected_weight = (isset($filter_info[$name]['weight']) ? $filter_info[$name]['weight'] : 0);
$this->assertEqual($settings['weight'], $expected_weight, format_string('@name filter weight %saved equals %default', array(
'@name' => $name,
'%saved' => $settings['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);
$filter_defaults_format->filters = filter_list_format($filter_defaults_format->format);
// Verify that saved filter settings have not been changed.
foreach ($filter_defaults_format->filters as $name => $settings) {
$this->assertEqual($settings->weight, $saved_settings[$name]['weight'], format_string('@name filter weight %saved equals %previous', array(
'@name' => $name,
'%saved' => $settings->weight,
'%previous' => $saved_settings[$name]['weight'],
)));
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment