| 1 | <?php |
| 2 | /** |
| 3 | * Test the number_format_i18n function by providing a string, wrong format, |
| 4 | * custom separators, and agains the values from en_US (, for thousands - . for decimal) |
| 5 | * and pt_BR (. for thousands - , for decimal). |
| 6 | * |
| 7 | * @group functions |
| 8 | */ |
| 9 | class Tests_Functions_number_format_i18n extends WP_UnitTestCase { |
| 10 | |
| 11 | /** |
| 12 | * |
| 13 | */ |
| 14 | function test_number_format_i18n_number_is_not_number() { |
| 15 | |
| 16 | $this->assertEquals( '0', number_format_i18n( 'seven' ) ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * |
| 21 | */ |
| 22 | function test_number_format_i18n_decimal_is_not_number() { |
| 23 | |
| 24 | $this->assertEquals( number_format_i18n( 10, 'seven' ) , '10' ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * |
| 30 | */ |
| 31 | function test_number_format_i18n_custom_separator() { |
| 32 | global $wp_locale; |
| 33 | $wp_locale->number_format['decimal_point'] = '@'; |
| 34 | $wp_locale->number_format['thousands_sep'] = '^'; |
| 35 | |
| 36 | $this->assertEquals( '1^000@00', number_format_i18n( 1000.00, 2 ) ); |
| 37 | $this->assertEquals( '1^000@00', number_format_i18n( (int)1000, 2 ) ); |
| 38 | $this->assertEquals( '1^234^567^890@00000', number_format_i18n( 1234567890.00, 5 ) ); |
| 39 | $this->assertEquals( '1^234^567^890@00000', number_format_i18n( 1234567890.99999, 5 ) ); |
| 40 | $this->assertEquals( '1^234^567^890@00000', number_format_i18n( 1234567890.55555, 5 ) ); |
| 41 | // clear $wp_locale |
| 42 | $wp_locale = null; |
| 43 | } |
| 44 | /** |
| 45 | * |
| 46 | */ |
| 47 | function test_number_format_i18n_no_global_and_us() { |
| 48 | |
| 49 | $this->assertEquals( '1,000.00', number_format_i18n( 1000.00, 2 ) ); |
| 50 | $this->assertEquals( '1,000.00', number_format_i18n( (int)1000, 2 ) ); |
| 51 | $this->assertEquals( '1,234,567,890.00000', number_format_i18n( 1234567890.00, 5 ) ); |
| 52 | $this->assertEquals( '1,234,567,890.00000', number_format_i18n( 1234567890.99999, 5 ) ); |
| 53 | $this->assertEquals( '1,234,567,890.00000', number_format_i18n( 1234567890.55555, 5 ) ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * |
| 58 | */ |
| 59 | function test_number_format_i18n_brazil() { |
| 60 | global $wp_locale; |
| 61 | $wp_locale->number_format['decimal_point'] = ','; |
| 62 | $wp_locale->number_format['thousands_sep'] = '.'; |
| 63 | |
| 64 | $this->assertEquals( '1.000,00', number_format_i18n( 1000.00, 2 ) ); |
| 65 | $this->assertEquals( '1.000,00', number_format_i18n( (int)1000, 2 ) ); |
| 66 | $this->assertEquals( '1.234.567.890,00000', number_format_i18n( 1234567890.00, 5 ) ); |
| 67 | $this->assertEquals( '1.234.567.890,00000', number_format_i18n( 1234567890.99999, 5 ) ); |
| 68 | $this->assertEquals( '1.234.567.890,00000', number_format_i18n( 1234567890.55555, 5 ) ); |
| 69 | // clear $wp_locale |
| 70 | $wp_locale = null; |
| 71 | } |
| 72 | } |
| 73 | No newline at end of file |