FieldDefaultTokenNodeTest.php in Field default token 8
File
tests/src/Kernel/FieldDefaultTokenNodeTest.php
View source
<?php
namespace Drupal\Tests\field_default_token\Kernel;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
class FieldDefaultTokenNodeTest extends FieldDefaultTokenKernelTestBase {
protected $entityTypeId = 'node';
protected $bundle = 'article';
public static $modules = [
'node',
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
NodeType::create([
'type' => $this->bundle,
])
->save();
}
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',
]);
$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));
}
}