diff --git a/core/modules/filter/config/filter.format.plain_text.yml b/core/modules/filter/config/filter.format.plain_text.yml index ceff5d2..5967ffe 100644 --- a/core/modules/filter/config/filter.format.plain_text.yml +++ b/core/modules/filter/config/filter.format.plain_text.yml @@ -1,13 +1,45 @@ format: plain_text -name: Plain text -weight: 10 +name: 'Plain text' +cache: '1' +status: '1' +weight: '10' +roles: + anonymous: anonymous + authenticated: authenticated + administrator: administrator filters: filter_html_escape: - weight: 0 - status: 1 + module: filter + settings: { } + status: '1' + weight: '0' filter_url: - weight: 1 - status: 1 + module: filter + settings: + filter_url_length: '72' + status: '1' + weight: '1' filter_autop: - weight: 2 - status: 1 + module: filter + settings: { } + status: '1' + weight: '2' + filter_html: + module: filter + settings: + allowed_html: '' + filter_html_help: '0' + filter_html_nofollow: '0' + status: '0' + weight: '0' + filter_html_image_secure: + module: filter + settings: { } + status: '0' + weight: '0' + filter_htmlcorrector: + module: filter + settings: { } + status: '0' + weight: '0' +langcode: und diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 45646d0..8118345 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -632,18 +632,22 @@ function _filter_list_cmp($a, $b) { } /** - * Sorts an array of filters by filter weight, module, name. + * Sorts an array of filters by filter status, weight, module, name. * - * Callback for uasort() within filter_list_format(). + * @see filter_list_format() + * @see Drupal\filter\Plugin\Core\Entity\FilterFormat::save() */ function _filter_format_filter_cmp($a, $b) { - if ($a->weight != $b->weight) { - return ($a->weight < $b->weight) ? -1 : 1; + if ($a['status'] != $b['status']) { + return !empty($a['status']) ? -1 : 1; + } + if ($a['weight'] != $b['weight']) { + return ($a['weight'] < $b['weight']) ? -1 : 1; } - elseif ($a->module != $b->module) { - return strcmp($a->module, $b->module); + elseif ($a['module'] != $b['module']) { + return strcmp($a['module'], $b['module']); } - return strcmp($a->name, $b->name); + return strcmp($a['name'], $b['name']); } /** @@ -721,9 +725,15 @@ function filter_list_format($format_id) { foreach ($filter_formats as $filter_format) { foreach ($filter_format->filters as $filter_name => $filter) { $filter['name'] = $filter_name; - $filters['all'][$filter_format->format][$filter_name] = (object)$filter; + $filters['all'][$filter_format->format][$filter_name] = $filter; } @uasort($filters['all'][$filter_format->format], '_filter_format_filter_cmp'); + foreach ($filters['all'][$filter_format->format] as $filter_name => $filter) { + // Before Conversion to CMI, filter were objects, now they are arrays. + // Convert filters back to objects to reduce the impact of changes. + // @todo Follow-up: filters should be arrays instead of objects. + $filters['all'][$filter_format->format][$filter_name] = (object)$filter; + } } cache()->set('filter_list_format', $filters['all']); } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php index 85f9d7d..01e3cc6 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php @@ -129,21 +129,17 @@ public function save() { else { $this->filters[$name]['settings'] = isset($filter['default settings']) ? $filter['default settings'] : array(); } + + // Sort filters properties by key, to minimize diff issues. + ksort($this->filters[$name]); } - $return = parent::save(); + // Sort filters by enabled/disabled first then by weight + @uasort($this->filters, '_filter_format_filter_cmp'); - if ($return == SAVED_NEW) { - module_invoke_all('filter_format_insert', $this); - } - else { - module_invoke_all('filter_format_update', $this); - // Explicitly indicate that the format was updated. We need to do this - // since if the filters were updated but the format object itself was not, - // the merge query above would not return an indication that anything had - // changed. - $return = SAVED_UPDATED; + $return = parent::save(); + if ($return == SAVED_UPDATED) { // Clear the filter cache whenever a text format is updated. cache('filter')->invalidateTags(array('filter_format' => $this->format)); } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php index 893394b..aa46c91 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php @@ -152,20 +152,29 @@ function testFilterAdmin() { )); $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.'); - $filter_format = filter_format_load($filtered); - - // The filter format is not saved in 'order', but the order is defined - // in the filter array. So, check if after ordering the filter, the - // expected order is correct. - $filter_format_filters = $filter_format->filters; - @uasort($filter_format_filters, '_filter_format_filter_cmp'); - foreach ($filter_format_filters as $filter_name => $filter) { + $filter_format = entity_load('filter_format', $filtered); + foreach ($filter_format->filters as $filter_name => $filter) { if ($filter_name == $second_filter || $filter_name == $first_filter) { $filters[] = $filter_name; } } $this->assertTrue(($filters[0] == $second_filter && $filters[1] == $first_filter), t('Order confirmed in database.')); + // Reorder filters, test markup. + $text = '

Drupal

'; + + // Plain text filter format converts html into plain text and wrap the text + // with

. + $this->assertEqual(check_markup($text, $plain), '

<h1>Drupal</h1>

'); + + $edit = array(); + // Move 'Escape HTML' at the end of the list of filters + $edit['filters[filter_html_escape][weight]'] = 50; + $this->drupalPost('admin/config/content/formats/' . $plain, $edit, t('Save configuration')); + + // After reorder the filters, the wrapper

should be escaped too. + $this->assertEqual(check_markup($text, $plain), '<p><h1>Drupal</h1></p>'); + // Add format. $edit = array(); $edit['format'] = drupal_strtolower($this->randomName()); diff --git a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php index 187c386..af707c7 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php @@ -112,6 +112,8 @@ protected function entityCreate($entity_type) { return entity_create('node', array('title' => $this->randomString())); case 'user': return entity_create('user', array('name' => $this->randomName())); + case 'filter_format': + return entity_create('filter_format', array('format' => $this->randomName())); default: return entity_create($entity_type, array()); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradeFilterFormatTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradeFilterFormatTest.php new file mode 100644 index 0000000..e26702a --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradeFilterFormatTest.php @@ -0,0 +1,47 @@ + 'Filter Formats upgrade test', + 'description' => 'Upgrade tests with filter formats data.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + $this->databaseDumpFiles = array( + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.filter_formats.database.php', + ); + parent::setUp(); + } + + /** + * Tests expected filter formats entities after a successful upgrade. + */ + public function testFilterFormatUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Checks that all the formats were upgraded + foreach (array('format_one', 'format_two') as $format) { + $filter_format = filter_format_load($format); + $this->assertTrue(!empty($filter_format), 'Filter Format ' . $filter_format->format . ' was successfully upgraded'); + } + + } +} diff --git a/core/modules/system/tests/upgrade/drupal-7.filter_formats.database.php b/core/modules/system/tests/upgrade/drupal-7.filter_formats.database.php new file mode 100644 index 0000000..a0ffe0a --- /dev/null +++ b/core/modules/system/tests/upgrade/drupal-7.filter_formats.database.php @@ -0,0 +1,63 @@ +fields(array( + 'rid', + 'name', + 'weight', +)) +// Adds a role with an umlaut in it. +->values(array( + 'rid' => '4', + 'name' => 'gärtner', + 'weight' => '3', +)) +// Adds a very long role name. +->values(array( + 'rid' => '5', + 'name' => 'very long role name that has exactly sixty-four characters in it', + 'weight' => '4', +)) +// Adds a very similar role name to test edge cases. +->values(array( + 'rid' => '6', + 'name' => 'very_long role name that has exactly sixty-four characters in it', + 'weight' => '5', +)) +->execute(); + +// Add the "Edit own comments" permission to the gärtner test role. +db_insert('role_permission')->fields(array( + 'rid', + 'permission', + 'module', +)) +->values(array( + 'rid' => '4', + 'permission' => 'edit own comments', + 'module' => 'comment', +)) +->execute(); + +// Adds some role visibility settings on the who's online block for the long +// role. +db_insert('block_role')->fields(array( + 'module', + 'delta', + 'rid', +)) +->values(array( + 'module' => 'user', + 'delta' => 'online', + 'rid' => '5', +)) +->execute(); diff --git a/core/profiles/standard/config/filter.format.filtered_html.yml b/core/profiles/standard/config/filter.format.filtered_html.yml index 1b905c6..963132f 100644 --- a/core/profiles/standard/config/filter.format.filtered_html.yml +++ b/core/profiles/standard/config/filter.format.filtered_html.yml @@ -1,16 +1,45 @@ format: filtered_html -name: Filtered HTML -weight: 0 +name: 'Filtered HTML' +cache: '1' +status: '1' +weight: '0' +roles: + anonymous: anonymous + authenticated: authenticated + administrator: administrator filters: filter_url: - weight: 0 - status: 1 + module: filter + settings: + filter_url_length: '72' + status: '1' + weight: '0' filter_html: - weight: 1 - status: 1 + module: filter + settings: + allowed_html: '