You are here

function IntegerFormatterTest::testFormat in Currency 7.2

Test amount formatting.

File

currency/vendor/bartfeenstra/cldr/src/BartFeenstra/Tests/CLDR/IntegerFormatterTest.php, line 36
Contains class \BartFeenstra\Tests\CLDR\IntegerFormatterTest.

Class

IntegerFormatterTest
Tests \BartFeenstra\CLDR\IntegerFormatter

Namespace

BartFeenstra\Tests\CLDR

Code

function testFormat() {
  $numbers = array(
    123456789123456789,
    -123456789123456789,
  );
  $patterns = array(
    // Test using the decimal separator as a non-special symbol and a custom
    // negative pattern.
    array(
      'formatter' => new IntegerFormatter('#,##0.00;#,##0.00-', array(
        IntegerFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '.',
      )),
      'results' => array(
        '123.45678.91234.567.89',
        '123.45678.91234.567.89-',
      ),
    ),
    // Test without grouping separators and a default negative pattern.
    array(
      'formatter' => new IntegerFormatter('#0.00', array(
        IntegerFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '',
      )),
      'results' => array(
        '1234567891234567.89',
        '-1234567891234567.89',
      ),
    ),
    // Test redundant hashes and escaped hashes..
    array(
      'formatter' => new IntegerFormatter("###,###,###,###,###,###,#'#'##", array(
        IntegerFormatter::SYMBOL_SPECIAL_GROUPING_SEPARATOR => '#',
      )),
      'results' => array(
        '123#456#789#123#456#7#89',
        '-123#456#789#123#456#7#89',
      ),
    ),
  );
  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\\IntegerFormatter::format() formats amount ' . $number . ' as ' . $result_expected . ' using pattern ' . $formatter->pattern . ' (result was ' . $result . ').');
    }
  }
}