You are here

public function ContentModerationStateTest::testChangingContentLangcode in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateTest::testChangingContentLangcode()

Test changing the language of content without adding a translation.

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testChangingContentLangcode() {
  $this
    ->createContentType([
    'type' => 'test_type',
  ]);
  $workflow = $this
    ->createEditorialWorkflow();
  $this
    ->addEntityTypeAndBundleToWorkflow($workflow, 'node', 'test_type');
  $entity = Node::create([
    'title' => 'Test node',
    'langcode' => 'en',
    'type' => 'test_type',
  ]);
  $entity
    ->save();
  $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
  $this
    ->assertCount(1, $entity
    ->getTranslationLanguages());
  $this
    ->assertCount(1, $content_moderation_state
    ->getTranslationLanguages());
  $this
    ->assertEquals('en', $entity->langcode->value);
  $this
    ->assertEquals('en', $content_moderation_state->langcode->value);
  $entity->langcode = 'fr';
  $entity
    ->save();
  $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
  $this
    ->assertCount(1, $entity
    ->getTranslationLanguages());
  $this
    ->assertCount(1, $content_moderation_state
    ->getTranslationLanguages());
  $this
    ->assertEquals('fr', $entity->langcode->value);
  $this
    ->assertEquals('fr', $content_moderation_state->langcode->value);
}