From 40a068a287c385e9ee4fd658ec332e2b80d018fc Mon Sep 17 00:00:00 2001 From: Jorge M Date: Wed, 14 Aug 2024 20:57:31 +0200 Subject: [PATCH 1/9] Fix issue with comma separators --- src/Shipping/ZoneMethodsParser.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Shipping/ZoneMethodsParser.php b/src/Shipping/ZoneMethodsParser.php index c7238c0ab1..00a64797ab 100644 --- a/src/Shipping/ZoneMethodsParser.php +++ b/src/Shipping/ZoneMethodsParser.php @@ -123,7 +123,9 @@ protected function get_flat_rate_method_rate( object $method ): ?float { $rate = null; $flat_cost = 0; - $cost = $method->get_option( 'cost' ); + $locale = localeconv(); + $decimals = [ wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' ]; + $cost = str_replace( $decimals, '.', $method->get_option( 'cost' ) ); // Check if the cost is a numeric value (and not null or a math expression). if ( is_numeric( $cost ) ) { $flat_cost = (float) $cost; From d1e147a36f6fcc6bcaf0067be9b3d7fb97d94be9 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Wed, 14 Aug 2024 21:22:04 +0200 Subject: [PATCH 2/9] Parse cost --- src/Shipping/ZoneMethodsParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shipping/ZoneMethodsParser.php b/src/Shipping/ZoneMethodsParser.php index 00a64797ab..0f0e26b951 100644 --- a/src/Shipping/ZoneMethodsParser.php +++ b/src/Shipping/ZoneMethodsParser.php @@ -125,7 +125,7 @@ protected function get_flat_rate_method_rate( object $method ): ?float { $flat_cost = 0; $locale = localeconv(); $decimals = [ wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' ]; - $cost = str_replace( $decimals, '.', $method->get_option( 'cost' ) ); + $cost = str_replace( $decimals, '.', (string) $method->get_option( 'cost' ) ); // Check if the cost is a numeric value (and not null or a math expression). if ( is_numeric( $cost ) ) { $flat_cost = (float) $cost; From b23328b634579c2eb461a531ef85bda07bf9b9bc Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 19 Aug 2024 18:38:56 +0200 Subject: [PATCH 3/9] Add helper to convert decimals to dot --- src/PluginHelper.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/PluginHelper.php b/src/PluginHelper.php index 015a3b8646..836aa25dc8 100644 --- a/src/PluginHelper.php +++ b/src/PluginHelper.php @@ -198,4 +198,20 @@ protected function get_site_url(): string { protected function strip_url_protocol( string $url ): string { return preg_replace( '#^https?://#', '', untrailingslashit( $url ) ); } + + /** + * Replace any decimal separators, like commas, with dots for decimal places. + * This is useful with functions like is_numeric as it doesn't recognize commas as decimal separators. + * Note: Using wc_format_decimal with a dot as the decimal separator (WC -> Settings -> General) will strip out commas but won’t replace them with dots. + * For example, wc_format_decimal('2,4') will return 24 instead of 2.4. + * + * @param string $number The number to convert. + * + * @return string The number as a valid decimal. + */ + protected function convert_to_decimal_with_dot( string $number ) { + $locale = localeconv(); + $decimals = [ wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' ]; + return str_replace( $decimals, '.', (string) $number ); + } } From 8c863f28ab1dad591ac47660c6534b5a598c8adf Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 19 Aug 2024 18:39:37 +0200 Subject: [PATCH 4/9] Add tests for conver to decimals helper --- tests/Unit/Plugin/PluginHelperTraitTest.php | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/Unit/Plugin/PluginHelperTraitTest.php diff --git a/tests/Unit/Plugin/PluginHelperTraitTest.php b/tests/Unit/Plugin/PluginHelperTraitTest.php new file mode 100644 index 0000000000..74bf12a46d --- /dev/null +++ b/tests/Unit/Plugin/PluginHelperTraitTest.php @@ -0,0 +1,65 @@ +trait = new class { + use PluginHelper { + convert_to_decimal_with_dot as public; + } + }; + } + + + public function test_comma_decimals_gets_converted_to_dot_decimals() { + $this->assertEquals( '10.5', $this->trait->convert_to_decimal_with_dot( '10,5' ) ); + } + + public function test_dot_decimals_remain_unchanged() { + $this->assertEquals( '10.5', $this->trait->convert_to_decimal_with_dot( '10.5' ) ); + } + + public function test_invalid_numbers() { + $this->assertEquals( 'no valid. number', $this->trait->convert_to_decimal_with_dot( 'no valid, number' ) ); + } + + public function test_with_different_wc_decimal_separator() { + add_filter( + 'wc_get_price_decimal_separator', + [ $this, 'callback_filter_decimal_separator' ] + ); + + $this->assertEquals( '10.5', $this->trait->convert_to_decimal_with_dot( '10-5' ) ); + } + + public function callback_filter_decimal_separator() { + return '-'; + } + + public function tearDown(): void { + parent::tearDown(); + remove_filter( 'wc_get_price_decimal_separator', [ $this, 'callback_filter_decimal_separator' ] ); + } +} From 18d14693635d81186057469c4e2c639cb09a821c Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 19 Aug 2024 18:40:15 +0200 Subject: [PATCH 5/9] Update parse to use the helper --- src/Shipping/ZoneMethodsParser.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Shipping/ZoneMethodsParser.php b/src/Shipping/ZoneMethodsParser.php index 0f0e26b951..bbaa73fbd7 100644 --- a/src/Shipping/ZoneMethodsParser.php +++ b/src/Shipping/ZoneMethodsParser.php @@ -5,6 +5,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service; use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\WC; +use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper; use WC_Shipping_Method; use WC_Shipping_Zone; @@ -19,6 +20,8 @@ */ class ZoneMethodsParser implements Service { + use PluginHelper; + public const METHOD_FLAT_RATE = 'flat_rate'; public const METHOD_FREE = 'free_shipping'; @@ -88,7 +91,7 @@ protected function shipping_method_to_rates( object $method ): array { // Check if free shipping requires a minimum order amount. $requires = $method->get_option( 'requires' ); if ( in_array( $requires, [ 'min_amount', 'either' ], true ) ) { - $shipping_rate->set_min_order_amount( (float) $method->get_option( 'min_amount' ) ); + $shipping_rate->set_min_order_amount( (float) $this->convert_to_decimal_with_dot( (string) $method->get_option( 'min_amount' ) ) ); } elseif ( in_array( $requires, [ 'coupon', 'both' ], true ) ) { // We can't sync this method if free shipping requires a coupon. return []; @@ -123,9 +126,7 @@ protected function get_flat_rate_method_rate( object $method ): ?float { $rate = null; $flat_cost = 0; - $locale = localeconv(); - $decimals = [ wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' ]; - $cost = str_replace( $decimals, '.', (string) $method->get_option( 'cost' ) ); + $cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'cost' ) ); // Check if the cost is a numeric value (and not null or a math expression). if ( is_numeric( $cost ) ) { $flat_cost = (float) $cost; @@ -133,7 +134,7 @@ protected function get_flat_rate_method_rate( object $method ): ?float { } // Add the no class cost. - $no_class_cost = $method->get_option( 'no_class_cost' ); + $no_class_cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'no_class_cost' ) ); if ( is_numeric( $no_class_cost ) ) { $rate = $flat_cost + (float) $no_class_cost; } @@ -157,7 +158,7 @@ protected function get_flat_rate_method_class_rates( object $method ): array { $class_rates = []; $flat_cost = 0; - $cost = $method->get_option( 'cost' ); + $cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'cost' ) ); // Check if the cost is a numeric value (and not null or a math expression). if ( is_numeric( $cost ) ) { $flat_cost = (float) $cost; @@ -166,7 +167,7 @@ protected function get_flat_rate_method_class_rates( object $method ): array { // Add shipping class costs. $shipping_classes = $this->wc->get_shipping_classes(); foreach ( $shipping_classes as $shipping_class ) { - $shipping_class_cost = $method->get_option( 'class_cost_' . $shipping_class->term_id ); + $shipping_class_cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'class_cost_' . $shipping_class->term_id ) ); if ( is_numeric( $shipping_class_cost ) ) { // Add the flat rate cost to the shipping class cost. $class_rates[ $shipping_class->slug ] = [ From a6407f7b1213f4c908e39d1d901c5514615394e7 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 19 Aug 2024 18:40:38 +0200 Subject: [PATCH 6/9] Adjust tests for Zone Parser --- tests/Unit/Shipping/ZoneMethodsParserTest.php | 82 +++++++++++++++++-- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/tests/Unit/Shipping/ZoneMethodsParserTest.php b/tests/Unit/Shipping/ZoneMethodsParserTest.php index 040a16b16b..ead7a31e7d 100644 --- a/tests/Unit/Shipping/ZoneMethodsParserTest.php +++ b/tests/Unit/Shipping/ZoneMethodsParserTest.php @@ -46,6 +46,48 @@ public function test_returns_flat_rate_methods() { $this->assertEquals( 10, $shipping_rates[0]->get_rate() ); } + public function test_returns_flat_rate_methods_with_decimals_and_comma() { + $flat_rate = $this->createMock( WC_Shipping_Flat_Rate::class ); + $flat_rate->id = ZoneMethodsParser::METHOD_FLAT_RATE; + $flat_rate->expects( $this->any() ) + ->method( 'get_option' ) + ->willReturnMap( + [ + [ 'cost', null, '10,6' ], + ] + ); + + $zone = $this->createMock( WC_Shipping_Zone::class ); + $zone->expects( $this->any() ) + ->method( 'get_shipping_methods' ) + ->willReturn( [ $flat_rate ] ); + + $shipping_rates = $this->methods_parser->parse( $zone ); + $this->assertCount( 1, $shipping_rates ); + $this->assertEquals( 10.6, $shipping_rates[0]->get_rate() ); + } + + public function test_returns_flat_rate_methods_with_decimals_and_dot() { + $flat_rate = $this->createMock( WC_Shipping_Flat_Rate::class ); + $flat_rate->id = ZoneMethodsParser::METHOD_FLAT_RATE; + $flat_rate->expects( $this->any() ) + ->method( 'get_option' ) + ->willReturnMap( + [ + [ 'cost', null, '10.6' ], + ] + ); + + $zone = $this->createMock( WC_Shipping_Zone::class ); + $zone->expects( $this->any() ) + ->method( 'get_shipping_methods' ) + ->willReturn( [ $flat_rate ] ); + + $shipping_rates = $this->methods_parser->parse( $zone ); + $this->assertCount( 1, $shipping_rates ); + $this->assertEquals( 10.6, $shipping_rates[0]->get_rate() ); + } + public function test_returns_flat_rate_methods_including_shipping_classes() { // Return three sample shipping classes. $light_class = new \stdClass(); @@ -69,10 +111,10 @@ public function test_returns_flat_rate_methods_including_shipping_classes() { ->willReturnMap( [ [ 'cost', null, 10 ], - [ 'class_cost_0', null, 5 ], + [ 'class_cost_0', null, '5,20' ], // Comma decimal separator will be converted to dot. [ 'class_cost_1', null, 15 ], [ 'class_cost_2', null, '[qty] / 10' ], - [ 'no_class_cost', null, 2 ], + [ 'no_class_cost', null, '6,7' ], ] ); @@ -103,11 +145,11 @@ function ( ShippingRate $shipping_rate ) { foreach ( $shipping_rates as $shipping_rate ) { if ( [] === $shipping_rate->get_applicable_classes() ) { - // The `no_class_cost` should be added to the flat rate method cost (10+2=12). - $this->assertEquals( 12, $shipping_rate->get_rate() ); + // The `no_class_cost` should be added to the flat rate method cost (10+6.7=16.7). + $this->assertEquals( 16.7, $shipping_rate->get_rate() ); } elseif ( [ 'light' ] === $shipping_rate->get_applicable_classes() ) { - // The shipping class costs should be added to the flat rate method cost (10+5=15). - $this->assertEquals( 15, $shipping_rate->get_rate() ); + // The shipping class costs should be added to the flat rate method cost (10+5.20=15.20). + $this->assertEquals( 15.20, $shipping_rate->get_rate() ); } elseif ( [ 'heavy' ] === $shipping_rate->get_applicable_classes() ) { // The shipping class costs should be added to the flat rate method cost (10+15=25). $this->assertEquals( 25, $shipping_rate->get_rate() ); @@ -143,6 +185,34 @@ public function test_returns_free_shipping_methods( string $requires ) { $this->assertEquals( 99.99, $shipping_rates[0]->get_min_order_amount() ); } + /** + * @param string $requires + * + * @dataProvider return_free_shipping_min_amount_requirements + */ + public function test_returns_free_shipping_methods_string_cost_with_commas( string $requires ) { + $free_shipping = $this->createMock( WC_Shipping_Free_Shipping::class ); + $free_shipping->id = ZoneMethodsParser::METHOD_FREE; + $free_shipping->expects( $this->any() ) + ->method( 'get_option' ) + ->willReturnMap( + [ + [ 'requires', null, $requires ], + [ 'min_amount', null, '99,99' ], + ] + ); + + $zone = $this->createMock( WC_Shipping_Zone::class ); + $zone->expects( $this->any() ) + ->method( 'get_shipping_methods' ) + ->willReturn( [ $free_shipping ] ); + + $shipping_rates = $this->methods_parser->parse( $zone ); + $this->assertCount( 1, $shipping_rates ); + $this->assertEquals( 0, $shipping_rates[0]->get_rate() ); + $this->assertEquals( 99.99, $shipping_rates[0]->get_min_order_amount() ); + } + /** * @param string $requires * From 6310f9c00372b348ac248822146bf44f2ce524ac Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 19 Aug 2024 19:10:31 +0200 Subject: [PATCH 7/9] Convert min amount as it is always int --- src/Shipping/ZoneMethodsParser.php | 2 +- tests/Unit/Shipping/ZoneMethodsParserTest.php | 28 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/Shipping/ZoneMethodsParser.php b/src/Shipping/ZoneMethodsParser.php index bbaa73fbd7..b36c69ab14 100644 --- a/src/Shipping/ZoneMethodsParser.php +++ b/src/Shipping/ZoneMethodsParser.php @@ -91,7 +91,7 @@ protected function shipping_method_to_rates( object $method ): array { // Check if free shipping requires a minimum order amount. $requires = $method->get_option( 'requires' ); if ( in_array( $requires, [ 'min_amount', 'either' ], true ) ) { - $shipping_rate->set_min_order_amount( (float) $this->convert_to_decimal_with_dot( (string) $method->get_option( 'min_amount' ) ) ); + $shipping_rate->set_min_order_amount( (float) $method->get_option( 'min_amount' ) ); } elseif ( in_array( $requires, [ 'coupon', 'both' ], true ) ) { // We can't sync this method if free shipping requires a coupon. return []; diff --git a/tests/Unit/Shipping/ZoneMethodsParserTest.php b/tests/Unit/Shipping/ZoneMethodsParserTest.php index ead7a31e7d..596ed7a3bc 100644 --- a/tests/Unit/Shipping/ZoneMethodsParserTest.php +++ b/tests/Unit/Shipping/ZoneMethodsParserTest.php @@ -185,34 +185,6 @@ public function test_returns_free_shipping_methods( string $requires ) { $this->assertEquals( 99.99, $shipping_rates[0]->get_min_order_amount() ); } - /** - * @param string $requires - * - * @dataProvider return_free_shipping_min_amount_requirements - */ - public function test_returns_free_shipping_methods_string_cost_with_commas( string $requires ) { - $free_shipping = $this->createMock( WC_Shipping_Free_Shipping::class ); - $free_shipping->id = ZoneMethodsParser::METHOD_FREE; - $free_shipping->expects( $this->any() ) - ->method( 'get_option' ) - ->willReturnMap( - [ - [ 'requires', null, $requires ], - [ 'min_amount', null, '99,99' ], - ] - ); - - $zone = $this->createMock( WC_Shipping_Zone::class ); - $zone->expects( $this->any() ) - ->method( 'get_shipping_methods' ) - ->willReturn( [ $free_shipping ] ); - - $shipping_rates = $this->methods_parser->parse( $zone ); - $this->assertCount( 1, $shipping_rates ); - $this->assertEquals( 0, $shipping_rates[0]->get_rate() ); - $this->assertEquals( 99.99, $shipping_rates[0]->get_min_order_amount() ); - } - /** * @param string $requires * From de9bd60cb43bee7c380bd05d2e7ecdc96645aea6 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Wed, 21 Aug 2024 21:08:13 +0200 Subject: [PATCH 8/9] Tweak function to convert to a valid decimal --- src/PluginHelper.php | 26 ++++++++++++++------- src/Shipping/ZoneMethodsParser.php | 8 +++---- tests/Unit/Plugin/PluginHelperTraitTest.php | 18 ++++++++++---- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/PluginHelper.php b/src/PluginHelper.php index 836aa25dc8..1cd71fd982 100644 --- a/src/PluginHelper.php +++ b/src/PluginHelper.php @@ -200,18 +200,28 @@ protected function strip_url_protocol( string $url ): string { } /** - * Replace any decimal separators, like commas, with dots for decimal places. - * This is useful with functions like is_numeric as it doesn't recognize commas as decimal separators. + * It tries to convert a string to a decimal number using the dot as the decimal separator. + * This is useful with functions like is_numeric as it doesn't recognize commas as decimal separators or any thousands separator. * Note: Using wc_format_decimal with a dot as the decimal separator (WC -> Settings -> General) will strip out commas but won’t replace them with dots. * For example, wc_format_decimal('2,4') will return 24 instead of 2.4. * - * @param string $number The number to convert. + * @param string $numeric_string The number to convert. * - * @return string The number as a valid decimal. + * @return string The number as a standard decimal. 1.245,63 -> 1245.65 */ - protected function convert_to_decimal_with_dot( string $number ) { - $locale = localeconv(); - $decimals = [ wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' ]; - return str_replace( $decimals, '.', (string) $number ); + protected function convert_to_standard_decimal( string $numeric_string ): string { + $locale = localeconv(); + + $separators = [ wc_get_price_decimal_separator(), wc_get_price_thousand_separator(), $locale['thousands_sep'], $locale['mon_thousands_sep'], $locale['decimal_point'], $locale['mon_decimal_point'], ',' ]; + + if ( wc_get_price_decimals() > 0 ) { + // Replace all posible separators with dots. + $numeric_string = str_replace( $separators, '.', $numeric_string ); + // Leave only the last dot that is the decimal separator. + return (string) preg_replace( '/\.(?=.*\.)/', '', $numeric_string ); + } else { + // If no decimals remove all separators. + return str_replace( $separators, '', $numeric_string ); + } } } diff --git a/src/Shipping/ZoneMethodsParser.php b/src/Shipping/ZoneMethodsParser.php index b36c69ab14..d1a92e09fc 100644 --- a/src/Shipping/ZoneMethodsParser.php +++ b/src/Shipping/ZoneMethodsParser.php @@ -126,7 +126,7 @@ protected function get_flat_rate_method_rate( object $method ): ?float { $rate = null; $flat_cost = 0; - $cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'cost' ) ); + $cost = $this->convert_to_standard_decimal( (string) $method->get_option( 'cost' ) ); // Check if the cost is a numeric value (and not null or a math expression). if ( is_numeric( $cost ) ) { $flat_cost = (float) $cost; @@ -134,7 +134,7 @@ protected function get_flat_rate_method_rate( object $method ): ?float { } // Add the no class cost. - $no_class_cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'no_class_cost' ) ); + $no_class_cost = $this->convert_to_standard_decimal( (string) $method->get_option( 'no_class_cost' ) ); if ( is_numeric( $no_class_cost ) ) { $rate = $flat_cost + (float) $no_class_cost; } @@ -158,7 +158,7 @@ protected function get_flat_rate_method_class_rates( object $method ): array { $class_rates = []; $flat_cost = 0; - $cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'cost' ) ); + $cost = $this->convert_to_standard_decimal( (string) $method->get_option( 'cost' ) ); // Check if the cost is a numeric value (and not null or a math expression). if ( is_numeric( $cost ) ) { $flat_cost = (float) $cost; @@ -167,7 +167,7 @@ protected function get_flat_rate_method_class_rates( object $method ): array { // Add shipping class costs. $shipping_classes = $this->wc->get_shipping_classes(); foreach ( $shipping_classes as $shipping_class ) { - $shipping_class_cost = $this->convert_to_decimal_with_dot( (string) $method->get_option( 'class_cost_' . $shipping_class->term_id ) ); + $shipping_class_cost = $this->convert_to_standard_decimal( (string) $method->get_option( 'class_cost_' . $shipping_class->term_id ) ); if ( is_numeric( $shipping_class_cost ) ) { // Add the flat rate cost to the shipping class cost. $class_rates[ $shipping_class->slug ] = [ diff --git a/tests/Unit/Plugin/PluginHelperTraitTest.php b/tests/Unit/Plugin/PluginHelperTraitTest.php index 74bf12a46d..c91d1c0874 100644 --- a/tests/Unit/Plugin/PluginHelperTraitTest.php +++ b/tests/Unit/Plugin/PluginHelperTraitTest.php @@ -27,31 +27,39 @@ public function setUp(): void { // phpcs:ignore Universal.Classes.RequireAnonClassParentheses.Missing $this->trait = new class { use PluginHelper { - convert_to_decimal_with_dot as public; + convert_to_standard_decimal as public; } }; } public function test_comma_decimals_gets_converted_to_dot_decimals() { - $this->assertEquals( '10.5', $this->trait->convert_to_decimal_with_dot( '10,5' ) ); + $this->assertEquals( '10.5', $this->trait->convert_to_standard_decimal( '10,5' ) ); } public function test_dot_decimals_remain_unchanged() { - $this->assertEquals( '10.5', $this->trait->convert_to_decimal_with_dot( '10.5' ) ); + $this->assertEquals( '10.5', $this->trait->convert_to_standard_decimal( '10.5' ) ); } public function test_invalid_numbers() { - $this->assertEquals( 'no valid. number', $this->trait->convert_to_decimal_with_dot( 'no valid, number' ) ); + $this->assertEquals( 'no valid. number', $this->trait->convert_to_standard_decimal( 'no valid, number' ) ); } + public function test_with_thousands_separator() { + $this->assertEquals( '1234.5', $this->trait->convert_to_standard_decimal( '1'.wc_get_price_thousand_separator().'234,5' ) ); + } + + public function test_with_no_decimals() { + $this->assertEquals( '12345', $this->trait->convert_to_standard_decimal( '12345' ) ); + } + public function test_with_different_wc_decimal_separator() { add_filter( 'wc_get_price_decimal_separator', [ $this, 'callback_filter_decimal_separator' ] ); - $this->assertEquals( '10.5', $this->trait->convert_to_decimal_with_dot( '10-5' ) ); + $this->assertEquals( '10.5', $this->trait->convert_to_standard_decimal( '10-5' ) ); } public function callback_filter_decimal_separator() { From 70b3f1f2bff9dbf4e704c45d9ae3788a15edc2e4 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Wed, 21 Aug 2024 21:21:00 +0200 Subject: [PATCH 9/9] PHPCS fix --- tests/Unit/Plugin/PluginHelperTraitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Plugin/PluginHelperTraitTest.php b/tests/Unit/Plugin/PluginHelperTraitTest.php index c91d1c0874..d486e32ddf 100644 --- a/tests/Unit/Plugin/PluginHelperTraitTest.php +++ b/tests/Unit/Plugin/PluginHelperTraitTest.php @@ -46,12 +46,12 @@ public function test_invalid_numbers() { } public function test_with_thousands_separator() { - $this->assertEquals( '1234.5', $this->trait->convert_to_standard_decimal( '1'.wc_get_price_thousand_separator().'234,5' ) ); + $this->assertEquals( '1234.5', $this->trait->convert_to_standard_decimal( '1' . wc_get_price_thousand_separator() . '234,5' ) ); } public function test_with_no_decimals() { $this->assertEquals( '12345', $this->trait->convert_to_standard_decimal( '12345' ) ); - } + } public function test_with_different_wc_decimal_separator() { add_filter(