$metadata_tests['[user:display-name]'
] =
$bubbleable_metadata;
foreach ($tests as $input =>
$expected) { $bubbleable_metadata =
new BubbleableMetadata();
$output =
$token_service->
replace($input,
['user' =>
$anonymous_user],
['langcode' =>
$language_interface->
getId()],
$bubbleable_metadata);
$this->
assertSame((string) $expected,
(string) $output, "Failed test case: {
$input}"
);
$this->
assertEquals($metadata_tests[$input],
$bubbleable_metadata);
} // Generate login and cancel link.
$tests =
[];
$tests['[user:one-time-login-url]'
] =
user_pass_reset_url($account);
$tests['[user:cancel-url]'
] =
user_cancel_url($account);
// Generate tokens with interface language.
$link = Url::
fromRoute('user.page',
[],
['absolute' => TRUE
])->
toString();
foreach ($tests as $input =>
$expected) { $output =
$token_service->
replace($input,
['user' =>
$account],
['langcode' =>
$language_interface->
getId(), 'callback' => 'user_mail_tokens', 'clear' => TRUE
]);
$this->
assertStringStartsWith($link,
$output, 'Generated URL is in interface language.'
);
} // Generate tokens with the user's preferred language.
$account->preferred_langcode = 'de';