You are here

public function NodeRevisionsUiTest::testNodeRevisionDoubleEscapeFix in Zircon Profile 8

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

Checks HTML double escaping of revision logs.

File

core/modules/node/src/Tests/NodeRevisionsUiTest.php, line 87
Contains \Drupal\node\Tests\NodeRevisionsUiTest.

Class

NodeRevisionsUiTest
Tests the UI for controlling node revision behavior.

Namespace

Drupal\node\Tests

Code

public function testNodeRevisionDoubleEscapeFix() {
  $this
    ->drupalLogin($this->editor);
  $nodes = [];

  // Create the node.
  $node = $this
    ->drupalCreateNode();
  $username = [
    '#theme' => 'username',
    '#account' => $this->editor,
  ];
  $editor = \Drupal::service('renderer')
    ->renderPlain($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 = format_date($nodes[0]->revision_timestamp->value, 'short');
  $url = new Url('entity.node.revision', [
    'node' => $nodes[0]
      ->id(),
    'node_revision' => $nodes[0]
      ->getRevisionId(),
  ]);
  $this
    ->assertRaw(\Drupal::l($date, $url) . ' by ' . $editor);

  // Assert the current revision message.
  $date = format_date($nodes[1]->revision_timestamp->value, 'short');
  $this
    ->assertRaw($nodes[1]
    ->link($date) . ' by ' . $editor . '<p class="revision-log">' . $revision_log . '</p>');
}