diff --git a/tests/src/Kernel/FieldTest.php b/tests/src/Kernel/FieldTest.php index 20839ac..6990c77 100644 --- a/tests/src/Kernel/FieldTest.php +++ b/tests/src/Kernel/FieldTest.php @@ -26,6 +26,11 @@ use Drupal\node\Entity\NodeType; class FieldTest extends KernelTestBase { /** + * @var \Drupal\filter\FilterFormatInterface + */ + protected $testFormat; + + /** * Modules to enable. * * @var array @@ -61,28 +66,28 @@ class FieldTest extends KernelTestBase { 'label' => 'Test field', ]); $field->save(); - } - /** - * Tests [entity:field_name] tokens. - */ - public function testEntityFieldTokens() { - // Create a node with a value in the text field and test its token. - $format = FilterFormat::create([ + $this->testFormat = FilterFormat::create([ 'format' => 'test', 'weight' => 1, 'filters' => [ 'filter_html_escape' => ['status' => TRUE], ], ]); - $format->save(); + $this->testFormat->save(); + } + /** + * Tests [entity:field_name] tokens. + */ + public function testEntityFieldTokens() { + // Create a node with a value in the text field and test its token. $entity = Node::create([ 'title' => 'Test node title', 'type' => 'article', 'test_field' => [ 'value' => 'foo', - 'format' => $format->id(), + 'format' => $this->testFormat->id(), ], ]); $entity->save(); @@ -152,24 +157,20 @@ class FieldTest extends KernelTestBase { */ public function testTokenViewMode() { $value = 'A really long string that should be trimmed by the special formatter on token view we are going to have.'; + + // The formatter we are going to use will eventually call Unicode::strlen. + // This expects that the Unicode has already been explicitly checked, which + // happens in DrupalKernel. But since that doesn't run in kernel tests, we + // explicitly call this here. Unicode::check(); // Create a node with a value in the text field and test its token. - $format = FilterFormat::create([ - 'format' => 'test', - 'weight' => 1, - 'filters' => [ - 'filter_html_escape' => ['status' => TRUE], - ], - ]); - $format->save(); - $entity = Node::create([ 'title' => 'Test node title', 'type' => 'article', 'test_field' => [ 'value' => $value, - 'format' => $format->id(), + 'format' => $this->testFormat->id(), ], ]); $entity->save(); @@ -178,6 +179,10 @@ class FieldTest extends KernelTestBase { 'test_field' => Markup::create($value), ]); + // Now, create a token view mode which sets a different format for + // test_field. When replacing tokens, this formatter should be picked over + // the default formatter for the field type. + // @see field_tokens(). $view_mode = EntityViewMode::create([ 'id' => 'node.token', 'targetEntityType' => 'node',