diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 5e237f39fb6e9b09ea35be448bcf32e4196c97b4..db80eea1a607773b76f1791dd94f3324e7a1ee30 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -7,9 +7,7 @@ use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Language\LanguageInterface; -use Drupal\entity_test\Entity\EntityTestBundle; use Drupal\entity_test\Entity\EntityTestRev; -use Drupal\entity_test\Entity\EntityTestWithBundle; use Drupal\KernelTests\KernelTestBase; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\node\Entity\Node; @@ -59,7 +57,6 @@ protected function setUp() { $this->installSchema('node', 'node_access'); $this->installEntitySchema('node'); $this->installEntitySchema('user'); - $this->installEntitySchema('entity_test_with_bundle'); $this->installEntitySchema('entity_test_rev'); $this->installEntitySchema('entity_test_no_bundle'); $this->installEntitySchema('entity_test_mulrevpub'); @@ -84,11 +81,6 @@ protected function setUp() { * The bundle identifier. */ protected function setupBundleEntityType($entity_type_id) { - // Make the 'entity_test_with_bundle' entity type revisionable. - if ($entity_type_id == 'entity_test_with_bundle') { - $this->setEntityTestWithBundleKeys(['revision' => 'revision_id']); - } - $bundle_id = $entity_type_id; $bundle_entity_type_id = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType(); if ($bundle_entity_type_id) { @@ -215,9 +207,6 @@ public function basicModerationTestCases() { 'Media' => [ 'media', ], - 'Test Entity with Bundle' => [ - 'entity_test_with_bundle', - ], 'Test entity - revisions, data table, and published interface' => [ 'entity_test_mulrevpub', ], @@ -434,34 +423,23 @@ public function testModerationWithSpecialLanguages() { * Tests that a non-translatable entity type with a langcode can be moderated. */ public function testNonTranslatableEntityTypeModeration() { - // Make the 'entity_test_with_bundle' entity type revisionable. - $this->setEntityTestWithBundleKeys(['revision' => 'revision_id']); - - // Create a test bundle. - $entity_test_bundle = EntityTestBundle::create([ - 'id' => 'example', - ]); - $entity_test_bundle->save(); - $workflow = Workflow::load('editorial'); - $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_with_bundle', 'example'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev'); $workflow->save(); // Check that the tested entity type is not translatable. - $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); + $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_rev'); $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.'); // Create a test entity. - $entity_test_with_bundle = EntityTestWithBundle::create([ - 'type' => 'example' - ]); - $entity_test_with_bundle->save(); - $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->value); + $entity = EntityTestRev::create(); + $entity->save(); + $this->assertEquals('draft', $entity->moderation_state->value); - $entity_test_with_bundle->moderation_state->value = 'published'; - $entity_test_with_bundle->save(); + $entity->moderation_state->value = 'published'; + $entity->save(); - $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->value); + $this->assertEquals('published', EntityTestRev::load($entity->id())->moderation_state->value); } /** @@ -469,54 +447,35 @@ public function testNonTranslatableEntityTypeModeration() { * moderated. */ public function testNonLangcodeEntityTypeModeration() { - // Make the 'entity_test_with_bundle' entity type revisionable and unset - // the langcode entity key. - $this->setEntityTestWithBundleKeys(['revision' => 'revision_id'], ['langcode']); - - // Create a test bundle. - $entity_test_bundle = EntityTestBundle::create([ - 'id' => 'example', - ]); - $entity_test_bundle->save(); + // Unset the langcode entity key for 'entity_test_rev'. + $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_rev'); + $keys = $entity_type->getKeys(); + unset($keys['langcode']); + $entity_type->set('entity_keys', $keys); + \Drupal::state()->set('entity_test_rev.entity_type', $entity_type); + + // Update the entity type in order to remove the 'langcode' field. + \Drupal::entityDefinitionUpdateManager()->applyUpdates(); $workflow = Workflow::load('editorial'); - $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_with_bundle', 'example'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev'); $workflow->save(); - // Check that the tested entity type is not translatable. - $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); + // Check that the tested entity type is not translatable and does not have a + // 'langcode' entity key. + $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_rev'); $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.'); + $this->assertFalse($entity_type->getKey('langcode'), "The test entity type does not have a 'langcode' entity key."); // Create a test entity. - $entity_test_with_bundle = EntityTestWithBundle::create([ - 'type' => 'example' - ]); - $entity_test_with_bundle->save(); - $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->value); - - $entity_test_with_bundle->moderation_state->value = 'published'; - $entity_test_with_bundle->save(); + $entity = EntityTestRev::create(); + $entity->save(); + $this->assertEquals('draft', $entity->moderation_state->value); - $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->value); - } + $entity->moderation_state->value = 'published'; + $entity->save(); - /** - * Set the keys on the test entity type. - * - * @param array $keys - * The entity keys to override - * @param array $remove_keys - * Keys to remove. - */ - protected function setEntityTestWithBundleKeys($keys, $remove_keys = []) { - $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); - $original_keys = $entity_type->getKeys(); - foreach ($remove_keys as $remove_key) { - unset($original_keys[$remove_key]); - } - $entity_type->set('entity_keys', $keys + $original_keys); - \Drupal::state()->set('entity_test_with_bundle.entity_type', $entity_type); - \Drupal::entityDefinitionUpdateManager()->applyUpdates(); + $this->assertEquals('published', EntityTestRev::load($entity->id())->moderation_state->value); } /** diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 0839f8b4e00da1c14ecc269366ba88e827f01a20..4d35275db8e9e8227e783157408086c9000e37e1 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -94,8 +94,8 @@ function entity_test_entity_type_alter(array &$entity_types) { } } - // Allow entity_test_with_bundle tests to override the entity type definition. - $entity_types['entity_test_with_bundle'] = $state->get('entity_test_with_bundle.entity_type', $entity_types['entity_test_with_bundle']); + // Allow entity_test_rev tests to override the entity type definition. + $entity_types['entity_test_rev'] = $state->get('entity_test_rev.entity_type', $entity_types['entity_test_rev']); // Enable the entity_test_new only when needed. if (!$state->get('entity_test_new')) { @@ -103,17 +103,6 @@ function entity_test_entity_type_alter(array &$entity_types) { } } -/** - * Implements hook_module_implements_alter(). - */ -function entity_test_module_implements_alter(&$implementations, $hook) { - // Move our hook_entity_type_alter() implementation to the beginning of the - // list in order to run before content_moderation_entity_type_alter(). - if ($hook === 'entity_type_alter') { - $implementations = ['entity_test' => $implementations['entity_test']] + $implementations; - } -} - /** * Implements hook_entity_base_field_info(). */