annotate core/modules/node/src/Tests/NodeRevisionsTest.php @ 16:c2387f117808

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