Make WordPress Core

Ticket #36029: 36029.diff

File 36029.diff, 1.7 KB (added by swissspidy, 8 years ago)
  • new file tests/phpunit/tests/functions/numberFormatI18n.php

    diff --git tests/phpunit/tests/functions/numberFormatI18n.php tests/phpunit/tests/functions/numberFormatI18n.php
    new file mode 100644
    index 0000000..753e811
    - +  
     1<?php
     2
     3/**
     4 * Tests for number_format_i18n()
     5 *
     6 * @group functions.php
     7 * @group i18n
     8 */
     9class Tests_Functions_Number_Format_I18n extends WP_UnitTestCase {
     10        /**
     11         * @var WP_Locale
     12         */
     13        protected $locale;
     14
     15        public function setUp() {
     16                $this->locale = clone $GLOBALS['wp_locale'];
     17        }
     18
     19        public function tearDown() {
     20                $GLOBALS['wp_locale'] = $this->locale;
     21        }
     22
     23        public function test_should_fall_back_to_number_format_when_wp_locale_is_not_set(  ) {
     24                $GLOBALS['wp_locale'] = null;
     25
     26                $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) );
     27                $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, 4 ) );
     28        }
     29
     30        public function test_should_respect_number_format_of_locale(  ) {
     31                global $wp_locale;
     32                $wp_locale->number_format['decimal_point'] = '@';
     33                $wp_locale->number_format['thousands_sep'] = '^';
     34
     35                $this->assertEquals( '123^457', number_format_i18n( 123456.789, 0 ) );
     36                $this->assertEquals( '123^456@7890', number_format_i18n( 123456.789, 4 ) );
     37        }
     38
     39        public function test_should_default_to_en_us_format(  ) {
     40                $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) );
     41                $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, 4 ) );
     42        }
     43
     44        public function test_should_handle_negative_precision(  ) {
     45                $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) );
     46                $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, -4 ) );
     47        }
     48}