annotate core/modules/node/tests/src/Functional/NodeRevisionsTest.php @ 19:fa3358dc1485 tip

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