mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
fix: HPOS order mutation data loss, COT cursor pagination, email tests, checkout auth (#1003)
* devops: WC email template tests, COT cursor HPOS fix, checkout account auth WC Email Template Tests: - Add WooCommerceEmailTemplatesTest verifying WC email templates are used for registerCustomer, checkout with account creation, and password reset - Use MockPHPMailer to capture emails and verify HTML content type - Disable deferred transactional emails during tests via GRAPHQL_TESTING flag COT Cursor HPOS Fix: - Fix COT_Cursor::compare_with to resolve orderby aliases and legacy meta keys (_order_total, _date_completed, etc.) to COT column names - Add resolve_orderby_alias() mapping short aliases and meta keys to columns - Add DB_Hooks::clean_query_vars to translate post_* and meta_key orderby to COT-compatible equivalents via woocommerce_order_query_args filter Checkout Account Authentication: - Add authenticate field to CreateAccountInput type - Gate wc_set_customer_auth_cookie() behind authenticate flag in checkout mutation so account creation doesn't auto-authenticate by default Closes #882 * devops: codeception.dist.yml updated * fix: Functional test cleanup and CI coverage condition Test fixes: - Enable authorizing URL fields in ProtectedRouterCest and DownloadableItemAuthCest via setWooGraphQLSetting - Add stale data cleanup (sessions, users, products, orders) to GraphQLE2E _setupStore/getCatalog/setupStoreAndUsers - Fix CartTransactionQueueCest and CartQueriesTest for test isolation CI: - Only run coverage job when at least one upstream job succeeds * chore: Linter compliances met * fix: HPOS order mutation data loss and CI coverage condition Refactor order create/update mutations to set all props on a single WC_Order instance before saving, mirroring the WC REST API pattern. Previously, separate add_order_meta() and add_items() calls each loaded their own order instance and saved independently, causing HPOS data loss for payment method, addresses, and other fields. Also fix CI coverage job to only run when all upstream jobs succeed, and correct test assertions for RAW format line item totals. Closes #591 * chore: Linter compliances met * chore: Remove dead code from Order_Mutation after prepare_order refactor Removes add_items() and update_address() which are no longer called after the prepare_order() consolidation. * chore: Remove dead code add_order_meta and update_item_meta_data
This commit is contained in:
@@ -233,7 +233,7 @@ jobs:
|
||||
|
||||
coverage:
|
||||
needs: [acceptance, functional, wpunit]
|
||||
if: ${{ always() }}
|
||||
if: ${{ needs.acceptance.result == 'success' && needs.functional.result == 'success' && needs.wpunit.result == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
name: Aggregate Coverage & Push to Coveralls
|
||||
steps:
|
||||
|
||||
@@ -49,7 +49,7 @@ modules:
|
||||
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
|
||||
dump: 'local/db/app_db.sql'
|
||||
populate: false
|
||||
cleanup: true
|
||||
cleanup: false
|
||||
waitlock: 0
|
||||
url: '%WORDPRESS_URL%'
|
||||
urlReplacement: true
|
||||
|
||||
@@ -50,9 +50,6 @@
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"files": [
|
||||
"tests/_data/config.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Tests\\WPGraphQL\\WooCommerce\\": "tests/_support/"
|
||||
}
|
||||
|
||||
Generated
+7
-6
@@ -8,16 +8,16 @@
|
||||
"packages": [
|
||||
{
|
||||
"name": "firebase/php-jwt",
|
||||
"version": "v7.0.3",
|
||||
"version": "v7.0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/firebase/php-jwt.git",
|
||||
"reference": "28aa0694bcfdfa5e2959c394d5a1ee7a5083629e"
|
||||
"reference": "e41f1bd7dbe3c5455c3f72d4338cfeb083b71931"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/28aa0694bcfdfa5e2959c394d5a1ee7a5083629e",
|
||||
"reference": "28aa0694bcfdfa5e2959c394d5a1ee7a5083629e",
|
||||
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/e41f1bd7dbe3c5455c3f72d4338cfeb083b71931",
|
||||
"reference": "e41f1bd7dbe3c5455c3f72d4338cfeb083b71931",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -25,6 +25,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"phpfastcache/phpfastcache": "^9.2",
|
||||
"phpspec/prophecy-phpunit": "^2.0",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"psr/cache": "^2.0||^3.0",
|
||||
@@ -65,9 +66,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/firebase/php-jwt/issues",
|
||||
"source": "https://github.com/firebase/php-jwt/tree/v7.0.3"
|
||||
"source": "https://github.com/firebase/php-jwt/tree/v7.0.4"
|
||||
},
|
||||
"time": "2026-02-25T22:16:40+00:00"
|
||||
"time": "2026-03-27T21:17:19+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
||||
@@ -182,7 +182,7 @@ class General extends Section {
|
||||
'desc' => __( 'Query parameter name of the nonce included in the "cartUrl" field', 'wp-graphql-woocommerce' )
|
||||
. ( $cart_url_hardcoded ? __( ' This setting is disabled. The "CART_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
|
||||
'type' => 'text',
|
||||
'value' => $cart_url_hardcoded ? CART_URL_NONCE_PARAM : woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
|
||||
'value' => $cart_url_hardcoded ? constant( 'CART_URL_NONCE_PARAM' ) : woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
|
||||
'disabled' => defined( 'CART_URL_NONCE_PARAM' ) || ! in_array( 'cart_url', $enabled_authorizing_url_fields, true ),
|
||||
'sanitize_callback' => static function ( $value ) {
|
||||
$other_nonces = self::get_other_nonce_values( 'cart_url' );
|
||||
@@ -206,7 +206,7 @@ class General extends Section {
|
||||
'desc' => __( 'Query parameter name of the nonce included in the "checkoutUrl" field', 'wp-graphql-woocommerce' )
|
||||
. ( $checkout_url_hardcoded ? __( ' This setting is disabled. The "CHECKOUT_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
|
||||
'type' => 'text',
|
||||
'value' => $checkout_url_hardcoded ? CHECKOUT_URL_NONCE_PARAM : woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
|
||||
'value' => $checkout_url_hardcoded ? constant( 'CHECKOUT_URL_NONCE_PARAM' ) : woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
|
||||
'disabled' => defined( 'CHECKOUT_URL_NONCE_PARAM' ) || ! in_array( 'checkout_url', $enabled_authorizing_url_fields, true ),
|
||||
'sanitize_callback' => static function ( $value ) {
|
||||
$other_nonces = self::get_other_nonce_values( 'checkout_url' );
|
||||
@@ -230,7 +230,7 @@ class General extends Section {
|
||||
'desc' => __( 'Query parameter name of the nonce included in the "accountUrl" field', 'wp-graphql-woocommerce' )
|
||||
. ( $account_url_hardcoded ? __( ' This setting is disabled. The "ACCOUNT_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
|
||||
'type' => 'text',
|
||||
'value' => $account_url_hardcoded ? ACCOUNT_URL_NONCE_PARAM : woographql_setting( 'account_url_nonce_param', '_wc_account' ),
|
||||
'value' => $account_url_hardcoded ? constant( 'ACCOUNT_URL_NONCE_PARAM' ) : woographql_setting( 'account_url_nonce_param', '_wc_account' ),
|
||||
'disabled' => defined( 'ACCOUNT_URL_NONCE_PARAM' ) || ! in_array( 'account_url', $enabled_authorizing_url_fields, true ),
|
||||
'sanitize_callback' => static function ( $value ) {
|
||||
$other_nonces = self::get_other_nonce_values( 'account_url' );
|
||||
@@ -254,7 +254,7 @@ class General extends Section {
|
||||
'desc' => __( 'Query parameter name of the nonce included in the "addPaymentMethodUrl" field', 'wp-graphql-woocommerce' )
|
||||
. ( $add_payment_method_url_hardcoded ? __( ' This setting is disabled. The "ADD_PAYMENT_METHOD_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
|
||||
'type' => 'text',
|
||||
'value' => $add_payment_method_url_hardcoded ? ADD_PAYMENT_METHOD_URL_NONCE_PARAM : woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
|
||||
'value' => $add_payment_method_url_hardcoded ? constant( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) : woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
|
||||
'disabled' => defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) || ! in_array( 'add_payment_method_url', $enabled_authorizing_url_fields, true ),
|
||||
'sanitize_callback' => static function ( $value ) {
|
||||
$other_nonces = self::get_other_nonce_values( 'add_payment_method_url' );
|
||||
|
||||
@@ -18,9 +18,87 @@ class DB_Hooks {
|
||||
* DB_Hooks constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'woocommerce_order_query_args', [ $this, 'clean_query_vars' ] );
|
||||
add_filter( 'woocommerce_orders_table_query_clauses', [ $this, 'add_cursor' ], 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta key to COT column mapping for orderby translation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $meta_to_column = [
|
||||
'_order_total' => 'total',
|
||||
'_order_tax' => 'tax_amount',
|
||||
'_cart_discount' => 'discount_total_amount',
|
||||
'_date_paid' => 'date_paid',
|
||||
'_date_completed' => 'date_completed',
|
||||
'_order_key' => 'order_key',
|
||||
];
|
||||
|
||||
/**
|
||||
* Translate legacy meta_key orderby to COT column orderby in query vars.
|
||||
*
|
||||
* When HPOS is active, meta keys like _order_total are stored as columns
|
||||
* in the orders table, not in the meta table. This replaces meta_value_num
|
||||
* orderby with the direct column name so WC's OrdersTableQuery doesn't
|
||||
* generate an invalid meta join.
|
||||
*
|
||||
* @param array $query_vars The query vars.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function clean_query_vars( $query_vars ) {
|
||||
if ( true !== is_graphql_request() ) {
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
if ( ! \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
// Map post_* orderby fields to COT-compatible equivalents.
|
||||
$post_field_map = [
|
||||
'post_date' => 'date',
|
||||
'post_modified' => 'date_modified',
|
||||
'post_parent' => 'parent',
|
||||
];
|
||||
|
||||
$orderby = $query_vars['orderby'] ?? [];
|
||||
if ( is_array( $orderby ) ) {
|
||||
foreach ( $post_field_map as $post_field => $cot_field ) {
|
||||
if ( isset( $orderby[ $post_field ] ) ) {
|
||||
$orderby[ $cot_field ] = $orderby[ $post_field ];
|
||||
unset( $orderby[ $post_field ] );
|
||||
}
|
||||
}
|
||||
$query_vars['orderby'] = $orderby;
|
||||
}
|
||||
|
||||
// Map meta_key orderby to COT column orderby.
|
||||
$meta_key = $query_vars['meta_key'] ?? '';
|
||||
if ( empty( $meta_key ) || ! isset( self::$meta_to_column[ $meta_key ] ) ) {
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
$column = self::$meta_to_column[ $meta_key ];
|
||||
$default_order = isset( $query_vars['graphql_cursor_compare'] ) && '>' === $query_vars['graphql_cursor_compare']
|
||||
? 'DESC'
|
||||
: 'ASC';
|
||||
|
||||
$orderby = $query_vars['orderby'] ?? [];
|
||||
if ( is_array( $orderby ) ) {
|
||||
$order = $orderby['meta_value_num'] ?? ( $orderby['meta_value'] ?? $default_order );
|
||||
unset( $orderby['meta_value_num'], $orderby['meta_value'] );
|
||||
$orderby[ $column ] = $order;
|
||||
$query_vars['orderby'] = $orderby;
|
||||
}
|
||||
|
||||
unset( $query_vars['meta_key'] );
|
||||
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the cursor to the WHERE clause of the query.
|
||||
*
|
||||
|
||||
@@ -616,7 +616,6 @@ class Product_Connection_Resolver extends AbstractConnectionResolver {
|
||||
|
||||
if ( isset( $where_args['featured'] ) ) {
|
||||
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
|
||||
\codecept_debug( $product_visibility_term_ids );
|
||||
if ( $where_args['featured'] ) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'product_visibility',
|
||||
|
||||
@@ -89,6 +89,38 @@ class COT_Cursor extends AbstractCursor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an orderby alias (e.g. 'date', 'total') to the fully qualified
|
||||
* COT column name used in the column_mappings.
|
||||
*
|
||||
* @param string $alias The orderby alias.
|
||||
*
|
||||
* @return string The resolved column name, or the original alias if no mapping found.
|
||||
*/
|
||||
public function resolve_orderby_alias( $alias ) {
|
||||
$alias_map = [
|
||||
// Short aliases used by WC OrdersTableQuery.
|
||||
'post_date' => 'date_created_gmt',
|
||||
'date' => 'date_created_gmt',
|
||||
'date_created' => 'date_created_gmt',
|
||||
'modified' => 'date_updated_gmt',
|
||||
'date_modified' => 'date_updated_gmt',
|
||||
'type' => 'type',
|
||||
'parent' => 'parent_order_id',
|
||||
'total' => 'total_amount',
|
||||
'order_total' => 'total_amount',
|
||||
// Legacy meta keys that map to COT columns in HPOS mode.
|
||||
'_order_total' => 'total_amount',
|
||||
'_order_tax' => 'tax_amount',
|
||||
'_cart_discount' => 'discount_total_amount',
|
||||
'_date_paid' => 'date_paid_gmt',
|
||||
'_date_completed' => 'date_completed_gmt',
|
||||
'_order_key' => 'order_key',
|
||||
];
|
||||
|
||||
return $alias_map[ $alias ] ?? $alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
@@ -188,22 +220,42 @@ class COT_Cursor extends AbstractCursor {
|
||||
return;
|
||||
}
|
||||
|
||||
$meta_orderby_keys = $this->meta_query ? $this->meta_query->get_orderby_keys() : [];
|
||||
// Check for explicit cursor compare fields set by the connection resolver.
|
||||
$key = $this->get_query_var( "graphql_cursor_compare_by_{$by}_key" );
|
||||
$value = $this->get_query_var( "graphql_cursor_compare_by_{$by}_value" );
|
||||
if ( ! empty( $key ) && ! empty( $value ) ) {
|
||||
$this->builder->add_field( $key, $value, null, $order );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( in_array( $by, $meta_orderby_keys, true ) && null !== $this->meta_query ) {
|
||||
$orderby = $this->meta_query->get_orderby_clause_for_key( $by );
|
||||
$value = $this->cursor_node->get_meta( $by, true ) ?? null;
|
||||
} else {
|
||||
$orderby = $by;
|
||||
$getter_name = $this->column_mappings[ $orderby ];
|
||||
// Resolve the orderby key to a COT column. For meta_value/meta_value_num,
|
||||
// use the meta_key query var since that holds the actual field name.
|
||||
$table_name = $this->tables['orders'];
|
||||
$source = in_array( $by, [ 'meta_value', 'meta_value_num' ], true )
|
||||
? ( $this->get_query_var( 'meta_key' ) ?? $by )
|
||||
: $by;
|
||||
$column = $this->resolve_orderby_alias( $source );
|
||||
$orderby = "{$table_name}.{$column}";
|
||||
$getter_name = $this->column_mappings[ $orderby ] ?? null;
|
||||
|
||||
if ( null !== $getter_name ) {
|
||||
$method = "get_{$getter_name}";
|
||||
$value = is_callable( [ $this->cursor_node, $method ] ) ? $this->cursor_node->$method() : null;
|
||||
} else {
|
||||
// Fall back to meta query if the field doesn't map to a COT column.
|
||||
$meta_orderby_keys = $this->meta_query ? $this->meta_query->get_orderby_keys() : [];
|
||||
|
||||
if ( in_array( $by, $meta_orderby_keys, true ) && null !== $this->meta_query ) {
|
||||
$orderby = $this->meta_query->get_orderby_clause_for_key( $by );
|
||||
$value = $this->cursor_node->get_meta( $source, true ) ?? null;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $value ) && is_a( $value, '\WC_DateTime' ) ) {
|
||||
$value = ( new \DateTime( $value ) )->setTimezone( new \DateTimeZone( '+00:00' ) )->format( 'Y-m-d H:i:s' );
|
||||
$this->builder->add_field( $by, $value, 'DATETIME', $order );
|
||||
$this->builder->add_field( $orderby, $value, 'DATETIME', $order );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -211,7 +263,7 @@ class COT_Cursor extends AbstractCursor {
|
||||
* Compare by the post field if the key matches a value
|
||||
*/
|
||||
if ( ! empty( $value ) ) {
|
||||
$this->builder->add_field( $by, $value, null, $order );
|
||||
$this->builder->add_field( $orderby, $value, null, $order );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ class Checkout_Mutation {
|
||||
$data = [
|
||||
'terms' => (int) isset( $input['terms'] ),
|
||||
'createaccount' => (int) ! empty( $input['account'] ),
|
||||
'authenticate_account' => ! empty( $input['account']['authenticate'] ),
|
||||
'payment_method' => isset( $input['paymentMethod'] ) ? $input['paymentMethod'] : '',
|
||||
'shipping_method' => isset( $input['shippingMethod'] ) ? $input['shippingMethod'] : '',
|
||||
'ship_to_different_address' => ! empty( $input['shipToDifferentAddress'] ) && ! wc_ship_to_billing_address_only(),
|
||||
@@ -304,10 +305,12 @@ class Checkout_Mutation {
|
||||
throw new UserError( $customer_id->get_error_message() );
|
||||
}
|
||||
|
||||
wc_set_customer_auth_cookie( $customer_id );
|
||||
if ( ! empty( $data['authenticate_account'] ) ) {
|
||||
wc_set_customer_auth_cookie( $customer_id );
|
||||
|
||||
// As we are now logged in, checkout will need to refresh to show logged in data.
|
||||
WC()->session->set( 'reload_checkout', true );
|
||||
// As we are now logged in, checkout will need to refresh to show logged in data.
|
||||
WC()->session->set( 'reload_checkout', true );
|
||||
}
|
||||
|
||||
// Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering.
|
||||
WC()->cart->calculate_totals();
|
||||
@@ -513,7 +516,6 @@ class Checkout_Mutation {
|
||||
|
||||
if ( WC()->cart->needs_payment() ) {
|
||||
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||
\codecept_debug( $available_gateways );
|
||||
if ( ! isset( $available_gateways[ $data['payment_method'] ] ) ) {
|
||||
$errors->add( 'payment', __( 'Invalid payment method.', 'wp-graphql-woocommerce' ) );
|
||||
} else {
|
||||
|
||||
@@ -133,102 +133,6 @@ class Order_Mutation {
|
||||
return $order->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items to order.
|
||||
*
|
||||
* @param array $input Input data describing order.
|
||||
* @param int $order_id Order object.
|
||||
* @param \WPGraphQL\AppContext $context AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info ResolveInfo instance.
|
||||
*
|
||||
* @throws \Exception Failed to retrieve order.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function add_items( $input, $order_id, $context, $info ) {
|
||||
/** @var \WC_Order|false $order */
|
||||
$order = \WC_Order_Factory::get_order( $order_id );
|
||||
if ( false === $order ) {
|
||||
throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
$item_group_keys = [
|
||||
'lineItems' => 'line_item',
|
||||
'shippingLines' => 'shipping',
|
||||
'feeLines' => 'fee',
|
||||
];
|
||||
|
||||
$order_items = [];
|
||||
foreach ( $input as $key => $group_items ) {
|
||||
if ( array_key_exists( $key, $item_group_keys ) ) {
|
||||
$type = $item_group_keys[ $key ];
|
||||
$order_items[ $type ] = [];
|
||||
|
||||
/**
|
||||
* Action called before an item group is added to an order.
|
||||
*
|
||||
* @param array $group_items Items data being added.
|
||||
* @param \WC_Order $order Order object.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( "graphql_woocommerce_before_{$type}s_added_to_order", $group_items, $order, $context, $info );
|
||||
|
||||
foreach ( $group_items as $item_data ) {
|
||||
$item = self::set_item(
|
||||
$item_data,
|
||||
$type,
|
||||
$order,
|
||||
$context,
|
||||
$info
|
||||
);
|
||||
|
||||
/**
|
||||
* Action called before an item group is added to an order.
|
||||
*
|
||||
* @param \WC_Order_Item $item Order item object.
|
||||
* @param array $item_data Item data being added.
|
||||
* @param \WC_Order $order Order object.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( "graphql_woocommerce_before_{$type}_added_to_order", $item, $item_data, $order, $context, $info );
|
||||
|
||||
if ( 0 === $item->get_id() ) {
|
||||
$order->add_item( $item );
|
||||
$order_items[ $type ][] = $item;
|
||||
} else {
|
||||
$item->save();
|
||||
$order_items[ $type ][] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action called after an item group is added to an order, and before the order has been saved with the new items.
|
||||
*
|
||||
* @param array $group_items Item data being added.
|
||||
* @param \WC_Order $order Order object.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( "graphql_woocommerce_after_{$type}s_added_to_order", $group_items, $order, $context, $info );
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
/**
|
||||
* Action called after all items have been added and right before the new items have been saved.
|
||||
*
|
||||
* @param array<string, array<\WC_Order_Item>> $order_items Order items.
|
||||
* @param \WC_Order $order WC_Order instance.
|
||||
* @param array $input Input data describing order.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( 'graphql_woocommerce_before_new_order_items_save', $order_items, $order, $input, $context, $info );
|
||||
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array<string, mixed> $item_data Item data.
|
||||
@@ -435,63 +339,87 @@ class Order_Mutation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create/Update order item meta data.
|
||||
* Sets all order props, address fields, items, and meta on the provided order object
|
||||
* and saves once, mirroring the WC REST API pattern to avoid HPOS data loss from
|
||||
* multiple save() calls across different object instances.
|
||||
*
|
||||
* @param int $item_id Order item ID.
|
||||
* @param array $meta_data Array of meta data.
|
||||
* @param \WPGraphQL\AppContext $context AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info ResolveInfo instance.
|
||||
*
|
||||
* @throws \GraphQL\Error\UserError|\Exception Invalid item input | Failed to retrieve order item.
|
||||
* @param \WC_Order $order WC_Order instance.
|
||||
* @param array $input Input data describing order.
|
||||
* @param \WPGraphQL\AppContext $context AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info ResolveInfo instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function update_item_meta_data( $item_id, $meta_data, $context, $info ) {
|
||||
$item = \WC_Order_Factory::get_order_item( $item_id );
|
||||
if ( ! is_object( $item ) ) {
|
||||
throw new \Exception( __( 'Failed to retrieve order item.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
foreach ( $meta_data as $entry ) {
|
||||
$exists = $item->get_meta( $entry['key'], true, 'edit' );
|
||||
if ( '' !== $exists && $exists !== $entry['value'] ) {
|
||||
\wc_update_order_item_meta( $item_id, $entry['key'], $entry['value'] );
|
||||
} else {
|
||||
\wc_add_order_item_meta( $item_id, $entry['key'], $entry['value'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta data not set in self::create_order().
|
||||
*
|
||||
* @param int $order_id Order ID.
|
||||
* @param array $input Order properties.
|
||||
* @param \WPGraphQL\AppContext $context AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info ResolveInfo instance.
|
||||
*
|
||||
* @throws \Exception Failed to retrieve order.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function add_order_meta( $order_id, $input, $context, $info ) {
|
||||
$order = \WC_Order_Factory::get_order( $order_id );
|
||||
if ( ! is_object( $order ) ) {
|
||||
throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
public static function prepare_order( $order, $input, $context, $info ) {
|
||||
|
||||
foreach ( $input as $key => $value ) {
|
||||
switch ( $key ) {
|
||||
case 'clientMutationId':
|
||||
case 'id':
|
||||
case 'orderId':
|
||||
case 'coupons':
|
||||
case 'lineItems':
|
||||
case 'shippingLines':
|
||||
case 'feeLines':
|
||||
case 'status':
|
||||
case 'isPaid':
|
||||
break;
|
||||
case 'billing':
|
||||
case 'shipping':
|
||||
self::update_address( $value, $order_id, $key );
|
||||
$order->apply_changes();
|
||||
$formatted_address = Customer_Mutation::address_input_mapping( $value, $key );
|
||||
foreach ( $formatted_address as $field => $field_value ) {
|
||||
if ( is_callable( [ $order, "set_{$key}_{$field}" ] ) ) {
|
||||
$order->{"set_{$key}_{$field}"}( $field_value );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'lineItems':
|
||||
case 'shippingLines':
|
||||
case 'feeLines':
|
||||
$item_group_keys = [
|
||||
'lineItems' => 'line_item',
|
||||
'shippingLines' => 'shipping',
|
||||
'feeLines' => 'fee',
|
||||
];
|
||||
$type = $item_group_keys[ $key ];
|
||||
|
||||
/**
|
||||
* Action called before an item group is added to an order.
|
||||
*
|
||||
* @param array $value Items data being added.
|
||||
* @param \WC_Order $order Order object.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( "graphql_woocommerce_before_{$type}s_added_to_order", $value, $order, $context, $info );
|
||||
|
||||
foreach ( $value as $item_data ) {
|
||||
$item = self::set_item( $item_data, $type, $order, $context, $info );
|
||||
|
||||
/**
|
||||
* Action called before an item is added to an order.
|
||||
*
|
||||
* @param \WC_Order_Item $item Order item object.
|
||||
* @param array $item_data Item data being added.
|
||||
* @param \WC_Order $order Order object.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( "graphql_woocommerce_before_{$type}_added_to_order", $item, $item_data, $order, $context, $info );
|
||||
|
||||
if ( 0 === $item->get_id() ) {
|
||||
$order->add_item( $item );
|
||||
} else {
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action called after an item group is added to an order.
|
||||
*
|
||||
* @param array $value Item data being added.
|
||||
* @param \WC_Order $order Order object.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
do_action( "graphql_woocommerce_after_{$type}s_added_to_order", $value, $order, $context, $info );
|
||||
break;
|
||||
case 'metaData':
|
||||
if ( is_array( $value ) ) {
|
||||
@@ -513,7 +441,7 @@ class Order_Mutation {
|
||||
* Action called before changes to order meta are saved.
|
||||
*
|
||||
* @param \WC_Order $order WC_Order instance.
|
||||
* @param array $props Order props array.
|
||||
* @param array $input Order props array.
|
||||
* @param \WPGraphQL\AppContext $context Request AppContext instance.
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $info Request ResolveInfo instance.
|
||||
*/
|
||||
@@ -524,47 +452,14 @@ class Order_Mutation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update address.
|
||||
* Applies coupons to WC_Order instance.
|
||||
*
|
||||
* @param array $address Address data.
|
||||
* @param integer $order_id WC_Order instance.
|
||||
* @param string $type Address type.
|
||||
*
|
||||
* @throws \Exception Failed to retrieve order.
|
||||
* @param \WC_Order $order WC_Order instance.
|
||||
* @param array $coupons Coupon codes to be applied to order.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function update_address( $address, $order_id, $type = 'billing' ) {
|
||||
$order = \WC_Order_Factory::get_order( $order_id );
|
||||
if ( ! is_object( $order ) ) {
|
||||
throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
$formatted_address = Customer_Mutation::address_input_mapping( $address, $type );
|
||||
foreach ( $formatted_address as $key => $value ) {
|
||||
if ( is_callable( [ $order, "set_{$type}_{$key}" ] ) ) {
|
||||
$order->{"set_{$type}_{$key}"}( $value );
|
||||
}
|
||||
}
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies coupons to WC_Order instance
|
||||
*
|
||||
* @param int $order_id Order ID.
|
||||
* @param array $coupons Coupon codes to be applied to order.
|
||||
*
|
||||
* @throws \Exception Failed to retrieve order.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function apply_coupons( $order_id, $coupons ) {
|
||||
$order = \WC_Order_Factory::get_order( $order_id );
|
||||
if ( ! is_object( $order ) ) {
|
||||
throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
public static function apply_coupons( $order, $coupons ) {
|
||||
// Remove all coupons first to ensure calculation is correct.
|
||||
foreach ( $order->get_items( 'coupon' ) as $coupon ) {
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ class Customer extends Model {
|
||||
'isPrivate',
|
||||
'isPublic',
|
||||
'id',
|
||||
'customerId',
|
||||
'databaseId',
|
||||
];
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
||||
|
||||
@@ -149,15 +149,7 @@ class Order_Create {
|
||||
$order = null;
|
||||
try {
|
||||
$order_id = Order_Mutation::create_order( $input, $context, $info );
|
||||
Order_Mutation::add_order_meta( $order_id, $input, $context, $info );
|
||||
Order_Mutation::add_items( $input, $order_id, $context, $info );
|
||||
|
||||
// Apply coupons.
|
||||
if ( ! empty( $input['coupons'] ) ) {
|
||||
Order_Mutation::apply_coupons( $order_id, $input['coupons'] );
|
||||
}
|
||||
|
||||
$order = WC_Order_Factory::get_order( $order_id );
|
||||
$order = WC_Order_Factory::get_order( $order_id );
|
||||
|
||||
if ( ! is_object( $order ) ) {
|
||||
throw new UserError( __( 'Order could not be created.', 'wp-graphql-woocommerce' ) );
|
||||
@@ -171,6 +163,14 @@ class Order_Create {
|
||||
throw new UserError( __( 'Customer ID is invalid.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
// Set all props, address, items, and meta on the order and save once.
|
||||
Order_Mutation::prepare_order( $order, $input, $context, $info );
|
||||
|
||||
// Apply coupons.
|
||||
if ( ! empty( $input['coupons'] ) ) {
|
||||
Order_Mutation::apply_coupons( $order, $input['coupons'] );
|
||||
}
|
||||
|
||||
$order->set_created_via( 'graphql-api' );
|
||||
$order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
|
||||
$order->calculate_totals( true );
|
||||
|
||||
@@ -116,17 +116,9 @@ class Order_Update {
|
||||
*/
|
||||
do_action( 'graphql_woocommerce_before_order_update', $order_id, $input, $context, $info );
|
||||
|
||||
Order_Mutation::add_order_meta( $order_id, $input, $context, $info );
|
||||
Order_Mutation::add_items( $input, $order_id, $context, $info );
|
||||
|
||||
// Apply coupons.
|
||||
if ( ! empty( $input['coupons'] ) ) {
|
||||
Order_Mutation::apply_coupons( $order_id, $input['coupons'] );
|
||||
}
|
||||
|
||||
$order = WC_Order_Factory::get_order( $order_id );
|
||||
|
||||
if ( ! is_object( $order ) ) {
|
||||
if ( ! is_object( $order ) || ! $order->get_id() ) {
|
||||
throw new UserError( __( 'Order not found.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
@@ -138,6 +130,14 @@ class Order_Update {
|
||||
throw new UserError( __( 'New customer ID is invalid.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
// Set all props, address, items, and meta on the order and save once.
|
||||
Order_Mutation::prepare_order( $order, $input, $context, $info );
|
||||
|
||||
// Apply coupons.
|
||||
if ( ! empty( $input['coupons'] ) ) {
|
||||
Order_Mutation::apply_coupons( $order, $input['coupons'] );
|
||||
}
|
||||
|
||||
$order->set_created_via( 'graphql-api' );
|
||||
$order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
|
||||
$order->calculate_totals( true );
|
||||
|
||||
@@ -23,14 +23,18 @@ class Create_Account_Input {
|
||||
[
|
||||
'description' => __( 'Customer account credentials', 'wp-graphql-woocommerce' ),
|
||||
'fields' => [
|
||||
'username' => [
|
||||
'username' => [
|
||||
'type' => [ 'non_null' => 'String' ],
|
||||
'description' => __( 'Customer username', 'wp-graphql-woocommerce' ),
|
||||
],
|
||||
'password' => [
|
||||
'password' => [
|
||||
'type' => [ 'non_null' => 'String' ],
|
||||
'description' => __( 'Customer password', 'wp-graphql-woocommerce' ),
|
||||
],
|
||||
'authenticate' => [
|
||||
'type' => 'Boolean',
|
||||
'description' => __( 'Set the current user to the newly created customer after checkout.', 'wp-graphql-woocommerce' ),
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* fatal errors when the autoloader is loaded twice
|
||||
*/
|
||||
|
||||
|
||||
if ( ! defined( 'GRAPHQL_TESTING' ) ) {
|
||||
define( 'GRAPHQL_TESTING', true );
|
||||
}
|
||||
|
||||
if ( ! defined( 'GRAPHQL_DEBUG' ) ) {
|
||||
define( 'GRAPHQL_DEBUG', true );
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
modules:
|
||||
config:
|
||||
\Tests\WPGraphQL\Codeception\Module\WPGraphQL:
|
||||
endpoint: '%WORDPRESS_URL%/graphql'
|
||||
WPDb:
|
||||
dsn: 'mysql:host=testing_db;dbname=wordpress'
|
||||
user: wordpress
|
||||
password: password
|
||||
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
|
||||
dump: 'tests/_data/app_db.sql'
|
||||
populate: true
|
||||
cleanup: false
|
||||
waitlock: 10
|
||||
url: '%WORDPRESS_URL%'
|
||||
urlReplacement: true
|
||||
tablePrefix: 'wp_'
|
||||
WPBrowser:
|
||||
url: '%WORDPRESS_URL%'
|
||||
wpRootFolder: /var/www/html
|
||||
adminUsername: admin
|
||||
adminPassword: password
|
||||
adminPath: '/wp-admin'
|
||||
REST:
|
||||
depends: WPBrowser
|
||||
url: '%WORDPRESS_URL%'
|
||||
WPFilesystem:
|
||||
wpRootFolder: '/var/www/html'
|
||||
plugins: '/wp-content/plugins'
|
||||
mu-plugins: '/wp-content/mu-plugins'
|
||||
themes: '/wp-content/themes'
|
||||
uploads: '/wp-content/uploads'
|
||||
WPLoader:
|
||||
wpRootFolder: '/var/www/html'
|
||||
dbName: wordpress
|
||||
dbHost: testing_db
|
||||
dbUser: wordpress
|
||||
dbPassword: password
|
||||
tablePrefix: wp_
|
||||
domain: '%WORDPRESS_DOMAIN%'
|
||||
adminEmail: 'admin@example.com'
|
||||
title: 'WPGraphQL for WooCommerce Tests'
|
||||
plugins:
|
||||
- woocommerce/woocommerce.php
|
||||
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
|
||||
- wp-graphql/wp-graphql.php
|
||||
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
|
||||
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
|
||||
activatePlugins:
|
||||
- woocommerce/woocommerce.php
|
||||
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
|
||||
- wp-graphql/wp-graphql.php
|
||||
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
|
||||
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
|
||||
configFile: 'tests/_data/config.php'
|
||||
@@ -629,6 +629,11 @@ class GraphQLE2E extends \Codeception\Module {
|
||||
public function getCatalog() {
|
||||
$this->_setupStore();
|
||||
|
||||
// Clear stale data from previous tests so Apache doesn't
|
||||
// pick up sessions, carts, or users from prior runs.
|
||||
$db = $this->getModule( 'WPDb' );
|
||||
$db->dontHavePostInDatabase( [ 'post_type' => 'product' ], true );
|
||||
|
||||
$product_catalog = [];
|
||||
$products = [
|
||||
[
|
||||
@@ -672,6 +677,118 @@ class GraphQLE2E extends \Codeception\Module {
|
||||
$product_catalog[ $product['post_title'] ] = $product_id;
|
||||
}
|
||||
|
||||
return $product_catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes store options and actions
|
||||
*
|
||||
* @param \Helper\AcceptanceTester $I
|
||||
* @return void
|
||||
*/
|
||||
public function _setupStore() {
|
||||
$wpdb = $this->getModule( 'WPDb' );
|
||||
|
||||
$wpdb->useTheme( 'twentytwentyone' );
|
||||
// Turn on tax calculations and store shipping countries. Important!
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_ship_to_countries', 'all' );
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_prices_include_tax', 'no' );
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_calc_taxes', 'yes' );
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_tax_round_at_subtotal', 'no' );
|
||||
|
||||
// Enable payment gateway.
|
||||
$wpdb->haveOptionInDatabase(
|
||||
'woocommerce_bacs_settings',
|
||||
[
|
||||
'enabled' => 'yes',
|
||||
'title' => 'Direct bank transfer',
|
||||
'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
|
||||
'instructions' => 'Instructions that will be added to the thank you page and emails.',
|
||||
'account' => '',
|
||||
]
|
||||
);
|
||||
|
||||
// forcing has_block_template to be false
|
||||
add_filter( 'woocommerce_has_block_template', '__return_false', 10, 2 );
|
||||
|
||||
//Additional cart fees.
|
||||
add_action(
|
||||
'woocommerce_cart_calculate_fees',
|
||||
static function () {
|
||||
$percentage = 0.01;
|
||||
$surcharge = ( WC()->cart->cart_contents_total + WC()->cart->shipping_total ) * $percentage;
|
||||
WC()->cart->add_fee( 'Surcharge', $surcharge, true, '' );
|
||||
}
|
||||
);
|
||||
|
||||
// Create Shipping Zones.
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'Local' );
|
||||
$zone->set_zone_order( 1 );
|
||||
$zone->add_location( 'GB', 'country' );
|
||||
$zone->add_location( 'CB*', 'postcode' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'Europe' );
|
||||
$zone->set_zone_order( 2 );
|
||||
$zone->add_location( 'EU', 'continent' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'California' );
|
||||
$zone->set_zone_order( 3 );
|
||||
$zone->add_location( 'US:CA', 'state' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'US' );
|
||||
$zone->set_zone_order( 4 );
|
||||
$zone->add_location( 'US', 'country' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'US' );
|
||||
$zone->set_zone_order( 5 );
|
||||
$zone->add_location( 'US:NY', 'state' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
global $wp_rewrite;
|
||||
|
||||
//Write the rule
|
||||
$wp_rewrite->set_permalink_structure('/%postname%/');
|
||||
|
||||
//Set the option
|
||||
update_option( "rewrite_rules", FALSE );
|
||||
|
||||
//Flush the rules and tell it to write htaccess
|
||||
$wp_rewrite->flush_rules( true );
|
||||
|
||||
$this->_createWoocommercePages();
|
||||
|
||||
if ( function_exists( 'WC' ) && WC()->cart ) {
|
||||
WC()->cart->empty_cart( true );
|
||||
}
|
||||
wp_set_current_user( 0 );
|
||||
\WC()->customer = null;
|
||||
\WC()->session = null;
|
||||
\WC()->cart = null;
|
||||
|
||||
\WC()->initialize_session();
|
||||
\WC()->initialize_cart();
|
||||
}
|
||||
|
||||
private function _createWooCommercePages() {
|
||||
$cart_page_content = '<!-- wp:woocommerce/cart -->
|
||||
<div class="wp-block-woocommerce-cart alignwide is-loading"><!-- wp:woocommerce/filled-cart-block -->
|
||||
<div class="wp-block-woocommerce-filled-cart-block"><!-- wp:woocommerce/cart-items-block -->
|
||||
@@ -860,103 +977,6 @@ class GraphQLE2E extends \Codeception\Module {
|
||||
]
|
||||
);
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_checkout_page_id', $checkout_page_id );
|
||||
|
||||
return $product_catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes store options and actions
|
||||
*
|
||||
* @param \Helper\AcceptanceTester $I
|
||||
* @return void
|
||||
*/
|
||||
public function _setupStore() {
|
||||
$wpdb = $this->getModule( 'WPDb' );
|
||||
|
||||
$wpdb->useTheme( 'twentytwentyone' );
|
||||
// Turn on tax calculations and store shipping countries. Important!
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_ship_to_countries', 'all' );
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_prices_include_tax', 'no' );
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_calc_taxes', 'yes' );
|
||||
$wpdb->haveOptionInDatabase( 'woocommerce_tax_round_at_subtotal', 'no' );
|
||||
|
||||
// Enable payment gateway.
|
||||
$wpdb->haveOptionInDatabase(
|
||||
'woocommerce_bacs_settings',
|
||||
[
|
||||
'enabled' => 'yes',
|
||||
'title' => 'Direct bank transfer',
|
||||
'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
|
||||
'instructions' => 'Instructions that will be added to the thank you page and emails.',
|
||||
'account' => '',
|
||||
]
|
||||
);
|
||||
|
||||
// forcing has_block_template to be false
|
||||
add_filter( 'woocommerce_has_block_template', '__return_false', 10, 2 );
|
||||
|
||||
//Additional cart fees.
|
||||
add_action(
|
||||
'woocommerce_cart_calculate_fees',
|
||||
static function () {
|
||||
$percentage = 0.01;
|
||||
$surcharge = ( WC()->cart->cart_contents_total + WC()->cart->shipping_total ) * $percentage;
|
||||
WC()->cart->add_fee( 'Surcharge', $surcharge, true, '' );
|
||||
}
|
||||
);
|
||||
|
||||
// Create Shipping Zones.
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'Local' );
|
||||
$zone->set_zone_order( 1 );
|
||||
$zone->add_location( 'GB', 'country' );
|
||||
$zone->add_location( 'CB*', 'postcode' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'Europe' );
|
||||
$zone->set_zone_order( 2 );
|
||||
$zone->add_location( 'EU', 'continent' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'California' );
|
||||
$zone->set_zone_order( 3 );
|
||||
$zone->add_location( 'US:CA', 'state' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'US' );
|
||||
$zone->set_zone_order( 4 );
|
||||
$zone->add_location( 'US', 'country' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
$zone->set_zone_name( 'US' );
|
||||
$zone->set_zone_order( 5 );
|
||||
$zone->add_location( 'US:NY', 'state' );
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'flat_rate' );
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
|
||||
global $wp_rewrite;
|
||||
|
||||
//Write the rule
|
||||
$wp_rewrite->set_permalink_structure('/%postname%/');
|
||||
|
||||
//Set the option
|
||||
update_option( "rewrite_rules", FALSE );
|
||||
|
||||
//Flush the rules and tell it to write htaccess
|
||||
$wp_rewrite->flush_rules( true );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1039,6 +1059,15 @@ class GraphQLE2E extends \Codeception\Module {
|
||||
$this->_setupStore();
|
||||
|
||||
$wpdb = $this->getModule( 'WPDb' );
|
||||
|
||||
// Clear stale data from previous tests so Apache doesn't
|
||||
// pick up sessions, carts, or users from prior runs.
|
||||
$wpdb->dontHaveInDatabase( 'wp_woocommerce_sessions', [] );
|
||||
$wpdb->dontHaveUserInDatabase( 'jimbo1234', true );
|
||||
$wpdb->dontHavePostInDatabase( [ 'post_type' => 'shop_order' ], true );
|
||||
$wpdb->dontHavePostInDatabase( [ 'post_type' => 'shop_order_refund' ], true );
|
||||
|
||||
|
||||
$userId = $wpdb->haveUserInDatabase(
|
||||
'jimbo1234',
|
||||
'customer',
|
||||
@@ -1047,6 +1076,8 @@ class GraphQLE2E extends \Codeception\Module {
|
||||
'user_email' => 'jimbo1234@example.com',
|
||||
]
|
||||
);
|
||||
|
||||
return $userId;
|
||||
}
|
||||
|
||||
public function verifyRedirect( $startUrl, $endUrl, $redirectCode = 301 ) {
|
||||
|
||||
@@ -15,4 +15,4 @@ modules:
|
||||
- Asserts
|
||||
- \Tests\WPGraphQL\Codeception\Module\WPGraphQL
|
||||
- \Tests\WPGraphQL\Codeception\Module\QueryAsserts
|
||||
- \Helper\GraphQLE2E
|
||||
- \Helper\GraphQLE2E
|
||||
@@ -230,7 +230,7 @@ class CartTransactionQueueCest {
|
||||
'woocommerce-session' => "Session {$session_token}",
|
||||
],
|
||||
];
|
||||
$responses = $I->concurrentRequests( $operations, $selected_options, 200 );
|
||||
$responses = $I->concurrentRequests( $operations, $selected_options, 300 );
|
||||
|
||||
$I->assertQuerySuccessful(
|
||||
$responses[0],
|
||||
|
||||
@@ -15,6 +15,17 @@ class DownloadableItemAuthCest {
|
||||
define( 'GRAPHQL_WOOCOMMERCE_SECRET_KEY', 'testestestestestestestestestest!!' );
|
||||
}
|
||||
|
||||
// Enable authorizing URL fields for download URL nonce handling.
|
||||
$I->setWooGraphQLSetting(
|
||||
'enable_authorizing_url_fields',
|
||||
[
|
||||
'cart_url' => 'cart_url',
|
||||
'checkout_url' => 'checkout_url',
|
||||
'account_url' => 'account_url',
|
||||
'add_payment_method_url' => 'add_payment_method_url',
|
||||
]
|
||||
);
|
||||
|
||||
// Disable approved download directories check for tests.
|
||||
update_option( 'wc_downloads_approved_directories_mode', 'disabled' );
|
||||
wp_cache_flush();
|
||||
|
||||
@@ -13,6 +13,18 @@ class ProtectedRouterCest {
|
||||
if ( ! defined( 'GRAPHQL_WOOCOMMERCE_SECRET_KEY' ) ) {
|
||||
define( 'GRAPHQL_WOOCOMMERCE_SECRET_KEY', 'testestestestestestestestestest!!' );
|
||||
}
|
||||
|
||||
// Enable authorizing URL fields so checkoutNonce, accountNonce, and
|
||||
// addPaymentMethodNonce fields are registered on the Customer type.
|
||||
$I->setWooGraphQLSetting(
|
||||
'enable_authorizing_url_fields',
|
||||
[
|
||||
'cart_url' => 'cart_url',
|
||||
'checkout_url' => 'checkout_url',
|
||||
'account_url' => 'account_url',
|
||||
'add_payment_method_url' => 'add_payment_method_url',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -696,9 +696,14 @@ class CartQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTe
|
||||
|
||||
// Flat rate is $10, tax is 10% = $1. Cost should be $11 (incl tax), subtotal $10.
|
||||
$expected = [
|
||||
$this->expectedField( 'cart.availableShippingMethods.0.rates.0.cost', '$11.00' ),
|
||||
$this->expectedField( 'cart.availableShippingMethods.0.rates.0.subtotal', '$10.00' ),
|
||||
$this->expectedField( 'cart.availableShippingMethods.0.rates.0.taxTotal', '$1.00' ),
|
||||
$this->expectedObject(
|
||||
'cart.availableShippingMethods.0.rates.#',
|
||||
[
|
||||
$this->expectedField( 'cost', '$11.00' ),
|
||||
$this->expectedField( 'subtotal', '$10.00' ),
|
||||
$this->expectedField( 'taxTotal', '$1.00' ),
|
||||
]
|
||||
),
|
||||
];
|
||||
|
||||
$this->assertQuerySuccessful( $response, $expected );
|
||||
@@ -752,11 +757,11 @@ class CartQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTe
|
||||
// Cost and subtotal should both be $10 (excl tax), taxTotal still $1.
|
||||
$expected = [
|
||||
$this->expectedObject(
|
||||
'cart.availableShippingMethods.#',
|
||||
'cart.availableShippingMethods.0.rates.#',
|
||||
[
|
||||
$this->expectedField( 'rates.0.cost', '$10.00' ),
|
||||
$this->expectedField( 'rates.0.subtotal', '$10.00' ),
|
||||
$this->expectedField( 'rates.0.taxTotal', '$1.00' ),
|
||||
$this->expectedField( 'cost', '$10.00' ),
|
||||
$this->expectedField( 'subtotal', '$10.00' ),
|
||||
$this->expectedField( 'taxTotal', '$1.00' ),
|
||||
]
|
||||
),
|
||||
];
|
||||
|
||||
@@ -23,6 +23,8 @@ class OrderMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
|
||||
$cod_gateway = $gateways['cod'];
|
||||
$cod_gateway->settings['enabled'] = 'yes';
|
||||
update_option( $cod_gateway->get_option_key(), $cod_gateway->settings );
|
||||
|
||||
\WC()->payment_gateways->init();
|
||||
|
||||
// Create a tax rate.
|
||||
$this->factory->tax_rate->create(
|
||||
@@ -180,10 +182,10 @@ class OrderMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
|
||||
variationId
|
||||
quantity
|
||||
taxClass
|
||||
subtotal(format: RAW)
|
||||
subtotalTax(format: RAW)
|
||||
total(format: RAW)
|
||||
totalTax(format: RAW)
|
||||
subtotal
|
||||
subtotalTax
|
||||
total
|
||||
totalTax
|
||||
taxStatus
|
||||
product {
|
||||
node {
|
||||
@@ -1438,8 +1440,8 @@ class OrderMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
|
||||
nodes {
|
||||
productId
|
||||
quantity
|
||||
total(format: RAW)
|
||||
subtotal(format: RAW)
|
||||
total
|
||||
subtotal
|
||||
product {
|
||||
node {
|
||||
... on SimpleProduct {
|
||||
@@ -1468,8 +1470,8 @@ class OrderMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
|
||||
$expected = [
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.productId', $product_id ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.quantity', 1 ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.total', '25' ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.subtotal', '25' ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.total', '$25.00' ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.subtotal', '$25.00' ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.product.node.name', 'Test Widget' ),
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
class WooCommerceEmailTemplatesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
// Reset captured emails from previous tests.
|
||||
reset_phpmailer_instance();
|
||||
|
||||
// Enable bacs payment gateway.
|
||||
$gateways = \WC()->payment_gateways->payment_gateways();
|
||||
$bacs_gateway = $gateways['bacs'];
|
||||
$bacs_gateway->settings['enabled'] = 'yes';
|
||||
update_option( $bacs_gateway->get_option_key(), $bacs_gateway->settings );
|
||||
\WC()->payment_gateways->init();
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
// Reset WC state to prevent test contamination.
|
||||
\WC()->customer = null;
|
||||
\WC()->session = null;
|
||||
\WC()->cart = null;
|
||||
\WC()->initialize_session();
|
||||
\WC()->initialize_cart();
|
||||
|
||||
$this->loginAs( 0 );
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a sent email by recipient address in the mock mailer.
|
||||
*
|
||||
* @param string $to_address Recipient email address.
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
private function find_sent_email( $to_address ) {
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
if ( ! $mailer ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ( $mailer->mock_sent as $index => $sent ) {
|
||||
$recipient = $mailer->get_recipient( 'to', $index );
|
||||
if ( $recipient && $to_address === $recipient->address ) {
|
||||
return $mailer->get_sent( $index );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function testRegisterCustomerSendsWooCommerceNewAccountEmail() {
|
||||
$query = '
|
||||
mutation ($input: RegisterCustomerInput!) {
|
||||
registerCustomer(input: $input) {
|
||||
customer {
|
||||
databaseId
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
$variables = [
|
||||
'input' => [
|
||||
'email' => 'newcustomer@example.com',
|
||||
'username' => 'newcustomer',
|
||||
'password' => 'testpassword123',
|
||||
'authenticate' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->graphql( compact( 'query', 'variables' ) );
|
||||
|
||||
$this->assertQuerySuccessful(
|
||||
$response,
|
||||
[
|
||||
$this->expectedField( 'registerCustomer.customer.databaseId', static::NOT_FALSY ),
|
||||
$this->expectedField( 'registerCustomer.customer.email', 'newcustomer@example.com' ),
|
||||
]
|
||||
);
|
||||
|
||||
$sent = $this->find_sent_email( 'newcustomer@example.com' );
|
||||
$this->assertNotNull( $sent, 'WC new account email should be sent to the registered customer.' );
|
||||
$this->assertStringContainsString( 'text/html', $sent->header, 'New account email should use HTML content type from WooCommerce template.' );
|
||||
}
|
||||
|
||||
public function testCheckoutWithAccountCreationSendsWooCommerceNewAccountEmail() {
|
||||
// Enable guest checkout and account creation.
|
||||
update_option( 'woocommerce_enable_guest_checkout', 'yes' );
|
||||
update_option( 'woocommerce_enable_signup_and_login_from_checkout', 'yes' );
|
||||
|
||||
$product_id = $this->factory->product->createSimple( [ 'virtual' => true ] );
|
||||
WC()->cart->add_to_cart( $product_id, 1 );
|
||||
|
||||
$query = '
|
||||
mutation ($input: CheckoutInput!) {
|
||||
checkout(input: $input) {
|
||||
order {
|
||||
databaseId
|
||||
}
|
||||
customer {
|
||||
databaseId
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
$variables = [
|
||||
'input' => [
|
||||
'paymentMethod' => 'bacs',
|
||||
'isPaid' => true,
|
||||
'billing' => [
|
||||
'firstName' => 'John',
|
||||
'lastName' => 'Doe',
|
||||
'email' => 'checkoutcustomer@example.com',
|
||||
'address1' => '123 Test St',
|
||||
'city' => 'Testville',
|
||||
'state' => 'CA',
|
||||
'postcode' => '90210',
|
||||
'country' => 'US',
|
||||
],
|
||||
'account' => [
|
||||
'username' => 'checkoutcustomer',
|
||||
'password' => 'testpassword123',
|
||||
'authenticate' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->graphql( compact( 'query', 'variables' ) );
|
||||
|
||||
$this->assertQuerySuccessful(
|
||||
$response,
|
||||
[
|
||||
$this->expectedField( 'checkout.order.databaseId', static::NOT_FALSY ),
|
||||
$this->expectedField( 'checkout.customer.databaseId', static::NOT_FALSY ),
|
||||
$this->expectedField( 'checkout.customer.email', 'checkoutcustomer@example.com' ),
|
||||
]
|
||||
);
|
||||
|
||||
$sent = $this->find_sent_email( 'checkoutcustomer@example.com' );
|
||||
$this->assertNotNull( $sent, 'WC new account email should be sent when creating account during checkout.' );
|
||||
$this->assertStringContainsString( 'text/html', $sent->header, 'Checkout account creation email should use HTML content type from WooCommerce template.' );
|
||||
}
|
||||
|
||||
public function testResetPasswordSendsWooCommerceEmail() {
|
||||
$this->factory->customer->create(
|
||||
[ 'email' => 'resetuser@example.com' ]
|
||||
);
|
||||
|
||||
$query = '
|
||||
mutation ($input: SendPasswordResetEmailInput!) {
|
||||
sendPasswordResetEmail(input: $input) {
|
||||
success
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
$variables = [
|
||||
'input' => [
|
||||
'username' => 'resetuser@example.com',
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->graphql( compact( 'query', 'variables' ) );
|
||||
|
||||
$this->assertQuerySuccessful(
|
||||
$response,
|
||||
[
|
||||
$this->expectedField( 'sendPasswordResetEmail.success', true ),
|
||||
]
|
||||
);
|
||||
|
||||
$sent = $this->find_sent_email( 'resetuser@example.com' );
|
||||
$this->assertNotNull( $sent, 'A password reset email should be sent.' );
|
||||
$this->assertStringContainsString( 'text/html', $sent->header, 'Password reset email should use HTML content type from WooCommerce template.' );
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,12 @@ function create_order_custom_table_if_not_exist() {
|
||||
$features_controller = wc_get_container()->get( \Automattic\WooCommerce\Internal\Features\FeaturesController::class );
|
||||
$features_controller->change_feature_enable( 'custom_order_tables', true );
|
||||
|
||||
update_option( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, 'yes' );
|
||||
wp_cache_flush();
|
||||
|
||||
$wc_data_store = WC_Data_Store::load( 'order' );
|
||||
assert( is_a( $wc_data_store->get_current_class_name(), \Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore::class, true ) === true, 'data store\'s classname is "' . $wc_data_store->get_current_class_name() . '", but HPOS is enabled' );
|
||||
|
||||
$synchronizer = wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer::class );
|
||||
if ( ! $synchronizer->check_orders_table_exists() ) {
|
||||
$synchronizer->create_database_tables();
|
||||
@@ -79,6 +85,7 @@ function initialize_hpos() {
|
||||
|
||||
if ( defined( 'HPOS' ) ) {
|
||||
\codecept_debug( 'HPOS activated!!!' );
|
||||
initialize_hpos();
|
||||
//add_action( 'woocommerce_init', 'initialize_hpos' );
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,8 @@ class CachedKeySet implements ArrayAccess
|
||||
$jwksResponse = $this->httpClient->sendRequest($request);
|
||||
if ($jwksResponse->getStatusCode() !== 200) {
|
||||
throw new UnexpectedValueException(
|
||||
\sprintf('HTTP Error: %d %s for URI "%s"',
|
||||
\sprintf(
|
||||
'HTTP Error: %d %s for URI "%s"',
|
||||
$jwksResponse->getStatusCode(),
|
||||
$jwksResponse->getReasonPhrase(),
|
||||
$this->jwksUri,
|
||||
|
||||
@@ -37,7 +37,7 @@ class JWT
|
||||
private const ASN1_SEQUENCE = 0x10;
|
||||
private const ASN1_BIT_STRING = 0x03;
|
||||
|
||||
private const RSA_KEY_MIN_LENGTH=2048;
|
||||
private const RSA_KEY_MIN_LENGTH = 2048;
|
||||
|
||||
/**
|
||||
* When checking nbf, iat or expiration times,
|
||||
@@ -290,20 +290,8 @@ class JWT
|
||||
}
|
||||
return $signature;
|
||||
case 'sodium_crypto':
|
||||
if (!\function_exists('sodium_crypto_sign_detached')) {
|
||||
throw new DomainException('libsodium is not available');
|
||||
}
|
||||
if (!\is_string($key)) {
|
||||
throw new InvalidArgumentException('key must be a string when using EdDSA');
|
||||
}
|
||||
try {
|
||||
// The last non-empty line is used as the key.
|
||||
$lines = array_filter(explode("\n", $key));
|
||||
$key = base64_decode((string) end($lines));
|
||||
if (\strlen($key) === 0) {
|
||||
throw new DomainException('Key cannot be empty string');
|
||||
}
|
||||
return sodium_crypto_sign_detached($msg, $key);
|
||||
return sodium_crypto_sign_detached($msg, self::validateEdDSAKey($key));
|
||||
} catch (Exception $e) {
|
||||
throw new DomainException($e->getMessage(), 0, $e);
|
||||
}
|
||||
@@ -358,19 +346,8 @@ class JWT
|
||||
'OpenSSL error: ' . \openssl_error_string()
|
||||
);
|
||||
case 'sodium_crypto':
|
||||
if (!\function_exists('sodium_crypto_sign_verify_detached')) {
|
||||
throw new DomainException('libsodium is not available');
|
||||
}
|
||||
if (!\is_string($keyMaterial)) {
|
||||
throw new InvalidArgumentException('key must be a string when using EdDSA');
|
||||
}
|
||||
try {
|
||||
// The last non-empty line is used as the key.
|
||||
$lines = array_filter(explode("\n", $keyMaterial));
|
||||
$key = base64_decode((string) end($lines));
|
||||
if (\strlen($key) === 0) {
|
||||
throw new DomainException('Key cannot be empty string');
|
||||
}
|
||||
$key = self::validateEdDSAKey($keyMaterial);
|
||||
if (\strlen($signature) === 0) {
|
||||
throw new DomainException('Signature cannot be empty string');
|
||||
}
|
||||
@@ -479,7 +456,6 @@ class JWT
|
||||
return \str_replace('=', '', \strtr(\base64_encode($input), '+/', '-_'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if an algorithm has been provided for each Key
|
||||
*
|
||||
@@ -751,4 +727,25 @@ class JWT
|
||||
throw new DomainException('Provided key is too short');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial
|
||||
* @return non-empty-string
|
||||
*/
|
||||
private static function validateEdDSAKey(#[\SensitiveParameter] $keyMaterial): string
|
||||
{
|
||||
if (!\function_exists('sodium_crypto_sign_verify_detached')) {
|
||||
throw new DomainException('libsodium is not available');
|
||||
}
|
||||
if (!\is_string($keyMaterial)) {
|
||||
throw new InvalidArgumentException('key must be a string when using EdDSA');
|
||||
}
|
||||
// The last non-empty line is used as the key.
|
||||
$lines = array_filter(explode("\n", $keyMaterial));
|
||||
$key = self::urlsafeB64Decode((string) end($lines));
|
||||
if (\strlen($key) === 0) {
|
||||
throw new DomainException('Key cannot be empty string');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,3 +219,13 @@ add_action(
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Disable deferred transactional emails during tests so WC emails send
|
||||
* synchronously and can be captured by MockPHPMailer. This must run before
|
||||
* WC_Emails is instantiated, which happens during plugins_loaded — too early
|
||||
* for the wpunit bootstrap.php to hook in.
|
||||
*/
|
||||
if ( defined( 'GRAPHQL_TESTING' ) && GRAPHQL_TESTING ) {
|
||||
add_filter( 'woocommerce_defer_transactional_emails', '__return_false' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user