You are here

function EntityTest::testEntityOriginal in Token 8

Test the [entity:original:*] tokens.

File

tests/src/Kernel/EntityTest.php, line 80

Class

EntityTest
Tests entity tokens.

Namespace

Drupal\Tests\token\Kernel

Code

function testEntityOriginal() {
  $node = Node::create([
    'type' => 'page',
    'title' => 'Original title',
  ]);
  $node
    ->save();
  $tokens = [
    'nid' => $node
      ->id(),
    'title' => 'Original title',
    'original' => NULL,
    'original:nid' => NULL,
  ];
  $this
    ->assertTokens('node', [
    'node' => $node,
  ], $tokens);

  // Emulate the original entity property that would be available from
  // node_save() and change the title for the node.
  $node->original = \Drupal::entityTypeManager()
    ->getStorage('node')
    ->loadUnchanged($node
    ->id());
  $node->title = 'New title';
  $tokens = [
    'nid' => $node
      ->id(),
    'title' => 'New title',
    'original' => 'Original title',
    'original:nid' => $node
      ->id(),
  ];
  $this
    ->assertTokens('node', [
    'node' => $node,
  ], $tokens);
}