diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 39d8d3c..946ae91 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -32,6 +32,7 @@ class ContentModerationStateTest extends KernelTestBase { 'system', 'language', 'content_translation', + 'text', ]; /** @@ -216,31 +217,42 @@ public function testMultilingualModeration() { $this->assertEquals(6, $english_node->getRevisionId()); } - public function testEntityTestModeration() { + /** + * Tests that non-translatable entity types can be moderated. + */ + public function testNonTranslatableEntityTypeModeration() { + // Make the 'entity_test_with_bundle' entity type revisionable. $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); $keys = $entity_type->getKeys(); $keys['revision'] = 'revision_id'; $entity_type->set('entity_keys', $keys); \Drupal::state()->set('entity_test_with_bundle.entity_type', $entity_type); - $entity_test_type = EntityTestBundle::create([ + \Drupal::entityDefinitionUpdateManager()->applyUpdates(); + + // Create a test bundle. + $entity_test_bundle = EntityTestBundle::create([ 'id' => 'example', ]); - if ($entity_test_type instanceof ThirdPartySettingsInterface) { - $entity_test_type->setThirdPartySetting('content_moderation', 'enabled', TRUE); - $entity_test_type->setThirdPartySetting('content_moderation', 'allowed_moderation_states', [ - 'draft', - 'published' - ]); - $entity_test_type->setThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'); - } - $entity_test_type->save(); + $entity_test_bundle->setThirdPartySetting('content_moderation', 'enabled', TRUE); + $entity_test_bundle->setThirdPartySetting('content_moderation', 'allowed_moderation_states', [ + 'draft', + 'published' + ]); + $entity_test_bundle->setThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'); + $entity_test_bundle->save(); + + // Check that the tested entity type is not translatable. + $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); + $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->entity->id()); - $entity_test_with_bundle->moderation_state->entity = 'published'; + $entity_test_with_bundle->moderation_state->target_id = 'published'; $entity_test_with_bundle->save(); $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->entity->id()); 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 4004259..1ae36be 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -105,6 +105,17 @@ 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(). */ function entity_test_entity_base_field_info(EntityTypeInterface $entity_type) { diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php index c668bd3..1028ce7 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php @@ -32,7 +32,6 @@ * "uuid" = "uuid", * "bundle" = "type", * "label" = "name", - * "langcode" = "langcode", * }, * bundle_entity_type = "entity_test_bundle", * links = {