function ContentModerationStateTest::testNonLangcodeEntityTypeModeration

Same name in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testNonLangcodeEntityTypeModeration()
  2. 10 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testNonLangcodeEntityTypeModeration()
  3. 11.x core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testNonLangcodeEntityTypeModeration()

Tests moderation of a non-translatable entity type with no langcode.

File

core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php, line 553

Class

ContentModerationStateTest
Tests links between a content entity and a content_moderation_state entity.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.