diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 0d99fc60be..6961cde900 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -357,7 +357,7 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) { * @see \Drupal\Core\Entity\EntityViewBuilderInterface::view() */ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE) { - @trigger_error('entity_view() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, $view_mode, $langcode); instead. See https://www.drupal.org/node/3033656', E_USER_DEPRECATED); + @trigger_error('entity_view() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656', E_USER_DEPRECATED); $render_controller = \Drupal::entityManager()->getViewBuilder($entity->getEntityTypeId()); if ($reset) { $render_controller->resetCache([$entity]); @@ -397,7 +397,7 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $res * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewMultiple() */ function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $reset = FALSE) { - @trigger_error('entity_view_multiple() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->viewMultiple($entities, $view_mode, $langcode); instead. See https://www.drupal.org/node/3033656', E_USER_DEPRECATED); + @trigger_error('entity_view_multiple() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->viewMultiple($entities, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656', E_USER_DEPRECATED); $render_controller = \Drupal::entityManager()->getViewBuilder(reset($entities)->getEntityTypeId()); if ($reset) { $render_controller->resetCache($entities); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 21496c8c27..fdf1ee0851 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -277,7 +277,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie * @see https://www.drupal.org/node/3033656 */ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode = NULL) { - @trigger_error("comment_view() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->view(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("comment_view() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('comment') ->view($comment, $view_mode, $langcode); @@ -307,7 +307,7 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode * @see \Drupal\Core\Render\RendererInterface::render() */ function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) { - @trigger_error("comment_view_multiple() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->viewMultiple(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("comment_view_multiple() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('comment') ->viewMultiple($comments, $view_mode, $langcode); diff --git a/core/modules/comment/tests/src/Kernel/CommentLegacyTest.php b/core/modules/comment/tests/src/Kernel/CommentLegacyTest.php new file mode 100644 index 0000000000..d748d95ecb --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/CommentLegacyTest.php @@ -0,0 +1,104 @@ +installEntitySchema('comment'); + $this->installSchema('comment', ['comment_entity_statistics']); + CommentType::create([ + 'id' => 'comment', + 'label' => $this->randomString(), + 'target_entity_type_id' => 'entity_test', + ])->save(); + FieldStorageConfig::create([ + 'entity_type' => 'entity_test', + 'type' => 'comment', + 'field_name' => 'comments', + 'settings' => [ + 'comment_type' => 'comment', + ], + ])->save(); + FieldConfig::create([ + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', + 'field_name' => 'comments', + ])->save(); + $this->entity = EntityTest::create(['name' => $this->randomString()]); + $this->entity->save(); + } + + /** + * Constructs comment entity. + * + * @return \Drupal\comment\CommentInterface + * Created comment entity. + */ + protected function createComment() { + return Comment::create([ + 'entity_type' => 'entity_test', + 'field_name' => 'comments', + 'entity_id' => $this->entity->id(), + 'comment_type' => 'comment', + ]); + } + + /** + * Tests deprecation of the comment_view() function. + * + * @expectedDeprecation comment_view() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->view() instead. See https://www.drupal.org/node/3033656 + */ + public function testCommentView() { + $entity = $this->createComment(); + $this->assertEntityView(comment_view($entity)); + } + + /** + * Tests deprecation of the entity_view_multiple() function. + * + * @expectedDeprecation comment_view_multiple() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->viewMultiple() instead. See https://www.drupal.org/node/3033656 + */ + public function testCommentViewMultiple() { + $entities = [ + $this->createComment(), + $this->createComment(), + ]; + $this->assertEntityViewMultiple(comment_view_multiple($entities)); + } + +} diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index e7fa6b4ecd..2e94ee8488 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -141,7 +141,7 @@ function contact_mail($key, &$message, $params) { $message['subject'] .= t('[@form] @subject', $variables, $options); $message['body'][] = t("@sender-name (@sender-url) sent a message using the contact form at @form-url.", $variables, $options); $build = \Drupal::entityTypeManager() - ->getViewBuilder($contact_message->getEntityTypeId()) + ->getViewBuilder('contact_message') ->view($contact_message, 'mail'); $message['body'][] = \Drupal::service('renderer')->renderPlain($build); break; @@ -162,7 +162,7 @@ function contact_mail($key, &$message, $params) { $message['body'][] = t("@sender-name (@sender-url) has sent you a message via your contact form at @site-name.", $variables, $options); $message['body'][] = t("If you don't want to receive such emails, you can change your settings at @recipient-edit-url.", $variables, $options); $build = \Drupal::entityTypeManager() - ->getViewBuilder($contact_message->getEntityTypeId()) + ->getViewBuilder('contact_message') ->view($contact_message, 'mail'); $message['body'][] = \Drupal::service('renderer')->renderPlain($build); break; diff --git a/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php b/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php index d6156b8882..6113f0ffcd 100644 --- a/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php +++ b/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php @@ -243,7 +243,7 @@ public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $tex // Render a cloned node, so that we do not alter the original. $clone = clone $node; $element = \Drupal::entityTypeManager() - ->getViewBuilder($clone->getEntityTypeId()) + ->getViewBuilder('node') ->view($clone, $view_mode); $output = (string) \Drupal::service('renderer')->renderRoot($element); $this->verbose(t('Rendered node - view mode: @view_mode', ['@view_mode' => $view_mode]) . '
' . $output); diff --git a/core/modules/file/tests/src/Kernel/FileItemTest.php b/core/modules/file/tests/src/Kernel/FileItemTest.php index 413a459100..72f0bbfd36 100644 --- a/core/modules/file/tests/src/Kernel/FileItemTest.php +++ b/core/modules/file/tests/src/Kernel/FileItemTest.php @@ -142,7 +142,7 @@ public function testFileItem() { $entity->file_test = ['entity' => $file3]; $uri = $file3->getFileUri(); $output = \Drupal::entityTypeManager() - ->getViewBuilder($entity->getEntityTypeId()) + ->getViewBuilder('entity_test') ->view($entity, 'default'); \Drupal::service('renderer')->renderRoot($output); $this->assertTrue(!empty($entity->file_test->entity)); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 63c15655e7..d1303da344 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -818,13 +818,13 @@ function node_get_recent($number = 10) { * @return array * An array as expected by \Drupal\Core\Render\RendererInterface::render(). * - * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. - * Use \Drupal::entityTypeManager()->getViewBuilder('node')->view(). + * @deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. + * Use \Drupal::entityTypeManager()->getViewBuilder('node')->view() instead. * * @see https://www.drupal.org/node/3033656 */ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) { - @trigger_error("node_view() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->view(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("node_view() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('node') ->view($node, $view_mode, $langcode); @@ -845,13 +845,14 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) { * An array in the format expected by * \Drupal\Core\Render\RendererInterface::render(). * - * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. - * Use \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple(). + * @deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use + * \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple() + * instead. * * @see https://www.drupal.org/node/3033656 */ function node_view_multiple($nodes, $view_mode = 'teaser', $langcode = NULL) { - @trigger_error("node_view_multiple() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("node_view_multiple() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('node') ->viewMultiple($nodes, $view_mode, $langcode); diff --git a/core/modules/node/tests/src/Kernel/NodeLegacyTest.php b/core/modules/node/tests/src/Kernel/NodeLegacyTest.php index fe25f457e0..fe227b77a5 100644 --- a/core/modules/node/tests/src/Kernel/NodeLegacyTest.php +++ b/core/modules/node/tests/src/Kernel/NodeLegacyTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\node\Kernel; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; +use Drupal\KernelTests\Core\Entity\EntityLegacyTestTrait; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\node\NodeInterface; @@ -15,6 +16,7 @@ * @group legacy */ class NodeLegacyTest extends EntityKernelTestBase { + use EntityLegacyTestTrait; /** * Modules to enable. @@ -63,4 +65,27 @@ public function testEntityLegacyCode() { $this->assertInstanceOf(NodeTypeInterface::class, node_type_load('page')); } + /** + * Tests deprecation of the node_view() function. + * + * @expectedDeprecation node_view() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->view() instead. See https://www.drupal.org/node/3033656 + */ + public function testNodeView() { + $entity = Node::create(['type' => 'page']); + $this->assertEntityView(node_view($entity)); + } + + /** + * Tests deprecation of the node_view_multiple() function. + * + * @expectedDeprecation node_view_multiple() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple() instead. See https://www.drupal.org/node/3033656 + */ + public function testNodeViewMultiple() { + $entities = [ + Node::create(['type' => 'page']), + Node::create(['type' => 'page']), + ]; + $this->assertEntityViewMultiple(node_view_multiple($entities)); + } + } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index e17584718a..b1d5a52fb9 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -198,13 +198,14 @@ function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $c * A $page element suitable for use by * \Drupal\Core\Render\RendererInterface::render(). * - * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. - * Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view(). + * @deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use + * \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view() + * instead. * * @see https://www.drupal.org/node/3033656 */ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) { - @trigger_error("taxonomy_term_view() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("taxonomy_term_view() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('taxonomy_term') ->view($term, $view_mode, $langcode); @@ -225,13 +226,14 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) { * An array in the format expected by * \Drupal\Core\Render\RendererInterface::render(). * - * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use - * \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple(). + * @deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use + * \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple() + * instead. * * @see https://www.drupal.org/node/3033656 */ function taxonomy_term_view_multiple(array $terms, $view_mode = 'full', $langcode = NULL) { - @trigger_error("taxonomy_term_view_multiple() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("taxonomy_term_view_multiple() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('taxonomy_term') ->viewMultiple($terms, $view_mode, $langcode); diff --git a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php index 429e6fdafd..f466756395 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\taxonomy\Kernel; +use Drupal\KernelTests\Core\Entity\EntityLegacyTestTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\taxonomy\TermInterface; use Drupal\taxonomy\VocabularyInterface; @@ -15,6 +16,7 @@ */ class TaxonomyLegacyTest extends KernelTestBase { use TaxonomyTestTrait; + use EntityLegacyTestTrait; /** * Modules to enable. @@ -56,4 +58,27 @@ public function testEntityLegacyCode() { $this->assertInstanceOf(VocabularyInterface::class, taxonomy_vocabulary_load($vocab->id())); } + /** + * Tests deprecation of the taxonomy_term_view() function. + * + * @expectedDeprecation taxonomy_term_view() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view() instead. See https://www.drupal.org/node/3033656 + */ + public function testTaxonomyTermView() { + $entity = $this->createTerm($this->createVocabulary()); + $this->assertEntityView(taxonomy_term_view($entity)); + } + + /** + * Tests deprecation of the taxonomy_term_view_multiple() function. + * + * @expectedDeprecation taxonomy_term_view_multiple() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple() instead. See https://www.drupal.org/node/3033656 + */ + public function testTaxonomyTermViewMultiple() { + $entities = [ + $this->createTerm($this->createVocabulary()), + $this->createTerm($this->createVocabulary()), + ]; + $this->assertEntityViewMultiple(taxonomy_term_view_multiple($entities)); + } + } diff --git a/core/modules/user/tests/src/Kernel/UserLegacyTest.php b/core/modules/user/tests/src/Kernel/UserLegacyTest.php index 7decba06f8..6ab207608a 100644 --- a/core/modules/user/tests/src/Kernel/UserLegacyTest.php +++ b/core/modules/user/tests/src/Kernel/UserLegacyTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\user\Kernel; +use Drupal\KernelTests\Core\Entity\EntityLegacyTestTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\user\Entity\User; use Drupal\user\UserInterface; @@ -13,6 +14,7 @@ * @group legacy */ class UserLegacyTest extends KernelTestBase { + use EntityLegacyTestTrait; /** * Modules to enable. @@ -45,4 +47,27 @@ public function testEntityLegacyCode() { $this->assertInstanceOf(UserInterface::class, user_load(1)); } + /** + * Tests deprecation of the user_view() function. + * + * @expectedDeprecation user_view() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. See https://www.drupal.org/node/3033656 + */ + public function testUserView() { + $entity = User::create(); + $this->assertEntityView(user_view($entity)); + } + + /** + * Tests deprecation of the user_view_multiple() function. + * + * @expectedDeprecation user_view_multiple() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple() instead. See https://www.drupal.org/node/3033656 + */ + public function testUserViewMultiple() { + $entities = [ + User::create(), + User::create(), + ]; + $this->assertEntityViewMultiple(user_view_multiple($entities)); + } + } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index e6c0a1b446..7dd0cc69cf 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -906,13 +906,13 @@ function user_delete_multiple(array $uids) { * @return array * An array as expected by \Drupal\Core\Render\RendererInterface::render(). * - * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. - * Use \Drupal::entityTypeManager()->getViewBuilder('user')->view(). + * @deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use + * \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. * * @see https://www.drupal.org/node/3033656 */ function user_view($account, $view_mode = 'full', $langcode = NULL) { - @trigger_error("user_view() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("user_view() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('user') ->view($account, $view_mode, $langcode); @@ -933,13 +933,14 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) { * An array in the format expected by * \Drupal\Core\Render\RendererInterface::render(). * - * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. - * Use \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple(). + * @deprecated in drupal:8.7.0 and will be removed before Drupal 9.0.0. Use + * \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple() + * instead. * * @see https://www.drupal.org/node/3033656 */ function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) { - @trigger_error("user_view_multiple() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple(); instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); + @trigger_error("user_view_multiple() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED); return \Drupal::entityTypeManager() ->getViewBuilder('user') ->viewMultiple($accounts, $view_mode, $langcode); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php index ff13f6c2b2..0401d18bb9 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php @@ -14,6 +14,7 @@ * @group legacy */ class EntityLegacyTest extends KernelTestBase { + use EntityLegacyTestTrait; /** * {@inheritdoc} @@ -51,4 +52,27 @@ public function testEntityLegacyCode() { $this->assertInstanceOf(EntityInterface::class, entity_load('entity_test', 1)); } + /** + * Tests deprecation of the entity_view() function. + * + * @expectedDeprecation entity_view() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656 + */ + public function testEntityView() { + $entity = EntityTest::create(); + $this->assertEntityView(entity_view($entity, 'default')); + } + + /** + * Tests deprecation of the entity_view_multiple() function. + * + * @expectedDeprecation entity_view_multiple() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->viewMultiple($entities, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656 + */ + public function testEntityViewMultiple() { + $entities = [ + EntityTest::create(), + EntityTest::create(), + ]; + $this->assertEntityViewMultiple(entity_view_multiple($entities, 'default')); + } + } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTestTrait.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTestTrait.php new file mode 100644 index 0000000000..57acd4a7cf --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTestTrait.php @@ -0,0 +1,31 @@ +assertNotEmpty($build); + } + + /** + * Asserts that build array of multiple entities is valid. + * + * @param array $build + * An array returned by entity builder for multiple entities. + */ + protected function assertEntityViewMultiple(array $build) { + unset($build['#sorted'], $build['#pre_render']); + $this->assertEquals(2, count($build)); + } + +}