function DecimalFormatterTest::testFormat in Currency 7.2
Test amount formatting.
@depends testPatternValidation
File
- currency/
vendor/ bartfeenstra/ cldr/ src/ BartFeenstra/ Tests/ CLDR/ DecimalFormatterTest.php, line 81 - Contains class \BartFeenstra\Tests\CLDR\DecimalFormatterTest.
Class
Namespace
BartFeenstra\Tests\CLDRCode
function testFormat() {
$numbers = array(
123456789,
-12345678.9,
1234567.89,
-123456.789,
);
$patterns = array(
// Test inconsistent group sizes and a custom negative pattern.
array(
'formatter' => new DecimalFormatter('#,##0.00;#,##0.00-', array(
DecimalFormatter::SYMBOL_SPECIAL_DECIMAL_SEPARATOR => ',',
DecimalFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '.',
)),
'results' => array(
'123.456.789,00',
'12.345.678,90-',
'1.234.567,89',
'123.456,789-',
),
),
// Test without grouping separators, a default negative pattern, no
// decimals, and a pattern that is shorter than the numbers.
array(
'formatter' => new DecimalFormatter('#0.', array(
DecimalFormatter::SYMBOL_SPECIAL_DECIMAL_SEPARATOR => ',',
DecimalFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '',
)),
'results' => array(
'123456789,',
'-12345678,',
'1234567,',
'-123456,',
),
),
// Test identical decimal and grouping separators, identical positive
// and negative patterns, and redundant hashes and grouping separators.
array(
'formatter' => new DecimalFormatter('###,###,###,##0.00;###,###,###,##0.00', array(
DecimalFormatter::SYMBOL_SPECIAL_DECIMAL_SEPARATOR => '.',
DecimalFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '.',
)),
'results' => array(
'123.456.789.00',
'12.345.678.90',
'1.234.567.89',
'123.456.789',
),
),
// Test some unusual character combinations and positions, and an
// empty decimal separator.
array(
'formatter' => new DecimalFormatter("####000/@##0.<span style=\"text-transform: uppercase';'\">00</span>--;-####000/@##0.<span style=\"text-transform: uppercase';'\">00</span>--", array(
DecimalFormatter::SYMBOL_SPECIAL_DECIMAL_SEPARATOR => '',
DecimalFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '.',
)),
'results' => array(
'123456/@789<span style="text-transform: uppercase;">00</span>--',
'-12345/@678<span style="text-transform: uppercase;">90</span>--',
'1234/@567<span style="text-transform: uppercase;">89</span>--',
'-123/@456<span style="text-transform: uppercase;">789</span>--',
),
),
// Test character escaping.
array(
'formatter' => new DecimalFormatter("##'#'.00", array(
DecimalFormatter::SYMBOL_SPECIAL_DECIMAL_SEPARATOR => ',',
DecimalFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '.',
)),
'results' => array(
'123456789#,00',
'-12345678#,90',
'1234567#,89',
'-123456#,789',
),
),
);
foreach ($patterns as $pattern_info) {
foreach ($numbers as $i => $number) {
$formatter = $pattern_info['formatter'];
$result_expected = $pattern_info['results'][$i];
$result = $formatter
->format($number);
$this
->assertSame($result, $result_expected, 'BartFeenstra\\CLDR\\DecimalFormatter::format() formats amount ' . $number . ' as ' . $result_expected . ' using pattern ' . $formatter->pattern . ' (result was ' . $result . ').');
}
}
}