Skip to content
Snippets Groups Projects
Unverified Commit f7cd4d7d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2944531 by trwill, timmillwood, Berdir: User performing revert should...

Issue #2944531 by trwill, timmillwood, Berdir: User performing revert should be set as revision author (revision_uid)
parent db479e49
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -128,6 +128,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->revision = $this->prepareRevertedRevision($this->revision, $form_state);
$this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
$this->revision->setRevisionUserId($this->currentUser()->id());
$this->revision->setRevisionCreationTime($this->time->getRequestTime());
$this->revision->setChangedTime($this->time->getRequestTime());
$this->revision->save();
......
......@@ -109,8 +109,8 @@ protected function setUp() {
$node->untranslatable_string_field->value = $this->randomString();
$node->setNewRevision();
// Edit the 2nd revision with a different user.
if ($i == 1) {
// Edit the 1st and 2nd revision with a different user.
if ($i < 2) {
$editor = $this->drupalCreateUser();
$node->setRevisionUserId($editor->id());
}
......@@ -179,6 +179,10 @@ public function testRevisions() {
$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() != $nodes[1]->getRevisionUserId(), 'Node revision author is not original revision author.');
// Confirm that this is not the default version.
$node = node_revision_load($node->getRevisionId());
......
......@@ -26,6 +26,13 @@ class NodeRevisionsAllTest extends NodeTestBase {
*/
protected $revisionLogs;
/**
* An arbitrary user for revision authoring.
*
* @var \Drupal\user\UserInterface
*/
protected $revisionUser;
/**
* {@inheritdoc}
*/
......@@ -47,6 +54,10 @@ protected function setUp() {
// 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 @@ protected function createNodeRevision(NodeInterface $node) {
'format' => filter_default_format(),
];
$node->setNewRevision();
// Ensure the revision author is a different user.
$node->setRevisionUserId($this->revisionUser->id());
$node->save();
return $node;
......@@ -141,6 +154,11 @@ public function testRevisions() {
$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.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment