@@ -352,7 +352,7 @@ public function testEmptyCartMutation() {
352352 $ product_id = $ this ->factory ->product ->createSimple ();
353353 $ cart = \WC ()->cart ;
354354 $ cart_item_key = $ cart ->add_to_cart ( $ product_id , 1 );
355- $ cart_item = \ WC ()-> cart ->get_cart_item ( $ cart_item_key );
355+ $ cart_item = $ cart ->get_cart_item ( $ cart_item_key );
356356
357357 $ query = '
358358 mutation( $input: EmptyCartInput! ) {
@@ -402,6 +402,7 @@ public function testEmptyCartMutation() {
402402 'id ' => $ this ->toRelayId ( 'product ' , $ cart_item ['product_id ' ] ),
403403 ),
404404 ),
405+ 'variation ' => null ,
405406 'quantity ' => $ cart_item ['quantity ' ],
406407 'subtotal ' => wc_graphql_price ( $ cart_item ['line_subtotal ' ] ),
407408 'subtotalTax ' => wc_graphql_price ( $ cart_item ['line_subtotal_tax ' ] ),
@@ -474,14 +475,14 @@ public function testApplyCouponMutation() {
474475 $ response = $ this ->graphql ( compact ( 'query ' , 'variables ' ) );
475476
476477 // Get updated cart item.
477- $ cart_item = \ WC ()-> cart ->get_cart_item ( $ cart_item_key );
478+ $ cart_item = $ cart ->get_cart_item ( $ cart_item_key );
478479
479480 $ this ->assertQuerySuccessful (
480481 $ response ,
481482 array (
482483 $ this ->expectedObject ( 'applyCoupon.clientMutationId ' , 'someId ' ),
483484 $ this ->expectedNode (
484- 'applyCoupon.cart.appliedCoupons.nodes ' ,
485+ 'applyCoupon.cart.appliedCoupons ' ,
485486 array (
486487 'code ' => $ coupon_code ,
487488 )
@@ -659,7 +660,7 @@ public function testRemoveCouponMutation() {
659660 $ response ,
660661 array (
661662 $ this ->expectedObject ( 'removeCoupons.clientMutationId ' , 'someId ' ),
662- $ this ->expectedObject ( 'removeCoupons.cart.appliedCoupons.0.code ' , $ coupon_code ),
663+ $ this ->expectedObject ( 'removeCoupons.cart.appliedCoupons ' , ' null ' ),
663664 $ this ->expectedNode (
664665 'removeCoupons.cart.contents.nodes ' ,
665666 array (
@@ -775,12 +776,12 @@ public function testAddToCartMutationErrors() {
775776 cartItem {
776777 key
777778 product {
778- nodes {
779+ node {
779780 id
780781 }
781782 }
782783 variation {
783- nodes {
784+ node {
784785 id
785786 }
786787 }
@@ -820,9 +821,9 @@ public function testAddToCartMutationErrors() {
820821
821822 public function testAddCartItemsMutationAndErrors () {
822823 // Create variable product for later use.
823- $ variation_ids = $ this ->variation -> create ( $ this -> product -> create_variable () );
824- $ product = \wc_get_product ( $ variation_ids ['product ' ] );
825- $ attribute = new WC_Product_Attribute ();
824+ $ variation_ids = $ this ->factory -> product_variation -> createSome ( );
825+ $ product = \wc_get_product ( $ variation_ids ['product ' ] );
826+ $ attribute = new WC_Product_Attribute ();
826827 $ attribute ->set_id ( 0 );
827828 $ attribute ->set_name ( 'test ' );
828829 $ attribute ->set_options ( array ( 'yes ' , 'no ' ) );
@@ -834,7 +835,7 @@ public function testAddCartItemsMutationAndErrors() {
834835 $ product ->set_attributes ( $ attributes );
835836 $ product ->save ();
836837
837- $ product_one = $ this ->product ->create_simple ();
838+ $ product_one = $ this ->factory -> product ->createSimple ();
838839 $ invalid_product = 1000 ;
839840
840841 $ query = '
@@ -892,6 +893,10 @@ public function testAddCartItemsMutationAndErrors() {
892893 'attributeName ' => 'test ' ,
893894 'attributeValue ' => 'yes ' ,
894895 ),
896+ array (
897+ 'attributeName ' => 'color ' ,
898+ 'attributeValue ' => 'green ' ,
899+ ),
895900 )
896901 )
897902 ),
@@ -930,7 +935,7 @@ public function testAddCartItemsMutationAndErrors() {
930935 'addCartItems.cartErrors ' ,
931936 array (
932937 'type ' => 'INVALID_CART_ITEM ' ,
933- 'reasons ' => array ( 'test is a required field ' ),
938+ 'reasons ' => array ( 'color and test are required fields ' ),
934939 'productId ' => $ variation_ids ['product ' ],
935940 'quantity ' => 5 ,
936941 'variationId ' => $ variation_ids ['variations ' ][0 ],
@@ -956,24 +961,20 @@ public function testAddCartItemsMutationAndErrors() {
956961
957962 public function testFillCartMutationAndErrors () {
958963 // Create products.
959- $ product_one = $ this ->product ->create_simple (
960- array ( 'regular_price ' => 100 )
961- );
962- $ product_two = $ this ->product ->create_simple (
963- array ( 'regular_price ' => 40 )
964- );
964+ $ product_one = $ this ->factory ->product ->createSimple ( array ( 'regular_price ' => 100 ) );
965+ $ product_two = $ this ->factory ->product ->createSimple ( array ( 'regular_price ' => 40 ) );
965966
966967 // Create coupons.
967968 $ coupon_code_one = wc_get_coupon_code_by_id (
968- $ this ->coupon ->create (
969- array (
970- 'amount ' => 0.5 ,
971- 'product_ids ' => array ( $ product_one )
972- )
973- )
974- );
969+ $ this -> factory ->coupon ->create (
970+ array (
971+ 'amount ' => 0.5 ,
972+ 'product_ids ' => array ( $ product_one )
973+ )
974+ )
975+ );
975976 $ coupon_code_two = wc_get_coupon_code_by_id (
976- $ this ->coupon ->create (
977+ $ this ->factory -> coupon ->create (
977978 array (
978979 'amount ' => 0.2 ,
979980 'product_ids ' => array ( $ product_two )
@@ -1058,7 +1059,7 @@ public function testFillCartMutationAndErrors() {
10581059 $ response ,
10591060 array (
10601061 $ this ->expectedObject ( 'fillCart.clientMutationId ' , 'someId ' ),
1061- $ this ->expectedNode ( 'fillCart.cart.chosenShippingMethod ' , 'legacy_flat_rate ' ),
1062+ $ this ->expectedNode ( 'fillCart.cart.chosenShippingMethods ' , 'legacy_flat_rate ' ),
10621063 $ this ->expectedNode (
10631064 'fillCart.cart.contents.nodes ' ,
10641065 array (
@@ -1124,8 +1125,8 @@ public function testFillCartMutationAndErrors() {
11241125 'fillCart.cartErrors ' ,
11251126 array (
11261127 'type ' => 'INVALID_SHIPPING_METHOD ' ,
1128+ 'chosenMethod ' => $ invalid_shipping_method ,
11271129 'package ' => 1 ,
1128- 'chosenMethod ' => $ invalid_shipping_method
11291130 )
11301131 ),
11311132 )
0 commit comments