-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2527 from woocommerce/fix/flat-method-shipping-co…
…st-with-comma-separator Fix issue with comma separators for Shipping Rates
- Loading branch information
Showing
4 changed files
with
154 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
declare( strict_types=1 ); | ||
|
||
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\API\Site\Controllers; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper; | ||
|
||
|
||
/** | ||
* Class PluginHelperTraitTest | ||
* | ||
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\API\Site\Controllers | ||
*/ | ||
class PluginHelperTraitTest extends TestCase { | ||
|
||
|
||
/** @var PluginHelper $trait */ | ||
protected $trait; | ||
|
||
/** | ||
* Runs before each test is executed. | ||
*/ | ||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
// phpcs:ignore Universal.Classes.RequireAnonClassParentheses.Missing | ||
$this->trait = new class { | ||
use PluginHelper { | ||
convert_to_standard_decimal as public; | ||
} | ||
}; | ||
} | ||
|
||
|
||
public function test_comma_decimals_gets_converted_to_dot_decimals() { | ||
$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_standard_decimal( '10.5' ) ); | ||
} | ||
|
||
public function test_invalid_numbers() { | ||
$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_standard_decimal( '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' ] ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters