function ContentTranslationNewTranslationWithExistingRevisionsTest::testCreatingNewDraftDoesNotInvokeDeleteHook
Same name in other branches
- 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationNewTranslationWithExistingRevisionsTest::testCreatingNewDraftDoesNotInvokeDeleteHook()
Test translation delete hooks are not invoked.
File
-
core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationNewTranslationWithExistingRevisionsTest.php, line 111
Class
- ContentTranslationNewTranslationWithExistingRevisionsTest
- Tests that new translations do not delete existing ones.
Namespace
Drupal\Tests\content_translation\FunctionalCode
public function testCreatingNewDraftDoesNotInvokeDeleteHook() : 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]' => 'draft',
];
$this->submitForm($edit, 'Save (this translation)');
// If the translation delete hook was incorrectly invoked, the state
// variable would be set.
$this->assertNull($this->container
->get('state')
->get('content_translation_test.translation_deleted'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.