Update wc_format_decimal() tests to check for multiple decimals points

This commit is contained in:
Claudio Sanches 2019-07-31 19:54:58 -03:00
parent a646d96bec
commit 83c0e69637
2 changed files with 9 additions and 1 deletions

View File

@ -293,6 +293,8 @@ function wc_format_decimal( $number, $dp = false, $trim_zeros = false ) {
if ( ! is_float( $number ) ) {
$number = str_replace( $decimals, '.', $number );
$number = preg_replace( '/[^0-9\.,-]/', '', wc_clean( $number ) );
// Convert multiple dots to just one.
$number = preg_replace( '/\.+/', '.', $number );
}

View File

@ -290,6 +290,9 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Given string.
$this->assertEquals( '9.99', wc_format_decimal( '9.99' ) );
// Given string with multiple decimals points.
$this->assertEquals( '9.99', wc_format_decimal( '9...99' ) );
// Float.
$this->assertEquals( '9.99', wc_format_decimal( 9.99 ) );
@ -316,7 +319,10 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
update_option( 'woocommerce_price_thousand_sep', '.' );
// Given string.
$this->assertEquals( '9.99', wc_format_decimal( '9.99' ) );
$this->assertEquals( '9.99', wc_format_decimal( '9,99' ) );
// Given string with multiple decimals points.
$this->assertEquals( '9.99', wc_format_decimal( '9,,,99' ) );
// Float.
$this->assertEquals( '9.99', wc_format_decimal( 9.99 ) );