public function ContentModerationStateTest::testNonLangcodeEntityTypeModeration in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testNonLangcodeEntityTypeModeration()
Tests that a non-translatable entity type without a langcode can be moderated.
File
- core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateTest.php, line 540
Class
- ContentModerationStateTest
- Tests links between a content entity and a content_moderation_state entity.
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testNonLangcodeEntityTypeModeration() {
// Unset the langcode entity key for 'entity_test_rev'.
$entity_type = clone $this->entityTypeManager
->getDefinition($this->revEntityTypeId);
$keys = $entity_type
->getKeys();
unset($keys['langcode']);
$entity_type
->set('entity_keys', $keys);
\Drupal::state()
->set($this->revEntityTypeId . '.entity_type', $entity_type);
// Update the entity type in order to remove the 'langcode' field.
\Drupal::entityDefinitionUpdateManager()
->updateFieldableEntityType($entity_type, \Drupal::service('entity_field.manager')
->getFieldStorageDefinitions($entity_type
->id()));
$workflow = $this
->createEditorialWorkflow();
$this
->addEntityTypeAndBundleToWorkflow($workflow, $this->revEntityTypeId, $this->revEntityTypeId);
// Check that the tested entity type is not translatable and does not have a
// 'langcode' entity key.
$entity_type = $this->entityTypeManager
->getDefinition($this->revEntityTypeId);
$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.
$storage = $this->entityTypeManager
->getStorage($this->revEntityTypeId);
$entity = $storage
->create();
$entity
->save();
$this
->assertEquals('draft', $entity->moderation_state->value);
$entity->moderation_state->value = 'published';
$entity
->save();
$this
->assertEquals('published', $storage
->load($entity
->id())->moderation_state->value);
}