diff --git a/core/modules/comment/tests/src/Kernel/CommentItemTest.php b/core/modules/comment/tests/src/Kernel/CommentItemTest.php index 1a7fc655d554737d9aa846f8c974b0f84a00153a..85f6112561886c2767c2bf5a715a5c1a1c7d53f0 100644 --- a/core/modules/comment/tests/src/Kernel/CommentItemTest.php +++ b/core/modules/comment/tests/src/Kernel/CommentItemTest.php @@ -71,6 +71,9 @@ public function testCommentItem() { public function testCommentAuthorName() { $this->installEntitySchema('comment'); + $host = EntityTest::create(['name' => $this->randomString()]); + $host->save(); + // Create some comments. $comment = Comment::create([ 'subject' => 'My comment title', @@ -78,6 +81,7 @@ public function testCommentAuthorName() { 'name' => 'entity-test', 'mail' => 'entity@localhost', 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', 'status' => 1, ]); @@ -95,6 +99,7 @@ public function testCommentAuthorName() { 'mail' => 'test@example.com', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', 'status' => 1, ]); diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php index ffb91b0688747a1f4bb24162c23cdad8d9d50e29..08a326dde426d7cff72ec2dc0f6a6105e7700cdf 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php @@ -18,6 +18,13 @@ */ class CommentLinksTest extends CommentViewsKernelTestBase { + /** + * Modules to enable. + * + * @var array + */ + public static $modules = ['entity_test']; + /** * Views used by this test. * @@ -25,15 +32,27 @@ class CommentLinksTest extends CommentViewsKernelTestBase { */ public static $testViews = ['test_comment']; + /** + * {@inheritdoc} + */ + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); + + $this->installEntitySchema('entity_test'); + } + /** * Test the comment approve link. */ public function testLinkApprove() { + $host = EntityTest::create(['name' => $this->randomString()]); + $host->save(); // Create an unapproved comment. $comment = $this->commentStorage->create([ 'uid' => $this->adminUser->id(), 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', 'status' => 0, ]); @@ -91,8 +110,7 @@ public function testLinkApprove() { * Test the comment reply link. */ public function testLinkReply() { - $this->enableModules(['field', 'entity_test']); - $this->installEntitySchema('entity_test'); + $this->enableModules(['field']); $this->installSchema('comment', ['comment_entity_statistics']); $this->installConfig(['field']); diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php index e1b3c943361480241a82c8a9d8a869080ef0a52c..2fb8c745706927de958c667152a738c67b51347c 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php @@ -4,6 +4,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Core\Session\AnonymousUserSession; +use Drupal\entity_test\Entity\EntityTest; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\user\Entity\Role; use Drupal\user\Entity\User; @@ -36,6 +37,7 @@ protected function setUp($import_test_views = TRUE) { $this->installEntitySchema('user'); $this->installEntitySchema('comment'); + $this->installEntitySchema('entity_test'); // Create the anonymous role. $this->installConfig(['user']); @@ -67,12 +69,16 @@ protected function setUp($import_test_views = TRUE) { ]); $this->adminUser->save(); + $host = EntityTest::create(['name' => $this->randomString()]); + $host->save(); + // Create some comments. $comment = Comment::create([ 'subject' => 'My comment title', 'uid' => $this->adminUser->id(), 'name' => $this->adminUser->label(), 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', 'status' => 1, ]); @@ -85,6 +91,7 @@ protected function setUp($import_test_views = TRUE) { 'mail' => 'test@example.com', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', 'created' => 123456, 'status' => 1, diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php index f807c58d82089425551f69872bee5729e88e34f5..1ca5e43971f2f88cfcef0bd36f8cbf492e661bf9 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\comment\Kernel\Views; use Drupal\comment\Entity\Comment; +use Drupal\entity_test\Entity\EntityTest; use Drupal\user\Entity\User; use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase; @@ -25,6 +26,7 @@ protected function setUp($import_test_views = TRUE) { parent::setUp($import_test_views); $this->installEntitySchema('comment'); + $this->installEntitySchema('entity_test'); } /** @@ -36,10 +38,14 @@ public function testCommentFields() { ]); $user->save(); + $host = EntityTest::create(['name' => $this->randomString()]); + $host->save(); + $comment = Comment::create([ 'subject' => 'My comment title', 'uid' => $user->id(), 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', ]); $comment->save(); @@ -51,6 +57,7 @@ public function testCommentFields() { 'mail' => 'test@example.com', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), 'comment_type' => 'entity_test', 'created' => 123456, 'status' => 1, diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index e52bf961374400651b000612e82a0348a96eab80..00e364419a1a66e375ebf995d7078296ab3af03f 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -71,60 +71,13 @@ protected function setUp() { $this->entityTypeManager = $this->container->get('entity_type.manager'); } - /** - * Sets up a bundle entity type for the specified entity type, if needed. - * - * @param string $entity_type_id - * The entity type identifier. - * - * @return string - * The bundle identifier. - */ - protected function setupBundleEntityType($entity_type_id) { - $bundle_id = $entity_type_id; - $bundle_entity_type_id = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType(); - if ($bundle_entity_type_id) { - $bundle_entity_type_definition = $this->entityTypeManager->getDefinition($bundle_entity_type_id); - $entity_type_storage = $this->entityTypeManager->getStorage($bundle_entity_type_id); - - $entity_type = $entity_type_storage->create([ - $bundle_entity_type_definition->getKey('id') => 'example', - ]); - if ($entity_type_id == 'media') { - $entity_type->set('source', 'test'); - $entity_type->save(); - $source_field = $entity_type->getSource()->createSourceField($entity_type); - $source_field->getFieldStorageDefinition()->save(); - $source_field->save(); - $entity_type->set('source_configuration', [ - 'source_field' => $source_field->getName(), - ]); - } - $entity_type->save(); - $bundle_id = $entity_type->id(); - } - - $workflow = Workflow::load('editorial'); - $workflow->getTypePlugin()->addEntityTypeAndBundle($entity_type_id, $bundle_id); - $workflow->save(); - - return $bundle_id; - } - /** * Tests basic monolingual content moderation through the API. * * @dataProvider basicModerationTestCases */ public function testBasicModeration($entity_type_id) { - $bundle_id = $this->setupBundleEntityType($entity_type_id); - - /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); - $entity = $entity_storage->create([ - 'title' => 'Test title', - $this->entityTypeManager->getDefinition($entity_type_id)->getKey('bundle') => $bundle_id, - ]); + $entity = $this->createEntity($entity_type_id); if ($entity instanceof EntityPublishedInterface) { $entity->setUnpublished(); } @@ -175,6 +128,7 @@ public function testBasicModeration($entity_type_id) { $entity->save(); // Revert to the previous (published) revision. + $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); $previous_revision = $entity_storage->loadRevision(4); $previous_revision->isDefaultRevision(TRUE); $previous_revision->setNewRevision(TRUE); @@ -225,15 +179,9 @@ public function basicModerationTestCases() { * @dataProvider basicModerationTestCases */ public function testContentModerationStateDataRemoval($entity_type_id) { - $bundle_id = $this->setupBundleEntityType($entity_type_id); - // Test content moderation state deletion. - $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $entity_storage->create([ - 'title' => 'Test title', - $this->entityTypeManager->getDefinition($entity_type_id)->getKey('bundle') => $bundle_id, - ]); + $entity = $this->createEntity($entity_type_id); $entity->save(); $entity = $this->reloadEntity($entity); $entity->delete(); @@ -242,10 +190,7 @@ public function testContentModerationStateDataRemoval($entity_type_id) { // Test content moderation state revision deletion. /** @var \Drupal\Core\Entity\ContentEntityInterface $entity2 */ - $entity2 = $entity_storage->create([ - 'title' => 'Test title', - $this->entityTypeManager->getDefinition($entity_type_id)->getKey('bundle') => $bundle_id, - ]); + $entity2 = $this->createEntity($entity_type_id); $entity2->save(); $revision = clone $entity2; $revision->isDefaultRevision(FALSE); @@ -254,6 +199,7 @@ public function testContentModerationStateDataRemoval($entity_type_id) { $entity2 = $this->reloadEntity($entity2); $entity2->setNewRevision(TRUE); $entity2->save(); + $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); $entity_storage->deleteRevision($revision->getRevisionId()); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision); $this->assertFalse($content_moderation_state); @@ -263,15 +209,16 @@ public function testContentModerationStateDataRemoval($entity_type_id) { // Test content moderation state translation deletion. if ($this->entityTypeManager->getDefinition($entity_type_id)->isTranslatable()) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity3 */ - $entity3 = $entity_storage->create([ - 'title' => 'Test title', - $this->entityTypeManager->getDefinition($entity_type_id)->getKey('bundle') => $bundle_id, - ]); + $entity3 = $this->createEntity($entity_type_id); $langcode = 'it'; ConfigurableLanguage::createFromLangcode($langcode) ->save(); $entity3->save(); $translation = $entity3->addTranslation($langcode, ['title' => 'Titolo test']); + // Make sure we add values for all of the required fields. + if ($entity_type_id == 'block_content') { + $translation->info = $this->randomString(); + } $translation->save(); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity3); $this->assertTrue($content_moderation_state->hasTranslation($langcode)); @@ -589,6 +536,63 @@ public function testWorkflowNonConfigBundleDependencies() { ], $workflow->getDependencies()); } + /** + * Creates an entity. + * + * The entity will have required fields populated and the corresponding bundle + * will be enabled for content moderation. + * + * @param string $entity_type_id + * The entity type ID. + * + * @return \Drupal\Core\Entity\ContentEntityInterface + * The created entity. + */ + protected function createEntity($entity_type_id) { + $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); + + $bundle_id = $entity_type_id; + // Set up a bundle entity type for the specified entity type, if needed. + if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) { + $bundle_entity_type = $this->entityTypeManager->getDefinition($bundle_entity_type_id); + $bundle_entity_storage = $this->entityTypeManager->getStorage($bundle_entity_type_id); + + $bundle_id = 'example'; + if (!$bundle_entity_storage->load($bundle_id)) { + $bundle_entity = $bundle_entity_storage->create([ + $bundle_entity_type->getKey('id') => 'example', + ]); + if ($entity_type_id == 'media') { + $bundle_entity->set('source', 'test'); + $bundle_entity->save(); + $source_field = $bundle_entity->getSource()->createSourceField($bundle_entity); + $source_field->getFieldStorageDefinition()->save(); + $source_field->save(); + $bundle_entity->set('source_configuration', [ + 'source_field' => $source_field->getName(), + ]); + } + $bundle_entity->save(); + } + } + + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle($entity_type_id, $bundle_id); + $workflow->save(); + + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ + $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); + $entity = $entity_storage->create([ + $entity_type->getKey('label') => 'Test title', + $entity_type->getKey('bundle') => $bundle_id, + ]); + // Make sure we add values for all of the required fields. + if ($entity_type_id == 'block_content') { + $entity->info = $this->randomString(); + } + return $entity; + } + /** * Reloads the entity after clearing the static cache. * diff --git a/core/modules/menu_link_content/tests/src/Functional/LinksTest.php b/core/modules/menu_link_content/tests/src/Functional/LinksTest.php index 6a3d50b319f46c68f9aabab6de3c32839ec2d5dc..298af6fae3ecd6f5d78fea887e25126c4af2b091 100644 --- a/core/modules/menu_link_content/tests/src/Functional/LinksTest.php +++ b/core/modules/menu_link_content/tests/src/Functional/LinksTest.php @@ -127,6 +127,7 @@ public function testCreateLink() { 'menu_name' => 'menu_test', 'bundle' => 'menu_link_content', 'link' => [['uri' => 'internal:/']], + 'title' => 'Link test', ]; $link = MenuLinkContent::create($options); $link->save(); @@ -148,7 +149,12 @@ public function testCreateLink() { public function testMenuLinkOnEntityDelete() { $user = User::create(['name' => 'username']); $user->save(); - $menu_link_content = MenuLinkContent::create(['menu_name' => 'menu_test', 'link' => [['uri' => 'entity:user/' . $user->id()]], 'bundle' => 'menu_test']); + $menu_link_content = MenuLinkContent::create([ + 'title' => 'username profile', + 'menu_name' => 'menu_test', + 'link' => [['uri' => 'entity:user/' . $user->id()]], + 'bundle' => 'menu_test', + ]); $menu_link_content->save(); $menu_tree_condition = (new MenuTreeParameters())->addCondition('route_name', 'entity.user.canonical'); $this->assertCount(1, \Drupal::menuTree()->load('menu_test', $menu_tree_condition)); diff --git a/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php index a2ba9930fc1c52ed5e051689e7c9a7a27d900c1e..9fd1ce43fe97f20572c8bd91347dd839a77e7bcc 100644 --- a/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php +++ b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php @@ -70,7 +70,11 @@ public function testTranslationLinkOnMenuEditForm() { $this->drupalGet('admin/structure/menu/manage/tools'); $this->assertNoLink(t('Translate')); - $menu_link_content = MenuLinkContent::create(['menu_name' => 'tools', 'link' => ['uri' => 'internal:/admin/structure/menu']]); + $menu_link_content = MenuLinkContent::create([ + 'menu_name' => 'tools', + 'link' => ['uri' => 'internal:/admin/structure/menu'], + 'title' => 'Link test', + ]); $menu_link_content->save(); $this->drupalGet('admin/structure/menu/manage/tools'); $this->assertLink(t('Translate')); diff --git a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php index 414ecdeb0df1b1329d5975303cfff09780ea9300..118470fa1265cc5b33bae1cf2e23d3a092fee759 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php @@ -108,6 +108,7 @@ public function testOutboundPathAndRouteProcessing() { $menu_link_content = MenuLinkContent::create([ 'link' => ['uri' => $expectation['uri']], 'menu_name' => 'tools', + 'title' => 'Link test', ]); $menu_link_content->save(); $tree = $menu_tree->load('tools', new MenuTreeParameters()); @@ -128,6 +129,7 @@ public function testOutboundPathAndRouteProcessing() { $menu_link_content = MenuLinkContent::create([ 'link' => ['uri' => $expectation['uri']], 'menu_name' => 'tools', + 'title' => 'Link test', ]); $menu_link_content->save(); $expected_cacheability = $expected_cacheability->merge($expectation['cacheability']); diff --git a/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php b/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php index 9bb7f5455d2ceb88d537cbaabbfff9b3bd0a6872..04c04aa3e3f49ba1e69db55d5341311153b44a76 100644 --- a/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php @@ -62,9 +62,9 @@ public function testDeleteLinksInMenu() { \Drupal::entityManager()->getStorage('menu')->create(['id' => 'menu1'])->save(); \Drupal::entityManager()->getStorage('menu')->create(['id' => 'menu2'])->save(); - \Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'])->save(); - \Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'])->save(); - \Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu2', 'bundle' => 'menu_link_content'])->save(); + \Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content', 'title' => 'Link test'])->save(); + \Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content', 'title' => 'Link test'])->save(); + \Drupal::entityManager()->getStorage('menu_link_content')->create(['link' => ['uri' => 'internal:/menu_name_test'], 'menu_name' => 'menu2', 'bundle' => 'menu_link_content', 'title' => 'Link test'])->save(); $output = $this->linkTree->load('menu1', new MenuTreeParameters()); $this->assertEqual(count($output), 2);