function NodeRevisionsUiTest::testNodeRevisionDoubleEscapeFix

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php \Drupal\Tests\node\Functional\NodeRevisionsUiTest::testNodeRevisionDoubleEscapeFix()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php \Drupal\Tests\node\Functional\NodeRevisionsUiTest::testNodeRevisionDoubleEscapeFix()
  3. 10 core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php \Drupal\Tests\node\Functional\NodeRevisionsUiTest::testNodeRevisionDoubleEscapeFix()

Checks HTML double escaping of revision logs.

File

core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php, line 97

Class

NodeRevisionsUiTest
Tests the UI for controlling node revision behavior.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeRevisionDoubleEscapeFix() : void {
    $this->drupalLogin($this->editor);
    $nodes = [];
    // Create the node.
    $node = $this->drupalCreateNode();
    $username = [
        '#theme' => 'username',
        '#account' => $this->editor,
    ];
    $editor = \Drupal::service('renderer')->renderInIsolation($username);
    // Get original node.
    $nodes[] = clone $node;
    // Create revision with a random title and body and update variables.
    $node->title = $this->randomMachineName();
    $node->body = [
        'value' => $this->randomMachineName(32),
        'format' => filter_default_format(),
    ];
    $node->setNewRevision();
    $revision_log = 'Revision <em>message</em> with markup.';
    $node->revision_log->value = $revision_log;
    $node->save();
    // Make sure we get revision information.
    $node = Node::load($node->id());
    $nodes[] = clone $node;
    $this->drupalGet('node/' . $node->id() . '/revisions');
    // Assert the old revision message.
    $date = $this->container
        ->get('date.formatter')
        ->format($nodes[0]->revision_timestamp->value, 'short');
    $url = new Url('entity.node.revision', [
        'node' => $nodes[0]->id(),
        'node_revision' => $nodes[0]->getRevisionId(),
    ]);
    $this->assertSession()
        ->responseContains(Link::fromTextAndUrl($date, $url)->toString() . ' by ' . $editor);
    // Assert the current revision message.
    $date = $this->container
        ->get('date.formatter')
        ->format($nodes[1]->revision_timestamp->value, 'short');
    $this->assertSession()
        ->responseContains($nodes[1]->toLink($date)
        ->toString() . ' by ' . $editor . '<p class="revision-log">' . $revision_log . '</p>');
}

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