3 namespace Drupal\diff\Tests;
4 use Drupal\Tests\diff\Functional\CoreVersionUiTestTrait;
7 * Test diff functionality with localization and translation.
11 class DiffLocaleTest extends DiffTestBase {
13 use CoreVersionUiTestTrait;
20 public static $modules = [
22 'content_translation',
28 protected function setUp() {
31 $this->drupalLogin($this->rootUser);
33 // Add French language.
35 'predefined_langcode' => 'fr',
37 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
39 // Enable content translation on articles.
40 $this->drupalGet('admin/config/regional/content-language');
42 'entity_types[node]' => TRUE,
43 'settings[node][article][translatable]' => TRUE,
44 'settings[node][article][settings][language][language_alterable]' => TRUE,
46 $this->drupalPostForm(NULL, $edit, t('Save configuration'));
50 * Run all independent tests.
52 public function testAll() {
53 $this->doTestTranslationRevisions();
54 $this->doTestUndefinedTranslationFilter();
55 $this->doTestTranslationFilter();
59 * Test Diff functionality for the revisions of a translated node.
61 protected function doTestTranslationRevisions() {
63 // Create an article and its translation. Assert aliases.
65 'title[0][value]' => 'English node',
66 'langcode[0][value]' => 'en',
68 $this->drupalPostNodeForm('node/add/article', $edit, t('Save and publish'));
69 $english_node = $this->drupalGetNodeByTitle('English node');
71 $this->drupalGet('node/' . $english_node->id() . '/translations');
72 $this->clickLink(t('Add'));
74 'title[0][value]' => 'French node',
77 $this->drupalPostNodeForm(NULL, $edit, t('Save and keep published (this translation)'));
78 $this->rebuildContainer();
79 $english_node = $this->drupalGetNodeByTitle('English node');
80 $french_node = $english_node->getTranslation('fr');
82 // Create a new revision on both languages.
84 'title[0][value]' => 'Updated title',
87 $this->drupalPostNodeForm('node/' . $english_node->id() . '/edit', $edit, t('Save and keep published (this translation)'));
89 'title[0][value]' => 'Le titre',
92 $this->drupalPostNodeForm('fr/node/' . $english_node->id() . '/edit', $edit, t('Save and keep published (this translation)'));
94 // View differences between revisions. Check that they don't mix up.
95 $this->drupalGet('node/' . $english_node->id() . '/revisions');
96 $this->drupalGet('node/' . $english_node->id() . '/revisions/view/1/2/split_fields');
97 $this->assertText('Title');
98 $this->assertText('English node');
99 $this->assertText('Updated title');
100 $this->drupalGet('fr/node/' . $english_node->id() . '/revisions');
101 $this->drupalGet('fr/node/' . $english_node->id() . '/revisions/view/1/3/split_fields');
102 $this->assertText('Title');
103 $this->assertNoText('English node');
104 $this->assertNoText('Updated title');
105 $this->assertText('French node');
106 $this->assertText('Le titre');
110 * Tests the translation filtering when navigating trough revisions.
112 protected function doTestTranslationFilter() {
113 // Create a node in English.
114 $node = $this->drupalCreateNode([
116 'title' => 'english_revision_0',
118 $revision1 = $node->getRevisionId();
120 // Translate to french.
121 $node->addTranslation('fr', ['title' => 'french_revision_0']);
124 // Create a revision in English.
125 $english_node = $node->getTranslation('en');
126 $english_node->setTitle('english_revision_1');
127 $english_node->setNewRevision(TRUE);
128 $english_node->save();
129 $revision2 = $node->getRevisionId();
131 // Create a revision in French.
132 $french_node = $node->getTranslation('fr');
133 $french_node->setTitle('french_revision_1');
134 $french_node->setNewRevision(TRUE);
135 $french_node->save();
137 // Create a new revision in English.
138 $english_node = $node->getTranslation('en');
139 $english_node->setTitle('english_revision_2');
140 $english_node->setNewRevision(TRUE);
141 $english_node->save();
143 // Create a new revision in French.
144 $french_node = $node->getTranslation('fr');
145 $french_node->setTitle('french_revision_2');
146 $french_node->setNewRevision(TRUE);
147 $french_node->save();
149 // Compare first two revisions.
150 $this->drupalGet('node/' . $node->id() . '/revisions/view/' . $revision1 . '/' . $revision2 . '/split_fields');
151 $diffs = $this->xpath('//span[@class="diffchange"]');
152 $this->assertEqual($diffs[0], 'english_revision_0');
153 $this->assertEqual($diffs[1], 'english_revision_1');
155 // Check next difference.
156 $this->clickLink('Next change');
157 $diffs = $this->xpath('//span[@class="diffchange"]');
158 $this->assertEqual($diffs[0], 'english_revision_1');
159 $this->assertEqual($diffs[1], 'english_revision_2');
161 // There shouldn't be other differences in the current language.
162 $this->assertNoLink('Next change');
166 * Tests the undefined translation filtering when navigating trough revisions.
168 protected function doTestUndefinedTranslationFilter() {
169 // Create a node in with undefined langcode.
170 $node = $this->drupalCreateNode([
172 'title' => 'undefined_language_revision_0',
175 $revision1 = $node->getRevisionId();
177 // Create 3 new revisions of the node.
178 $node->setTitle('undefined_language_revision_1');
179 $node->setNewRevision(TRUE);
181 $revision2 = $node->getRevisionId();
183 $node->setTitle('undefined_language_revision_2');
184 $node->setNewRevision(TRUE);
187 $node->setTitle('undefined_language_revision_3');
188 $node->setNewRevision(TRUE);
191 // Check the amount of revisions displayed.
192 $this->drupalGet('node/' . $node->id() . '/revisions');
193 $element = $this->xpath('//*[@id="edit-node-revisions-table"]/tbody/tr');
194 $this->assertEqual(count($element), 4);
196 // Compare the first two revisions.
197 $this->drupalGet('node/' . $node->id() . '/revisions/view/' . $revision1 . '/' . $revision2 . '/split_fields');
198 $diffs = $this->xpath('//span[@class="diffchange"]');
199 $this->assertEqual($diffs[0], 'undefined_language_revision_0');
200 $this->assertEqual($diffs[1], 'undefined_language_revision_1');
202 // Compare the next two revisions.
203 $this->clickLink('Next change');
204 $diffs = $this->xpath('//span[@class="diffchange"]');
205 $this->assertEqual($diffs[0], 'undefined_language_revision_1');
206 $this->assertEqual($diffs[1], 'undefined_language_revision_2');