@@ -922,4 +922,159 @@ public function testDeleteOrderMutation() {
922922 $ this ->assertEquals ( $ initial_response ['data ' ]['createOrder ' ], $ actual ['data ' ]['deleteOrder ' ] );
923923 $ this ->assertFalse ( \WC_Order_Factory::get_order ( $ order ->get_id () ) );
924924 }
925+
926+ public function testDeleteOrderItemsMutation () {
927+ // Create products and coupons to be used in order creation.
928+ $ variable = $ this ->variation ->create ( $ this ->product ->create_variable () );
929+ $ product_ids = array (
930+ $ this ->product ->create_simple (),
931+ $ this ->product ->create_simple (),
932+ $ variable ['product ' ],
933+ );
934+ $ coupon = new WC_Coupon (
935+ $ this ->coupon ->create ( array ( 'product_ids ' => $ product_ids ) )
936+ );
937+
938+ // Create initial order input.
939+ $ initial_input = array (
940+ 'clientMutationId ' => 'someId ' ,
941+ 'customerId ' => $ this ->customer ,
942+ 'customerNote ' => 'Customer test note ' ,
943+ 'coupons ' => array (
944+ $ coupon ->get_code (),
945+ ),
946+ 'paymentMethod ' => 'bacs ' ,
947+ 'paymentMethodTitle ' => 'Direct Bank Transfer ' ,
948+ 'billing ' => array (
949+ 'firstName ' => 'May ' ,
950+ 'lastName ' => 'Parker ' ,
951+ 'address1 ' => '20 Ingram St ' ,
952+ 'city ' => 'New York City ' ,
953+ 'state ' => 'NY ' ,
954+ 'postcode ' => '12345 ' ,
955+ 'country ' => 'US ' ,
956+ 957+ 'phone ' => '555-555-1234 ' ,
958+ ),
959+ 'shipping ' => array (
960+ 'firstName ' => 'May ' ,
961+ 'lastName ' => 'Parker ' ,
962+ 'address1 ' => '20 Ingram St ' ,
963+ 'city ' => 'New York City ' ,
964+ 'state ' => 'NY ' ,
965+ 'postcode ' => '12345 ' ,
966+ 'country ' => 'US ' ,
967+ ),
968+ 'lineItems ' => array (
969+ array (
970+ 'productId ' => $ product_ids [0 ],
971+ 'quantity ' => 5 ,
972+ 'metaData ' => array (
973+ array (
974+ 'key ' => 'test_product_key ' ,
975+ 'value ' => 'test product value ' ,
976+ ),
977+ ),
978+ ),
979+ array (
980+ 'productId ' => $ product_ids [1 ],
981+ 'quantity ' => 2 ,
982+ ),
983+ array (
984+ 'productId ' => $ product_ids [2 ],
985+ 'quantity ' => 6 ,
986+ 'variationId ' => $ variable ['variations ' ][0 ]
987+ ),
988+ ),
989+ 'shippingLines ' => array (
990+ array (
991+ 'methodId ' => 'flat_rate_shipping ' ,
992+ 'methodTitle ' => 'Flat Rate shipping ' ,
993+ 'total ' => '10 ' ,
994+ ),
995+ ),
996+ 'feeLines ' => array (
997+ array (
998+ 'name ' => 'Some Fee ' ,
999+ 'taxStatus ' => 'TAXABLE ' ,
1000+ 'total ' => '100 ' ,
1001+ 'taxClass ' => 'STANDARD ' ,
1002+ ),
1003+ ),
1004+ 'metaData ' => array (
1005+ array (
1006+ 'key ' => 'test_key ' ,
1007+ 'value ' => 'test value ' ,
1008+ ),
1009+ ),
1010+ 'isPaid ' => false ,
1011+ );
1012+
1013+ // Create order to delete.
1014+ wp_set_current_user ( $ this ->shop_manager );
1015+ $ initial_response = $ this ->orderMutation ( $ initial_input );
1016+
1017+ // use --debug flag to view.
1018+ codecept_debug ( $ initial_response );
1019+
1020+ // Clear loader cache.
1021+ $ this ->getModule ('\Helper\Wpunit ' )->clear_loader_cache ( 'wc_post_crud ' );
1022+
1023+ // Retrieve order and items
1024+ $ order_id = $ initial_response ['data ' ]['createOrder ' ]['order ' ]['orderId ' ];
1025+ $ order = \WC_Order_Factory::get_order ( $ order_id );
1026+ $ line_items = $ order ->get_items ();
1027+ $ shipping_lines = $ order ->get_items ( 'shipping ' );
1028+ $ fee_lines = $ order ->get_items ( 'fee ' );
1029+ $ coupon_lines = $ order ->get_items ( 'coupon ' );
1030+ $ tax_lines = $ order ->get_items ( 'tax ' );
1031+
1032+ // Create DeleteOrderInput.
1033+ $ deleted_items_input = array (
1034+ 'clientMutationId ' => 'someId ' ,
1035+ 'orderId ' => $ order ->get_id (),
1036+ 'itemIds ' => array (
1037+ current ( $ line_items )->get_id (),
1038+ current ( $ coupon_lines )->get_id (),
1039+ ),
1040+ );
1041+
1042+ /**
1043+ * Assertion One
1044+ *
1045+ * User without necessary capabilities cannot delete order an order.
1046+ */
1047+ wp_set_current_user ( $ this ->customer );
1048+ $ actual = $ this ->orderMutation (
1049+ $ deleted_items_input ,
1050+ 'deleteOrderItems ' ,
1051+ 'DeleteOrderItemsInput '
1052+ );
1053+
1054+ // use --debug flag to view.
1055+ codecept_debug ( $ actual );
1056+
1057+ $ this ->assertArrayHasKey ('errors ' , $ actual );
1058+
1059+ /**
1060+ * Assertion Two
1061+ *
1062+ * Test mutation and input.
1063+ */
1064+ wp_set_current_user ( $ this ->shop_manager );
1065+ $ actual = $ this ->orderMutation (
1066+ $ deleted_items_input ,
1067+ 'deleteOrderItems ' ,
1068+ 'DeleteOrderItemsInput '
1069+ );
1070+
1071+ // use --debug flag to view.
1072+ codecept_debug ( $ actual );
1073+
1074+ $ this ->assertArrayHasKey ( 'data ' , $ actual );
1075+ $ this ->assertArrayHasKey ( 'deleteOrderItems ' , $ actual ['data ' ] );
1076+ $ this ->assertEquals ( $ initial_response ['data ' ]['createOrder ' ], $ actual ['data ' ]['deleteOrderItems ' ] );
1077+ $ this ->assertFalse ( \WC_Order_Factory::get_order_item ( current ( $ line_items ) ) );
1078+ $ this ->assertFalse ( \WC_Order_Factory::get_order_item ( current ( $ coupon_lines ) ) );
1079+ }
9251080}
0 commit comments