diff --git a/core/modules/node/src/Tests/NodeRevisionsAuthorTest.php b/core/modules/node/src/Tests/NodeRevisionsAuthorTest.php new file mode 100644 index 0000000..280de18 --- /dev/null +++ b/core/modules/node/src/Tests/NodeRevisionsAuthorTest.php @@ -0,0 +1,157 @@ +user1 = $this->drupalCreateUser($user_permissions); + $this->user2 = $this->drupalCreateUser($user_permissions); + // Third user is an author only and needs no permissions + $this->user3 = $this->drupalCreateUser(); + + // Create initial node (author: $user1) + $this->drupalLogin($this->user1); + $this->originalNode = $this->drupalCreateNode(); + + // Create a revision (as $user2) showing $user3 as author. + $this->revisedNode = clone $this->originalNode; + $this->revisedNode->revision_log = 'Changed author'; + $this->revisedNode->title = $this->randomMachineName(); + $this->revisedNode->body = array( + 'value' => $this->randomMachineName(32), + 'format' => filter_default_format(), + ); + $this->revisedNode->setOwnerId ($this->user3->id()); + $this->revisedNode->setRevisionAuthorId ($this->user2->id()); + $this->revisedNode->setNewRevision(); + $this->revisedNode->save(); + + // Make sure we reload with revision information + $this->revisedNode = Node::load ($this->revisedNode->id()); + } + + /** + * Checks node revision related operations. + */ + function testRevisions() { + $node_storage = $this->container->get('entity.manager')->getStorage('node'); + + // Confirm the correct revision text appears on "view revisions" page. + $node = $this->revisedNode; + $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/view"); + $this->assertText($node->body->value, 'Correct text displays for version.'); + + // Confirm that in the revised node, $user3 is the author and $user2 is + // the revisor + $this->assertTrue($node->getOwnerId() == $this->user3->id(), + 'The revised node has the correct author.'); + $this->assertTrue($node->getRevisionAuthor()->id() == $this->user2->id(), + 'The revised node has the correct revision author.'); + + // Revert to the original node + $uri = String::format ('node/!nid/revisions/!orignid/revert', + array ( + '!nid' => $node->id(), + '!orignid' => $this->originalNode->getRevisionid() + )); + $this->drupalPostForm($uri, array(), t('Revert')); + $this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.', + array('@type' => 'Basic page', '%title' => $this->originalNode->label(), + '%revision-date' => format_date($this->originalNode->getRevisionCreationTime()))), 'Revision reverted.'); + + // With the reversion done, reload the node and verify that the + // authorship fields have reverted correctly. + $node_storage->resetCache(array($node->id())); + $reverted_node = $node_storage->load($node->id()); + $this->assertTrue(($this->originalNode->body->value == $reverted_node->body->value), 'Node reverted correctly.'); + $this->assertTrue($reverted_node->getOwnerId() == $this->user1->id(), 'Reverted node has the correct author.'); + $this->assertNotNull($reverted_node->getRevisionAuthor(), 'Reverted node has revision author information.'); + $this->assertTrue($reverted_node->getRevisionAuthor()->id() == $this->user1->id(), 'Reverted node has the correct revision author.'); + + // Revert again to the revised version and check that node author and + // revision author fields are correct. + // Revert to the original node + $uri = String::format ('node/!nid/revisions/!revisednid/revert', + array ( + '!nid' => $reverted_node->id(), + '!revisednid' => $this->revisedNode->getRevisionid() + )); + $this->drupalPostForm($uri, array(), t('Revert')); + $this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.', + array('@type' => 'Basic page', '%title' => $this->revisedNode->label(), + '%revision-date' => format_date($this->revisedNode->getRevisionCreationTime()))), 'Revision re-reverted.'); + + // With the reversion done, reload the node and verify that the + // authorship fields have reverted correctly. + $node_storage->resetCache(array($reverted_node->id())); + $rereverted_node = $node_storage->load($reverted_node->id()); + $this->assertTrue(($this->revisedNode->body->value == $rereverted_node->body->value), 'Node re-reverted correctly.'); + $this->assertTrue($rereverted_node->getOwnerId() == $this->user3->id(), 'Re-reverted node has the correct author.'); + $this->assertNotNull($rereverted_node->getRevisionAuthor(), 'Re-reverted node has revision author information.'); + $this->assertTrue($rereverted_node->getRevisionAuthor()->id() == $this->user2->id(), 'Re-reverted node has the correct revision author.'); + } + +}