1 node.test NodeRevisionsTestCase::testNodeRevisionWithoutLogMessage()

Checks that revisions are correctly saved without log messages.

File

core/modules/node/tests/node.test, line 307
Tests for node.module.

Class

NodeRevisionsTestCase
Tests the node revision functionality.

Code

function testNodeRevisionWithoutLogMessage() {
  // Create a node with an initial log message.
  $log = $this->randomName(10);
  $node = $this->backdropCreateNode(array('log' => $log));

  // Save over the same revision and explicitly provide an empty log message
  // (for example, to mimic the case of a node form submitted with no text in
  // the "log message" field), and check that the original log message is
  // preserved.
  $new_title = $this->randomName(10) . 'testNodeRevisionWithoutLogMessage1';

  $node = clone $node;
  $node->title = $new_title;
  $node->log = '';
  $node->revision = FALSE;

  $node->save();
  $this->backdropGet('node/' . $node->nid);
  $this->assertText($new_title, 'New node title appears on the page.');
  $node_revision = node_load($node->nid, NULL, TRUE);
  $this->assertEqual($node_revision->log, $log, 'After an existing node revision is re-saved without a log message, the original log message is preserved.');

  // Create another node with an initial log message.
  $node = $this->backdropCreateNode(array('log' => $log));

  // Save a new node revision without providing a log message, and check that
  // this revision has an empty log message.
  $new_title = $this->randomName(10) . 'testNodeRevisionWithoutLogMessage2';

  $node = clone $node;
  $node->title = $new_title;
  $node->revision = TRUE;
  $node->log = NULL;

  $node->save();
  $this->backdropGet('node/' . $node->nid);
  $this->assertText($new_title, 'New node title appears on the page.');
  $node_revision = node_load($node->nid, NULL, TRUE);
  $this->assertTrue(empty($node_revision->log), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
}