diff --git a/core/modules/filter/src/Tests/FilterAdminTest.php b/core/modules/filter/src/Tests/FilterAdminTest.php
deleted file mode 100644
index aceeff5..0000000
--- a/core/modules/filter/src/Tests/FilterAdminTest.php
+++ /dev/null
@@ -1,458 +0,0 @@
-<?php
-
-namespace Drupal\filter\Tests;
-
-use Drupal\Component\Utility\Html;
-use Drupal\Component\Utility\Unicode;
-use Drupal\filter\Entity\FilterFormat;
-use Drupal\node\Entity\Node;
-use Drupal\node\Entity\NodeType;
-use Drupal\simpletest\WebTestBase;
-use Drupal\user\RoleInterface;
-
-/**
- * Thoroughly test the administrative interface of the filter module.
- *
- * @group filter
- */
-class FilterAdminTest extends WebTestBase {
-
-  /**
-   * {@inheritdoc}
-   */
-  public static $modules = ['block', 'filter', 'node', 'filter_test_plugin', 'dblog'];
-
-  /**
-   * An user with administration permissions.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $adminUser;
-
-  /**
-   * An user with permissions to create pages.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $webUser;
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
-
-    // Set up the filter formats used by this test.
-    $basic_html_format = FilterFormat::create([
-      'format' => 'basic_html',
-      'name' => 'Basic HTML',
-      'filters' => [
-        'filter_html' => [
-          'status' => 1,
-          'settings' => [
-            'allowed_html' => '<p> <br> <strong> <a> <em>',
-          ],
-        ],
-      ],
-    ]);
-    $basic_html_format->save();
-    $restricted_html_format = FilterFormat::create([
-      'format' => 'restricted_html',
-      'name' => 'Restricted HTML',
-      'filters' => [
-        'filter_html' => [
-          'status' => TRUE,
-          'weight' => -10,
-          'settings' => [
-            'allowed_html' => '<p> <br> <strong> <a> <em> <h4>',
-          ],
-        ],
-        'filter_autop' => [
-          'status' => TRUE,
-          'weight' => 0,
-        ],
-        'filter_url' => [
-          'status' => TRUE,
-          'weight' => 0,
-        ],
-        'filter_htmlcorrector' => [
-          'status' => TRUE,
-          'weight' => 10,
-        ],
-      ],
-    ]);
-    $restricted_html_format->save();
-    $full_html_format = FilterFormat::create([
-      'format' => 'full_html',
-      'name' => 'Full HTML',
-      'weight' => 1,
-      'filters' => [],
-    ]);
-    $full_html_format->save();
-
-    $this->adminUser = $this->drupalCreateUser([
-      'administer filters',
-      $basic_html_format->getPermissionName(),
-      $restricted_html_format->getPermissionName(),
-      $full_html_format->getPermissionName(),
-      'access site reports',
-    ]);
-
-    $this->webUser = $this->drupalCreateUser(['create page content', 'edit own page content']);
-    user_role_grant_permissions('authenticated', [$basic_html_format->getPermissionName()]);
-    user_role_grant_permissions('anonymous', [$restricted_html_format->getPermissionName()]);
-    $this->drupalLogin($this->adminUser);
-    $this->drupalPlaceBlock('local_actions_block');
-  }
-
-  /**
-   * Tests the format administration functionality.
-   */
-  public function testFormatAdmin() {
-    // Add text format.
-    $this->drupalGet('admin/config/content/formats');
-    $this->clickLink('Add text format');
-    $format_id = Unicode::strtolower($this->randomMachineName());
-    $name = $this->randomMachineName();
-    $edit = [
-      'format' => $format_id,
-      'name' => $name,
-    ];
-    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
-
-    // Verify default weight of the text format.
-    $this->drupalGet('admin/config/content/formats');
-    $this->assertFieldByName("formats[$format_id][weight]", 0, 'Text format weight was saved.');
-
-    // Change the weight of the text format.
-    $edit = [
-      "formats[$format_id][weight]" => 5,
-    ];
-    $this->drupalPostForm('admin/config/content/formats', $edit, t('Save'));
-    $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was saved.');
-
-    // Edit text format.
-    $this->drupalGet('admin/config/content/formats');
-    // Cannot use the assertNoLinkByHref method as it does partial url matching
-    // and 'admin/config/content/formats/manage/' . $format_id . '/disable'
-    // exists.
-    // @todo: See https://www.drupal.org/node/2031223 for the above.
-    $edit_link = $this->xpath('//a[@href=:href]', [
-      ':href' => \Drupal::url('entity.filter_format.edit_form', ['filter_format' => $format_id])
-    ]);
-    $this->assertTrue($edit_link, format_string('Link href %href found.',
-      ['%href' => 'admin/config/content/formats/manage/' . $format_id]
-    ));
-    $this->drupalGet('admin/config/content/formats/manage/' . $format_id);
-    $this->drupalPostForm(NULL, [], t('Save configuration'));
-
-    // Verify that the custom weight of the text format has been retained.
-    $this->drupalGet('admin/config/content/formats');
-    $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was retained.');
-
-    // Disable text format.
-    $this->assertLinkByHref('admin/config/content/formats/manage/' . $format_id . '/disable');
-    $this->drupalGet('admin/config/content/formats/manage/' . $format_id . '/disable');
-    $this->drupalPostForm(NULL, [], t('Disable'));
-
-    // Verify that disabled text format no longer exists.
-    $this->drupalGet('admin/config/content/formats/manage/' . $format_id);
-    $this->assertResponse(404, 'Disabled text format no longer exists.');
-
-    // Attempt to create a format of the same machine name as the disabled
-    // format but with a different human readable name.
-    $edit = [
-      'format' => $format_id,
-      'name' => 'New format',
-    ];
-    $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
-    $this->assertText('The machine-readable name is already in use. It must be unique.');
-
-    // Attempt to create a format of the same human readable name as the
-    // disabled format but with a different machine name.
-    $edit = [
-      'format' => 'new_format',
-      'name' => $name,
-    ];
-    $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
-    $this->assertRaw(t('Text format names must be unique. A format named %name already exists.', [
-      '%name' => $name,
-    ]));
-  }
-
-  /**
-   * Tests filter administration functionality.
-   */
-  public function testFilterAdmin() {
-    $first_filter = 'filter_autop';
-    $second_filter = 'filter_url';
-
-    $basic = 'basic_html';
-    $restricted = 'restricted_html';
-    $full = 'full_html';
-    $plain = 'plain_text';
-
-    // Check that the fallback format exists and cannot be disabled.
-    $this->assertTrue($plain == filter_fallback_format(), 'The fallback format is set to plain text.');
-    $this->drupalGet('admin/config/content/formats');
-    $this->assertNoRaw('admin/config/content/formats/manage/' . $plain . '/disable', 'Disable link for the fallback format not found.');
-    $this->drupalGet('admin/config/content/formats/manage/' . $plain . '/disable');
-    $this->assertResponse(403, 'The fallback format cannot be disabled.');
-
-    // Verify access permissions to Full HTML format.
-    $full_format = FilterFormat::load($full);
-    $this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.');
-    $this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.');
-
-    // Add an additional tag and extra spaces and returns.
-    $edit = [];
-    $edit['filters[filter_html][settings][allowed_html]'] = "<a>   <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>\r\n<quote>";
-    $this->drupalPostForm('admin/config/content/formats/manage/' . $restricted, $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->drupalGet('admin/config/content/formats/manage/' . $restricted);
-    $this->assertFieldByName('filters[filter_html][settings][allowed_html]', "<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>", 'Allowed HTML tag added.');
-
-    $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', [
-      ':first' => 'filters[' . $first_filter . '][weight]',
-      ':second' => 'filters[' . $second_filter . '][weight]',
-    ]);
-    $this->assertTrue(!empty($elements), 'Order confirmed in admin interface.');
-
-    // Reorder filters.
-    $edit = [];
-    $edit['filters[' . $second_filter . '][weight]'] = 1;
-    $edit['filters[' . $first_filter . '][weight]'] = 2;
-    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->drupalGet('admin/config/content/formats/manage/' . $restricted);
-    $this->assertFieldByName('filters[' . $second_filter . '][weight]', 1, 'Order saved successfully.');
-    $this->assertFieldByName('filters[' . $first_filter . '][weight]', 2, 'Order saved successfully.');
-
-    $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', [
-      ':first' => 'filters[' . $second_filter . '][weight]',
-      ':second' => 'filters[' . $first_filter . '][weight]',
-    ]);
-    $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');
-
-    $filter_format = FilterFormat::load($restricted);
-    foreach ($filter_format->filters() as $filter_name => $filter) {
-      if ($filter_name == $second_filter || $filter_name == $first_filter) {
-        $filters[] = $filter_name;
-      }
-    }
-    // Ensure that the second filter is now before the first filter.
-    $this->assertEqual($filter_format->filters($second_filter)->weight + 1, $filter_format->filters($first_filter)->weight, 'Order confirmed in configuration.');
-
-    // Add format.
-    $edit = [];
-    $edit['format'] = Unicode::strtolower($this->randomMachineName());
-    $edit['name'] = $this->randomMachineName();
-    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
-    $edit['filters[' . $second_filter . '][status]'] = TRUE;
-    $edit['filters[' . $first_filter . '][status]'] = TRUE;
-    $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->assertRaw(t('Added text format %format.', ['%format' => $edit['name']]), 'New filter created.');
-
-    filter_formats_reset();
-    $format = FilterFormat::load($edit['format']);
-    $this->assertNotNull($format, 'Format found in database.');
-    $this->drupalGet('admin/config/content/formats/manage/' . $format->id());
-    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', '', 'Role found.');
-    $this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.');
-    $this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'URL filter found.');
-
-    // Disable new filter.
-    $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->assertRaw(t('Disabled text format %format.', ['%format' => $edit['name']]), 'Format successfully disabled.');
-
-    // Allow authenticated users on full HTML.
-    $format = FilterFormat::load($full);
-    $edit = [];
-    $edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0;
-    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
-    $this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->assertRaw(t('The text format %format has been updated.', ['%format' => $format->label()]), 'Full HTML format successfully updated.');
-
-    // Switch user.
-    $this->drupalLogin($this->webUser);
-
-    $this->drupalGet('node/add/page');
-    $this->assertRaw('<option value="' . $full . '">Full HTML</option>', 'Full HTML filter accessible.');
-
-    // Use basic HTML and see if it removes tags that are not allowed.
-    $body = '<em>' . $this->randomMachineName() . '</em>';
-    $extra_text = 'text';
-    $text = $body . '<random>' . $extra_text . '</random>';
-
-    $edit = [];
-    $edit['title[0][value]'] = $this->randomMachineName();
-    $edit['body[0][value]'] = $text;
-    $edit['body[0][format]'] = $basic;
-    $this->drupalPostForm('node/add/page', $edit, t('Save'));
-    $this->assertText(t('Basic page @title has been created.', ['@title' => $edit['title[0][value]']]), 'Filtered node created.');
-
-    // Verify that the creation message contains a link to a node.
-    $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
-    $this->assert(isset($view_link), 'The message area contains a link to a node');
-
-    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
-    $this->assertTrue($node, 'Node found in database.');
-
-    $this->drupalGet('node/' . $node->id());
-    $this->assertRaw($body . $extra_text, 'Filter removed invalid tag.');
-
-    // Use plain text and see if it escapes all tags, whether allowed or not.
-    // In order to test plain text, we have to enable the hidden variable for
-    // "show_fallback_format", which displays plain text in the format list.
-    $this->config('filter.settings')
-      ->set('always_show_fallback_choice', TRUE)
-      ->save();
-    $edit = [];
-    $edit['body[0][format]'] = $plain;
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
-    $this->drupalGet('node/' . $node->id());
-    $this->assertEscaped($text, 'The "Plain text" text format escapes all HTML tags.');
-    $this->config('filter.settings')
-      ->set('always_show_fallback_choice', FALSE)
-      ->save();
-
-    // Switch user.
-    $this->drupalLogin($this->adminUser);
-
-    // Clean up.
-    // Allowed tags.
-    $edit = [];
-    $edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>';
-    $this->drupalPostForm('admin/config/content/formats/manage/' . $basic, $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->drupalGet('admin/config/content/formats/manage/' . $basic);
-    $this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Changes reverted.');
-
-    // Full HTML.
-    $edit = [];
-    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = FALSE;
-    $this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->assertRaw(t('The text format %format has been updated.', ['%format' => $format->label()]), 'Full HTML format successfully reverted.');
-    $this->drupalGet('admin/config/content/formats/manage/' . $full);
-    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'], 'Changes reverted.');
-
-    // Filter order.
-    $edit = [];
-    $edit['filters[' . $second_filter . '][weight]'] = 2;
-    $edit['filters[' . $first_filter . '][weight]'] = 1;
-    $this->drupalPostForm('admin/config/content/formats/manage/' . $basic, $edit, t('Save configuration'));
-    $this->assertUrl('admin/config/content/formats');
-    $this->drupalGet('admin/config/content/formats/manage/' . $basic);
-    $this->assertFieldByName('filters[' . $second_filter . '][weight]', $edit['filters[' . $second_filter . '][weight]'], 'Changes reverted.');
-    $this->assertFieldByName('filters[' . $first_filter . '][weight]', $edit['filters[' . $first_filter . '][weight]'], 'Changes reverted.');
-  }
-
-  /**
-   * Tests the URL filter settings form is properly validated.
-   */
-  public function testUrlFilterAdmin() {
-    // The form does not save with an invalid filter URL length.
-    $edit = [
-      'filters[filter_url][settings][filter_url_length]' => $this->randomMachineName(4),
-    ];
-    $this->drupalPostForm('admin/config/content/formats/manage/basic_html', $edit, t('Save configuration'));
-    $this->assertNoRaw(t('The text format %format has been updated.', ['%format' => 'Basic HTML']));
-  }
-
-  /**
-   * Tests whether filter tips page is not HTML escaped.
-   */
-  public function testFilterTipHtmlEscape() {
-    $this->drupalLogin($this->adminUser);
-    global $base_url;
-
-    $site_name_with_markup = 'Filter test <script>alert(\'here\');</script> site name';
-    $this->config('system.site')->set('name', $site_name_with_markup)->save();
-
-    // It is not possible to test the whole filter tip page.
-    // Therefore we test only some parts.
-    $link = '<a href="' . $base_url . '">' . Html::escape($site_name_with_markup) . '</a>';
-    $ampersand = '&amp;';
-    $link_as_code = '<code>' . Html::escape($link) . '</code>';
-    $ampersand_as_code = '<code>' . Html::escape($ampersand) . '</code>';
-
-    $this->drupalGet('filter/tips');
-
-    $this->assertRaw('<td class="type">' . $link_as_code . '</td>');
-    $this->assertRaw('<td class="get">' . $link . '</td>');
-    $this->assertRaw('<td class="type">' . $ampersand_as_code . '</td>');
-    $this->assertRaw('<td class="get">' . $ampersand . '</td>');
-  }
-
-  /**
-   * Tests whether a field using a disabled format is rendered.
-   */
-  public function testDisabledFormat() {
-    // Create a node type and add a standard body field.
-    $node_type = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName())]);
-    $node_type->save();
-    node_add_body_field($node_type, $this->randomString());
-
-    // Create a text format with a filter that returns a static string.
-    $format = FilterFormat::create([
-      'name' => $this->randomString(),
-      'format' => $format_id = Unicode::strtolower($this->randomMachineName()),
-    ]);
-    $format->setFilterConfig('filter_static_text', ['status' => TRUE]);
-    $format->save();
-
-    // Create a new node of the new node type.
-    $node = Node::create([
-      'type' => $node_type->id(),
-      'title' => $this->randomString(),
-    ]);
-    $body_value = $this->randomString();
-    $node->body->value = $body_value;
-    $node->body->format = $format_id;
-    $node->save();
-
-    // The format is used and we should see the static text instead of the body
-    // value.
-    $this->drupalGet($node->urlInfo());
-    $this->assertText('filtered text');
-
-    // Disable the format.
-    $format->disable()->save();
-
-    $this->drupalGet($node->urlInfo());
-
-    // The format is not used anymore.
-    $this->assertNoText('filtered text');
-    // The text is not displayed unfiltered or escaped.
-    $this->assertNoRaw($body_value);
-    $this->assertNoEscaped($body_value);
-
-    // Visit the dblog report page.
-    $this->drupalLogin($this->adminUser);
-    $this->drupalGet('admin/reports/dblog');
-    // The correct message has been logged.
-    $this->assertRaw(sprintf('Disabled text format: %s.', $format_id));
-
-    // Programmatically change the text format to something random so we trigger
-    // the missing text format message.
-    $format_id = $this->randomMachineName();
-    $node->body->format = $format_id;
-    $node->save();
-    $this->drupalGet($node->urlInfo());
-    // The text is not displayed unfiltered or escaped.
-    $this->assertNoRaw($body_value);
-    $this->assertNoEscaped($body_value);
-
-    // Visit the dblog report page.
-    $this->drupalGet('admin/reports/dblog');
-    // The missing text format message has been logged.
-    $this->assertRaw(sprintf('Missing text format: %s.', $format_id));
-  }
-
-}
diff --git a/core/modules/filter/src/Tests/FilterFormTest.php b/core/modules/filter/src/Tests/FilterFormTest.php
deleted file mode 100644
index 9d0641e..0000000
--- a/core/modules/filter/src/Tests/FilterFormTest.php
+++ /dev/null
@@ -1,311 +0,0 @@
-<?php
-
-namespace Drupal\filter\Tests;
-
-use Drupal\Component\Utility\SafeMarkup;
-use Drupal\filter\Entity\FilterFormat;
-use Drupal\simpletest\WebTestBase;
-
-/**
- * Tests form elements with associated text formats.
- *
- * @group filter
- */
-class FilterFormTest extends WebTestBase {
-
-  /**
-   * Modules to enable for this test.
-   *
-   * @var array
-   */
-  protected static $modules = ['filter', 'filter_test'];
-
-  /**
-   * An administrative user account that can administer text formats.
-   *
-   * @var \Drupal\user\Entity\User
-   */
-  protected $adminUser;
-
-  /**
-   * An basic user account that can only access basic HTML text format.
-   *
-   * @var \Drupal\user\Entity\User
-   */
-  protected $webUser;
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    /** @var \Drupal\filter\FilterFormatInterface $filter_test_format */
-    $filter_test_format = FilterFormat::load('filter_test');
-    /** @var \Drupal\filter\FilterFormatInterface $filtered_html_format */
-    $filtered_html_format = FilterFormat::load('filtered_html');
-    /** @var \Drupal\filter\FilterFormatInterface $full_html_format */
-    $full_html_format = FilterFormat::load('full_html');
-
-    // Create users.
-    $this->adminUser = $this->drupalCreateUser([
-      'administer filters',
-      $filtered_html_format->getPermissionName(),
-      $full_html_format->getPermissionName(),
-      $filter_test_format->getPermissionName(),
-    ]);
-
-    $this->webUser = $this->drupalCreateUser([
-      $filtered_html_format->getPermissionName(),
-      $filter_test_format->getPermissionName(),
-    ]);
-  }
-
-  /**
-   * Tests various different configurations of the 'text_format' element.
-   */
-  public function testFilterForm() {
-    $this->doFilterFormTestAsAdmin();
-    $this->doFilterFormTestAsNonAdmin();
-    // Ensure that enabling modules which provide filter plugins behaves
-    // correctly.
-    // @see https://www.drupal.org/node/2387983
-    \Drupal::service('module_installer')->install(['filter_test_plugin']);
-    // Force rebuild module data.
-    _system_rebuild_module_data();
-  }
-
-  /**
-   * Tests the behavior of the 'text_format' element as an administrator.
-   */
-  protected function doFilterFormTestAsAdmin() {
-    $this->drupalLogin($this->adminUser);
-    $this->drupalGet('filter-test/text-format');
-
-    // Test a text format element with all formats.
-    $formats = ['filtered_html', 'full_html', 'filter_test'];
-    $this->assertEnabledTextarea('edit-all-formats-no-default-value');
-    // If no default is given, the format with the lowest weight becomes the
-    // default.
-    $this->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html');
-    $this->assertEnabledTextarea('edit-all-formats-default-value');
-    // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses
-    // 'filter_test' as the default value in this case.
-    $this->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test');
-    $this->assertEnabledTextarea('edit-all-formats-default-missing-value');
-    // If a missing format is set as the default, administrators must select a
-    // valid replacement format.
-    $this->assertRequiredSelectAndOptions('edit-all-formats-default-missing-format--2', $formats);
-
-    // Test a text format element with a predefined list of formats.
-    $formats = ['full_html', 'filter_test'];
-    $this->assertEnabledTextarea('edit-restricted-formats-no-default-value');
-    $this->assertOptions('edit-restricted-formats-no-default-format--2', $formats, 'full_html');
-    $this->assertEnabledTextarea('edit-restricted-formats-default-value');
-    $this->assertOptions('edit-restricted-formats-default-format--2', $formats, 'full_html');
-    $this->assertEnabledTextarea('edit-restricted-formats-default-missing-value');
-    $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-missing-format--2', $formats);
-    $this->assertEnabledTextarea('edit-restricted-formats-default-disallowed-value');
-    $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-disallowed-format--2', $formats);
-
-    // Test a text format element with a fixed format.
-    $formats = ['filter_test'];
-    // When there is only a single option there is no point in choosing.
-    $this->assertEnabledTextarea('edit-single-format-no-default-value');
-    $this->assertNoSelect('edit-single-format-no-default-format--2');
-    $this->assertEnabledTextarea('edit-single-format-default-value');
-    $this->assertNoSelect('edit-single-format-default-format--2');
-    // If the select has a missing or disallowed format, administrators must
-    // explicitly choose the format.
-    $this->assertEnabledTextarea('edit-single-format-default-missing-value');
-    $this->assertRequiredSelectAndOptions('edit-single-format-default-missing-format--2', $formats);
-    $this->assertEnabledTextarea('edit-single-format-default-disallowed-value');
-    $this->assertRequiredSelectAndOptions('edit-single-format-default-disallowed-format--2', $formats);
-  }
-
-  /**
-   * Tests the behavior of the 'text_format' element as a normal user.
-   */
-  protected function doFilterFormTestAsNonAdmin() {
-    $this->drupalLogin($this->webUser);
-    $this->drupalGet('filter-test/text-format');
-
-    // Test a text format element with all formats. Only formats the user has
-    // access to are shown.
-    $formats = ['filtered_html', 'filter_test'];
-    $this->assertEnabledTextarea('edit-all-formats-no-default-value');
-    // If no default is given, the format with the lowest weight becomes the
-    // default. This happens to be 'filtered_html'.
-    $this->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html');
-    $this->assertEnabledTextarea('edit-all-formats-default-value');
-    // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses
-    // 'filter_test' as the default value in this case.
-    $this->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test');
-    // If a missing format is given as default, non-admin users are presented
-    // with a disabled textarea.
-    $this->assertDisabledTextarea('edit-all-formats-default-missing-value');
-
-    // Test a text format element with a predefined list of formats.
-    $this->assertEnabledTextarea('edit-restricted-formats-no-default-value');
-    // The user only has access to the 'filter_test' format, so when no default
-    // is given that is preselected and the text format select is hidden.
-    $this->assertNoSelect('edit-restricted-formats-no-default-format--2');
-    // When the format that the user does not have access to is preselected, the
-    // textarea should be disabled.
-    $this->assertDisabledTextarea('edit-restricted-formats-default-value');
-    $this->assertDisabledTextarea('edit-restricted-formats-default-missing-value');
-    $this->assertDisabledTextarea('edit-restricted-formats-default-disallowed-value');
-
-    // Test a text format element with a fixed format.
-    // When there is only a single option there is no point in choosing.
-    $this->assertEnabledTextarea('edit-single-format-no-default-value');
-    $this->assertNoSelect('edit-single-format-no-default-format--2');
-    $this->assertEnabledTextarea('edit-single-format-default-value');
-    $this->assertNoSelect('edit-single-format-default-format--2');
-    // If the select has a missing or disallowed format make sure the textarea
-    // is disabled.
-    $this->assertDisabledTextarea('edit-single-format-default-missing-value');
-    $this->assertDisabledTextarea('edit-single-format-default-disallowed-value');
-  }
-
-  /**
-   * Makes sure that no select element with the given ID exists on the page.
-   *
-   * @param string $id
-   *   The HTML ID of the select element.
-   *
-   * @return bool
-   *   TRUE if the assertion passed; FALSE otherwise.
-   */
-  protected function assertNoSelect($id) {
-    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
-    return $this->assertFalse($select, SafeMarkup::format('Field @id does not exist.', [
-      '@id' => $id,
-    ]));
-  }
-
-  /**
-   * Asserts that a select element has the correct options.
-   *
-   * @param string $id
-   *   The HTML ID of the select element.
-   * @param array $expected_options
-   *   An array of option values.
-   * @param string $selected
-   *   The value of the selected option.
-   *
-   * @return bool
-   *   TRUE if the assertion passed; FALSE otherwise.
-   */
-  protected function assertOptions($id, array $expected_options, $selected) {
-    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
-    $select = reset($select);
-    $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @id exists.', [
-      '@id' => $id,
-    ]));
-
-    $found_options = $this->getAllOptions($select);
-    foreach ($found_options as $found_key => $found_option) {
-      $expected_key = array_search($found_option->attributes()->value, $expected_options);
-      if ($expected_key !== FALSE) {
-        $this->pass(SafeMarkup::format('Option @option for field @id exists.', [
-          '@option' => $expected_options[$expected_key],
-          '@id' => $id,
-        ]));
-        unset($found_options[$found_key]);
-        unset($expected_options[$expected_key]);
-      }
-    }
-
-    // Make sure that all expected options were found and that there are no
-    // unexpected options.
-    foreach ($expected_options as $expected_option) {
-      $this->fail(SafeMarkup::format('Option @option for field @id exists.', [
-        '@option' => $expected_option,
-        '@id' => $id,
-      ]));
-      $passed = FALSE;
-    }
-    foreach ($found_options as $found_option) {
-      $this->fail(SafeMarkup::format('Option @option for field @id does not exist.', [
-        '@option' => $found_option->attributes()->value,
-        '@id' => $id,
-      ]));
-      $passed = FALSE;
-    }
-
-    return $passed && $this->assertOptionSelected($id, $selected);
-  }
-
-  /**
-   * Asserts that there is a select element with the given ID that is required.
-   *
-   * @param string $id
-   *   The HTML ID of the select element.
-   * @param array $options
-   *   An array of option values that are contained in the select element
-   *   besides the "- Select -" option.
-   *
-   * @return bool
-   *   TRUE if the assertion passed; FALSE otherwise.
-   */
-  protected function assertRequiredSelectAndOptions($id, array $options) {
-    $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [
-      ':id' => $id,
-    ]);
-    $select = reset($select);
-    $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Required field @id exists.', [
-      '@id' => $id,
-    ]));
-    // A required select element has a "- Select -" option whose key is an empty
-    // string.
-    $options[] = '';
-    return $passed && $this->assertOptions($id, $options, '');
-  }
-
-  /**
-   * Asserts that a textarea with a given ID exists and is not disabled.
-   *
-   * @param string $id
-   *   The HTML ID of the textarea.
-   *
-   * @return bool
-   *   TRUE if the assertion passed; FALSE otherwise.
-   */
-  protected function assertEnabledTextarea($id) {
-    $textarea = $this->xpath('//textarea[@id=:id and not(contains(@disabled, "disabled"))]', [
-      ':id' => $id,
-    ]);
-    $textarea = reset($textarea);
-    return $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Enabled field @id exists.', [
-      '@id' => $id,
-    ]));
-  }
-
-  /**
-   * Asserts that a textarea with a given ID has been disabled from editing.
-   *
-   * @param string $id
-   *   The HTML ID of the textarea.
-   *
-   * @return bool
-   *   TRUE if the assertion passed; FALSE otherwise.
-   */
-  protected function assertDisabledTextarea($id) {
-    $textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', [
-      ':id' => $id,
-    ]);
-    $textarea = reset($textarea);
-    $passed = $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Disabled field @id exists.', [
-      '@id' => $id,
-    ]));
-    $expected = 'This field has been disabled because you do not have sufficient permissions to edit it.';
-    $passed = $passed && $this->assertEqual((string) $textarea, $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [
-      '@id' => $id,
-    ]));
-    // Make sure the text format select is not shown.
-    $select_id = str_replace('value', 'format--2', $id);
-    return $passed && $this->assertNoSelect($select_id);
-  }
-
-}
diff --git a/core/modules/filter/src/Tests/FilterFormatAccessTest.php b/core/modules/filter/src/Tests/FilterFormatAccessTest.php
deleted file mode 100644
index a4c23b2..0000000
--- a/core/modules/filter/src/Tests/FilterFormatAccessTest.php
+++ /dev/null
@@ -1,335 +0,0 @@
-<?php
-
-namespace Drupal\filter\Tests;
-
-use Drupal\Component\Utility\Unicode;
-use Drupal\Core\Access\AccessResult;
-use Drupal\filter\Entity\FilterFormat;
-use Drupal\simpletest\WebTestBase;
-
-/**
- * Tests access to text formats.
- *
- * @group Access
- * @group filter
- */
-class FilterFormatAccessTest extends WebTestBase {
-
-  /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = ['block', 'filter', 'node'];
-
-  /**
-   * A user with administrative permissions.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $adminUser;
-
-  /**
-   * A user with 'administer filters' permission.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $filterAdminUser;
-
-  /**
-   * A user with permission to create and edit own content.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $webUser;
-
-  /**
-   * An object representing an allowed text format.
-   *
-   * @var object
-   */
-  protected $allowedFormat;
-
-  /**
-   * An object representing a secondary allowed text format.
-   *
-   * @var object
-   */
-  protected $secondAllowedFormat;
-
-  /**
-   * An object representing a disallowed text format.
-   *
-   * @var object
-   */
-  protected $disallowedFormat;
-
-  protected function setUp() {
-    parent::setUp();
-
-    $this->drupalPlaceBlock('page_title_block');
-
-    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
-
-    // Create a user who can administer text formats, but does not have
-    // specific permission to use any of them.
-    $this->filterAdminUser = $this->drupalCreateUser([
-      'administer filters',
-      'create page content',
-      'edit any page content',
-    ]);
-
-    // Create three text formats. Two text formats are created for all users so
-    // that the drop-down list appears for all tests.
-    $this->drupalLogin($this->filterAdminUser);
-    $formats = [];
-    for ($i = 0; $i < 3; $i++) {
-      $edit = [
-        'format' => Unicode::strtolower($this->randomMachineName()),
-        'name' => $this->randomMachineName(),
-      ];
-      $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
-      $this->resetFilterCaches();
-      $formats[] = FilterFormat::load($edit['format']);
-    }
-    list($this->allowedFormat, $this->secondAllowedFormat, $this->disallowedFormat) = $formats;
-    $this->drupalLogout();
-
-    // Create a regular user with access to two of the formats.
-    $this->webUser = $this->drupalCreateUser([
-      'create page content',
-      'edit any page content',
-      $this->allowedFormat->getPermissionName(),
-      $this->secondAllowedFormat->getPermissionName(),
-    ]);
-
-    // Create an administrative user who has access to use all three formats.
-    $this->adminUser = $this->drupalCreateUser([
-      'administer filters',
-      'create page content',
-      'edit any page content',
-      $this->allowedFormat->getPermissionName(),
-      $this->secondAllowedFormat->getPermissionName(),
-      $this->disallowedFormat->getPermissionName(),
-    ]);
-    $this->drupalPlaceBlock('local_tasks_block');
-  }
-
-  /**
-   * Tests the Filter format access permissions functionality.
-   */
-  public function testFormatPermissions() {
-    // Make sure that a regular user only has access to the text formats for
-    // which they were granted access.
-    $fallback_format = FilterFormat::load(filter_fallback_format());
-    $disallowed_format_name = $this->disallowedFormat->getPermissionName();
-    $this->assertTrue($this->allowedFormat->access('use', $this->webUser), 'A regular user has access to use a text format they were granted access to.');
-    $this->assertEqual(AccessResult::allowed()->addCacheContexts(['user.permissions']), $this->allowedFormat->access('use', $this->webUser, TRUE), 'A regular user has access to use a text format they were granted access to.');
-    $this->assertFalse($this->disallowedFormat->access('use', $this->webUser), 'A regular user does not have access to use a text format they were not granted access to.');
-    $this->assertEqual(AccessResult::neutral("The '$disallowed_format_name' permission is required.")->cachePerPermissions(), $this->disallowedFormat->access('use', $this->webUser, TRUE), 'A regular user does not have access to use a text format they were not granted access to.');
-    $this->assertTrue($fallback_format->access('use', $this->webUser), 'A regular user has access to use the fallback format.');
-    $this->assertEqual(AccessResult::allowed(), $fallback_format->access('use', $this->webUser, TRUE), 'A regular user has access to use the fallback format.');
-
-    // Perform similar checks as above, but now against the entire list of
-    // available formats for this user.
-    $this->assertTrue(in_array($this->allowedFormat->id(), array_keys(filter_formats($this->webUser))), 'The allowed format appears in the list of available formats for a regular user.');
-    $this->assertFalse(in_array($this->disallowedFormat->id(), array_keys(filter_formats($this->webUser))), 'The disallowed format does not appear in the list of available formats for a regular user.');
-    $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_formats($this->webUser))), 'The fallback format appears in the list of available formats for a regular user.');
-
-    // Make sure that a regular user only has permission to use the format
-    // they were granted access to.
-    $this->assertTrue($this->webUser->hasPermission($this->allowedFormat->getPermissionName()), 'A regular user has permission to use the allowed text format.');
-    $this->assertFalse($this->webUser->hasPermission($this->disallowedFormat->getPermissionName()), 'A regular user does not have permission to use the disallowed text format.');
-
-    // Make sure that the allowed format appears on the node form and that
-    // the disallowed format does not.
-    $this->drupalLogin($this->webUser);
-    $this->drupalGet('node/add/page');
-    $elements = $this->xpath('//select[@name=:name]/option', [
-      ':name' => 'body[0][format]',
-      ':option' => $this->allowedFormat->id(),
-    ]);
-    $options = [];
-    foreach ($elements as $element) {
-      $options[(string) $element['value']] = $element;
-    }
-    $this->assertTrue(isset($options[$this->allowedFormat->id()]), 'The allowed text format appears as an option when adding a new node.');
-    $this->assertFalse(isset($options[$this->disallowedFormat->id()]), 'The disallowed text format does not appear as an option when adding a new node.');
-    $this->assertFalse(isset($options[filter_fallback_format()]), 'The fallback format does not appear as an option when adding a new node.');
-
-    // Check regular user access to the filter tips pages.
-    $this->drupalGet('filter/tips/' . $this->allowedFormat->id());
-    $this->assertResponse(200);
-    $this->drupalGet('filter/tips/' . $this->disallowedFormat->id());
-    $this->assertResponse(403);
-    $this->drupalGet('filter/tips/' . filter_fallback_format());
-    $this->assertResponse(200);
-    $this->drupalGet('filter/tips/invalid-format');
-    $this->assertResponse(404);
-
-    // Check admin user access to the filter tips pages.
-    $this->drupalLogin($this->adminUser);
-    $this->drupalGet('filter/tips/' . $this->allowedFormat->id());
-    $this->assertResponse(200);
-    $this->drupalGet('filter/tips/' . $this->disallowedFormat->id());
-    $this->assertResponse(200);
-    $this->drupalGet('filter/tips/' . filter_fallback_format());
-    $this->assertResponse(200);
-    $this->drupalGet('filter/tips/invalid-format');
-    $this->assertResponse(404);
-  }
-
-  /**
-   * Tests if text format is available to a role.
-   */
-  public function testFormatRoles() {
-    // Get the role ID assigned to the regular user.
-    $roles = $this->webUser->getRoles(TRUE);
-    $rid = $roles[0];
-
-    // Check that this role appears in the list of roles that have access to an
-    // allowed text format, but does not appear in the list of roles that have
-    // access to a disallowed text format.
-    $this->assertTrue(in_array($rid, array_keys(filter_get_roles_by_format($this->allowedFormat))), 'A role which has access to a text format appears in the list of roles that have access to that format.');
-    $this->assertFalse(in_array($rid, array_keys(filter_get_roles_by_format($this->disallowedFormat))), 'A role which does not have access to a text format does not appear in the list of roles that have access to that format.');
-
-    // Check that the correct text format appears in the list of formats
-    // available to that role.
-    $this->assertTrue(in_array($this->allowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
-    $this->assertFalse(in_array($this->disallowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');
-
-    // Check that the fallback format is always allowed.
-    $this->assertEqual(filter_get_roles_by_format(FilterFormat::load(filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
-    $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), 'The fallback format appears in the list of allowed formats for any role.');
-  }
-
-  /**
-   * Tests editing a page using a disallowed text format.
-   *
-   * Verifies that regular users and administrators are able to edit a page, but
-   * not allowed to change the fields which use an inaccessible text format.
-   * Also verifies that fields which use a text format that does not exist can
-   * be edited by administrators only, but that the administrator is forced to
-   * choose a new format before saving the page.
-   */
-  public function testFormatWidgetPermissions() {
-    $body_value_key = 'body[0][value]';
-    $body_format_key = 'body[0][format]';
-
-    // Create node to edit.
-    $this->drupalLogin($this->adminUser);
-    $edit = [];
-    $edit['title[0][value]'] = $this->randomMachineName(8);
-    $edit[$body_value_key] = $this->randomMachineName(16);
-    $edit[$body_format_key] = $this->disallowedFormat->id();
-    $this->drupalPostForm('node/add/page', $edit, t('Save'));
-    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
-
-    // Try to edit with a less privileged user.
-    $this->drupalLogin($this->webUser);
-    $this->drupalGet('node/' . $node->id());
-    $this->clickLink(t('Edit'));
-
-    // Verify that body field is read-only and contains replacement value.
-    $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
-
-    // Verify that title can be changed, but preview displays original body.
-    $new_edit = [];
-    $new_edit['title[0][value]'] = $this->randomMachineName(8);
-    $this->drupalPostForm(NULL, $new_edit, t('Preview'));
-    $this->assertText($edit[$body_value_key], 'Old body found in preview.');
-
-    // Save and verify that only the title was changed.
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $new_edit, t('Save'));
-    $this->assertNoText($edit['title[0][value]'], 'Old title not found.');
-    $this->assertText($new_edit['title[0][value]'], 'New title found.');
-    $this->assertText($edit[$body_value_key], 'Old body found.');
-
-    // Check that even an administrator with "administer filters" permission
-    // cannot edit the body field if they do not have specific permission to
-    // use its stored format. (This must be disallowed so that the
-    // administrator is never forced to switch the text format to something
-    // else.)
-    $this->drupalLogin($this->filterAdminUser);
-    $this->drupalGet('node/' . $node->id() . '/edit');
-    $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
-
-    // Disable the text format used above.
-    $this->disallowedFormat->disable()->save();
-    $this->resetFilterCaches();
-
-    // Log back in as the less privileged user and verify that the body field
-    // is still disabled, since the less privileged user should not be able to
-    // edit content that does not have an assigned format.
-    $this->drupalLogin($this->webUser);
-    $this->drupalGet('node/' . $node->id() . '/edit');
-    $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
-
-    // Log back in as the filter administrator and verify that the body field
-    // can be edited.
-    $this->drupalLogin($this->filterAdminUser);
-    $this->drupalGet('node/' . $node->id() . '/edit');
-    $this->assertNoFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", NULL, 'Text format access denied message not found.');
-    $this->assertFieldByXPath("//select[@name='$body_format_key']", NULL, 'Text format selector found.');
-
-    // Verify that trying to save the node without selecting a new text format
-    // produces an error message, and does not result in the node being saved.
-    $old_title = $new_edit['title[0][value]'];
-    $new_title = $this->randomMachineName(8);
-    $edit = [];
-    $edit['title[0][value]'] = $new_title;
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
-    $this->assertText(t('@name field is required.', ['@name' => t('Text format')]), 'Error message is displayed.');
-    $this->drupalGet('node/' . $node->id());
-    $this->assertText($old_title, 'Old title found.');
-    $this->assertNoText($new_title, 'New title not found.');
-
-    // Now select a new text format and make sure the node can be saved.
-    $edit[$body_format_key] = filter_fallback_format();
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
-    $this->assertUrl('node/' . $node->id());
-    $this->assertText($new_title, 'New title found.');
-    $this->assertNoText($old_title, 'Old title not found.');
-
-    // Switch the text format to a new one, then disable that format and all
-    // other formats on the site (leaving only the fallback format).
-    $this->drupalLogin($this->adminUser);
-    $edit = [$body_format_key => $this->allowedFormat->id()];
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
-    $this->assertUrl('node/' . $node->id());
-    foreach (filter_formats() as $format) {
-      if (!$format->isFallbackFormat()) {
-        $format->disable()->save();
-      }
-    }
-
-    // Since there is now only one available text format, the widget for
-    // selecting a text format would normally not display when the content is
-    // edited. However, we need to verify that the filter administrator still
-    // is forced to make a conscious choice to reassign the text to a different
-    // format.
-    $this->drupalLogin($this->filterAdminUser);
-    $old_title = $new_title;
-    $new_title = $this->randomMachineName(8);
-    $edit = [];
-    $edit['title[0][value]'] = $new_title;
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
-    $this->assertText(t('@name field is required.', ['@name' => t('Text format')]), 'Error message is displayed.');
-    $this->drupalGet('node/' . $node->id());
-    $this->assertText($old_title, 'Old title found.');
-    $this->assertNoText($new_title, 'New title not found.');
-    $edit[$body_format_key] = filter_fallback_format();
-    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
-    $this->assertUrl('node/' . $node->id());
-    $this->assertText($new_title, 'New title found.');
-    $this->assertNoText($old_title, 'Old title not found.');
-  }
-
-  /**
-   * Rebuilds text format and permission caches in the thread running the tests.
-   */
-  protected function resetFilterCaches() {
-    filter_formats_reset();
-  }
-
-}
diff --git a/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php
deleted file mode 100644
index 249021a..0000000
--- a/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php
+++ /dev/null
@@ -1,158 +0,0 @@
-<?php
-
-namespace Drupal\filter\Tests;
-
-use Drupal\comment\Tests\CommentTestTrait;
-use Drupal\Core\StreamWrapper\PublicStream;
-use Drupal\simpletest\WebTestBase;
-use Drupal\filter\Entity\FilterFormat;
-
-/**
- * Tests restriction of IMG tags in HTML input.
- *
- * @group filter
- */
-class FilterHtmlImageSecureTest extends WebTestBase {
-
-  use CommentTestTrait;
-
-  /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = ['filter', 'node', 'comment'];
-
-  /**
-   * An authenticated user.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $webUser;
-
-  protected function setUp() {
-    parent::setUp();
-
-    // Setup Filtered HTML text format.
-    $filtered_html_format = FilterFormat::create([
-      'format' => 'filtered_html',
-      'name' => 'Filtered HTML',
-      'filters' => [
-        'filter_html' => [
-          'status' => 1,
-          'settings' => [
-            'allowed_html' => '<img src testattribute> <a>',
-          ],
-        ],
-        'filter_autop' => [
-          'status' => 1,
-        ],
-        'filter_html_image_secure' => [
-          'status' => 1,
-        ],
-      ],
-    ]);
-    $filtered_html_format->save();
-
-    // Setup users.
-    $this->webUser = $this->drupalCreateUser([
-      'access content',
-      'access comments',
-      'post comments',
-      'skip comment approval',
-      $filtered_html_format->getPermissionName(),
-    ]);
-    $this->drupalLogin($this->webUser);
-
-    // Setup a node to comment and test on.
-    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
-    // Add a comment field.
-    $this->addDefaultCommentField('node', 'page');
-    $this->node = $this->drupalCreateNode();
-  }
-
-  /**
-   * Tests removal of images having a non-local source.
-   */
-  public function testImageSource() {
-    global $base_url;
-
-    $public_files_path = PublicStream::basePath();
-
-    $http_base_url = preg_replace('/^https?/', 'http', $base_url);
-    $https_base_url = preg_replace('/^https?/', 'https', $base_url);
-    $files_path = base_path() . $public_files_path;
-    $csrf_path = $public_files_path . '/' . implode('/', array_fill(0, substr_count($public_files_path, '/') + 1, '..'));
-
-    $druplicon = 'core/misc/druplicon.png';
-    $red_x_image = base_path() . 'core/misc/icons/e32700/error.svg';
-    $alt_text = t('Image removed.');
-    $title_text = t('This image has been removed. For security reasons, only images from the local domain are allowed.');
-
-    // Put a test image in the files directory.
-    $test_images = $this->drupalGetTestFiles('image');
-    $test_image = $test_images[0]->filename;
-
-    // Put a test image in the files directory with special filename.
-    $special_filename = 'tést fïle nàme.png';
-    $special_image = rawurlencode($special_filename);
-    $special_uri = str_replace($test_images[0]->filename, $special_filename, $test_images[0]->uri);
-    file_unmanaged_copy($test_images[0]->uri, $special_uri);
-
-    // Create a list of test image sources.
-    // The keys become the value of the IMG 'src' attribute, the values are the
-    // expected filter conversions.
-    $host = \Drupal::request()->getHost();
-    $host_pattern = '|^http\://' . $host . '(\:[0-9]{0,5})|';
-    $images = [
-      $http_base_url . '/' . $druplicon => base_path() . $druplicon,
-      $https_base_url . '/' . $druplicon => base_path() . $druplicon,
-      // Test a url that includes a port.
-      preg_replace($host_pattern, 'http://' . $host . ':', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
-      preg_replace($host_pattern, 'http://' . $host . ':80', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
-      preg_replace($host_pattern, 'http://' . $host . ':443', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
-      preg_replace($host_pattern, 'http://' . $host . ':8080', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
-      base_path() . $druplicon => base_path() . $druplicon,
-      $files_path . '/' . $test_image => $files_path . '/' . $test_image,
-      $http_base_url . '/' . $public_files_path . '/' . $test_image => $files_path . '/' . $test_image,
-      $https_base_url . '/' . $public_files_path . '/' . $test_image => $files_path . '/' . $test_image,
-      $http_base_url . '/' . $public_files_path . '/' . $special_image => $files_path . '/' . $special_image,
-      $https_base_url . '/' . $public_files_path . '/' . $special_image => $files_path . '/' . $special_image,
-      $files_path . '/example.png' => $red_x_image,
-      'http://example.com/' . $druplicon => $red_x_image,
-      'https://example.com/' . $druplicon => $red_x_image,
-      'javascript:druplicon.png' => $red_x_image,
-      $csrf_path . '/logout' => $red_x_image,
-    ];
-    $comment = [];
-    foreach ($images as $image => $converted) {
-      // Output the image source as plain text for debugging.
-      $comment[] = $image . ':';
-      // Hash the image source in a custom test attribute, because it might
-      // contain characters that confuse XPath.
-      $comment[] = '<img src="' . $image . '" testattribute="' . hash('sha256', $image) . '" />';
-    }
-    $edit = [
-      'comment_body[0][value]' => implode("\n", $comment),
-    ];
-    $this->drupalPostForm('node/' . $this->node->id(), $edit, t('Save'));
-    foreach ($images as $image => $converted) {
-      $found = FALSE;
-      foreach ($this->xpath('//img[@testattribute="' . hash('sha256', $image) . '"]') as $element) {
-        $found = TRUE;
-        if ($converted == $red_x_image) {
-          $this->assertEqual((string) $element['src'], $red_x_image);
-          $this->assertEqual((string) $element['alt'], $alt_text);
-          $this->assertEqual((string) $element['title'], $title_text);
-          $this->assertEqual((string) $element['height'], '16');
-          $this->assertEqual((string) $element['width'], '16');
-        }
-        else {
-          $this->assertEqual((string) $element['src'], $converted);
-        }
-      }
-      $this->assertTrue($found, format_string('@image was found.', ['@image' => $image]));
-    }
-  }
-
-}
diff --git a/core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterSparkles.php b/core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterSparkles.php
index be2055b..f363fa9 100644
--- a/core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterSparkles.php
+++ b/core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterSparkles.php
@@ -11,7 +11,7 @@
  * This filter does not do anything, but enabling of its module is done in a
  * test.
  *
- * @see \Drupal\filter\Tests\FilterFormTest::testFilterForm()
+ * @see \Drupal\Tests\filter\Functional\FilterFormTest::testFilterForm()
  *
  * @Filter(
  *   id = "filter_sparkles",
diff --git a/core/modules/filter/tests/src/Functional/FilterAdminTest.php b/core/modules/filter/tests/src/Functional/FilterAdminTest.php
new file mode 100644
index 0000000..83746e1
--- /dev/null
+++ b/core/modules/filter/tests/src/Functional/FilterAdminTest.php
@@ -0,0 +1,458 @@
+<?php
+
+namespace Drupal\Tests\filter\Functional;
+
+use Drupal\Component\Utility\Html;
+use Drupal\Component\Utility\Unicode;
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\node\Entity\Node;
+use Drupal\node\Entity\NodeType;
+use Drupal\Tests\BrowserTestBase;
+use Drupal\user\RoleInterface;
+
+/**
+ * Thoroughly test the administrative interface of the filter module.
+ *
+ * @group filter
+ */
+class FilterAdminTest extends BrowserTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['block', 'filter', 'node', 'filter_test_plugin', 'dblog'];
+
+  /**
+   * An user with administration permissions.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $adminUser;
+
+  /**
+   * An user with permissions to create pages.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $webUser;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
+
+    // Set up the filter formats used by this test.
+    $basic_html_format = FilterFormat::create([
+      'format' => 'basic_html',
+      'name' => 'Basic HTML',
+      'filters' => [
+        'filter_html' => [
+          'status' => 1,
+          'settings' => [
+            'allowed_html' => '<p> <br> <strong> <a> <em>',
+          ],
+        ],
+      ],
+    ]);
+    $basic_html_format->save();
+    $restricted_html_format = FilterFormat::create([
+      'format' => 'restricted_html',
+      'name' => 'Restricted HTML',
+      'filters' => [
+        'filter_html' => [
+          'status' => TRUE,
+          'weight' => -10,
+          'settings' => [
+            'allowed_html' => '<p> <br> <strong> <a> <em> <h4>',
+          ],
+        ],
+        'filter_autop' => [
+          'status' => TRUE,
+          'weight' => 0,
+        ],
+        'filter_url' => [
+          'status' => TRUE,
+          'weight' => 0,
+        ],
+        'filter_htmlcorrector' => [
+          'status' => TRUE,
+          'weight' => 10,
+        ],
+      ],
+    ]);
+    $restricted_html_format->save();
+    $full_html_format = FilterFormat::create([
+      'format' => 'full_html',
+      'name' => 'Full HTML',
+      'weight' => 1,
+      'filters' => [],
+    ]);
+    $full_html_format->save();
+
+    $this->adminUser = $this->drupalCreateUser([
+      'administer filters',
+      $basic_html_format->getPermissionName(),
+      $restricted_html_format->getPermissionName(),
+      $full_html_format->getPermissionName(),
+      'access site reports',
+    ]);
+
+    $this->webUser = $this->drupalCreateUser(['create page content', 'edit own page content']);
+    user_role_grant_permissions('authenticated', [$basic_html_format->getPermissionName()]);
+    user_role_grant_permissions('anonymous', [$restricted_html_format->getPermissionName()]);
+    $this->drupalLogin($this->adminUser);
+    $this->drupalPlaceBlock('local_actions_block');
+  }
+
+  /**
+   * Tests the format administration functionality.
+   */
+  public function testFormatAdmin() {
+    // Add text format.
+    $this->drupalGet('admin/config/content/formats');
+    $this->clickLink('Add text format');
+    $format_id = Unicode::strtolower($this->randomMachineName());
+    $name = $this->randomMachineName();
+    $edit = [
+      'format' => $format_id,
+      'name' => $name,
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+
+    // Verify default weight of the text format.
+    $this->drupalGet('admin/config/content/formats');
+    $this->assertFieldByName("formats[$format_id][weight]", 0, 'Text format weight was saved.');
+
+    // Change the weight of the text format.
+    $edit = [
+      "formats[$format_id][weight]" => 5,
+    ];
+    $this->drupalPostForm('admin/config/content/formats', $edit, t('Save'));
+    $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was saved.');
+
+    // Edit text format.
+    $this->drupalGet('admin/config/content/formats');
+    // Cannot use the assertNoLinkByHref method as it does partial url matching
+    // and 'admin/config/content/formats/manage/' . $format_id . '/disable'
+    // exists.
+    // @todo: See https://www.drupal.org/node/2031223 for the above.
+    $edit_link = $this->xpath('//a[@href=:href]', [
+      ':href' => \Drupal::url('entity.filter_format.edit_form', ['filter_format' => $format_id])
+    ]);
+    $this->assertTrue(!empty($edit_link), format_string('Link href %href found.',
+      ['%href' => 'admin/config/content/formats/manage/' . $format_id]
+    ));
+    $this->drupalGet('admin/config/content/formats/manage/' . $format_id);
+    $this->drupalPostForm(NULL, [], t('Save configuration'));
+
+    // Verify that the custom weight of the text format has been retained.
+    $this->drupalGet('admin/config/content/formats');
+    $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was retained.');
+
+    // Disable text format.
+    $this->assertLinkByHref('admin/config/content/formats/manage/' . $format_id . '/disable');
+    $this->drupalGet('admin/config/content/formats/manage/' . $format_id . '/disable');
+    $this->drupalPostForm(NULL, [], t('Disable'));
+
+    // Verify that disabled text format no longer exists.
+    $this->drupalGet('admin/config/content/formats/manage/' . $format_id);
+    $this->assertResponse(404, 'Disabled text format no longer exists.');
+
+    // Attempt to create a format of the same machine name as the disabled
+    // format but with a different human readable name.
+    $edit = [
+      'format' => $format_id,
+      'name' => 'New format',
+    ];
+    $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
+    $this->assertText('The machine-readable name is already in use. It must be unique.');
+
+    // Attempt to create a format of the same human readable name as the
+    // disabled format but with a different machine name.
+    $edit = [
+      'format' => 'new_format',
+      'name' => $name,
+    ];
+    $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
+    $this->assertRaw(t('Text format names must be unique. A format named %name already exists.', [
+      '%name' => $name,
+    ]));
+  }
+
+  /**
+   * Tests filter administration functionality.
+   */
+  public function testFilterAdmin() {
+    $first_filter = 'filter_autop';
+    $second_filter = 'filter_url';
+
+    $basic = 'basic_html';
+    $restricted = 'restricted_html';
+    $full = 'full_html';
+    $plain = 'plain_text';
+
+    // Check that the fallback format exists and cannot be disabled.
+    $this->assertTrue($plain == filter_fallback_format(), 'The fallback format is set to plain text.');
+    $this->drupalGet('admin/config/content/formats');
+    $this->assertNoRaw('admin/config/content/formats/manage/' . $plain . '/disable', 'Disable link for the fallback format not found.');
+    $this->drupalGet('admin/config/content/formats/manage/' . $plain . '/disable');
+    $this->assertResponse(403, 'The fallback format cannot be disabled.');
+
+    // Verify access permissions to Full HTML format.
+    $full_format = FilterFormat::load($full);
+    $this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.');
+    $this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.');
+
+    // Add an additional tag and extra spaces and returns.
+    $edit = [];
+    $edit['filters[filter_html][settings][allowed_html]'] = "<a>   <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>\r\n<quote>";
+    $this->drupalPostForm('admin/config/content/formats/manage/' . $restricted, $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->drupalGet('admin/config/content/formats/manage/' . $restricted);
+    $this->assertFieldByName('filters[filter_html][settings][allowed_html]', "<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>", 'Allowed HTML tag added.');
+
+    $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', [
+      ':first' => 'filters[' . $first_filter . '][weight]',
+      ':second' => 'filters[' . $second_filter . '][weight]',
+    ]);
+    $this->assertTrue(!empty($elements), 'Order confirmed in admin interface.');
+
+    // Reorder filters.
+    $edit = [];
+    $edit['filters[' . $second_filter . '][weight]'] = 1;
+    $edit['filters[' . $first_filter . '][weight]'] = 2;
+    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->drupalGet('admin/config/content/formats/manage/' . $restricted);
+    $this->assertFieldByName('filters[' . $second_filter . '][weight]', 1, 'Order saved successfully.');
+    $this->assertFieldByName('filters[' . $first_filter . '][weight]', 2, 'Order saved successfully.');
+
+    $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', [
+      ':first' => 'filters[' . $second_filter . '][weight]',
+      ':second' => 'filters[' . $first_filter . '][weight]',
+    ]);
+    $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');
+
+    $filter_format = FilterFormat::load($restricted);
+    foreach ($filter_format->filters() as $filter_name => $filter) {
+      if ($filter_name == $second_filter || $filter_name == $first_filter) {
+        $filters[] = $filter_name;
+      }
+    }
+    // Ensure that the second filter is now before the first filter.
+    $this->assertEqual($filter_format->filters($second_filter)->weight + 1, $filter_format->filters($first_filter)->weight, 'Order confirmed in configuration.');
+
+    // Add format.
+    $edit = [];
+    $edit['format'] = Unicode::strtolower($this->randomMachineName());
+    $edit['name'] = $this->randomMachineName();
+    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
+    $edit['filters[' . $second_filter . '][status]'] = TRUE;
+    $edit['filters[' . $first_filter . '][status]'] = TRUE;
+    $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->assertRaw(t('Added text format %format.', ['%format' => $edit['name']]), 'New filter created.');
+
+    filter_formats_reset();
+    $format = FilterFormat::load($edit['format']);
+    $this->assertNotNull($format, 'Format found in database.');
+    $this->drupalGet('admin/config/content/formats/manage/' . $format->id());
+    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', RoleInterface::AUTHENTICATED_ID);
+    $this->assertFieldByName('filters[' . $second_filter . '][status]', TRUE);
+    $this->assertFieldByName('filters[' . $first_filter . '][status]', TRUE);
+
+    // Disable new filter.
+    $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->assertRaw(t('Disabled text format %format.', ['%format' => $edit['name']]), 'Format successfully disabled.');
+
+    // Allow authenticated users on full HTML.
+    $format = FilterFormat::load($full);
+    $edit = [];
+    $edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0;
+    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
+    $this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->assertRaw(t('The text format %format has been updated.', ['%format' => $format->label()]), 'Full HTML format successfully updated.');
+
+    // Switch user.
+    $this->drupalLogin($this->webUser);
+
+    $this->drupalGet('node/add/page');
+    $this->assertRaw('<option value="' . $full . '">Full HTML</option>', 'Full HTML filter accessible.');
+
+    // Use basic HTML and see if it removes tags that are not allowed.
+    $body = '<em>' . $this->randomMachineName() . '</em>';
+    $extra_text = 'text';
+    $text = $body . '<random>' . $extra_text . '</random>';
+
+    $edit = [];
+    $edit['title[0][value]'] = $this->randomMachineName();
+    $edit['body[0][value]'] = $text;
+    $edit['body[0][format]'] = $basic;
+    $this->drupalPostForm('node/add/page', $edit, t('Save'));
+    $this->assertText(t('Basic page @title has been created.', ['@title' => $edit['title[0][value]']]), 'Filtered node created.');
+
+    // Verify that the creation message contains a link to a node.
+    $view_link = $this->xpath('//div[contains(@class, "messages")]//a[contains(@href, :href)]', [':href' => 'node/']);
+    $this->assertTrue(!empty($view_link), 'The message area contains a link to a node');
+
+    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
+    $this->assertTrue($node, 'Node found in database.');
+
+    $this->drupalGet('node/' . $node->id());
+    $this->assertRaw($body . $extra_text, 'Filter removed invalid tag.');
+
+    // Use plain text and see if it escapes all tags, whether allowed or not.
+    // In order to test plain text, we have to enable the hidden variable for
+    // "show_fallback_format", which displays plain text in the format list.
+    $this->config('filter.settings')
+      ->set('always_show_fallback_choice', TRUE)
+      ->save();
+    $edit = [];
+    $edit['body[0][format]'] = $plain;
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
+    $this->drupalGet('node/' . $node->id());
+    $this->assertEscaped($text, 'The "Plain text" text format escapes all HTML tags.');
+    $this->config('filter.settings')
+      ->set('always_show_fallback_choice', FALSE)
+      ->save();
+
+    // Switch user.
+    $this->drupalLogin($this->adminUser);
+
+    // Clean up.
+    // Allowed tags.
+    $edit = [];
+    $edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>';
+    $this->drupalPostForm('admin/config/content/formats/manage/' . $basic, $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->drupalGet('admin/config/content/formats/manage/' . $basic);
+    $this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Changes reverted.');
+
+    // Full HTML.
+    $edit = [];
+    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = FALSE;
+    $this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->assertRaw(t('The text format %format has been updated.', ['%format' => $format->label()]), 'Full HTML format successfully reverted.');
+    $this->drupalGet('admin/config/content/formats/manage/' . $full);
+    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'], 'Changes reverted.');
+
+    // Filter order.
+    $edit = [];
+    $edit['filters[' . $second_filter . '][weight]'] = 2;
+    $edit['filters[' . $first_filter . '][weight]'] = 1;
+    $this->drupalPostForm('admin/config/content/formats/manage/' . $basic, $edit, t('Save configuration'));
+    $this->assertUrl('admin/config/content/formats');
+    $this->drupalGet('admin/config/content/formats/manage/' . $basic);
+    $this->assertFieldByName('filters[' . $second_filter . '][weight]', $edit['filters[' . $second_filter . '][weight]'], 'Changes reverted.');
+    $this->assertFieldByName('filters[' . $first_filter . '][weight]', $edit['filters[' . $first_filter . '][weight]'], 'Changes reverted.');
+  }
+
+  /**
+   * Tests the URL filter settings form is properly validated.
+   */
+  public function testUrlFilterAdmin() {
+    // The form does not save with an invalid filter URL length.
+    $edit = [
+      'filters[filter_url][settings][filter_url_length]' => $this->randomMachineName(4),
+    ];
+    $this->drupalPostForm('admin/config/content/formats/manage/basic_html', $edit, t('Save configuration'));
+    $this->assertNoRaw(t('The text format %format has been updated.', ['%format' => 'Basic HTML']));
+  }
+
+  /**
+   * Tests whether filter tips page is not HTML escaped.
+   */
+  public function testFilterTipHtmlEscape() {
+    $this->drupalLogin($this->adminUser);
+    global $base_url;
+
+    $site_name_with_markup = 'Filter test <script>alert(\'here\');</script> site name';
+    $this->config('system.site')->set('name', $site_name_with_markup)->save();
+
+    // It is not possible to test the whole filter tip page.
+    // Therefore we test only some parts.
+    $link = '<a href="' . $base_url . '">' . Html::escape($site_name_with_markup) . '</a>';
+    $ampersand = '&amp;';
+    $link_as_code = '<code>' . Html::escape($link) . '</code>';
+    $ampersand_as_code = '<code>' . Html::escape($ampersand) . '</code>';
+
+    $this->drupalGet('filter/tips');
+
+    $this->assertRaw('<td class="type">' . $link_as_code . '</td>');
+    $this->assertRaw('<td class="get">' . $link . '</td>');
+    $this->assertRaw('<td class="type">' . $ampersand_as_code . '</td>');
+    $this->assertRaw('<td class="get">' . $ampersand . '</td>');
+  }
+
+  /**
+   * Tests whether a field using a disabled format is rendered.
+   */
+  public function testDisabledFormat() {
+    // Create a node type and add a standard body field.
+    $node_type = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName())]);
+    $node_type->save();
+    node_add_body_field($node_type, $this->randomString());
+
+    // Create a text format with a filter that returns a static string.
+    $format = FilterFormat::create([
+      'name' => $this->randomString(),
+      'format' => $format_id = Unicode::strtolower($this->randomMachineName()),
+    ]);
+    $format->setFilterConfig('filter_static_text', ['status' => TRUE]);
+    $format->save();
+
+    // Create a new node of the new node type.
+    $node = Node::create([
+      'type' => $node_type->id(),
+      'title' => $this->randomString(),
+    ]);
+    $body_value = $this->randomString();
+    $node->body->value = $body_value;
+    $node->body->format = $format_id;
+    $node->save();
+
+    // The format is used and we should see the static text instead of the body
+    // value.
+    $this->drupalGet($node->urlInfo());
+    $this->assertText('filtered text');
+
+    // Disable the format.
+    $format->disable()->save();
+
+    $this->drupalGet($node->urlInfo());
+
+    // The format is not used anymore.
+    $this->assertNoText('filtered text');
+    // The text is not displayed unfiltered or escaped.
+    $this->assertNoRaw($body_value);
+    $this->assertNoEscaped($body_value);
+
+    // Visit the dblog report page.
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('admin/reports/dblog');
+    // The correct message has been logged.
+    $this->assertRaw(sprintf('Disabled text format: %s.', $format_id));
+
+    // Programmatically change the text format to something random so we trigger
+    // the missing text format message.
+    $format_id = $this->randomMachineName();
+    $node->body->format = $format_id;
+    $node->save();
+    $this->drupalGet($node->urlInfo());
+    // The text is not displayed unfiltered or escaped.
+    $this->assertNoRaw($body_value);
+    $this->assertNoEscaped($body_value);
+
+    // Visit the dblog report page.
+    $this->drupalGet('admin/reports/dblog');
+    // The missing text format message has been logged.
+    $this->assertRaw(sprintf('Missing text format: %s.', $format_id));
+  }
+
+}
diff --git a/core/modules/filter/tests/src/Functional/FilterFormTest.php b/core/modules/filter/tests/src/Functional/FilterFormTest.php
new file mode 100644
index 0000000..c2b97c4
--- /dev/null
+++ b/core/modules/filter/tests/src/Functional/FilterFormTest.php
@@ -0,0 +1,303 @@
+<?php
+
+namespace Drupal\Tests\filter\Functional;
+
+use Drupal\Component\Utility\SafeMarkup;
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Tests form elements with associated text formats.
+ *
+ * @group filter
+ */
+class FilterFormTest extends BrowserTestBase {
+
+  /**
+   * Modules to enable for this test.
+   *
+   * @var array
+   */
+  protected static $modules = ['filter', 'filter_test'];
+
+  /**
+   * An administrative user account that can administer text formats.
+   *
+   * @var \Drupal\user\Entity\User
+   */
+  protected $adminUser;
+
+  /**
+   * An basic user account that can only access basic HTML text format.
+   *
+   * @var \Drupal\user\Entity\User
+   */
+  protected $webUser;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    /** @var \Drupal\filter\FilterFormatInterface $filter_test_format */
+    $filter_test_format = FilterFormat::load('filter_test');
+    /** @var \Drupal\filter\FilterFormatInterface $filtered_html_format */
+    $filtered_html_format = FilterFormat::load('filtered_html');
+    /** @var \Drupal\filter\FilterFormatInterface $full_html_format */
+    $full_html_format = FilterFormat::load('full_html');
+
+    // Create users.
+    $this->adminUser = $this->drupalCreateUser([
+      'administer filters',
+      $filtered_html_format->getPermissionName(),
+      $full_html_format->getPermissionName(),
+      $filter_test_format->getPermissionName(),
+    ]);
+
+    $this->webUser = $this->drupalCreateUser([
+      $filtered_html_format->getPermissionName(),
+      $filter_test_format->getPermissionName(),
+    ]);
+  }
+
+  /**
+   * Tests various different configurations of the 'text_format' element.
+   */
+  public function testFilterForm() {
+    $this->doFilterFormTestAsAdmin();
+    $this->doFilterFormTestAsNonAdmin();
+    // Ensure that enabling modules which provide filter plugins behaves
+    // correctly.
+    // @see https://www.drupal.org/node/2387983
+    \Drupal::service('module_installer')->install(['filter_test_plugin']);
+    // Force rebuild module data.
+    _system_rebuild_module_data();
+  }
+
+  /**
+   * Tests the behavior of the 'text_format' element as an administrator.
+   */
+  protected function doFilterFormTestAsAdmin() {
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('filter-test/text-format');
+
+    // Test a text format element with all formats.
+    $formats = ['filtered_html', 'full_html', 'filter_test'];
+    $this->assertEnabledTextarea('edit-all-formats-no-default-value');
+    // If no default is given, the format with the lowest weight becomes the
+    // default.
+    $this->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html');
+    $this->assertEnabledTextarea('edit-all-formats-default-value');
+    // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses
+    // 'filter_test' as the default value in this case.
+    $this->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test');
+    $this->assertEnabledTextarea('edit-all-formats-default-missing-value');
+    // If a missing format is set as the default, administrators must select a
+    // valid replacement format.
+    $this->assertRequiredSelectAndOptions('edit-all-formats-default-missing-format--2', $formats);
+
+    // Test a text format element with a predefined list of formats.
+    $formats = ['full_html', 'filter_test'];
+    $this->assertEnabledTextarea('edit-restricted-formats-no-default-value');
+    $this->assertOptions('edit-restricted-formats-no-default-format--2', $formats, 'full_html');
+    $this->assertEnabledTextarea('edit-restricted-formats-default-value');
+    $this->assertOptions('edit-restricted-formats-default-format--2', $formats, 'full_html');
+    $this->assertEnabledTextarea('edit-restricted-formats-default-missing-value');
+    $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-missing-format--2', $formats);
+    $this->assertEnabledTextarea('edit-restricted-formats-default-disallowed-value');
+    $this->assertRequiredSelectAndOptions('edit-restricted-formats-default-disallowed-format--2', $formats);
+
+    // Test a text format element with a fixed format.
+    $formats = ['filter_test'];
+    // When there is only a single option there is no point in choosing.
+    $this->assertEnabledTextarea('edit-single-format-no-default-value');
+    $this->assertNoSelect('edit-single-format-no-default-format--2');
+    $this->assertEnabledTextarea('edit-single-format-default-value');
+    $this->assertNoSelect('edit-single-format-default-format--2');
+    // If the select has a missing or disallowed format, administrators must
+    // explicitly choose the format.
+    $this->assertEnabledTextarea('edit-single-format-default-missing-value');
+    $this->assertRequiredSelectAndOptions('edit-single-format-default-missing-format--2', $formats);
+    $this->assertEnabledTextarea('edit-single-format-default-disallowed-value');
+    $this->assertRequiredSelectAndOptions('edit-single-format-default-disallowed-format--2', $formats);
+  }
+
+  /**
+   * Tests the behavior of the 'text_format' element as a normal user.
+   */
+  protected function doFilterFormTestAsNonAdmin() {
+    $this->drupalLogin($this->webUser);
+    $this->drupalGet('filter-test/text-format');
+
+    // Test a text format element with all formats. Only formats the user has
+    // access to are shown.
+    $formats = ['filtered_html', 'filter_test'];
+    $this->assertEnabledTextarea('edit-all-formats-no-default-value');
+    // If no default is given, the format with the lowest weight becomes the
+    // default. This happens to be 'filtered_html'.
+    $this->assertOptions('edit-all-formats-no-default-format--2', $formats, 'filtered_html');
+    $this->assertEnabledTextarea('edit-all-formats-default-value');
+    // \Drupal\filter_test\Form\FilterTestFormatForm::buildForm() uses
+    // 'filter_test' as the default value in this case.
+    $this->assertOptions('edit-all-formats-default-format--2', $formats, 'filter_test');
+    // If a missing format is given as default, non-admin users are presented
+    // with a disabled textarea.
+    $this->assertDisabledTextarea('edit-all-formats-default-missing-value');
+
+    // Test a text format element with a predefined list of formats.
+    $this->assertEnabledTextarea('edit-restricted-formats-no-default-value');
+    // The user only has access to the 'filter_test' format, so when no default
+    // is given that is preselected and the text format select is hidden.
+    $this->assertNoSelect('edit-restricted-formats-no-default-format--2');
+    // When the format that the user does not have access to is preselected, the
+    // textarea should be disabled.
+    $this->assertDisabledTextarea('edit-restricted-formats-default-value');
+    $this->assertDisabledTextarea('edit-restricted-formats-default-missing-value');
+    $this->assertDisabledTextarea('edit-restricted-formats-default-disallowed-value');
+
+    // Test a text format element with a fixed format.
+    // When there is only a single option there is no point in choosing.
+    $this->assertEnabledTextarea('edit-single-format-no-default-value');
+    $this->assertNoSelect('edit-single-format-no-default-format--2');
+    $this->assertEnabledTextarea('edit-single-format-default-value');
+    $this->assertNoSelect('edit-single-format-default-format--2');
+    // If the select has a missing or disallowed format make sure the textarea
+    // is disabled.
+    $this->assertDisabledTextarea('edit-single-format-default-missing-value');
+    $this->assertDisabledTextarea('edit-single-format-default-disallowed-value');
+  }
+
+  /**
+   * Makes sure that no select element with the given ID exists on the page.
+   *
+   * @param string $id
+   *   The HTML ID of the select element.
+   */
+  protected function assertNoSelect($id) {
+    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
+    $this->assertTrue(empty($select), SafeMarkup::format('Field @id does not exist.', [
+      '@id' => $id,
+    ]));
+  }
+
+  /**
+   * Asserts that a select element has the correct options.
+   *
+   * @param string $id
+   *   The HTML ID of the select element.
+   * @param array $expected_options
+   *   An array of option values.
+   * @param string $selected
+   *   The value of the selected option.
+   *
+   * @return bool
+   *   TRUE if the assertion passed; FALSE otherwise.
+   */
+  protected function assertOptions($id, array $expected_options, $selected) {
+    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
+    $this->assertTrue(!empty($select), SafeMarkup::format('Field @id exists.', [
+      '@id' => $id,
+    ]));
+    $select = reset($select);
+    $found_options = $select->findAll('css', 'option');
+    foreach ($found_options as $found_key => $found_option) {
+      $expected_key = array_search($found_option->getValue(), $expected_options);
+      if ($expected_key !== FALSE) {
+        $this->pass(SafeMarkup::format('Option @option for field @id exists.', [
+          '@option' => $expected_options[$expected_key],
+          '@id' => $id,
+        ]));
+        unset($found_options[$found_key]);
+        unset($expected_options[$expected_key]);
+      }
+    }
+
+    // Make sure that all expected options were found and that there are no
+    // unexpected options.
+    foreach ($expected_options as $expected_option) {
+      $this->fail(SafeMarkup::format('Option @option for field @id exists.', [
+        '@option' => $expected_option,
+        '@id' => $id,
+      ]));
+    }
+    foreach ($found_options as $found_option) {
+      $this->fail(SafeMarkup::format('Option @option for field @id does not exist.', [
+        '@option' => $found_option->getValue(),
+        '@id' => $id,
+      ]));
+    }
+
+    $this->assertOptionSelected($id, $selected);
+  }
+
+  /**
+   * Asserts that there is a select element with the given ID that is required.
+   *
+   * @param string $id
+   *   The HTML ID of the select element.
+   * @param array $options
+   *   An array of option values that are contained in the select element
+   *   besides the "- Select -" option.
+   *
+   * @return bool
+   *   TRUE if the assertion passed; FALSE otherwise.
+   */
+  protected function assertRequiredSelectAndOptions($id, array $options) {
+    $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [
+      ':id' => $id,
+    ]);
+    $this->assertTrue(!empty($select), SafeMarkup::format('Required field @id exists.', [
+      '@id' => $id,
+    ]));
+    // A required select element has a "- Select -" option whose key is an empty
+    // string.
+    $options[] = '';
+    $this->assertOptions($id, $options, '');
+  }
+
+  /**
+   * Asserts that a textarea with a given ID exists and is not disabled.
+   *
+   * @param string $id
+   *   The HTML ID of the textarea.
+   *
+   * @return bool
+   *   TRUE if the assertion passed; FALSE otherwise.
+   */
+  protected function assertEnabledTextarea($id) {
+    $textarea = $this->xpath('//textarea[@id=:id and not(contains(@disabled, "disabled"))]', [
+      ':id' => $id,
+    ]);
+    $this->assertTrue(!empty($textarea), SafeMarkup::format('Enabled field @id exists.', [
+      '@id' => $id,
+    ]));
+  }
+
+  /**
+   * Asserts that a textarea with a given ID has been disabled from editing.
+   *
+   * @param string $id
+   *   The HTML ID of the textarea.
+   *
+   * @return bool
+   *   TRUE if the assertion passed; FALSE otherwise.
+   */
+  protected function assertDisabledTextarea($id) {
+    $textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', [
+      ':id' => $id,
+    ]);
+    $this->assertTrue(!empty($textarea), SafeMarkup::format('Disabled field @id exists.', [
+      '@id' => $id,
+    ]));
+    $textarea = reset($textarea);
+    $expected = 'This field has been disabled because you do not have sufficient permissions to edit it.';
+    $this->assertEqual($textarea->getText(), $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [
+      '@id' => $id,
+    ]));
+    // Make sure the text format select is not shown.
+    $select_id = str_replace('value', 'format--2', $id);
+    $this->assertNoSelect($select_id);
+  }
+
+}
diff --git a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
new file mode 100644
index 0000000..c5a0cd8
--- /dev/null
+++ b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
@@ -0,0 +1,335 @@
+<?php
+
+namespace Drupal\Tests\filter\Functional;
+
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Access\AccessResult;
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Tests access to text formats.
+ *
+ * @group Access
+ * @group filter
+ */
+class FilterFormatAccessTest extends BrowserTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['block', 'filter', 'node'];
+
+  /**
+   * A user with administrative permissions.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $adminUser;
+
+  /**
+   * A user with 'administer filters' permission.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $filterAdminUser;
+
+  /**
+   * A user with permission to create and edit own content.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $webUser;
+
+  /**
+   * An object representing an allowed text format.
+   *
+   * @var object
+   */
+  protected $allowedFormat;
+
+  /**
+   * An object representing a secondary allowed text format.
+   *
+   * @var object
+   */
+  protected $secondAllowedFormat;
+
+  /**
+   * An object representing a disallowed text format.
+   *
+   * @var object
+   */
+  protected $disallowedFormat;
+
+  protected function setUp() {
+    parent::setUp();
+
+    $this->drupalPlaceBlock('page_title_block');
+
+    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
+
+    // Create a user who can administer text formats, but does not have
+    // specific permission to use any of them.
+    $this->filterAdminUser = $this->drupalCreateUser([
+      'administer filters',
+      'create page content',
+      'edit any page content',
+    ]);
+
+    // Create three text formats. Two text formats are created for all users so
+    // that the drop-down list appears for all tests.
+    $this->drupalLogin($this->filterAdminUser);
+    $formats = [];
+    for ($i = 0; $i < 3; $i++) {
+      $edit = [
+        'format' => Unicode::strtolower($this->randomMachineName()),
+        'name' => $this->randomMachineName(),
+      ];
+      $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
+      $this->resetFilterCaches();
+      $formats[] = FilterFormat::load($edit['format']);
+    }
+    list($this->allowedFormat, $this->secondAllowedFormat, $this->disallowedFormat) = $formats;
+    $this->drupalLogout();
+
+    // Create a regular user with access to two of the formats.
+    $this->webUser = $this->drupalCreateUser([
+      'create page content',
+      'edit any page content',
+      $this->allowedFormat->getPermissionName(),
+      $this->secondAllowedFormat->getPermissionName(),
+    ]);
+
+    // Create an administrative user who has access to use all three formats.
+    $this->adminUser = $this->drupalCreateUser([
+      'administer filters',
+      'create page content',
+      'edit any page content',
+      $this->allowedFormat->getPermissionName(),
+      $this->secondAllowedFormat->getPermissionName(),
+      $this->disallowedFormat->getPermissionName(),
+    ]);
+    $this->drupalPlaceBlock('local_tasks_block');
+  }
+
+  /**
+   * Tests the Filter format access permissions functionality.
+   */
+  public function testFormatPermissions() {
+    // Make sure that a regular user only has access to the text formats for
+    // which they were granted access.
+    $fallback_format = FilterFormat::load(filter_fallback_format());
+    $disallowed_format_name = $this->disallowedFormat->getPermissionName();
+    $this->assertTrue($this->allowedFormat->access('use', $this->webUser), 'A regular user has access to use a text format they were granted access to.');
+    $this->assertEqual(AccessResult::allowed()->addCacheContexts(['user.permissions']), $this->allowedFormat->access('use', $this->webUser, TRUE), 'A regular user has access to use a text format they were granted access to.');
+    $this->assertFalse($this->disallowedFormat->access('use', $this->webUser), 'A regular user does not have access to use a text format they were not granted access to.');
+    $this->assertEqual(AccessResult::neutral("The '$disallowed_format_name' permission is required.")->cachePerPermissions(), $this->disallowedFormat->access('use', $this->webUser, TRUE), 'A regular user does not have access to use a text format they were not granted access to.');
+    $this->assertTrue($fallback_format->access('use', $this->webUser), 'A regular user has access to use the fallback format.');
+    $this->assertEqual(AccessResult::allowed(), $fallback_format->access('use', $this->webUser, TRUE), 'A regular user has access to use the fallback format.');
+
+    // Perform similar checks as above, but now against the entire list of
+    // available formats for this user.
+    $this->assertTrue(in_array($this->allowedFormat->id(), array_keys(filter_formats($this->webUser))), 'The allowed format appears in the list of available formats for a regular user.');
+    $this->assertFalse(in_array($this->disallowedFormat->id(), array_keys(filter_formats($this->webUser))), 'The disallowed format does not appear in the list of available formats for a regular user.');
+    $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_formats($this->webUser))), 'The fallback format appears in the list of available formats for a regular user.');
+
+    // Make sure that a regular user only has permission to use the format
+    // they were granted access to.
+    $this->assertTrue($this->webUser->hasPermission($this->allowedFormat->getPermissionName()), 'A regular user has permission to use the allowed text format.');
+    $this->assertFalse($this->webUser->hasPermission($this->disallowedFormat->getPermissionName()), 'A regular user does not have permission to use the disallowed text format.');
+
+    // Make sure that the allowed format appears on the node form and that
+    // the disallowed format does not.
+    $this->drupalLogin($this->webUser);
+    $this->drupalGet('node/add/page');
+    $elements = $this->xpath('//select[@name=:name]/option', [
+      ':name' => 'body[0][format]',
+      ':option' => $this->allowedFormat->id(),
+    ]);
+    $options = [];
+    foreach ($elements as $element) {
+      $options[(string) $element->getValue()] = $element;
+    }
+    $this->assertTrue(isset($options[$this->allowedFormat->id()]), 'The allowed text format appears as an option when adding a new node.');
+    $this->assertFalse(isset($options[$this->disallowedFormat->id()]), 'The disallowed text format does not appear as an option when adding a new node.');
+    $this->assertFalse(isset($options[filter_fallback_format()]), 'The fallback format does not appear as an option when adding a new node.');
+
+    // Check regular user access to the filter tips pages.
+    $this->drupalGet('filter/tips/' . $this->allowedFormat->id());
+    $this->assertResponse(200);
+    $this->drupalGet('filter/tips/' . $this->disallowedFormat->id());
+    $this->assertResponse(403);
+    $this->drupalGet('filter/tips/' . filter_fallback_format());
+    $this->assertResponse(200);
+    $this->drupalGet('filter/tips/invalid-format');
+    $this->assertResponse(404);
+
+    // Check admin user access to the filter tips pages.
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('filter/tips/' . $this->allowedFormat->id());
+    $this->assertResponse(200);
+    $this->drupalGet('filter/tips/' . $this->disallowedFormat->id());
+    $this->assertResponse(200);
+    $this->drupalGet('filter/tips/' . filter_fallback_format());
+    $this->assertResponse(200);
+    $this->drupalGet('filter/tips/invalid-format');
+    $this->assertResponse(404);
+  }
+
+  /**
+   * Tests if text format is available to a role.
+   */
+  public function testFormatRoles() {
+    // Get the role ID assigned to the regular user.
+    $roles = $this->webUser->getRoles(TRUE);
+    $rid = $roles[0];
+
+    // Check that this role appears in the list of roles that have access to an
+    // allowed text format, but does not appear in the list of roles that have
+    // access to a disallowed text format.
+    $this->assertTrue(in_array($rid, array_keys(filter_get_roles_by_format($this->allowedFormat))), 'A role which has access to a text format appears in the list of roles that have access to that format.');
+    $this->assertFalse(in_array($rid, array_keys(filter_get_roles_by_format($this->disallowedFormat))), 'A role which does not have access to a text format does not appear in the list of roles that have access to that format.');
+
+    // Check that the correct text format appears in the list of formats
+    // available to that role.
+    $this->assertTrue(in_array($this->allowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
+    $this->assertFalse(in_array($this->disallowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');
+
+    // Check that the fallback format is always allowed.
+    $this->assertEqual(filter_get_roles_by_format(FilterFormat::load(filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
+    $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), 'The fallback format appears in the list of allowed formats for any role.');
+  }
+
+  /**
+   * Tests editing a page using a disallowed text format.
+   *
+   * Verifies that regular users and administrators are able to edit a page, but
+   * not allowed to change the fields which use an inaccessible text format.
+   * Also verifies that fields which use a text format that does not exist can
+   * be edited by administrators only, but that the administrator is forced to
+   * choose a new format before saving the page.
+   */
+  public function testFormatWidgetPermissions() {
+    $body_value_key = 'body[0][value]';
+    $body_format_key = 'body[0][format]';
+
+    // Create node to edit.
+    $this->drupalLogin($this->adminUser);
+    $edit = [];
+    $edit['title[0][value]'] = $this->randomMachineName(8);
+    $edit[$body_value_key] = $this->randomMachineName(16);
+    $edit[$body_format_key] = $this->disallowedFormat->id();
+    $this->drupalPostForm('node/add/page', $edit, t('Save'));
+    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
+
+    // Try to edit with a less privileged user.
+    $this->drupalLogin($this->webUser);
+    $this->drupalGet('node/' . $node->id());
+    $this->clickLink(t('Edit'));
+
+    // Verify that body field is read-only and contains replacement value.
+    $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+
+    // Verify that title can be changed, but preview displays original body.
+    $new_edit = [];
+    $new_edit['title[0][value]'] = $this->randomMachineName(8);
+    $this->drupalPostForm(NULL, $new_edit, t('Preview'));
+    $this->assertText($edit[$body_value_key], 'Old body found in preview.');
+
+    // Save and verify that only the title was changed.
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $new_edit, t('Save'));
+    $this->assertNoText($edit['title[0][value]'], 'Old title not found.');
+    $this->assertText($new_edit['title[0][value]'], 'New title found.');
+    $this->assertText($edit[$body_value_key], 'Old body found.');
+
+    // Check that even an administrator with "administer filters" permission
+    // cannot edit the body field if they do not have specific permission to
+    // use its stored format. (This must be disallowed so that the
+    // administrator is never forced to switch the text format to something
+    // else.)
+    $this->drupalLogin($this->filterAdminUser);
+    $this->drupalGet('node/' . $node->id() . '/edit');
+    $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+
+    // Disable the text format used above.
+    $this->disallowedFormat->disable()->save();
+    $this->resetFilterCaches();
+
+    // Log back in as the less privileged user and verify that the body field
+    // is still disabled, since the less privileged user should not be able to
+    // edit content that does not have an assigned format.
+    $this->drupalLogin($this->webUser);
+    $this->drupalGet('node/' . $node->id() . '/edit');
+    $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+
+    // Log back in as the filter administrator and verify that the body field
+    // can be edited.
+    $this->drupalLogin($this->filterAdminUser);
+    $this->drupalGet('node/' . $node->id() . '/edit');
+    $this->assertNoFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", NULL, 'Text format access denied message not found.');
+    $this->assertFieldByXPath("//select[@name='$body_format_key']", NULL, 'Text format selector found.');
+
+    // Verify that trying to save the node without selecting a new text format
+    // produces an error message, and does not result in the node being saved.
+    $old_title = $new_edit['title[0][value]'];
+    $new_title = $this->randomMachineName(8);
+    $edit = [];
+    $edit['title[0][value]'] = $new_title;
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
+    $this->assertText(t('@name field is required.', ['@name' => t('Text format')]), 'Error message is displayed.');
+    $this->drupalGet('node/' . $node->id());
+    $this->assertText($old_title, 'Old title found.');
+    $this->assertNoText($new_title, 'New title not found.');
+
+    // Now select a new text format and make sure the node can be saved.
+    $edit[$body_format_key] = filter_fallback_format();
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
+    $this->assertUrl('node/' . $node->id());
+    $this->assertText($new_title, 'New title found.');
+    $this->assertNoText($old_title, 'Old title not found.');
+
+    // Switch the text format to a new one, then disable that format and all
+    // other formats on the site (leaving only the fallback format).
+    $this->drupalLogin($this->adminUser);
+    $edit = [$body_format_key => $this->allowedFormat->id()];
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
+    $this->assertUrl('node/' . $node->id());
+    foreach (filter_formats() as $format) {
+      if (!$format->isFallbackFormat()) {
+        $format->disable()->save();
+      }
+    }
+
+    // Since there is now only one available text format, the widget for
+    // selecting a text format would normally not display when the content is
+    // edited. However, we need to verify that the filter administrator still
+    // is forced to make a conscious choice to reassign the text to a different
+    // format.
+    $this->drupalLogin($this->filterAdminUser);
+    $old_title = $new_title;
+    $new_title = $this->randomMachineName(8);
+    $edit = [];
+    $edit['title[0][value]'] = $new_title;
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
+    $this->assertText(t('@name field is required.', ['@name' => t('Text format')]), 'Error message is displayed.');
+    $this->drupalGet('node/' . $node->id());
+    $this->assertText($old_title, 'Old title found.');
+    $this->assertNoText($new_title, 'New title not found.');
+    $edit[$body_format_key] = filter_fallback_format();
+    $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
+    $this->assertUrl('node/' . $node->id());
+    $this->assertText($new_title, 'New title found.');
+    $this->assertNoText($old_title, 'Old title not found.');
+  }
+
+  /**
+   * Rebuilds text format and permission caches in the thread running the tests.
+   */
+  protected function resetFilterCaches() {
+    filter_formats_reset();
+  }
+
+}
diff --git a/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php b/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php
new file mode 100644
index 0000000..77a263c
--- /dev/null
+++ b/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php
@@ -0,0 +1,160 @@
+<?php
+
+namespace Drupal\Tests\filter\Functional;
+
+use Drupal\comment\Tests\CommentTestTrait;
+use Drupal\Core\StreamWrapper\PublicStream;
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\TestFileCreationTrait;
+
+/**
+ * Tests restriction of IMG tags in HTML input.
+ *
+ * @group filter
+ */
+class FilterHtmlImageSecureTest extends BrowserTestBase {
+
+  use CommentTestTrait;
+  use TestFileCreationTrait;
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['filter', 'node', 'comment'];
+
+  /**
+   * An authenticated user.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $webUser;
+
+  protected function setUp() {
+    parent::setUp();
+
+    // Setup Filtered HTML text format.
+    $filtered_html_format = FilterFormat::create([
+      'format' => 'filtered_html',
+      'name' => 'Filtered HTML',
+      'filters' => [
+        'filter_html' => [
+          'status' => 1,
+          'settings' => [
+            'allowed_html' => '<img src testattribute> <a>',
+          ],
+        ],
+        'filter_autop' => [
+          'status' => 1,
+        ],
+        'filter_html_image_secure' => [
+          'status' => 1,
+        ],
+      ],
+    ]);
+    $filtered_html_format->save();
+
+    // Setup users.
+    $this->webUser = $this->drupalCreateUser([
+      'access content',
+      'access comments',
+      'post comments',
+      'skip comment approval',
+      $filtered_html_format->getPermissionName(),
+    ]);
+    $this->drupalLogin($this->webUser);
+
+    // Setup a node to comment and test on.
+    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
+    // Add a comment field.
+    $this->addDefaultCommentField('node', 'page');
+    $this->node = $this->drupalCreateNode();
+  }
+
+  /**
+   * Tests removal of images having a non-local source.
+   */
+  public function testImageSource() {
+    global $base_url;
+
+    $public_files_path = PublicStream::basePath();
+
+    $http_base_url = preg_replace('/^https?/', 'http', $base_url);
+    $https_base_url = preg_replace('/^https?/', 'https', $base_url);
+    $files_path = base_path() . $public_files_path;
+    $csrf_path = $public_files_path . '/' . implode('/', array_fill(0, substr_count($public_files_path, '/') + 1, '..'));
+
+    $druplicon = 'core/misc/druplicon.png';
+    $red_x_image = base_path() . 'core/misc/icons/e32700/error.svg';
+    $alt_text = t('Image removed.');
+    $title_text = t('This image has been removed. For security reasons, only images from the local domain are allowed.');
+
+    // Put a test image in the files directory.
+    $test_images = $this->getTestFiles('image');
+    $test_image = $test_images[0]->filename;
+
+    // Put a test image in the files directory with special filename.
+    $special_filename = 'tést fïle nàme.png';
+    $special_image = rawurlencode($special_filename);
+    $special_uri = str_replace($test_images[0]->filename, $special_filename, $test_images[0]->uri);
+    file_unmanaged_copy($test_images[0]->uri, $special_uri);
+
+    // Create a list of test image sources.
+    // The keys become the value of the IMG 'src' attribute, the values are the
+    // expected filter conversions.
+    $host = \Drupal::request()->getHost();
+    $host_pattern = '|^http\://' . $host . '(\:[0-9]{0,5})|';
+    $images = [
+      $http_base_url . '/' . $druplicon => base_path() . $druplicon,
+      $https_base_url . '/' . $druplicon => base_path() . $druplicon,
+      // Test a url that includes a port.
+      preg_replace($host_pattern, 'http://' . $host . ':', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
+      preg_replace($host_pattern, 'http://' . $host . ':80', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
+      preg_replace($host_pattern, 'http://' . $host . ':443', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
+      preg_replace($host_pattern, 'http://' . $host . ':8080', $http_base_url . '/' . $druplicon) => base_path() . $druplicon,
+      base_path() . $druplicon => base_path() . $druplicon,
+      $files_path . '/' . $test_image => $files_path . '/' . $test_image,
+      $http_base_url . '/' . $public_files_path . '/' . $test_image => $files_path . '/' . $test_image,
+      $https_base_url . '/' . $public_files_path . '/' . $test_image => $files_path . '/' . $test_image,
+      $http_base_url . '/' . $public_files_path . '/' . $special_image => $files_path . '/' . $special_image,
+      $https_base_url . '/' . $public_files_path . '/' . $special_image => $files_path . '/' . $special_image,
+      $files_path . '/example.png' => $red_x_image,
+      'http://example.com/' . $druplicon => $red_x_image,
+      'https://example.com/' . $druplicon => $red_x_image,
+      'javascript:druplicon.png' => $red_x_image,
+      $csrf_path . '/logout' => $red_x_image,
+    ];
+    $comment = [];
+    foreach ($images as $image => $converted) {
+      // Output the image source as plain text for debugging.
+      $comment[] = $image . ':';
+      // Hash the image source in a custom test attribute, because it might
+      // contain characters that confuse XPath.
+      $comment[] = '<img src="' . $image . '" testattribute="' . hash('sha256', $image) . '" />';
+    }
+    $edit = [
+      'comment_body[0][value]' => implode("\n", $comment),
+    ];
+    $this->drupalPostForm('node/' . $this->node->id(), $edit, t('Save'));
+    foreach ($images as $image => $converted) {
+      $found = FALSE;
+      foreach ($this->xpath('//img[@testattribute="' . hash('sha256', $image) . '"]') as $element) {
+        $found = TRUE;
+        if ($converted == $red_x_image) {
+          $this->assertEqual((string) $element->getAttribute('src'), $red_x_image);
+          $this->assertEqual((string) $element->getAttribute('alt'), $alt_text);
+          $this->assertEqual((string) $element->getAttribute('title'), $title_text);
+          $this->assertEqual((string) $element->getAttribute('height'), '16');
+          $this->assertEqual((string) $element->getAttribute('width'), '16');
+        }
+        else {
+          $this->assertEqual((string) $element->getAttribute('src'), $converted);
+        }
+      }
+      $this->assertTrue($found, format_string('@image was found.', ['@image' => $image]));
+    }
+  }
+
+}
