From 4bad4cd246b172d4a01f6149f81596d06c6ad053 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 1 Mar 2016 21:19:20 +0000 Subject: [PATCH] Tests: Add unit tests for `number_format_i18n()`. Props pbearne for initial patch. Fixes #36029. git-svn-id: https://develop.svn.wordpress.org/trunk@36795 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/functions/numberFormatI18n.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/phpunit/tests/functions/numberFormatI18n.php diff --git a/tests/phpunit/tests/functions/numberFormatI18n.php b/tests/phpunit/tests/functions/numberFormatI18n.php new file mode 100644 index 0000000000..8c514b319c --- /dev/null +++ b/tests/phpunit/tests/functions/numberFormatI18n.php @@ -0,0 +1,49 @@ +assertEquals( '123,457', $actual_1 ); + $this->assertEquals( '123,456.7890', $actual_2 ); + } + + public function test_should_respect_number_format_of_locale() { + $decimal_point = $GLOBALS['wp_locale']->number_format['decimal_point']; + $thousands_sep = $GLOBALS['wp_locale']->number_format['thousands_sep']; + + $GLOBALS['wp_locale']->number_format['decimal_point'] = '@'; + $GLOBALS['wp_locale']->number_format['thousands_sep'] = '^'; + + $actual_1 = number_format_i18n( 123456.789, 0 ); + $actual_2 = number_format_i18n( 123456.789, 4 ); + + $GLOBALS['wp_locale']->number_format['decimal_point'] = $decimal_point; + $GLOBALS['wp_locale']->number_format['thousands_sep'] = $thousands_sep; + + $this->assertEquals( '123^457', $actual_1 ); + $this->assertEquals( '123^456@7890', $actual_2 ); + } + + public function test_should_default_to_en_us_format() { + $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) ); + $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, 4 ) ); + } + + public function test_should_handle_negative_precision() { + $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) ); + $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, -4 ) ); + } +}