You are here

public function NodeRevisionsTest::testNodeRevisionWithoutLogMessage in Drupal 9

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

Checks that revisions are correctly saved without log messages.

File

core/modules/node/tests/src/Functional/NodeRevisionsTest.php, line 320

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\Tests\node\Functional

Code

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

  // Create a node with an initial log message.
  $revision_log = $this
    ->randomMachineName(10);
  $node = $this
    ->drupalCreateNode([
    '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
    ->assertSession()
    ->pageTextContains($new_title);
  $node_storage
    ->resetCache([
    $node
      ->id(),
  ]);
  $node_revision = $node_storage
    ->load($node
    ->id());
  $this
    ->assertEquals($revision_log, $node_revision->revision_log->value, '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([
    '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
    ->assertSession()
    ->pageTextContains($new_title);
  $node_storage
    ->resetCache([
    $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.');
}