protected function InvoiceConfirmationTest::setUp in Commerce Invoice 8.2
Overrides InvoiceKernelTestBase::setUp
File
- tests/
src/ Kernel/ InvoiceConfirmationTest.php, line 77
Class
- InvoiceConfirmationTest
- Tests the sending of multilingual invoice confirmation emails.
Namespace
Drupal\Tests\commerce_invoice\KernelCode
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'language',
]);
$this
->installSchema('locale', [
'locales_source',
'locales_target',
'locales_location',
]);
foreach (array_keys($this->translations) as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)
->save();
}
// Provide the translated strings by overriding in-memory settings.
$settings = Settings::getAll();
foreach ($this->translations as $langcode => $custom_translation) {
foreach ($custom_translation as $untranslated => $translated) {
$settings['locale_custom_strings_' . $langcode][''][$untranslated] = $translated;
}
}
new Settings($settings);
/** @var \Drupal\commerce_price\CurrencyImporterInterface $currency_importer */
$currency_importer = $this->container
->get('commerce_price.currency_importer');
$currency_importer
->importTranslations(array_keys($this->translations));
/** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
$language_manager = $this->container
->get('language_manager');
// The translated USD symbol is $US in both French and Spanish.
// Invent a new symbol translation for French, to test translations.
$fr_usd = $language_manager
->getLanguageConfigOverride('fr', 'commerce_price.commerce_currency.USD');
$fr_usd
->set('symbol', 'U$D');
$fr_usd
->save();
$this->store = $this
->reloadEntity($this->store);
$this->store
->addTranslation('es', [
'name' => $this->translations['es']['Default store'],
]);
$this->store
->addTranslation('fr', [
'name' => $this->translations['fr']['Default store'],
]);
$this->store
->save();
$user = $this
->createUser();
$this->user = $this
->reloadEntity($user);
$profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'US',
'postal_code' => '53177',
'locality' => 'Milwaukee',
'address_line1' => 'Pabst Blue Ribbon Dr',
'administrative_area' => 'WI',
'given_name' => 'Frederick',
'family_name' => 'Pabst',
],
'uid' => $this->user
->id(),
]);
$profile
->save();
$this->profile = $this
->reloadEntity($profile);
$order_item = OrderItem::create([
'type' => 'test',
'quantity' => 1,
'title' => $this
->randomString(),
'unit_price' => new Price('12.00', 'USD'),
]);
$order_item
->save();
$this->order = Order::create([
'type' => 'default',
'mail' => $this->user
->getEmail(),
'state' => 'completed',
'store_id' => $this->store,
'billing_profile' => $this->profile,
'uid' => $this->user
->id(),
'order_items' => [
$order_item,
],
]);
$this->order
->save();
$this->order = $this
->reloadEntity($this->order);
}