function NodeRevisionsTest::testNodeRevisionWithoutLogMessage

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeRevisionsTest.php \Drupal\Tests\node\Functional\NodeRevisionsTest::testNodeRevisionWithoutLogMessage()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeRevisionsTest.php \Drupal\Tests\node\Functional\NodeRevisionsTest::testNodeRevisionWithoutLogMessage()
  3. 10 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 340

Class

NodeRevisionsTest
Tests per-content-type node CRUD operation permissions.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeRevisionWithoutLogMessage() : void {
    $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->assertEmpty($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.');
}

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