You are here

public function FieldDefaultTokenNodeTest::testReplacement in Field default token 8

Test that tokens in a field default value get replaced properly.

File

tests/src/Kernel/FieldDefaultTokenNodeTest.php, line 45

Class

FieldDefaultTokenNodeTest
Tests that tokens in default values of node fields get replaced correctly.

Namespace

Drupal\Tests\field_default_token\Kernel

Code

public function testReplacement() {
  $field = $this
    ->createField();
  $field
    ->setDefaultValue('This is the node title: [node:title]')
    ->save();
  $node = Node::create([
    'type' => $this->bundle,
    'title' => 'Test node title',
  ]);

  // Make sure that the token is properly stripped before it can be replaced.
  $expected = [
    [
      'value' => 'This is the node title: ',
    ],
  ];
  $this
    ->assertEquals($expected, $field
    ->getDefaultValue($node));
  $node
    ->save();
  $expected = [
    [
      'value' => 'This is the node title: Test node title',
    ],
  ];
  $this
    ->assertEquals($expected, $field
    ->getDefaultValue($node));
}