Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function NodeRevisionsTestCase::testRevisions

Checks node revision related operations.

File

modules/node/node.test, line 218

Class

NodeRevisionsTestCase
Tests the node revision functionality.

Code

function testRevisions() {
 $nodes = $this->nodes ;
 $logs = $this->logs ;
 // Get last node for simple checks.
 $node = $nodes[3];
 // Confirm the correct revision text appears on "view revisions" page.
 $this->drupalGet ("node/{$node->nid}/revisions/{$node->vid}/view");
 $this->assertText ($node->body[LANGUAGE_NONE ][0]['value'], 'Correct text displays for version.');
 // Confirm the correct log message appears on "revisions overview" page.
 $this->drupalGet ("node/{$node->nid}/revisions");
 foreach ($logs as $log) {
 $this->assertText ($log, 'Log message found.');
 }
 // Confirm that revisions revert properly.
 $this->drupalPost ("node/{$node->nid}/revisions/{$nodes[1]->vid}/revert", array(), t ('Revert'));
 $this->assertRaw (t ('@type %title has been reverted back to the revision from %revision-date.', array(
 '@type' => 'Basic page',
 '%title' => $nodes[1]->title ,
 '%revision-date' => format_date ($nodes[1]->revision_timestamp),
 )), 'Revision reverted.');
 $reverted_node = node_load ($node->nid);
 $this->assertTrue($nodes[1]->body[LANGUAGE_NONE ][0]['value'] == $reverted_node->body[LANGUAGE_NONE ][0]['value'], 'Node reverted correctly.');
 // Confirm revisions delete properly.
 $this->drupalPost ("node/{$node->nid}/revisions/{$nodes[1]->vid}/delete", array(), t ('Delete'));
 $this->assertRaw (t ('Revision from %revision-date of @type %title has been deleted.', array(
 '%revision-date' => format_date ($nodes[1]->revision_timestamp),
 '@type' => 'Basic page',
 '%title' => $nodes[1]->title ,
 )), 'Revision deleted.');
 $this->assertTrue(db_query ('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(
 ':nid' => $node->nid,
 ':vid' => $nodes[1]->vid,
 ))
 ->fetchField () == 0, 'Revision not found.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.