function ContentTranslationNewTranslationWithExistingRevisionsTest::testDraftTranslationIsNotDeleted
Same name in other branches
- 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationNewTranslationWithExistingRevisionsTest::testDraftTranslationIsNotDeleted()
Tests a translation with a draft is not deleted.
File
-
core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationNewTranslationWithExistingRevisionsTest.php, line 45
Class
- ContentTranslationNewTranslationWithExistingRevisionsTest
- Tests that new translations do not delete existing ones.
Namespace
Drupal\Tests\content_translation\FunctionalCode
public function testDraftTranslationIsNotDeleted() : void {
$this->drupalLogin($this->translator);
// Create a test node.
$values = [
'title' => "Test EN",
'moderation_state' => 'published',
];
$id = $this->createEntity($values, 'en');
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->storage
->load($id);
// Add a published translation.
$add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
$entity->getEntityTypeId() => $id,
'source' => 'en',
'target' => 'it',
], [
'language' => ConfigurableLanguage::load('it'),
'absolute' => FALSE,
]);
$this->drupalGet($add_translation_url);
$edit = [
'title[0][value]' => "Test IT",
'moderation_state[0][state]' => 'published',
];
$this->submitForm($edit, 'Save (this translation)');
$it_revision = $this->loadRevisionTranslation($entity, 'it');
// Add a draft translation.
$this->drupalGet($this->getEditUrl($it_revision));
$edit = [
'title[0][value]' => "Test IT 2",
'moderation_state[0][state]' => 'draft',
];
$this->submitForm($edit, 'Save (this translation)');
// Add a new draft translation.
$add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
$entity->getEntityTypeId() => $id,
'source' => 'en',
'target' => 'fr',
], [
'language' => ConfigurableLanguage::load('fr'),
'absolute' => FALSE,
]);
$this->drupalGet($add_translation_url);
$edit = [
'title[0][value]' => "Test FR",
'moderation_state[0][state]' => 'published',
];
$this->submitForm($edit, 'Save (this translation)');
// Check the first translation still exists.
$entity = $this->storage
->loadUnchanged($id);
$this->assertTrue($entity->hasTranslation('it'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.