/** * {@inheritdoc} */ public function resolveCurrencyLocale($language_type = LanguageInterface::TYPE_CONTENT) { if (empty($this->currencyLocales[$language_type])) { $currency_locale = NULL; $language_code = $this->languageManager->getCurrentLanguage($language_type)->getId(); // Try this request's country code. $country_code = $this->eventDispatcher->resolveCountryCode(); if ($country_code) { $currency_locale = $this->currencyLocaleStorage->load($language_code . '_' . $country_code); } // Try the site's default country code. if (!$currency_locale) { $country_code = $this->configFactory->get('system.data')->get('country.default'); if ($country_code) { $currency_locale = $this->currencyLocaleStorage->load($language_code . '_' . $country_code); } } // Try the Currency default. if (!$currency_locale) { $currency_locale = $this->currencyLocaleStorage->load($this::DEFAULT_LOCALE); } if ($currency_locale) { $this->currencyLocales[$language_type] = $currency_locale; } else { throw new \RuntimeException(sprintf('The currency locale for %s could not be loaded.', $this::DEFAULT_LOCALE)); } } return $this->currencyLocales[$language_type]; }
/** * @covers ::resolveCurrencyLocale */ function testResolveCurrencyLocaleWithRequestCountry() { $this->prepareLanguageManager(); $request_country_code = 'IN'; $this->eventDispatcher->expects($this->atLeastOnce())->method('resolveCountryCode')->willReturn($request_country_code); $currency_locale = $this->getMock(CurrencyLocaleInterface::class); $this->currencyLocaleStorage->expects($this->any())->method('load')->with($this->languageManager->getCurrentLanguage(Language::TYPE_CONTENT)->getId() . '_' . $request_country_code)->willReturn($currency_locale); // Test loading the fallback locale. $this->assertSame($currency_locale, $this->sut->resolveCurrencyLocale()); }