Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Functional / NodeRevisionsAllTest.php
index 7e71847001e34c2b638d6554ce8ff18fa7a44277..238c7317e2a23fedc891964a366540975c399a36 100644 (file)
@@ -26,6 +26,13 @@ class NodeRevisionsAllTest extends NodeTestBase {
    */
   protected $revisionLogs;
 
+  /**
+   * An arbitrary user for revision authoring.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $revisionUser;
+
   /**
    * {@inheritdoc}
    */
@@ -39,7 +46,7 @@ class NodeRevisionsAllTest extends NodeTestBase {
         'revert page revisions',
         'delete page revisions',
         'edit any page content',
-        'delete any page content'
+        'delete any page content',
       ]
     );
     $this->drupalLogin($web_user);
@@ -47,6 +54,10 @@ class NodeRevisionsAllTest extends NodeTestBase {
     // Create an initial node.
     $node = $this->drupalCreateNode();
 
+    // Create a user for revision authoring.
+    // This must be different from user performing revert.
+    $this->revisionUser = $this->drupalCreateUser();
+
     $settings = get_object_vars($node);
     $settings['revision'] = 1;
 
@@ -86,6 +97,8 @@ class NodeRevisionsAllTest extends NodeTestBase {
       'format' => filter_default_format(),
     ];
     $node->setNewRevision();
+    // Ensure the revision author is a different user.
+    $node->setRevisionUserId($this->revisionUser->id());
     $node->save();
 
     return $node;
@@ -109,7 +122,7 @@ class NodeRevisionsAllTest extends NodeTestBase {
         'revert all revisions',
         'delete all revisions',
         'edit any page content',
-        'delete any page content'
+        'delete any page content',
       ]
     );
     $this->drupalLogin($content_admin);
@@ -134,13 +147,18 @@ class NodeRevisionsAllTest extends NodeTestBase {
       [
         '@type' => 'Basic page',
         '%title' => $nodes[1]->getTitle(),
-        '%revision-date' => format_date($nodes[1]->getRevisionCreationTime())
+        '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
       ]),
       'Revision reverted.');
     $node_storage->resetCache([$node->id()]);
     $reverted_node = $node_storage->load($node->id());
     $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.');
 
+    // Confirm the revision author is the user performing the revert.
+    $this->assertTrue($reverted_node->getRevisionUserId() == $this->loggedInUser->id(), 'Node revision author is user performing revert.');
+    // And that its not the revision author.
+    $this->assertTrue($reverted_node->getRevisionUserId() != $this->revisionUser->id(), 'Node revision author is not original revision author.');
+
     // Confirm that this is not the current version.
     $node = node_revision_load($node->getRevisionId());
     $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the current one.');