-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path35840.patch
121 lines (119 loc) · 3.43 KB
/
35840.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php (revision 36528)
+++ 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( (int) $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( (int) $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,99 @@
+<?php
+/**
+ * wordpress-develop.
+ * User: Paul
+ * Date: 2016-02-01
+ *
+ */
+
+if ( ! defined( 'WPINC' ) ) {
+ die;
+}
+
+
+/**
+ * Convert integer number to format based on the locale.
+ *
+ * @since 2.3.0
+ *
+ * @global WP_Locale $wp_locale
+ *
+ * @param int $number The number to convert based on locale.
+ * @param int $decimals Optional. Precision of the number of decimal places. Default 0.
+ * @return string Converted number in string format.
+ */
+function XXnumber_format_i18n( $number, $decimals = 0 ) {
+ 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'] );
+ } else {
+ $formatted = number_format( $number, absint( $decimals ) );
+ }
+
+ /**
+ * Filter the number formatted based on the locale.
+ *
+ * @since 2.8.0
+ *
+ * @param string $formatted Converted number in string format.
+ */
+ return apply_filters( 'number_format_i18n', $formatted );
+}
+
+
+
+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_decimal_is_not_number() {
+
+ $this->assertEquals( number_format_i18n( 10, 'seven' ) , '10' );
+ }
+
+ /**
+ *
+ */
+ function test_number_format_i18n_large() {
+ 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^234^567^890@00000', number_format_i18n( 1234567890.00, 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,234,567,890.00000', number_format_i18n( 1234567890.00, 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.234.567.890,00000', number_format_i18n( 1234567890.00, 5 ) );
+ // clear $wp_locale
+ $wp_locale = null;
+ }
+}
\ No newline at end of file