From 5a896991ddcff623ba142c030db491105a74373d Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Mon, 20 May 2024 15:38:22 -0400 Subject: [PATCH] devops: CartMutationsTest updated --- Dockerfile | 2 +- bin/_lib.sh | 2 +- .../class-cart-update-item-quantities.php | 11 ------- tests/wpunit/CartMutationsTest.php | 30 +++++++++---------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 467b2b7a..7caa176c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ ENV PATH "$PATH:~/.composer/vendor/bin" # Install wp-browser globally RUN composer global require --optimize-autoloader \ wp-cli/wp-cli-bundle:* \ - lucatume/wp-browser:^4 \ + lucatume/wp-browser:^3.5 \ phpunit/phpunit:^9.6 \ codeception/module-asserts:* \ codeception/module-cli:* \ diff --git a/bin/_lib.sh b/bin/_lib.sh index 0b76bcd8..6398ba05 100755 --- a/bin/_lib.sh +++ b/bin/_lib.sh @@ -65,7 +65,7 @@ install_local_test_library() { # Install testing library dependencies. composer install composer require --dev -W \ - lucatume/wp-browser:^4 \ + lucatume/wp-browser:^3.5 \ phpunit/phpunit:^9.6 \ codeception/lib-asserts:* \ codeception/module-asserts:* \ diff --git a/includes/mutation/class-cart-update-item-quantities.php b/includes/mutation/class-cart-update-item-quantities.php index 3b069a14..1f455b48 100644 --- a/includes/mutation/class-cart-update-item-quantities.php +++ b/includes/mutation/class-cart-update-item-quantities.php @@ -127,17 +127,6 @@ public static function mutate_and_get_payload() { continue; } - $cart_item = \WC()->cart->get_cart_item( $key ); - if ( ! $cart_item ) { - throw new UserError( - sprintf( - /* translators: %s: cart item key */ - __( 'Sorry, cart item matching key %s cannot be found', 'wp-graphql-woocommerce' ), - $key, - ) - ); - } - do_action( 'graphql_woocommerce_before_set_item_quantity', \WC()->cart->get_cart_item( $key ), $input, $context, $info ); $updated[ $key ] = \WC()->cart->set_quantity( $key, $quantity, true ); do_action( 'graphql_woocommerce_after_set_item_quantity', \WC()->cart->get_cart_item( $key ), $input, $context, $info ); diff --git a/tests/wpunit/CartMutationsTest.php b/tests/wpunit/CartMutationsTest.php index 418a39cf..af51deed 100644 --- a/tests/wpunit/CartMutationsTest.php +++ b/tests/wpunit/CartMutationsTest.php @@ -713,7 +713,7 @@ public function testRemoveCouponMutation() { $response, [ $this->expectedField( 'removeCoupons.clientMutationId', 'someId' ), - $this->expectedField( 'removeCoupons.cart.appliedCoupons', self::IS_NULL ), + $this->expectedField( 'removeCoupons.cart.appliedCoupons', static::IS_NULL ), $this->expectedNode( 'removeCoupons.cart.contents.nodes', [ @@ -1067,25 +1067,25 @@ public function testAddCartItemsMutationAndErrors() { $this->expectedNode( 'addCartItems.cartErrors', [ - 'type' => 'INVALID_CART_ITEM', - 'reasons' => [ 'Color and test are required fields' ], - 'productId' => $variation_ids['product'], - 'quantity' => 5, - 'variationId' => $variation_ids['variations'][0], - 'variation' => null, - 'extraData' => null, + $this->expectedField( 'type', 'INVALID_CART_ITEM' ), + $this->expectedField( 'reasons.0', static::NOT_NULL ), + $this->expectedField( 'productId', $variation_ids['product'] ), + $this->expectedField( 'quantity', 5 ), + $this->expectedField( 'variationId', $variation_ids['variations'][0] ), + $this->expectedField( 'variation', static::IS_NULL ), + $this->expectedField( 'extraData', static::IS_NULL ), ] ), $this->expectedNode( 'addCartItems.cartErrors', [ - 'type' => 'INVALID_CART_ITEM', - 'reasons' => [ 'No product found matching the ID provided' ], - 'productId' => $invalid_product, - 'quantity' => 4, - 'variationId' => null, - 'variation' => null, - 'extraData' => null, + $this->expectedField( 'type', 'INVALID_CART_ITEM' ), + $this->expectedField( 'reasons.0', 'No product found matching the ID provided' ), + $this->expectedField( 'productId', $invalid_product ), + $this->expectedField( 'quantity', 4 ), + $this->expectedField( 'variationId', static::IS_NULL ), + $this->expectedField( 'variation', static::IS_NULL ), + $this->expectedField( 'extraData', static::IS_NULL ), ] ), ]