// Set preferred_langcode to 'zh-hant'.
$user =
$this->
createUser();
$user->
set('preferred_langcode', 'zh-hant'
)->
save();
$preferredLangcode =
$user->
getPreferredLangcode();
$this->
assertSame('zh-hant',
$preferredLangcode);
// Recovery email should respect user preferred langcode by default if
// langcode not set.
$this->
config('system.site'
)->
set('mail', 'test@example.com'
)->
save();
$params['account'
] =
$user;
$default_email = \Drupal::
service('plugin.manager.mail'
)->
mail('user', 'password_reset',
$user->
getEmail(),
$preferredLangcode,
$params);
$this->
assertTrue($default_email['result'
]);
// Assert for zh.
$this->
assertMailString('subject', 'hant subject', 1
);
$this->
assertMailString('body', 'hant body', 1
);
$this->
assertMailString('body', 'zh/user/reset', 1
);
// Recovery email should be fr when langcode specified.
$french_email = \Drupal::
service('plugin.manager.mail'
)->
mail('user', 'password_reset',
$user->
getEmail(), 'fr',
$params);
$this->
assertTrue($french_email['result'
]);