Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alefesouza committed Nov 29, 2024
1 parent 2f145a1 commit 35a4234
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/class-wc-payments-woopay-button-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private function is_product_supported() {
}

// Products with 0 total price and do not need shipping.
if ( (int) $product->get_price() === 0 && ! $product->needs_shipping() ) {
if ( is_a( $product, 'WC_Product' ) && (int) $product->get_price() === 0 && ! $product->needs_shipping() ) {
$is_supported = false;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/woopay/test-class-woopay-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function test_is_country_available_in_test_mode_return_true() {
*/
public function test_should_enable_woopay_on_cart_or_checkout_logged_out() {
add_filter( 'woocommerce_is_checkout', '__return_true' );
add_filter( 'woocommerce_cart_get_total', '__return_true' );
wp_set_current_user( 0 );

$woopay_utilities = new WooPay_Utilities();
Expand All @@ -122,6 +123,7 @@ public function test_should_enable_woopay_on_cart_or_checkout_logged_out() {
*/
public function test_should_enable_woopay_on_cart_or_checkout_logged_in() {
add_filter( 'woocommerce_is_checkout', '__return_true' );
add_filter( 'woocommerce_cart_get_total', '__return_true' );
wp_set_current_user( 1 );

$woopay_utilities = new WooPay_Utilities();
Expand Down Expand Up @@ -153,6 +155,7 @@ public function test_should_enable_woopay_on_cart_or_checkout_logged_out_has_sub
*/
public function test_should_enable_woopay_on_cart_or_checkout_logged_in_has_subscription() {
add_filter( 'woocommerce_is_checkout', '__return_true' );
add_filter( 'woocommerce_cart_get_total', '__return_true' );
wp_set_current_user( 1 );
WC_Subscriptions_Cart::set_cart_contains_subscription( true );

Expand Down Expand Up @@ -193,6 +196,7 @@ public function test_should_save_platform_customer_in_classic_checkout() {

private function clean_up_should_enable_woopay_tests() {
remove_filter( 'woocommerce_is_checkout', '__return_true' );
remove_filter( 'woocommerce_cart_get_total', '__return_true' );
wp_set_current_user( 0 );
WC_Subscriptions_Cart::set_cart_contains_subscription( false );
update_option( 'woocommerce_enable_guest_checkout', 'yes' );
Expand Down

0 comments on commit 35a4234

Please sign in to comment.