mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
Merge branch 'release/v0.6.0' into feature/some-node-interfaces-support
This commit is contained in:
@@ -28,5 +28,6 @@ TESTS_ENVS=tests/_envs
|
||||
|
||||
CORE_BRANCH=develop
|
||||
JWT_AUTH_BRANCH=develop
|
||||
STRIPE_GATEWAY=1
|
||||
GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123
|
||||
SKIP_TESTS_CLEANUP=1
|
||||
|
||||
@@ -50,9 +50,16 @@ jobs:
|
||||
extensions: json, mbstring
|
||||
|
||||
- name: Get Composer Cache Directory
|
||||
id: composer-cache
|
||||
id: composercache
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.composercache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: ${{ runner.os }}-composer-
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --no-dev
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class Cart_Mutation {
|
||||
$cart_item_args = array( $input['productId'] );
|
||||
$cart_item_args[] = ! empty( $input['quantity'] ) ? $input['quantity'] : 1;
|
||||
$cart_item_args[] = ! empty( $input['variationId'] ) ? $input['variationId'] : 0;
|
||||
$cart_item_args[] = ! empty( $input['variation'] ) ? $input['variation'] : array();
|
||||
$cart_item_args[] = ! empty( $input['variation'] ) ? self::prepare_attributes( $input['productId'], $input['variation'] ) : array();
|
||||
$cart_item_args[] = ! empty( $input['extraData'] )
|
||||
? json_decode( $input['extraData'], true )
|
||||
: array();
|
||||
@@ -55,6 +55,40 @@ class Cart_Mutation {
|
||||
return apply_filters( 'graphql_woocommerce_new_cart_item_data', $cart_item_args, $input, $context, $info );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the provided variation attributes data for the cart.
|
||||
*
|
||||
* @param array $variation_data Variation data.
|
||||
* @return array
|
||||
*/
|
||||
private static function prepare_attributes( $product_id, array $variation_data = array() ) {
|
||||
$product = wc_get_product( $product_id );
|
||||
$attribute_names = array_keys( $product->get_attributes() );
|
||||
|
||||
$attributes = array();
|
||||
foreach( $variation_data as $attribute ) {
|
||||
$attribute_name = $attribute['attributeName'];
|
||||
if ( in_array( "pa_{$attribute_name}", $attribute_names, true ) ) {
|
||||
$attribute_name = "pa_{$attribute_name}";
|
||||
} elseif ( ! in_array( $attribute_name, $attribute_names, true ) ) {
|
||||
throw new UserError(
|
||||
sprintf(
|
||||
__( '%s is not a valid attribute of the product: %s.', 'wp-graphql-woocommerce' ),
|
||||
$attribute_name,
|
||||
$product->get_name()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$attribute_value = ! empty( $attribute['attributeValue'] ) ? $attribute['attributeValue'] : '';
|
||||
$attribute_key = "attribute_{$attribute_name}";
|
||||
|
||||
$attributes[ $attribute_key ] = $attribute_value;
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of cart items.
|
||||
*
|
||||
|
||||
@@ -452,6 +452,17 @@ class Checkout_Mutation {
|
||||
self::validate_data( $data );
|
||||
WC()->checkout()->check_cart_items();
|
||||
|
||||
|
||||
// Throw cart validation errors stored in the session.
|
||||
$cart_item_errors = wc_get_notices( 'error' );
|
||||
|
||||
|
||||
if ( ! empty( $cart_item_errors ) ) {
|
||||
$cart_item_error_msgs = implode( ' ', array_column( $cart_item_errors, 'notice' ) );
|
||||
\wc_clear_notices();
|
||||
throw new UserError( $cart_item_error_msgs );
|
||||
}
|
||||
|
||||
if ( WC()->cart->needs_shipping() ) {
|
||||
$shipping_country = WC()->customer->get_shipping_country();
|
||||
|
||||
|
||||
@@ -104,7 +104,11 @@ class Cart_Add_Item {
|
||||
$cart_item_args = Cart_Mutation::prepare_cart_item( $input, $context, $info );
|
||||
|
||||
// Add item to cart and get item key.
|
||||
$cart_item_key = \WC()->cart->add_to_cart( ...$cart_item_args );
|
||||
try {
|
||||
$cart_item_key = \WC()->cart->add_to_cart( ...$cart_item_args );
|
||||
} catch( \Exception $e ) { // Repackage any errors.
|
||||
throw new UserError( $e->getMessage() );
|
||||
}
|
||||
|
||||
// If cart item key valid return payload.
|
||||
if ( false !== $cart_item_key ) {
|
||||
@@ -115,6 +119,7 @@ class Cart_Add_Item {
|
||||
$notices = \WC()->session->get( 'wc_notices' );
|
||||
if ( ! empty( $notices['error'] ) ) {
|
||||
$cart_error_messages = implode( ' ', array_column( $notices['error'], 'notice' ) );
|
||||
\wc_clear_notices();
|
||||
throw new UserError( $cart_error_messages );
|
||||
} else {
|
||||
throw new UserError( __( 'Failed to add cart item. Please check input.', 'wp-graphql-woocommerce' ) );
|
||||
|
||||
@@ -22,11 +22,11 @@ class Product_Attribute_Input {
|
||||
array(
|
||||
'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ),
|
||||
'fields' => array(
|
||||
'attribute' => array(
|
||||
'attributeName' => array(
|
||||
'type' => array( 'non_null' => 'String' ),
|
||||
),
|
||||
'attributeTerm' => array(
|
||||
'type' => array( 'non_null' => 'String' ),
|
||||
'attributeValue' => array(
|
||||
'type' => 'String',
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ class Root_Query {
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args, AppContext $context ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
$coupon_id = null;
|
||||
@@ -166,38 +166,11 @@ class Root_Query {
|
||||
'type' => 'OrderIdTypeEnum',
|
||||
'description' => __( 'Type of ID being used identify order', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'orderId' => array(
|
||||
'type' => 'Int',
|
||||
'description' => __( 'Get the order by its database ID', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => __(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "order(id: value, idType: value)" instead',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
),
|
||||
'orderKey' => array(
|
||||
'type' => 'String',
|
||||
'description' => __( 'Get the order by its order number', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => __(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "order(id: value, idType: value)" instead',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args, AppContext $context ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
// Process deprecated arguments. Will be removed in v0.5.x.
|
||||
if ( ! empty( $args['orderId'] ) ) {
|
||||
$id = $args['orderId'];
|
||||
$id_type = 'database_id';
|
||||
} elseif ( ! empty( $args['orderKey'] ) ) {
|
||||
$id = $args['orderKey'];
|
||||
$id_type = 'order_number';
|
||||
}
|
||||
|
||||
$order_id = null;
|
||||
switch ( $id_type ) {
|
||||
case 'order_number':
|
||||
@@ -260,30 +233,11 @@ class Root_Query {
|
||||
'type' => 'ProductVariationIdTypeEnum',
|
||||
'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'variationId' => array(
|
||||
'type' => 'Int',
|
||||
'description' => __( 'Get the product variation by its database ID', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => __(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "productVariation(id: value, idType: DATABASE_ID)" instead',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args, AppContext $context ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
/**
|
||||
* Process deprecated arguments
|
||||
*
|
||||
* Will be removed in v0.5.x.
|
||||
*/
|
||||
if ( ! empty( $args['variationId'] ) ) {
|
||||
$id = $args['variationId'];
|
||||
$id_type = 'database_id';
|
||||
}
|
||||
|
||||
$variation_id = null;
|
||||
switch ( $id_type ) {
|
||||
case 'database_id':
|
||||
@@ -324,7 +278,7 @@ class Root_Query {
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args, AppContext $context ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
$refund_id = null;
|
||||
@@ -388,30 +342,11 @@ class Root_Query {
|
||||
'type' => 'ShippingMethodIdTypeEnum',
|
||||
'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'methodId' => array(
|
||||
'type' => 'ID',
|
||||
'description' => __( 'Get the shipping method by its database ID', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => __(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "shippingMethod(id: value, idType: DATABASE_ID)" instead.',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
/**
|
||||
* Process deprecated arguments
|
||||
*
|
||||
* Will be removed in v0.5.x.
|
||||
*/
|
||||
if ( ! empty( $args['methodId'] ) ) {
|
||||
$id = $args['methodId'];
|
||||
$id_type = 'database_id';
|
||||
}
|
||||
|
||||
$method_id = null;
|
||||
switch ( $id_type ) {
|
||||
case 'database_id':
|
||||
@@ -442,30 +377,11 @@ class Root_Query {
|
||||
'type' => 'TaxRateIdTypeEnum',
|
||||
'description' => __( 'Type of ID being used identify tax rate', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'rateId' => array(
|
||||
'type' => 'Int',
|
||||
'description' => __( 'Get the tax rate by its database ID', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => __(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "taxRate(id: value, idType: DATABASE_ID)" instead.',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args, AppContext $context ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
/**
|
||||
* Process deprecated arguments
|
||||
*
|
||||
* Will be removed in v0.5.x.
|
||||
*/
|
||||
if ( ! empty( $args['rateId'] ) ) {
|
||||
$id = $args['rateId'];
|
||||
$id_type = 'database_id';
|
||||
}
|
||||
|
||||
$rate_id = null;
|
||||
switch ( $id_type ) {
|
||||
case 'database_id':
|
||||
@@ -514,76 +430,11 @@ class Root_Query {
|
||||
'type' => 'ProductIdTypeEnum',
|
||||
'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
/**
|
||||
* DEPRECATED
|
||||
*
|
||||
* Will be removed in v0.5.x.
|
||||
*/
|
||||
'productId' => array(
|
||||
'type' => 'Int',
|
||||
'description' => __( 'Get the product by its database ID', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => sprintf(
|
||||
/* translators: %s: product type */
|
||||
__(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "%sProduct(id: value, idType: DATABASE_ID)" instead',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
$type
|
||||
),
|
||||
),
|
||||
/**
|
||||
* DEPRECATED
|
||||
*
|
||||
* Will be removed in v0.5.x.
|
||||
*/
|
||||
'slug' => array(
|
||||
'type' => 'String',
|
||||
'description' => __( 'Get the product by its slug', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => sprintf(
|
||||
/* translators: %s: product type */
|
||||
__(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "%sProduct(id: value, idType: SLUG)" instead',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
$type
|
||||
),
|
||||
),
|
||||
'sku' => array(
|
||||
'type' => 'String',
|
||||
'description' => __( 'Get the product by its sku', 'wp-graphql-woocommerce' ),
|
||||
'isDeprecated' => true,
|
||||
'deprecationReason' => sprintf(
|
||||
/* translators: %s: product type */
|
||||
__(
|
||||
'This argument has been deprecation, and will be removed in v0.5.x. Please use "%sProduct(id: value, idType: SKU)" instead',
|
||||
'wp-graphql-woocommerce'
|
||||
),
|
||||
$type
|
||||
),
|
||||
),
|
||||
),
|
||||
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $type ) {
|
||||
$id = isset( $args['id'] ) ? $args['id'] : null;
|
||||
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';
|
||||
|
||||
/**
|
||||
* Process deprecated arguments
|
||||
*
|
||||
* Will be removed in v0.5.x.
|
||||
*/
|
||||
if ( ! empty( $args['productId'] ) ) {
|
||||
$id = $args['productId'];
|
||||
$id_type = 'database_id';
|
||||
} elseif ( ! empty( $args['slug'] ) ) {
|
||||
$id = $args['slug'];
|
||||
$id_type = 'slug';
|
||||
} elseif ( ! empty( $args['sku'] ) ) {
|
||||
$id = $args['sku'];
|
||||
$id_type = 'sku';
|
||||
}
|
||||
|
||||
$product_id = null;
|
||||
switch ( $id_type ) {
|
||||
case 'sku':
|
||||
|
||||
@@ -181,15 +181,21 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 3,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Retrieve cart item key.
|
||||
$this->assertArrayHasKey('data', $actual );
|
||||
$this->assertArrayHasKey('addToCart', $actual['data'] );
|
||||
$this->assertArrayHasKey('cartItem', $actual['data']['addToCart'] );
|
||||
$this->assertArrayHasKey('key', $actual['data']['addToCart']['cartItem'] );
|
||||
$this->assertArrayHasKey( 'data', $actual );
|
||||
$this->assertArrayHasKey( 'addToCart', $actual['data'] );
|
||||
$this->assertArrayHasKey( 'cartItem', $actual['data']['addToCart'] );
|
||||
$this->assertArrayHasKey( 'key', $actual['data']['addToCart']['cartItem'] );
|
||||
$key = $actual['data']['addToCart']['cartItem']['key'];
|
||||
|
||||
// Get newly created cart item data.
|
||||
@@ -322,7 +328,13 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -364,6 +376,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -380,6 +398,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 3,
|
||||
'variationId' => $ids['variations'][1],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -422,6 +446,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -438,6 +468,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 3,
|
||||
'variationId' => $ids['variations'][1],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -479,6 +515,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -527,6 +569,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 2,
|
||||
'variationId' => $ids['variations'][0],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -543,6 +591,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
'productId' => $ids['product'],
|
||||
'quantity' => 1,
|
||||
'variationId' => $ids['variations'][1],
|
||||
'variation' => array(
|
||||
array(
|
||||
'attributeName' => 'color',
|
||||
'attributeValue' => 'red',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -589,7 +643,12 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
|
||||
// Add items to carts.
|
||||
$cart_item = $cart->get_cart_item(
|
||||
$cart->add_to_cart( $ids['product'], 2, $ids['variations'][0] )
|
||||
$cart->add_to_cart(
|
||||
$ids['product'],
|
||||
2,
|
||||
$ids['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
)
|
||||
);
|
||||
|
||||
$mutation = '
|
||||
@@ -1008,14 +1067,28 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
|
||||
public function testAddToCartMutationErrors() {
|
||||
// Create products.
|
||||
$product_id = $this->product->create_simple(
|
||||
$product_id = $this->product->create_simple(
|
||||
array(
|
||||
'manage_stock' => true,
|
||||
'stock_quantity' => 1,
|
||||
)
|
||||
);
|
||||
$variation_ids = $this->variation->create( $this->product->create_variable() );
|
||||
|
||||
$failed = $this->addToCart(
|
||||
\WC()->session->set( 'wc_notices', null );
|
||||
$missing_attributes = $this->addToCart(
|
||||
array(
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $product_id,
|
||||
'quantity' => 5,
|
||||
'variationId' => $variation_ids['variations'][0],
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey( 'errors', $missing_attributes );
|
||||
|
||||
\WC()->session->set( 'wc_notices', null );
|
||||
$not_enough_stock = $this->addToCart(
|
||||
array(
|
||||
'clientMutationId' => 'someId',
|
||||
'productId' => $product_id,
|
||||
@@ -1023,6 +1096,6 @@ class CartMutationsTest extends \Codeception\TestCase\WPTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey( 'errors', $failed );
|
||||
$this->assertArrayHasKey( 'errors', $not_enough_stock );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ class CartQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
$key = $cart->add_to_cart(
|
||||
$variations['product'],
|
||||
3,
|
||||
$variations['variations'][0]
|
||||
$variations['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
|
||||
$query = '
|
||||
|
||||
@@ -307,7 +307,12 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
|
||||
WC()->cart->add_to_cart( $product_ids[0], 3 );
|
||||
WC()->cart->add_to_cart( $product_ids[1], 6 );
|
||||
WC()->cart->add_to_cart( $product_ids[2], 2, $variable['variations'][0] );
|
||||
WC()->cart->add_to_cart(
|
||||
$product_ids[2],
|
||||
2,
|
||||
$variable['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
WC()->cart->apply_coupon( $coupon->get_code() );
|
||||
|
||||
$input = array(
|
||||
@@ -515,7 +520,12 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
);
|
||||
WC()->cart->add_to_cart( $product_ids[0], 3 );
|
||||
WC()->cart->add_to_cart( $product_ids[1], 6 );
|
||||
WC()->cart->add_to_cart( $product_ids[2], 2, $variable['variations'][0] );
|
||||
WC()->cart->add_to_cart(
|
||||
$product_ids[2],
|
||||
2,
|
||||
$variable['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
WC()->cart->apply_coupon( $coupon->get_code() );
|
||||
|
||||
$input = array(
|
||||
@@ -708,7 +718,12 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
);
|
||||
WC()->cart->add_to_cart( $product_ids[0], 3 );
|
||||
WC()->cart->add_to_cart( $product_ids[1], 6 );
|
||||
WC()->cart->add_to_cart( $product_ids[2], 2, $variable['variations'][0] );
|
||||
WC()->cart->add_to_cart(
|
||||
$product_ids[2],
|
||||
2,
|
||||
$variable['variations'][0],
|
||||
array( 'attribute_pa_color' => 'red' )
|
||||
);
|
||||
WC()->cart->apply_coupon( $coupon->get_code() );
|
||||
|
||||
$input = array(
|
||||
@@ -1296,5 +1311,52 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase {
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckoutMutationCartItemValidation() {
|
||||
add_filter( 'woocommerce_hold_stock_for_checkout', '__return_false' );
|
||||
|
||||
$product_id = $this->product->create_simple(
|
||||
array(
|
||||
'manage_stock' => true,
|
||||
'stock_quantity' => 3,
|
||||
)
|
||||
);
|
||||
|
||||
$key = WC()->cart->add_to_cart( $product_id, 3 );
|
||||
WC()->cart->set_quantity( $key, 5 );
|
||||
|
||||
/**
|
||||
* Assertion One
|
||||
*
|
||||
* Ensure that checkout failed when stock is too low.
|
||||
*/
|
||||
$input = array(
|
||||
'clientMutationId' => 'someId',
|
||||
'paymentMethod' => 'bacs',
|
||||
'shippingMethod' => array( 'flat rate' ),
|
||||
'billing' => array(
|
||||
'firstName' => 'May',
|
||||
'lastName' => 'Parker',
|
||||
'company' => 'Harris Teeter',
|
||||
'address1' => '20 Ingram St',
|
||||
'city' => 'New York City',
|
||||
'state' => 'NY',
|
||||
'postcode' => '12345',
|
||||
'country' => 'US',
|
||||
'email' => 'superfreak500@gmail.com',
|
||||
'phone' => '555-555-1234',
|
||||
),
|
||||
'account' => array(
|
||||
'username' => 'test_user_1',
|
||||
'password' => 'test_pass'
|
||||
)
|
||||
);
|
||||
$failed = $this->checkout( $input );
|
||||
|
||||
// use --debug flag to view.
|
||||
codecept_debug( $failed );
|
||||
|
||||
$this->assertArrayHasKey( 'errors', $failed );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class MetaDataQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
'product_id' => $this->variation_ids['product'],
|
||||
'quantity' => 2,
|
||||
'variation_id' => $this->variation_ids['variations'][0],
|
||||
'variation' => array(),
|
||||
'variation' => array( 'attribute_pa_color' => 'red' ),
|
||||
'cart_item_data' => $cart_meta_data
|
||||
)
|
||||
)[0];
|
||||
|
||||
@@ -28,8 +28,8 @@ class TaxRateQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
$id = Relay::toGlobalId( 'tax_rate', $this->rate );
|
||||
|
||||
$query = '
|
||||
query taxRateQuery( $id: ID, $rateId: Int ) {
|
||||
taxRate( id: $id, rateId: $rateId ) {
|
||||
query taxRateQuery( $id: ID, $idType: TaxRateIdTypeEnum ) {
|
||||
taxRate( id: $id, idType: $idType ) {
|
||||
id
|
||||
databaseId
|
||||
country
|
||||
@@ -66,7 +66,10 @@ class TaxRateQueriesTest extends \Codeception\TestCase\WPTestCase {
|
||||
*
|
||||
* tests query, "rateId" query arg, and results
|
||||
*/
|
||||
$variables = array( 'rateId' => $this->rate );
|
||||
$variables = array(
|
||||
'id' => $this->rate,
|
||||
'idType' => 'DATABASE_ID',
|
||||
);
|
||||
$actual = do_graphql_request( $query, 'taxRateQuery', $variables );
|
||||
$expected = array( 'data' => array( 'taxRate' => $this->helper->print_query( $this->rate ) ) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user