diff -u b/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php --- b/core/modules/comment/src/CommentLinkBuilder.php +++ b/core/modules/comment/src/CommentLinkBuilder.php @@ -205,7 +205,7 @@ $entity_links['comment__' . $field_name]['#attached']['library'][] = 'comment/drupal.node-new-comments-link'; // Embed the metadata for the "X new comments" link (if any) on this // entity. - $timestamps = \Drupal::service('history.repository')->getLastViewed($entity->getEntityTypeId(), [$entity->id()], \Drupal::currentUser()); + $timestamps = \Drupal::service('history.repository')->getLastViewed($entity->getEntityTypeId(), [$entity->id()], $this->currentUser); $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) $timestamps[$entity->id()]; $new_comments = $this->commentManager->getCountNewComments($entity); if ($new_comments > 0) { only in patch2: unchanged: --- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php +++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php @@ -9,6 +9,7 @@ use Drupal\node\NodeInterface; use Drupal\Tests\Traits\Core\GeneratePermutationsTrait; use Drupal\Tests\UnitTestCase; +use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @coversDefaultClass \Drupal\comment\CommentLinkBuilder @@ -87,6 +88,16 @@ protected function setUp() { $this->stringTranslation->expects($this->any()) ->method('formatPlural') ->willReturnArgument(1); + + $history_repository = $this->getMockBuilder('Drupal\history\HistoryRepositoryInterface') + ->disableOriginalConstructor() + ->getMock(); + $history_repository->expects($this->any()) + ->method('getLastViewed') + ->willReturn(0); + $container = new ContainerBuilder(); + $container->set('history.repository', $history_repository); + \Drupal::setContainer($container); } /** @@ -321,13 +332,3 @@ protected function getMockNode($has_field, $comment_status, $form_location, $com } } - -namespace Drupal\comment; - -if (!function_exists('history_read')) { - - function history_read() { - return 0; - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/history/tests/src/Functional/Update/HistoryUpdateTest.php @@ -0,0 +1,50 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Tests changing nid to entity_id and adding an entity_type field to the history table. + * + * @see history_update_8801() + */ + public function testUpdateHookN() { + $schema = \Drupal::database()->schema(); + + // Run updates. + $this->runUpdates(); + + // Ensure fields were added. + $this->assertTrue($schema->fieldExists('history', 'entity_type')); + $this->assertTrue($schema->fieldExists('history', 'entity_id')); + // Ensure field was removed. + $this->assertFalse($schema->fieldExists('history', 'nid')); + + $this->assertTrue($schema->indexExists('history', 'history_entity')); + $this->assertFalse($schema->indexExists('history', 'nid')); + } + +}