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 @@ -81,10 +81,11 @@ /** * Set the history repository service. - * @see https://www.drupal.org/node/2081585 * * @param \Drupal\history\HistoryRepositoryInterface $history_repository * The history repository service. + * + * @see https://www.drupal.org/node/2081585 */ public function setHistoryRepositoryService(HistoryRepositoryInterface $history_repository) { $this->historyRepository = $history_repository; diff -u b/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php --- b/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -100,7 +100,7 @@ * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository * The entity display repository service. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager, EntityDisplayRepositoryInterface $entity_display_repository, HistoryRepositoryInterface $history_repository = NULL) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager, EntityDisplayRepositoryInterface $entity_display_repository) { $this->entityTypeManager = $entity_type_manager; $this->userConfig = $config_factory->get('user.settings'); $this->stringTranslation = $string_translation; @@ -112,10 +112,11 @@ /** * Set the history repository service. - * @see https://www.drupal.org/node/2081585 * * @param \Drupal\history\HistoryRepositoryInterface $history_repository * The history repository service. + * + * @see https://www.drupal.org/node/2081585 */ public function setHistoryRepositoryService(HistoryRepositoryInterface $history_repository) { $this->historyRepository = $history_repository; diff -u b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php --- b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php +++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php @@ -83,20 +83,21 @@ $this->historyRepository = $this->createMock(HistoryRepositoryInterface::class); $this->moduleHandler = $this->createMock('\Drupal\Core\Extension\ModuleHandlerInterface'); $this->currentUser = $this->createMock('\Drupal\Core\Session\AccountProxyInterface'); - $this->commentLinkBuilder = new CommentLinkBuilder($this->currentUser, $this->commentManager, $this->moduleHandler, $this->stringTranslation, $this->entityTypeManager, $this->historyRepository); - $this->commentManager->expects($this->any()) + $this->commentLinkBuilder = new CommentLinkBuilder($this->currentUser, $this->commentManager, $this->moduleHandler, $this->stringTranslation, $this->entityTypeManager); + $this->commentLinkBuilder->setHistoryRepositoryService($this->historyRepository); + $this->commentManager->expects($this->atLeastOnce()) ->method('getFields') ->with('node') ->willReturn([ 'comment' => [], ]); - $this->commentManager->expects($this->any()) + $this->commentManager->expects($this->atLeastOnce()) ->method('forbiddenMessage') ->willReturn("Can't let you do that Dave."); - $this->stringTranslation->expects($this->any()) + $this->stringTranslation->expects($this->atLeastOnce()) ->method('formatPlural') ->willReturnArgument(1); - $this->historyRepository->expects($this->any()) + $this->historyRepository->expects($this->atLeastOnce()) ->method('getLastViewed') ->willReturn([1 => 0]); } @@ -125,20 +126,20 @@ * @covers ::buildCommentedEntityLinks */ public function testCommentLinkBuilder(NodeInterface $node, $context, $has_access_comments, $history_exists, $has_post_comments, $is_anonymous, $expected) { - $this->moduleHandler->expects($this->any()) + $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('history') ->willReturn($history_exists); - $this->currentUser->expects($this->any()) + $this->currentUser->expects($this->atLeastOnce()) ->method('hasPermission') ->willReturnMap([ ['access comments', $has_access_comments], ['post comments', $has_post_comments], ]); - $this->currentUser->expects($this->any()) + $this->currentUser->expects($this->atLeastOnce()) ->method('isAuthenticated') ->willReturn(!$is_anonymous); - $this->currentUser->expects($this->any()) + $this->currentUser->expects($this->atLeastOnce()) ->method('isAnonymous') ->willReturn($is_anonymous); $links = $this->commentLinkBuilder->buildCommentedEntityLinks($node, $context); @@ -282,7 +283,7 @@ */ protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) { $node = $this->createMock('\Drupal\node\NodeInterface'); - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('hasField') ->willReturn($has_field); @@ -294,35 +295,35 @@ 'comment_count' => $comment_count, 'last_comment_timestamp' => $this->timestamp, ]; - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('get') ->with('comment') ->willReturn($field_item); $field_definition = $this->createMock('\Drupal\Core\Field\FieldDefinitionInterface'); - $field_definition->expects($this->any()) + $field_definition->expects($this->atLeastOnce()) ->method('getSetting') ->with('form_location') ->willReturn($form_location); - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('getFieldDefinition') ->with('comment') ->willReturn($field_definition); - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('language') ->willReturn('und'); - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('getEntityTypeId') ->willReturn('node'); - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('id') ->willReturn(1); $url = Url::fromRoute('node.view'); - $node->expects($this->any()) + $node->expects($this->atLeastOnce()) ->method('toUrl') ->willReturn($url); diff -u b/core/modules/comment/tests/src/Unit/CommentManagerTest.php b/core/modules/comment/tests/src/Unit/CommentManagerTest.php --- b/core/modules/comment/tests/src/Unit/CommentManagerTest.php +++ b/core/modules/comment/tests/src/Unit/CommentManagerTest.php @@ -25,10 +25,10 @@ public function testGetFields() { // Set up a content entity type. $entity_type = $this->createMock('Drupal\Core\Entity\ContentEntityTypeInterface'); - $entity_type->expects($this->any()) + $entity_type->expects($this->atLeastOnce()) ->method('getClass') ->will($this->returnValue('Node')); - $entity_type->expects($this->any()) + $entity_type->expects($this->atLeastOnce()) ->method('entityClassImplements') ->with(FieldableEntityInterface::class) ->will($this->returnValue(TRUE)); @@ -47,11 +47,11 @@ ], ])); - $entity_type_manager->expects($this->any()) + $entity_type_manager->expects($this->atLeastOnce()) ->method('getDefinition') ->will($this->returnValue($entity_type)); - $history_repository->expects($this->any()) + $history_repository->expects($this->atLeastOnce()) ->method('getLastViewed') ->willReturn(0); @@ -62,9 +62,9 @@ $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface'), $this->createMock(AccountInterface::class), $entity_field_manager, - $this->prophesize(EntityDisplayRepositoryInterface::class)->reveal(), - $history_repository + $this->prophesize(EntityDisplayRepositoryInterface::class)->reveal() ); + $comment_manager->setHistoryRepositoryService($history_repository); $comment_fields = $comment_manager->getFields('node'); $this->assertArrayHasKey('field_foobar', $comment_fields); } diff -u b/core/modules/history/history.install b/core/modules/history/history.install --- b/core/modules/history/history.install +++ b/core/modules/history/history.install @@ -25,7 +25,6 @@ 'description' => 'The type of the entity that was read.', 'type' => 'varchar_ascii', 'not null' => TRUE, - 'default' => '', 'length' => EntityTypeInterface::ID_MAX_LENGTH, ], 'entity_id' => [ @@ -61,7 +60,7 @@ /** * Change {history}.nid to {history}.entity_id and add {history}.entity_type. */ -function history_update_9001() { +function history_update_9101() { $database = Database::getConnection(); $schema = $database->schema(); $schema->dropPrimaryKey('history'); @@ -77,7 +76,6 @@ 'description' => 'The type of the entity that was read.', 'type' => 'varchar_ascii', 'not null' => TRUE, - 'default' => '', 'length' => EntityTypeInterface::ID_MAX_LENGTH, ]); @@ -100,7 +98,6 @@ 'description' => 'The type of the entity that was read.', 'type' => 'varchar_ascii', 'not null' => TRUE, - 'default' => '', 'length' => EntityTypeInterface::ID_MAX_LENGTH, ], 'entity_id' => [ diff -u b/core/modules/history/history.module b/core/modules/history/history.module --- b/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -49,9 +49,11 @@ * * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use * \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead. + * * @see https://www.drupal.org/node/2197189 */ function history_read($nid) { + @trigger_error('history_read() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead. See https://www.drupal.org/node/2197189', E_USER_DEPRECATED); $timestamps = \Drupal::service('history.repository')->getLastViewed('node', [$nid]); return $timestamps[$nid]; } @@ -72,6 +74,7 @@ * @see https://www.drupal.org/node/2197189 */ function history_read_multiple($nids) { + @trigger_error('history_read_multiple() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead. See https://www.drupal.org/node/2197189', E_USER_DEPRECATED); return \Drupal::service('history.repository')->getLastViewed('node', $nids); }