You are here

function NodeRevisionsTest::testNodeRevisionWithoutLogMessage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeRevisionsTest.php \Drupal\node\Tests\NodeRevisionsTest::testNodeRevisionWithoutLogMessage()

Checks that revisions are correctly saved without log messages.

File

core/modules/node/src/Tests/NodeRevisionsTest.php, line 224
Contains \Drupal\node\Tests\NodeRevisionsTest.

Class

NodeRevisionsTest
Create a node with revisions and test viewing, saving, reverting, and deleting revisions for users with access for this content type.

Namespace

Drupal\node\Tests

Code

function testNodeRevisionWithoutLogMessage() {
  $node_storage = $this->container
    ->get('entity.manager')
    ->getStorage('node');

  // Create a node with an initial log message.
  $revision_log = $this
    ->randomMachineName(10);
  $node = $this
    ->drupalCreateNode(array(
    'revision_log' => $revision_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
    ->randomMachineName(10) . 'testNodeRevisionWithoutLogMessage1';
  $node = clone $node;
  $node->title = $new_title;
  $node->revision_log = '';
  $node
    ->setNewRevision(FALSE);
  $node
    ->save();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertText($new_title, 'New node title appears on the page.');
  $node_storage
    ->resetCache(array(
    $node
      ->id(),
  ));
  $node_revision = $node_storage
    ->load($node
    ->id());
  $this
    ->assertEqual($node_revision->revision_log->value, $revision_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 revision log message.
  $node = $this
    ->drupalCreateNode(array(
    'revision_log' => $revision_log,
  ));

  // Save a new node revision without providing a log message, and check that
  // this revision has an empty log message.
  $new_title = $this
    ->randomMachineName(10) . 'testNodeRevisionWithoutLogMessage2';
  $node = clone $node;
  $node->title = $new_title;
  $node
    ->setNewRevision();
  $node->revision_log = NULL;
  $node
    ->save();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertText($new_title, 'New node title appears on the page.');
  $node_storage
    ->resetCache(array(
    $node
      ->id(),
  ));
  $node_revision = $node_storage
    ->load($node
    ->id());
  $this
    ->assertTrue(empty($node_revision->revision_log->value), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
}