annotate core/modules/node/src/Tests/NodeRevisionsTest.php @ 12:7a779792577d

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