3 namespace Drupal\Tests\content_translation\Functional;
6 use Drupal\language\Entity\ConfigurableLanguage;
9 * Tests that revision translation deletion is handled correctly.
11 * @group content_translation
13 class ContentTranslationRevisionTranslationDeletionTest extends ContentTranslationPendingRevisionTestBase {
18 protected function setUp() {
20 $this->enableContentModeration();
24 * Tests that translation overview handles pending revisions correctly.
26 public function testOverview() {
33 foreach ($accounts as $account) {
34 $this->currentAccount = $account;
35 $this->doTestOverview($index++);
40 * Performs a test run.
45 public function doTestOverview($index) {
46 $this->drupalLogin($this->currentAccount);
48 // Create a test node.
50 'title' => "Test $index.1 EN",
51 'moderation_state' => 'published',
53 $id = $this->createEntity($values, 'en');
54 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
55 $entity = $this->storage->load($id);
57 // Add a draft translation and check that it is available only in the latest
59 $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
60 $entity->getEntityTypeId() => $id,
65 'language' => ConfigurableLanguage::load('it'),
69 $add_translation_href = $add_translation_url->toString();
70 $this->drupalGet($add_translation_url);
72 'title[0][value]' => "Test $index.2 IT",
73 'moderation_state[0][state]' => 'draft',
75 $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
76 $entity = $this->storage->loadUnchanged($id);
77 $this->assertFalse($entity->hasTranslation('it'));
78 $it_revision = $this->loadRevisionTranslation($entity, 'it');
79 $this->assertTrue($it_revision->hasTranslation('it'));
81 // Check that translations cannot be deleted in drafts.
82 $overview_url = $entity->toUrl('drupal:content-translation-overview');
83 $this->drupalGet($overview_url);
84 $it_delete_url = $this->getDeleteUrl($it_revision);
85 $it_delete_href = $it_delete_url->toString();
86 $this->assertSession()->linkByHrefNotExists($it_delete_href);
87 $warning = 'The "Delete translation" action is only available for published translations.';
88 $this->assertSession()->pageTextContains($warning);
89 $this->drupalGet($this->getEditUrl($it_revision));
90 $this->assertSession()->buttonNotExists('Delete translation');
92 // Publish the translation and verify it can be deleted.
94 'title[0][value]' => "Test $index.3 IT",
95 'moderation_state[0][state]' => 'published',
97 $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
98 $entity = $this->storage->loadUnchanged($id);
99 $this->assertTrue($entity->hasTranslation('it'));
100 $it_revision = $this->loadRevisionTranslation($entity, 'it');
101 $this->assertTrue($it_revision->hasTranslation('it'));
102 $this->drupalGet($overview_url);
103 $this->assertSession()->linkByHrefExists($it_delete_href);
104 $this->assertSession()->pageTextNotContains($warning);
105 $this->drupalGet($this->getEditUrl($it_revision));
106 $this->assertSession()->buttonExists('Delete translation');
108 // Create an English draft and verify the published translation was
110 $this->drupalLogin($this->editor);
111 $en_revision = $this->loadRevisionTranslation($entity, 'en');
112 $this->drupalGet($this->getEditUrl($en_revision));
114 'title[0][value]' => "Test $index.4 EN",
115 'moderation_state[0][state]' => 'draft',
117 $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
118 $entity = $this->storage->loadUnchanged($id);
119 $this->assertTrue($entity->hasTranslation('it'));
120 $en_revision = $this->loadRevisionTranslation($entity, 'en');
121 $this->assertTrue($en_revision->hasTranslation('it'));
122 $this->drupalLogin($this->currentAccount);
124 // Delete the translation and verify that it is actually gone and that it is
125 // possible to create it again.
126 $this->drupalGet($it_delete_url);
127 $this->drupalPostForm(NULL, [], 'Delete Italian translation');
128 $entity = $this->storage->loadUnchanged($id);
129 $this->assertFalse($entity->hasTranslation('it'));
130 $it_revision = $this->loadRevisionTranslation($entity, 'it');
131 $this->assertTrue($it_revision->wasDefaultRevision());
132 $this->assertTrue($it_revision->hasTranslation('it'));
133 $this->assertTrue($it_revision->getRevisionId() < $entity->getRevisionId());
134 $this->drupalGet($overview_url);
135 $this->assertSession()->linkByHrefNotExists($this->getEditUrl($it_revision)->toString());
136 $this->assertSession()->linkByHrefExists($add_translation_href);
138 // Publish the English draft and verify the translation is not accidentally
140 $this->drupalLogin($this->editor);
141 $en_revision = $this->loadRevisionTranslation($entity, 'en');
142 $this->drupalGet($this->getEditUrl($en_revision));
144 'title[0][value]' => "Test $index.6 EN",
145 'moderation_state[0][state]' => 'published',
147 $this->drupalPostForm(NULL, $edit, t('Save'));
148 $entity = $this->storage->loadUnchanged($id);
149 $this->assertFalse($entity->hasTranslation('it'));
150 $this->drupalLogin($this->currentAccount);
152 // Create a published translation again and verify it could be deleted.
153 $this->drupalGet($add_translation_url);
155 'title[0][value]' => "Test $index.7 IT",
156 'moderation_state[0][state]' => 'published',
158 $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
159 $entity = $this->storage->loadUnchanged($id);
160 $this->assertTrue($entity->hasTranslation('it'));
161 $it_revision = $this->loadRevisionTranslation($entity, 'it');
162 $this->assertTrue($it_revision->hasTranslation('it'));
163 $this->drupalGet($overview_url);
164 $this->assertSession()->linkByHrefExists($it_delete_href);
166 // Create a translation draft again and verify it cannot be deleted.
167 $this->drupalGet($this->getEditUrl($it_revision));
169 'title[0][value]' => "Test $index.8 IT",
170 'moderation_state[0][state]' => 'draft',
172 $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
173 $entity = $this->storage->loadUnchanged($id);
174 $this->assertTrue($entity->hasTranslation('it'));
175 $it_revision = $this->loadRevisionTranslation($entity, 'it');
176 $this->assertTrue($it_revision->hasTranslation('it'));
177 $this->drupalGet($overview_url);
178 $this->assertSession()->linkByHrefNotExists($it_delete_href);
180 // Delete the translation draft and verify the translation can be deleted
181 // again, since the active revision is now a default revision.
182 $this->drupalLogin($this->editor);
183 $this->drupalGet($it_revision->toUrl('version-history'));
184 $revision_deletion_url = Url::fromRoute('node.revision_delete_confirm', [
186 'node_revision' => $it_revision->getRevisionId(),
189 'language' => ConfigurableLanguage::load('it'),
193 $revision_deletion_href = $revision_deletion_url->toString();
194 $this->getSession()->getDriver()->click("//a[@href='$revision_deletion_href']");
195 $this->drupalPostForm(NULL, [], 'Delete');
196 $this->drupalLogin($this->currentAccount);
197 $this->drupalGet($overview_url);
198 $this->assertSession()->linkByHrefExists($it_delete_href);
200 // Verify that now the translation can be deleted.
201 $this->drupalGet($it_delete_url);
202 $this->drupalPostForm(NULL, [], 'Delete Italian translation');
203 $entity = $this->storage->loadUnchanged($id);
204 $this->assertFalse($entity->hasTranslation('it'));
205 $it_revision = $this->loadRevisionTranslation($entity, 'it');
206 $this->assertTrue($it_revision->wasDefaultRevision());
207 $this->assertTrue($it_revision->hasTranslation('it'));
208 $this->assertTrue($it_revision->getRevisionId() < $entity->getRevisionId());
209 $this->drupalGet($overview_url);
210 $this->assertSession()->linkByHrefNotExists($this->getEditUrl($it_revision)->toString());
211 $this->assertSession()->linkByHrefExists($add_translation_href);