--- /dev/null
+<?php
+
+/**
+ * @file
+ * Helper module for token tests.
+ */
+use Drupal\node\NodeInterface;
+
+/**
+ * Implements hook_page_attachments().
+ */
+function token_module_test_page_attachments() {
+ if ($debug = \Drupal::state()->get('token_page_tokens', array())) {
+ $debug += array('tokens' => array(), 'data' => array(), 'options' => array());
+ foreach (array_keys($debug['tokens']) as $token) {
+ $debug['values'][$token] = \Drupal::token()->replace($token, $debug['data'], $debug['options']);
+ }
+ \Drupal::state()->set('token_page_tokens', $debug);
+ }
+}
+
+/**
+ * Implements hook_ENTITY_TYPE_presave for Node entities.
+ */
+function token_module_test_node_presave(NodeInterface $node) {
+ // Transform tokens in the body.
+ // @see \Drupal\token\Tests\TokenMenuTest::testMenuTokens()
+ if ($node->hasField('body')) {
+ $node->body->value = \Drupal::token()
+ ->replace($node->body->value, ['node' => $node]);
+ }
+}