-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path35840_2.patch
107 lines (105 loc) · 3.73 KB
/
35840_2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php (revision 36792)
+++ src/wp-includes/functions.php (working copy)
@@ -219,9 +219,9 @@
global $wp_locale;
if ( isset( $wp_locale ) ) {
- $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
+ $formatted = number_format( (float) $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
} else {
- $formatted = number_format( $number, absint( $decimals ) );
+ $formatted = number_format( (float) $number, absint( $decimals ) );
}
/**
Index: tests/phpunit/tests/functions/number_format_i18n.php
===================================================================
--- tests/phpunit/tests/functions/number_format_i18n.php (nonexistent)
+++ tests/phpunit/tests/functions/number_format_i18n.php (working copy)
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Test the number_format_i18n function by providing a string, wrong format,
+ * custom separators, and agains the values from en_US (, for thousands - . for decimal)
+ * and pt_BR (. for thousands - , for decimal).
+ *
+ * @group functions
+ */
+class Tests_Functions_number_format_i18n extends WP_UnitTestCase {
+
+ /**
+ *
+ */
+ function test_number_format_i18n_number_is_not_number() {
+
+ $this->assertEquals( 0, number_format_i18n( 'seven' ) );
+
+ }
+ /**
+ *
+ */
+ function test_number_format_i18n_number_in_a_string() {
+
+ $this->assertEquals( 7, number_format_i18n( '7' ) );
+ }
+ /**
+ *
+ */
+ function test_number_format_i18n_decimal_is_not_number() {
+
+ $this->assertEquals( number_format_i18n( 10, 'seven' ) , '10' );
+ }
+ /**
+ *
+ */
+ function test_number_format_i18n_decimal_is_not_number_no_in_string() {
+
+ $this->assertEquals( number_format_i18n( 10, '7' ) , 10.0000000 );
+ }
+ /**
+ *
+ *
+ */
+ function test_number_format_i18n_custom_separator() {
+ global $wp_locale;
+ $wp_locale->number_format['decimal_point'] = '@';
+ $wp_locale->number_format['thousands_sep'] = '^';
+
+ $this->assertEquals( '1^000@00', number_format_i18n( 1000.00, 2 ) );
+ $this->assertEquals( '1^000@00', number_format_i18n( (int)1000, 2 ) );
+ $this->assertEquals( '1^234^567^890@00000', number_format_i18n( 1234567890.00, 5 ) );
+ $this->assertEquals( '1^234^567^890@99999', number_format_i18n( 1234567890.99999, 5 ) );
+ $this->assertEquals( '1^234^567^890@50000', number_format_i18n( 1234567890.5, 5 ) );
+ // clear $wp_locale
+ $wp_locale = null;
+ }
+ /**
+ *
+ */
+ function test_number_format_i18n_no_global_and_us() {
+
+ $this->assertEquals( '1,000.00', number_format_i18n( 1000.00, 2 ) );
+ $this->assertEquals( '1,000.00', number_format_i18n( (int)1000, 2 ) );
+ $this->assertEquals( '1,234,567,890.00000', number_format_i18n( 1234567890.00, 5 ) );
+ $this->assertEquals( '1,234,567,890.99999', number_format_i18n( 1234567890.99999, 5 ) );
+ $this->assertEquals( '1,234,567,890.50000', number_format_i18n( 1234567890.5, 5 ) );
+ }
+
+ /**
+ *
+ */
+ function test_number_format_i18n_brazil() {
+ global $wp_locale;
+ $wp_locale->number_format['decimal_point'] = ',';
+ $wp_locale->number_format['thousands_sep'] = '.';
+
+ $this->assertEquals( '1.000,00', number_format_i18n( 1000.00, 2 ) );
+ $this->assertEquals( '1.000,00', number_format_i18n( (int)1000, 2 ) );
+ $this->assertEquals( '1.234.567.890,00000', number_format_i18n( 1234567890.00, 5 ) );
+ $this->assertEquals( '1.234.567.890,99999', number_format_i18n( 1234567890.99999, 5 ) );
+ $this->assertEquals( '1.234.567.890,50000', number_format_i18n( 1234567890.5, 5 ) );
+ // clear $wp_locale
+ $wp_locale = null;
+ }
+}
\ No newline at end of file