comparison core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
15:e200cb7efeb3 16:c2387f117808
23 * Revision logs of nodes created by the setup method. 23 * Revision logs of nodes created by the setup method.
24 * 24 *
25 * @var string[] 25 * @var string[]
26 */ 26 */
27 protected $revisionLogs; 27 protected $revisionLogs;
28
29 /**
30 * An arbitrary user for revision authoring.
31 *
32 * @var \Drupal\user\UserInterface
33 */
34 protected $revisionUser;
28 35
29 /** 36 /**
30 * {@inheritdoc} 37 * {@inheritdoc}
31 */ 38 */
32 protected function setUp() { 39 protected function setUp() {
45 $this->drupalLogin($web_user); 52 $this->drupalLogin($web_user);
46 53
47 // Create an initial node. 54 // Create an initial node.
48 $node = $this->drupalCreateNode(); 55 $node = $this->drupalCreateNode();
49 56
57 // Create a user for revision authoring.
58 // This must be different from user performing revert.
59 $this->revisionUser = $this->drupalCreateUser();
60
50 $settings = get_object_vars($node); 61 $settings = get_object_vars($node);
51 $settings['revision'] = 1; 62 $settings['revision'] = 1;
52 63
53 $nodes = []; 64 $nodes = [];
54 $logs = []; 65 $logs = [];
84 $node->body = [ 95 $node->body = [
85 'value' => $this->randomMachineName(32), 96 'value' => $this->randomMachineName(32),
86 'format' => filter_default_format(), 97 'format' => filter_default_format(),
87 ]; 98 ];
88 $node->setNewRevision(); 99 $node->setNewRevision();
100 // Ensure the revision author is a different user.
101 $node->setRevisionUserId($this->revisionUser->id());
89 $node->save(); 102 $node->save();
90 103
91 return $node; 104 return $node;
92 } 105 }
93 106
138 ]), 151 ]),
139 'Revision reverted.'); 152 'Revision reverted.');
140 $node_storage->resetCache([$node->id()]); 153 $node_storage->resetCache([$node->id()]);
141 $reverted_node = $node_storage->load($node->id()); 154 $reverted_node = $node_storage->load($node->id());
142 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); 155 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.');
156
157 // Confirm the revision author is the user performing the revert.
158 $this->assertTrue($reverted_node->getRevisionUserId() == $this->loggedInUser->id(), 'Node revision author is user performing revert.');
159 // And that its not the revision author.
160 $this->assertTrue($reverted_node->getRevisionUserId() != $this->revisionUser->id(), 'Node revision author is not original revision author.');
143 161
144 // Confirm that this is not the current version. 162 // Confirm that this is not the current version.
145 $node = node_revision_load($node->getRevisionId()); 163 $node = node_revision_load($node->getRevisionId());
146 $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the current one.'); 164 $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the current one.');
147 165