function ContentModerationStateTest::testContentModerationStateTranslationDataRemoval

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

Tests removal of content moderation state translations.

@dataProvider basicModerationTestCases

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testContentModerationStateTranslationDataRemoval($entity_type_id) {
    // Test content moderation state translation deletion.
    if ($this->entityTypeManager
        ->getDefinition($entity_type_id)
        ->isTranslatable()) {
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
        $entity = $this->createEntity($entity_type_id, 'published');
        $langcode = 'fr';
        $translation = $entity->addTranslation($langcode, [
            'title' => 'French title test',
        ]);
        // Make sure we add values for all of the required fields.
        if ($entity_type_id == 'block_content') {
            $translation->info = $this->randomString();
        }
        $translation->save();
        $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
        $this->assertTrue($content_moderation_state->hasTranslation($langcode));
        $entity->removeTranslation($langcode);
        $entity->save();
        $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
        $this->assertFalse($content_moderation_state->hasTranslation($langcode));
    }
}

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