diff --git a/core/modules/comment/src/Tests/CommentOrphanedTest.php b/core/modules/comment/src/Tests/CommentOrphanedTest.php
new file mode 100644
index 0000000..bcc021c
--- /dev/null
+++ b/core/modules/comment/src/Tests/CommentOrphanedTest.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\comment\Tests\CommentOrphanedTest.
+ */
+
+namespace Drupal\comment\Tests;
+
+/**
+ * Tests operations on orphaned comments.
+ *
+ * @group comment
+ */
+class CommentOrphanedTest extends CommentTestBase {
+
+  /**
+   * Modules to install. We would like to have every module installed that
+   * implements hook_comment_storage_load(), so we can implicitly test it.
+   * At this moment, RDF is the only core module implementing the hook.
+   *
+   * @var array
+   */
+  public static $modules = ['comment_test', 'rdf', 'comment', 'node'];
+
+  /**
+   * Test the new comments field plugin.
+   */
+  public function testDeleteOrphanedComment() {
+    /** @var \Drupal\Core\Entity\EntityManagerInterface $manager */
+    $manager = $this->container->get('entity.manager');
+
+    // Mess with the comments to make them orphaned. We only know how to do
+    // this with SQL based entity storage.
+    $storage = $manager->getStorage('comment');
+    if (in_array('Drupal\Core\Entity\Sql\SqlEntityStorageInterface', class_implements($storage))) {
+      $manager->getDefinition('comment')->setHandlerClass('storage', 'Drupal\comment_test\CommentTestSqlEntityStorage');
+      $storage = $manager->getStorage('comment');
+
+      $ids = $storage->orphanComments();
+
+      // Now load and delete these comments, and implicitly test that nothing
+      // breaks.
+      $entities = $storage->loadMultiple($ids);
+      $storage->delete($entities);
+    }
+
+  }
+
+}
diff --git a/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php b/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php
new file mode 100644
index 0000000..f6d3a15
--- /dev/null
+++ b/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\comment_test\CommentTestSqlEntityStorage.
+ */
+
+namespace Drupal\comment_test;
+
+use Drupal\comment\CommentStorage;
+
+/**
+ * Comment storage handler for the comment_test.module.
+ */
+class CommentTestSqlEntityStorage extends CommentStorage {
+
+  /**
+   * Intentionally makes reference data (author, parent comment) invalid, in the
+   * SQL storage backend.
+   *
+   * @param array $comment_ids
+   *   IDs of comments to orphan. If not provided, one comment will be taken
+   *   semi randomly (if one exists).
+   *
+   * @return array
+   *   The orphaned comment ID(s), i.e. the input argument if it was nonempty.
+   */
+  public function orphanComments(array $comment_ids = array()) {
+
+    if (empty($comment_ids)) {
+      $query = $this->database->select('comment_field_data', 'c');
+      $query->addExpression('MAX(cid)');
+      $cid = $query->execute()->fetchField();
+      if ($cid) {
+        $comment_ids = array($cid);
+      }
+    }
+
+    if (!empty($comment_ids)) {
+      // Get the maximum parent/author and set it one higher; this emulates
+      // a parent/author which has been deleted after creating.
+      $query = $this->database->select('comment_field_data', 'c');
+      $query->addExpression('MAX(entity_id)', 'entity_id_max');
+      $query->addExpression('MAX(pid)', 'pid_max');
+      $query->addExpression('MAX(uid)', 'uid_max');
+      $row = $query->execute()->fetchObject();
+      if (!isset($row->pid_max)) {
+        $row->pid_max = 0;
+      }
+
+      $this->database->update('comment_field_data')
+        ->fields(array('entity_id' => $row->entity_id_max, 'pid' => $row->pid_max, 'uid' => $row->uid_max))
+        ->condition('cid', array($comment_ids))
+        ->execute();
+
+      $this->resetCache();
+    }
+  }
+
+}
