Skip to content

Commit

Permalink
Specific unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrosa committed Dec 26, 2024
1 parent 136f893 commit d43d35e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ public function get_normalized_postal_code( $postcode, $country ) {
if ( strlen( $spaceless_postcode ) < 5 ) {
// Always reintroduce the space so that Shipping Zones regex like 'N1 *' work to match N1 postcodes like N1 1AA, but don't match N10 postcodes like N10 1AA
return $spaceless_postcode . ' ***';
} else {
return $postcode; // 5 or more chars means it probably wasn't redacted and will likely validate unchanged.
}

return $postcode; // 5 or more chars means it probably wasn't redacted and will likely validate unchanged.
}

if ( 'CA' === $country ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ public function get_normalized_postal_code( $postcode, $country ) {
if ( strlen( $spaceless_postcode ) < 5 ) {
// Always reintroduce the space so that Shipping Zones regex like 'N1 *' work to match N1 postcodes like N1 1AA, but don't match N10 postcodes like N10 1AA
return $spaceless_postcode . ' ***';
} else {
return $postcode; // 5 or more chars means it probably wasn't redacted and will likely validate unchanged.
}

return $postcode; // 5 or more chars means it probably wasn't redacted and will likely validate unchanged.
}

if ( 'CA' === $country ) {
Expand Down
46 changes: 45 additions & 1 deletion tests/phpunit/test-wc-stripe-express-checkout-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function test_hides_ece_if_cannot_compute_taxes() {
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}
$original_gateways = WC()->payment_gateways()->payment_gateways;
$original_gateways = WC()->payment_gateways()->payment_gateways;
WC()->payment_gateways()->payment_gateways = [
'stripe' => new WC_Gateway_Stripe(),
];
Expand Down Expand Up @@ -267,4 +267,48 @@ public function test_is_account_creation_possible() {
update_option( 'woocommerce_enable_signup_from_checkout_for_subscriptions', 'yes' );
$this->assertTrue( $wc_stripe_ece_helper_mock2->is_account_creation_possible() );
}

/**
* Test for `get_normalized_postal_code`.
*
* @param string $postal_code Postal code.
* @param string $country Country code.
* @param string $expected Expected normalized postal code.
* @return void
* @dataProvider provide_test_get_normalized_postal_code
*/
public function test_get_normalized_postal_code( $postal_code, $country, $expected ) {
$wc_stripe_ece_helper = new WC_Stripe_Express_Checkout_Helper();
$this->assertEquals( $expected, $wc_stripe_ece_helper->get_normalized_postal_code( $postal_code, $country ) );
}

/**
* Provider for `test_get_normalized_postal_code`.
*
* @return array
*/
public function provide_test_get_normalized_postal_code() {
return [
'GB country' => [
'postal code' => 'SW1A 1AA',
'country' => 'GB',
'expected' => 'SW1A 1AA',
],
'GB country, redacted' => [
'postal code' => 'SW1A',
'country' => 'GB',
'expected' => 'SW1A ***',
],
'CA country' => [
'postal code' => 'K1A ',
'country' => 'CA',
'expected' => 'K1A***',
],
'US country' => [
'postal code' => '12345',
'country' => 'US',
'expected' => '12345',
],
];
}
}

0 comments on commit d43d35e

Please sign in to comment.