function ContentModerationStateTest::testNonTranslatableEntityTypeModeration

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

Tests that a non-translatable entity type with a langcode can be moderated.

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testNonTranslatableEntityTypeModeration() : void {
  $workflow = $this->createEditorialWorkflow();
  $this->addEntityTypeAndBundleToWorkflow($workflow, $this->revEntityTypeId, $this->revEntityTypeId);
  // Check that the tested entity type is not translatable.
  $entity_type = $this->entityTypeManager
    ->getDefinition($this->revEntityTypeId);
  $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.');
  // 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.