Skip to content

Commit

Permalink
Restore default locale tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Dec 17, 2024
1 parent 1febc5e commit 282adde
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

namespace VuFindTest\Service;

use NumberFormatter;

/**
* CurrencyFormatter Test Class
*
Expand All @@ -50,10 +52,30 @@ class CurrencyFormatterTest extends \PHPUnit\Framework\TestCase
*/
public function testFormatting()
{
// test default settings
$locale = setlocale(LC_MONETARY, '');
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
$defaultCurrencyCode = trim($formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE) ?: '') ?: 'USD';
$cc = new \VuFind\Service\CurrencyFormatter();
$this->assertEquals(
$formatter->formatCurrency(3000, $defaultCurrencyCode),
$cc->convertToDisplayFormat(3000)
);
$this->assertEquals(
$formatter->formatCurrency(3000, 'EUR'),
$cc->convertToDisplayFormat(3000, 'EUR')
);

// test overriding default currency
$cc = new \VuFind\Service\CurrencyFormatter('EUR', 'en_US');
$this->assertEquals('€3,000.00', $cc->convertToDisplayFormat(3000));
$this->assertEquals('$3,000.00', $cc->convertToDisplayFormat(3000, 'USD'));
$cc = new \VuFind\Service\CurrencyFormatter('EUR');
$this->assertEquals(
$formatter->formatCurrency(3000, 'EUR'),
$cc->convertToDisplayFormat(3000)
);
$this->assertEquals(
$formatter->formatCurrency(3000, 'USD'),
$cc->convertToDisplayFormat(3000, 'USD')
);

// test overriding default locale
$cc = new \VuFind\Service\CurrencyFormatter(null, 'de_DE');
Expand Down

0 comments on commit 282adde

Please sign in to comment.