Chris@17
|
1 <?php
|
Chris@17
|
2
|
Chris@17
|
3 namespace Drupal\Tests\node\Functional;
|
Chris@17
|
4
|
Chris@17
|
5 use Drupal\Core\Url;
|
Chris@17
|
6 use Drupal\field\Entity\FieldConfig;
|
Chris@17
|
7 use Drupal\field\Entity\FieldStorageConfig;
|
Chris@17
|
8 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@17
|
9 use Drupal\node\Entity\Node;
|
Chris@17
|
10 use Drupal\node\NodeInterface;
|
Chris@17
|
11 use Drupal\Component\Serialization\Json;
|
Chris@17
|
12
|
Chris@17
|
13 /**
|
Chris@17
|
14 * Create a node with revisions and test viewing, saving, reverting, and
|
Chris@17
|
15 * deleting revisions for users with access for this content type.
|
Chris@17
|
16 *
|
Chris@17
|
17 * @group node
|
Chris@17
|
18 */
|
Chris@17
|
19 class NodeRevisionsTest extends NodeTestBase {
|
Chris@17
|
20
|
Chris@17
|
21 /**
|
Chris@17
|
22 * An array of node revisions.
|
Chris@17
|
23 *
|
Chris@17
|
24 * @var \Drupal\node\NodeInterface[]
|
Chris@17
|
25 */
|
Chris@17
|
26 protected $nodes;
|
Chris@17
|
27
|
Chris@17
|
28 /**
|
Chris@17
|
29 * Revision log messages.
|
Chris@17
|
30 *
|
Chris@17
|
31 * @var array
|
Chris@17
|
32 */
|
Chris@17
|
33 protected $revisionLogs;
|
Chris@17
|
34
|
Chris@17
|
35 /**
|
Chris@17
|
36 * {@inheritdoc}
|
Chris@17
|
37 */
|
Chris@17
|
38 public static $modules = ['node', 'contextual', 'datetime', 'language', 'content_translation'];
|
Chris@17
|
39
|
Chris@17
|
40 /**
|
Chris@17
|
41 * {@inheritdoc}
|
Chris@17
|
42 */
|
Chris@17
|
43 protected function setUp() {
|
Chris@17
|
44 parent::setUp();
|
Chris@17
|
45
|
Chris@17
|
46 // Enable additional languages.
|
Chris@17
|
47 ConfigurableLanguage::createFromLangcode('de')->save();
|
Chris@17
|
48 ConfigurableLanguage::createFromLangcode('it')->save();
|
Chris@17
|
49
|
Chris@17
|
50 $field_storage_definition = [
|
Chris@17
|
51 'field_name' => 'untranslatable_string_field',
|
Chris@17
|
52 'entity_type' => 'node',
|
Chris@17
|
53 'type' => 'string',
|
Chris@17
|
54 'cardinality' => 1,
|
Chris@17
|
55 'translatable' => FALSE,
|
Chris@17
|
56 ];
|
Chris@17
|
57 $field_storage = FieldStorageConfig::create($field_storage_definition);
|
Chris@17
|
58 $field_storage->save();
|
Chris@17
|
59
|
Chris@17
|
60 $field_definition = [
|
Chris@17
|
61 'field_storage' => $field_storage,
|
Chris@17
|
62 'bundle' => 'page',
|
Chris@17
|
63 ];
|
Chris@17
|
64 $field = FieldConfig::create($field_definition);
|
Chris@17
|
65 $field->save();
|
Chris@17
|
66
|
Chris@17
|
67 // Enable translation for page nodes.
|
Chris@17
|
68 \Drupal::service('content_translation.manager')->setEnabled('node', 'page', TRUE);
|
Chris@17
|
69
|
Chris@17
|
70 // Create and log in user.
|
Chris@17
|
71 $web_user = $this->drupalCreateUser(
|
Chris@17
|
72 [
|
Chris@17
|
73 'view page revisions',
|
Chris@17
|
74 'revert page revisions',
|
Chris@17
|
75 'delete page revisions',
|
Chris@17
|
76 'edit any page content',
|
Chris@17
|
77 'delete any page content',
|
Chris@17
|
78 'access contextual links',
|
Chris@17
|
79 'translate any entity',
|
Chris@17
|
80 'administer content types',
|
Chris@17
|
81 ]
|
Chris@17
|
82 );
|
Chris@17
|
83
|
Chris@17
|
84 $this->drupalLogin($web_user);
|
Chris@17
|
85
|
Chris@17
|
86 // Create initial node.
|
Chris@17
|
87 $node = $this->drupalCreateNode();
|
Chris@17
|
88 $settings = get_object_vars($node);
|
Chris@17
|
89 $settings['revision'] = 1;
|
Chris@17
|
90 $settings['isDefaultRevision'] = TRUE;
|
Chris@17
|
91
|
Chris@17
|
92 $nodes = [];
|
Chris@17
|
93 $logs = [];
|
Chris@17
|
94
|
Chris@17
|
95 // Get original node.
|
Chris@17
|
96 $nodes[] = clone $node;
|
Chris@17
|
97
|
Chris@17
|
98 // Create three revisions.
|
Chris@17
|
99 $revision_count = 3;
|
Chris@17
|
100 for ($i = 0; $i < $revision_count; $i++) {
|
Chris@17
|
101 $logs[] = $node->revision_log = $this->randomMachineName(32);
|
Chris@17
|
102
|
Chris@17
|
103 // Create revision with a random title and body and update variables.
|
Chris@17
|
104 $node->title = $this->randomMachineName();
|
Chris@17
|
105 $node->body = [
|
Chris@17
|
106 'value' => $this->randomMachineName(32),
|
Chris@17
|
107 'format' => filter_default_format(),
|
Chris@17
|
108 ];
|
Chris@17
|
109 $node->untranslatable_string_field->value = $this->randomString();
|
Chris@17
|
110 $node->setNewRevision();
|
Chris@17
|
111
|
Chris@17
|
112 // Edit the 1st and 2nd revision with a different user.
|
Chris@17
|
113 if ($i < 2) {
|
Chris@17
|
114 $editor = $this->drupalCreateUser();
|
Chris@17
|
115 $node->setRevisionUserId($editor->id());
|
Chris@17
|
116 }
|
Chris@17
|
117 else {
|
Chris@17
|
118 $node->setRevisionUserId($web_user->id());
|
Chris@17
|
119 }
|
Chris@17
|
120
|
Chris@17
|
121 $node->save();
|
Chris@17
|
122
|
Chris@17
|
123 // Make sure we get revision information.
|
Chris@17
|
124 $node = Node::load($node->id());
|
Chris@17
|
125 $nodes[] = clone $node;
|
Chris@17
|
126 }
|
Chris@17
|
127
|
Chris@17
|
128 $this->nodes = $nodes;
|
Chris@17
|
129 $this->revisionLogs = $logs;
|
Chris@17
|
130 }
|
Chris@17
|
131
|
Chris@17
|
132 /**
|
Chris@17
|
133 * Checks node revision related operations.
|
Chris@17
|
134 */
|
Chris@17
|
135 public function testRevisions() {
|
Chris@17
|
136 $node_storage = $this->container->get('entity.manager')->getStorage('node');
|
Chris@17
|
137 $nodes = $this->nodes;
|
Chris@17
|
138 $logs = $this->revisionLogs;
|
Chris@17
|
139
|
Chris@17
|
140 // Get last node for simple checks.
|
Chris@17
|
141 $node = $nodes[3];
|
Chris@17
|
142
|
Chris@17
|
143 // Confirm the correct revision text appears on "view revisions" page.
|
Chris@17
|
144 $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/view");
|
Chris@17
|
145 $this->assertText($node->body->value, 'Correct text displays for version.');
|
Chris@17
|
146
|
Chris@17
|
147 // Confirm the correct log message appears on "revisions overview" page.
|
Chris@17
|
148 $this->drupalGet("node/" . $node->id() . "/revisions");
|
Chris@17
|
149 foreach ($logs as $revision_log) {
|
Chris@17
|
150 $this->assertText($revision_log, 'Revision log message found.');
|
Chris@17
|
151 }
|
Chris@17
|
152 // Original author, and editor names should appear on revisions overview.
|
Chris@17
|
153 $web_user = $nodes[0]->revision_uid->entity;
|
Chris@17
|
154 $this->assertText(t('by @name', ['@name' => $web_user->getAccountName()]));
|
Chris@17
|
155 $editor = $nodes[2]->revision_uid->entity;
|
Chris@17
|
156 $this->assertText(t('by @name', ['@name' => $editor->getAccountName()]));
|
Chris@17
|
157
|
Chris@17
|
158 // Confirm that this is the default revision.
|
Chris@17
|
159 $this->assertTrue($node->isDefaultRevision(), 'Third node revision is the default one.');
|
Chris@17
|
160
|
Chris@17
|
161 // Confirm that revisions revert properly.
|
Chris@17
|
162 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert", [], t('Revert'));
|
Chris@17
|
163 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [
|
Chris@17
|
164 '@type' => 'Basic page',
|
Chris@17
|
165 '%title' => $nodes[1]->label(),
|
Chris@17
|
166 '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
|
Chris@17
|
167 ]), 'Revision reverted.');
|
Chris@17
|
168 $node_storage->resetCache([$node->id()]);
|
Chris@17
|
169 $reverted_node = $node_storage->load($node->id());
|
Chris@17
|
170 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.');
|
Chris@17
|
171 // Confirm the revision author is the user performing the revert.
|
Chris@17
|
172 $this->assertTrue($reverted_node->getRevisionUserId() == $this->loggedInUser->id(), 'Node revision author is user performing revert.');
|
Chris@17
|
173 // And that its not the revision author.
|
Chris@17
|
174 $this->assertTrue($reverted_node->getRevisionUserId() != $nodes[1]->getRevisionUserId(), 'Node revision author is not original revision author.');
|
Chris@17
|
175
|
Chris@17
|
176 // Confirm that this is not the default version.
|
Chris@17
|
177 $node = node_revision_load($node->getRevisionId());
|
Chris@17
|
178 $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the default one.');
|
Chris@17
|
179
|
Chris@17
|
180 // Confirm revisions delete properly.
|
Chris@17
|
181 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete'));
|
Chris@17
|
182 $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', [
|
Chris@17
|
183 '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
|
Chris@17
|
184 '@type' => 'Basic page',
|
Chris@17
|
185 '%title' => $nodes[1]->label(),
|
Chris@17
|
186 ]), 'Revision deleted.');
|
Chris@17
|
187 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Revision not found.');
|
Chris@17
|
188 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Field revision not found.');
|
Chris@17
|
189
|
Chris@17
|
190 // Set the revision timestamp to an older date to make sure that the
|
Chris@17
|
191 // confirmation message correctly displays the stored revision date.
|
Chris@17
|
192 $old_revision_date = REQUEST_TIME - 86400;
|
Chris@17
|
193 db_update('node_revision')
|
Chris@17
|
194 ->condition('vid', $nodes[2]->getRevisionId())
|
Chris@17
|
195 ->fields([
|
Chris@17
|
196 'revision_timestamp' => $old_revision_date,
|
Chris@17
|
197 ])
|
Chris@17
|
198 ->execute();
|
Chris@17
|
199 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", [], t('Revert'));
|
Chris@17
|
200 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [
|
Chris@17
|
201 '@type' => 'Basic page',
|
Chris@17
|
202 '%title' => $nodes[2]->label(),
|
Chris@17
|
203 '%revision-date' => format_date($old_revision_date),
|
Chris@17
|
204 ]));
|
Chris@17
|
205
|
Chris@17
|
206 // Make a new revision and set it to not be default.
|
Chris@17
|
207 // This will create a new revision that is not "front facing".
|
Chris@17
|
208 $new_node_revision = clone $node;
|
Chris@17
|
209 $new_body = $this->randomMachineName();
|
Chris@17
|
210 $new_node_revision->body->value = $new_body;
|
Chris@17
|
211 // Save this as a non-default revision.
|
Chris@17
|
212 $new_node_revision->setNewRevision();
|
Chris@17
|
213 $new_node_revision->isDefaultRevision = FALSE;
|
Chris@17
|
214 $new_node_revision->save();
|
Chris@17
|
215
|
Chris@17
|
216 $this->drupalGet('node/' . $node->id());
|
Chris@17
|
217 $this->assertNoText($new_body, 'Revision body text is not present on default version of node.');
|
Chris@17
|
218
|
Chris@17
|
219 // Verify that the new body text is present on the revision.
|
Chris@17
|
220 $this->drupalGet("node/" . $node->id() . "/revisions/" . $new_node_revision->getRevisionId() . "/view");
|
Chris@17
|
221 $this->assertText($new_body, 'Revision body text is present when loading specific revision.');
|
Chris@17
|
222
|
Chris@17
|
223 // Verify that the non-default revision vid is greater than the default
|
Chris@17
|
224 // revision vid.
|
Chris@17
|
225 $default_revision = db_select('node', 'n')
|
Chris@17
|
226 ->fields('n', ['vid'])
|
Chris@17
|
227 ->condition('nid', $node->id())
|
Chris@17
|
228 ->execute()
|
Chris@17
|
229 ->fetchCol();
|
Chris@17
|
230 $default_revision_vid = $default_revision[0];
|
Chris@17
|
231 $this->assertTrue($new_node_revision->getRevisionId() > $default_revision_vid, 'Revision vid is greater than default revision vid.');
|
Chris@17
|
232
|
Chris@17
|
233 // Create an 'EN' node with a revision log message.
|
Chris@17
|
234 $node = $this->drupalCreateNode();
|
Chris@17
|
235 $node->title = 'Node title in EN';
|
Chris@17
|
236 $node->revision_log = 'Simple revision message (EN)';
|
Chris@17
|
237 $node->save();
|
Chris@17
|
238
|
Chris@17
|
239 $this->drupalGet("node/" . $node->id() . "/revisions");
|
Chris@17
|
240 $this->assertResponse(403);
|
Chris@17
|
241
|
Chris@17
|
242 // Create a new revision and new log message.
|
Chris@17
|
243 $node = Node::load($node->id());
|
Chris@17
|
244 $node->body->value = 'New text (EN)';
|
Chris@17
|
245 $node->revision_log = 'New revision message (EN)';
|
Chris@17
|
246 $node->setNewRevision();
|
Chris@17
|
247 $node->save();
|
Chris@17
|
248
|
Chris@17
|
249 // Check both revisions are shown on the node revisions overview page.
|
Chris@17
|
250 $this->drupalGet("node/" . $node->id() . "/revisions");
|
Chris@17
|
251 $this->assertText('Simple revision message (EN)');
|
Chris@17
|
252 $this->assertText('New revision message (EN)');
|
Chris@17
|
253
|
Chris@17
|
254 // Create an 'EN' node with a revision log message.
|
Chris@17
|
255 $node = $this->drupalCreateNode();
|
Chris@17
|
256 $node->langcode = 'en';
|
Chris@17
|
257 $node->title = 'Node title in EN';
|
Chris@17
|
258 $node->revision_log = 'Simple revision message (EN)';
|
Chris@17
|
259 $node->save();
|
Chris@17
|
260
|
Chris@17
|
261 $this->drupalGet("node/" . $node->id() . "/revisions");
|
Chris@17
|
262 $this->assertResponse(403);
|
Chris@17
|
263
|
Chris@17
|
264 // Add a translation in 'DE' and create a new revision and new log message.
|
Chris@17
|
265 $translation = $node->addTranslation('de');
|
Chris@17
|
266 $translation->title->value = 'Node title in DE';
|
Chris@17
|
267 $translation->body->value = 'New text (DE)';
|
Chris@17
|
268 $translation->revision_log = 'New revision message (DE)';
|
Chris@17
|
269 $translation->setNewRevision();
|
Chris@17
|
270 $translation->save();
|
Chris@17
|
271
|
Chris@17
|
272 // View the revision UI in 'IT', only the original node revision is shown.
|
Chris@17
|
273 $this->drupalGet("it/node/" . $node->id() . "/revisions");
|
Chris@17
|
274 $this->assertText('Simple revision message (EN)');
|
Chris@17
|
275 $this->assertNoText('New revision message (DE)');
|
Chris@17
|
276
|
Chris@17
|
277 // View the revision UI in 'DE', only the translated node revision is shown.
|
Chris@17
|
278 $this->drupalGet("de/node/" . $node->id() . "/revisions");
|
Chris@17
|
279 $this->assertNoText('Simple revision message (EN)');
|
Chris@17
|
280 $this->assertText('New revision message (DE)');
|
Chris@17
|
281
|
Chris@17
|
282 // View the revision UI in 'EN', only the original node revision is shown.
|
Chris@17
|
283 $this->drupalGet("node/" . $node->id() . "/revisions");
|
Chris@17
|
284 $this->assertText('Simple revision message (EN)');
|
Chris@17
|
285 $this->assertNoText('New revision message (DE)');
|
Chris@17
|
286 }
|
Chris@17
|
287
|
Chris@17
|
288 /**
|
Chris@17
|
289 * Checks that revisions are correctly saved without log messages.
|
Chris@17
|
290 */
|
Chris@17
|
291 public function testNodeRevisionWithoutLogMessage() {
|
Chris@17
|
292 $node_storage = $this->container->get('entity.manager')->getStorage('node');
|
Chris@17
|
293 // Create a node with an initial log message.
|
Chris@17
|
294 $revision_log = $this->randomMachineName(10);
|
Chris@17
|
295 $node = $this->drupalCreateNode(['revision_log' => $revision_log]);
|
Chris@17
|
296
|
Chris@17
|
297 // Save over the same revision and explicitly provide an empty log message
|
Chris@17
|
298 // (for example, to mimic the case of a node form submitted with no text in
|
Chris@17
|
299 // the "log message" field), and check that the original log message is
|
Chris@17
|
300 // preserved.
|
Chris@17
|
301 $new_title = $this->randomMachineName(10) . 'testNodeRevisionWithoutLogMessage1';
|
Chris@17
|
302
|
Chris@17
|
303 $node = clone $node;
|
Chris@17
|
304 $node->title = $new_title;
|
Chris@17
|
305 $node->revision_log = '';
|
Chris@17
|
306 $node->setNewRevision(FALSE);
|
Chris@17
|
307
|
Chris@17
|
308 $node->save();
|
Chris@17
|
309 $this->drupalGet('node/' . $node->id());
|
Chris@17
|
310 $this->assertText($new_title, 'New node title appears on the page.');
|
Chris@17
|
311 $node_storage->resetCache([$node->id()]);
|
Chris@17
|
312 $node_revision = $node_storage->load($node->id());
|
Chris@17
|
313 $this->assertEqual($node_revision->revision_log->value, $revision_log, 'After an existing node revision is re-saved without a log message, the original log message is preserved.');
|
Chris@17
|
314
|
Chris@17
|
315 // Create another node with an initial revision log message.
|
Chris@17
|
316 $node = $this->drupalCreateNode(['revision_log' => $revision_log]);
|
Chris@17
|
317
|
Chris@17
|
318 // Save a new node revision without providing a log message, and check that
|
Chris@17
|
319 // this revision has an empty log message.
|
Chris@17
|
320 $new_title = $this->randomMachineName(10) . 'testNodeRevisionWithoutLogMessage2';
|
Chris@17
|
321
|
Chris@17
|
322 $node = clone $node;
|
Chris@17
|
323 $node->title = $new_title;
|
Chris@17
|
324 $node->setNewRevision();
|
Chris@17
|
325 $node->revision_log = NULL;
|
Chris@17
|
326
|
Chris@17
|
327 $node->save();
|
Chris@17
|
328 $this->drupalGet('node/' . $node->id());
|
Chris@17
|
329 $this->assertText($new_title, 'New node title appears on the page.');
|
Chris@17
|
330 $node_storage->resetCache([$node->id()]);
|
Chris@17
|
331 $node_revision = $node_storage->load($node->id());
|
Chris@17
|
332 $this->assertTrue(empty($node_revision->revision_log->value), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
|
Chris@17
|
333 }
|
Chris@17
|
334
|
Chris@17
|
335 /**
|
Chris@17
|
336 * Gets server-rendered contextual links for the given contextual links IDs.
|
Chris@17
|
337 *
|
Chris@17
|
338 * @param string[] $ids
|
Chris@17
|
339 * An array of contextual link IDs.
|
Chris@17
|
340 * @param string $current_path
|
Chris@17
|
341 * The Drupal path for the page for which the contextual links are rendered.
|
Chris@17
|
342 *
|
Chris@17
|
343 * @return string
|
Chris@17
|
344 * The decoded JSON response body.
|
Chris@17
|
345 */
|
Chris@17
|
346 protected function renderContextualLinks(array $ids, $current_path) {
|
Chris@17
|
347 $post = [];
|
Chris@17
|
348 for ($i = 0; $i < count($ids); $i++) {
|
Chris@17
|
349 $post['ids[' . $i . ']'] = $ids[$i];
|
Chris@17
|
350 }
|
Chris@17
|
351 $response = $this->drupalPost('contextual/render', 'application/json', $post, ['query' => ['destination' => $current_path]]);
|
Chris@17
|
352
|
Chris@17
|
353 return Json::decode($response);
|
Chris@17
|
354 }
|
Chris@17
|
355
|
Chris@17
|
356 /**
|
Chris@17
|
357 * Tests the revision translations are correctly reverted.
|
Chris@17
|
358 */
|
Chris@17
|
359 public function testRevisionTranslationRevert() {
|
Chris@17
|
360 // Create a node and a few revisions.
|
Chris@17
|
361 $node = $this->drupalCreateNode(['langcode' => 'en']);
|
Chris@17
|
362
|
Chris@17
|
363 $initial_revision_id = $node->getRevisionId();
|
Chris@17
|
364 $initial_title = $node->label();
|
Chris@17
|
365 $this->createRevisions($node, 2);
|
Chris@17
|
366
|
Chris@17
|
367 // Translate the node and create a few translation revisions.
|
Chris@17
|
368 $translation = $node->addTranslation('it');
|
Chris@17
|
369 $this->createRevisions($translation, 3);
|
Chris@17
|
370 $revert_id = $node->getRevisionId();
|
Chris@17
|
371 $translated_title = $translation->label();
|
Chris@17
|
372 $untranslatable_string = $node->untranslatable_string_field->value;
|
Chris@17
|
373
|
Chris@17
|
374 // Create a new revision for the default translation in-between a series of
|
Chris@17
|
375 // translation revisions.
|
Chris@17
|
376 $this->createRevisions($node, 1);
|
Chris@17
|
377 $default_translation_title = $node->label();
|
Chris@17
|
378
|
Chris@17
|
379 // And create a few more translation revisions.
|
Chris@17
|
380 $this->createRevisions($translation, 2);
|
Chris@17
|
381 $translation_revision_id = $translation->getRevisionId();
|
Chris@17
|
382
|
Chris@17
|
383 // Now revert the a translation revision preceding the last default
|
Chris@17
|
384 // translation revision, and check that the desired value was reverted but
|
Chris@17
|
385 // the default translation value was preserved.
|
Chris@17
|
386 $revert_translation_url = Url::fromRoute('node.revision_revert_translation_confirm', [
|
Chris@17
|
387 'node' => $node->id(),
|
Chris@17
|
388 'node_revision' => $revert_id,
|
Chris@17
|
389 'langcode' => 'it',
|
Chris@17
|
390 ]);
|
Chris@17
|
391 $this->drupalPostForm($revert_translation_url, [], t('Revert'));
|
Chris@17
|
392 /** @var \Drupal\node\NodeStorage $node_storage */
|
Chris@17
|
393 $node_storage = $this->container->get('entity.manager')->getStorage('node');
|
Chris@17
|
394 $node_storage->resetCache();
|
Chris@17
|
395 /** @var \Drupal\node\NodeInterface $node */
|
Chris@17
|
396 $node = $node_storage->load($node->id());
|
Chris@17
|
397 $this->assertTrue($node->getRevisionId() > $translation_revision_id);
|
Chris@17
|
398 $this->assertEqual($node->label(), $default_translation_title);
|
Chris@17
|
399 $this->assertEqual($node->getTranslation('it')->label(), $translated_title);
|
Chris@17
|
400 $this->assertNotEqual($node->untranslatable_string_field->value, $untranslatable_string);
|
Chris@17
|
401
|
Chris@17
|
402 $latest_revision_id = $translation->getRevisionId();
|
Chris@17
|
403
|
Chris@17
|
404 // Now revert the a translation revision preceding the last default
|
Chris@17
|
405 // translation revision again, and check that the desired value was reverted
|
Chris@17
|
406 // but the default translation value was preserved. But in addition the
|
Chris@17
|
407 // untranslated field will be reverted as well.
|
Chris@17
|
408 $this->drupalPostForm($revert_translation_url, ['revert_untranslated_fields' => TRUE], t('Revert'));
|
Chris@17
|
409 $node_storage->resetCache();
|
Chris@17
|
410 /** @var \Drupal\node\NodeInterface $node */
|
Chris@17
|
411 $node = $node_storage->load($node->id());
|
Chris@17
|
412 $this->assertTrue($node->getRevisionId() > $latest_revision_id);
|
Chris@17
|
413 $this->assertEqual($node->label(), $default_translation_title);
|
Chris@17
|
414 $this->assertEqual($node->getTranslation('it')->label(), $translated_title);
|
Chris@17
|
415 $this->assertEqual($node->untranslatable_string_field->value, $untranslatable_string);
|
Chris@17
|
416
|
Chris@17
|
417 $latest_revision_id = $translation->getRevisionId();
|
Chris@17
|
418
|
Chris@17
|
419 // Now revert the entity revision to the initial one where the translation
|
Chris@17
|
420 // didn't exist.
|
Chris@17
|
421 $revert_url = Url::fromRoute('node.revision_revert_confirm', [
|
Chris@17
|
422 'node' => $node->id(),
|
Chris@17
|
423 'node_revision' => $initial_revision_id,
|
Chris@17
|
424 ]);
|
Chris@17
|
425 $this->drupalPostForm($revert_url, [], t('Revert'));
|
Chris@17
|
426 $node_storage->resetCache();
|
Chris@17
|
427 /** @var \Drupal\node\NodeInterface $node */
|
Chris@17
|
428 $node = $node_storage->load($node->id());
|
Chris@17
|
429 $this->assertTrue($node->getRevisionId() > $latest_revision_id);
|
Chris@17
|
430 $this->assertEqual($node->label(), $initial_title);
|
Chris@17
|
431 $this->assertFalse($node->hasTranslation('it'));
|
Chris@17
|
432 }
|
Chris@17
|
433
|
Chris@17
|
434 /**
|
Chris@17
|
435 * Creates a series of revisions for the specified node.
|
Chris@17
|
436 *
|
Chris@17
|
437 * @param \Drupal\node\NodeInterface $node
|
Chris@17
|
438 * The node object.
|
Chris@17
|
439 * @param $count
|
Chris@17
|
440 * The number of revisions to be created.
|
Chris@17
|
441 */
|
Chris@17
|
442 protected function createRevisions(NodeInterface $node, $count) {
|
Chris@17
|
443 for ($i = 0; $i < $count; $i++) {
|
Chris@17
|
444 $node->title = $this->randomString();
|
Chris@17
|
445 $node->untranslatable_string_field->value = $this->randomString();
|
Chris@17
|
446 $node->setNewRevision(TRUE);
|
Chris@17
|
447 $node->save();
|
Chris@17
|
448 }
|
Chris@17
|
449 }
|
Chris@17
|
450
|
Chris@17
|
451 }
|