diff --git a/core/modules/filter/src/Tests/FilterTwigDebugTest.php b/core/modules/filter/src/Tests/FilterTwigDebugTest.php
new file mode 100644
index 0000000..83302f1
--- /dev/null
+++ b/core/modules/filter/src/Tests/FilterTwigDebugTest.php
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\filter\Tests\FilterTwigDebugTest.
+ */
+
+namespace Drupal\filter\Tests;
+
+use Drupal\Core\Render\RenderContext;
+use Drupal\simpletest\WebTestBase;
+use Drupal\filter\FilterPluginCollection;
+
+/**
+ * Tests Filter module filters with twig debugging on.
+ *
+ * @group filter
+ */
+class FilterTwigDebugTest extends WebTestBase {
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('system', 'filter');
+
+  /**
+   * @var \Drupal\filter\Plugin\FilterInterface[]
+   */
+  protected $filters;
+
+  /**
+   * Ensures twig debugging is on in the current container.
+   */
+  protected function debugOn() {
+    // Enable debug, rebuild the service container, and clear all caches.
+    $parameters = $this->container->getParameter('twig.config');
+    if (! $parameters['debug']) {
+      $parameters['debug'] = TRUE;
+      $this->setContainerParameter('twig.config', $parameters);
+      $this->rebuildContainer();
+      $this->resetAll();
+    }
+  }
+
+  /**
+   * Ensures twig debugging is off in the current container.
+   */
+  protected function debugOff() {
+    // Disable debug, rebuild the service container, and clear all caches.
+    $parameters = $this->container->getParameter('twig.config');
+    if ($parameters['debug']) {
+      $parameters['debug'] = FALSE;
+      $this->setContainerParameter('twig.config', $parameters);
+      $this->rebuildContainer();
+      $this->resetAll();
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->debugOn();
+
+    $manager = $this->container->get('plugin.manager.filter');
+    $bag = new FilterPluginCollection($manager, array());
+    $this->filters = $bag->getAll();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function tearDown() {
+    $this->debugOff();
+  }
+
+  /**
+   * Tests the caption filter with twig debugging on.
+   */
+  function testCaptionFilter() {
+    /** @var \Drupal\Core\Render\RendererInterface $renderer */
+    $renderer = \Drupal::service('renderer');
+    $filter = $this->filters['filter_caption'];
+
+    $test = function($input) use ($filter, $renderer) {
+      return $renderer->executeInRenderContext(new RenderContext(), function () use ($input, $filter) {
+        return $filter->process($input, 'und');
+      });
+    };
+
+    $attached_library = array(
+      'library' => array(
+        'filter/caption',
+      ),
+    );
+
+    // No data-caption attribute.
+    $input = '<img src="llama.jpg" />';
+    $expected = $input;
+    $this->assertIdentical($expected, $test($input)->getProcessedText());
+
+    // Data-caption attribute.
+    $input = '<img src="llama.jpg" data-caption="Loquacious llama!" />';
+    $expected = '<img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption>';
+    $output = $test($input);
+    $output = $output->getProcessedText();
+    $this->assertTrue(strpos($output, $expected) !== false, "\"$output\" contains \"$expected\"");
+    $this->assertTrue(strpos($output, '<!-- THEME HOOK: \'filter_caption\' -->') !== false, 'filter_caption theme hook debug comment is present.');
+  }
+
+}
