diff -u b/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php b/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php --- b/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php +++ b/core/modules/comment/tests/modules/comment_test/src/CommentTestSqlEntityStorage.php @@ -16,8 +16,8 @@ * author) 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. + * IDs of comments to orphan. If empty, one comment will be taken semi + * randomly. * @param array $fields * Names of fields to change. Allowed values: 'pid', 'entity_id', 'uid'. If * not provided, all fields will be changed. diff -u b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php --- b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php +++ b/core/modules/comment/tests/src/Functional/CommentOrphanedTest.php @@ -2,20 +2,22 @@ namespace Drupal\Tests\comment\Functional; +use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; + /** * Tests operations on orphaned comments. * - * Drupal core will officially never orphan comments. An orphan comment is - * comment with a nonexistent parent comment or commented entities. + * An orphan comment is a comment with a nonexistent parent comment or commented + * entity. Drupal core should never orphan comments. * * This test exists despite the above because it's expected that in time someone * will try to be smart and delete old entities/comments from a large database, * a PHP process will die at exactly the wrong time, or whatever exotic event * happens that makes comments with invalid parent/entity references exist. When * this happens, a site should not start crashing during basic operations like - * loading/displaying a node page. Practice has shown that it's fairly easy to + * loading/displaying a node page. Experience has shown that it's fairly easy to * inadvertently write code that makes Drupal crash during loading/rendering - * orphaned comments; this test will draw attention to that code in Drupal core. + * orphaned comments. This test draws attention to such code in Drupal core. * * @group comment */ @@ -46,53 +48,51 @@ // We only know how to orphan comments on SQL based entity storage. $storage = $manager->getStorage('comment'); - if (in_array('Drupal\Core\Entity\Sql\SqlEntityStorageInterface', class_implements($storage))) { - $session = $this->assertSession(); + $this->assertInstanceOf(SqlEntityStorageInterface::class, $storage); + + $session = $this->assertSession(); - // Make sure we have a comment. - $this->drupalLogin($this->webUser); - $comment_text = $this->randomMachineName(); - $subject = $this->randomMachineName(); - $this->postComment($this->node, $comment_text, $subject); - - $this->drupalGet('node/2'); - $this->drupalGet('node/' . $this->node->id()); - $session->pageTextContains($comment_text); - $session->pageTextContains($subject); - - // Make the comment an orphan. - $original_class = get_class($storage); - $manager->clearCachedDefinitions(); - $manager->getDefinition('comment') - ->setStorageClass('Drupal\comment_test\CommentTestSqlEntityStorage'); - - $storage = $manager->getStorage('comment'); - // Invalidate the author/parent comment, not the commented entity. - $storage->orphanComments([], ['pid', 'uid']); - - // Render the entity, with orphaned comment, implicitly testing that - // nothing breaks. - $this->drupalGet('node/' . $this->node->id()); - $session->pageTextContains($comment_text); - $session->pageTextContains($subject); - - $ids = $storage->orphanComments(); - - // Load, render (standalone without commented entity) and delete comments, - // implicitly testing that nothing breaks when the commented entity is not - // available. This does not have a current practical application (there - // are no standalone 'comment pages') but it ensures some decoupling of - // the comment view/render code, which is a good thing in itself. - $entities = $storage->loadMultiple($ids); - $storage->delete($entities); - $manager->clearCachedDefinitions(); - $manager->getDefinition('comment')->setStorageClass($original_class); - - $this->drupalGet('node/' . $this->node->id()); - $session->pageTextNotContains($comment_text); - $session->pageTextNotContains($subject); - } + // Make sure we have a comment. + $this->drupalLogin($this->webUser); + $comment_text = $this->randomMachineName(); + $subject = $this->randomMachineName(); + $this->postComment($this->node, $comment_text, $subject); + + $this->drupalGet('node/' . $this->node->id()); + $session->pageTextContains($comment_text); + $session->pageTextContains($subject); + + // Make the comment an orphan. + $original_class = get_class($storage); + $manager->clearCachedDefinitions(); + $manager->getDefinition('comment') + ->setStorageClass('Drupal\comment_test\CommentTestSqlEntityStorage'); + + $storage = $manager->getStorage('comment'); + // Invalidate the author/parent comment, not the commented entity. + $storage->orphanComments([], ['pid', 'uid']); + // Render the entity, with orphaned comment, implicitly testing that + // nothing breaks. + $this->drupalGet('node/' . $this->node->id()); + $session->pageTextContains($comment_text); + $session->pageTextContains($subject); + + $ids = $storage->orphanComments(); + + // Load, render (standalone without commented entity) and delete comments, + // implicitly testing that nothing breaks when the commented entity is not + // available. This does not have a current practical application (there + // are no standalone 'comment pages') but it ensures some decoupling of + // the comment view/render code, which is a good thing in itself. + $entities = $storage->loadMultiple($ids); + $storage->delete($entities); + $manager->clearCachedDefinitions(); + $manager->getDefinition('comment')->setStorageClass($original_class); + + $this->drupalGet('node/' . $this->node->id()); + $session->pageTextNotContains($comment_text); + $session->pageTextNotContains($subject); } } diff -u b/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module --- b/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -237,9 +237,9 @@ ->getPreparedFieldMapping('created'); /** @var \Drupal\comment\CommentInterface $comment*/ $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment->get('created')->first()->toArray()); + // The current function is a storage level hook, so avoid to bubble + // bubbleable metadata, because it can be outside of a render context. if ($entity = $comment->getCommentedEntity()) { - // The current function is a storage level hook, so avoid to bubble - // bubbleable metadata, because it can be outside of a render context. $comment->rdf_data['entity_uri'] = $entity->toUrl()->toString(TRUE)->getGeneratedUrl(); } if ($parent = $comment->getParentComment()) {