From b7a14f95a11514d70ad18dfec70b3ff97bd06ede Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Thu, 1 Oct 2020 01:45:26 -0400 Subject: [PATCH] Session Handler upgraded. --- .env.dist | 4 +- .github/workflows/lint-code.yml | 8 +- .phpcs.xml | 8 +- bin/run-docker.sh | 27 +- codeception.dist.yml | 163 +++++----- composer.json | 20 +- docker-compose.yml | 1 + includes/class-core-schema-filters.php | 7 + includes/class-jwt-auth-schema-filters.php | 26 +- includes/connection/class-products.php | 22 ++ includes/data/class-factory.php | 33 -- includes/data/loader/class-wc-cpt-loader.php | 31 +- includes/model/class-customer.php | 2 +- includes/model/class-order.php | 27 +- includes/model/class-refund.php | 1 - includes/type/interface/class-product.php | 2 +- includes/type/object/class-customer-type.php | 32 +- includes/type/object/class-order-type.php | 4 + .../object/class-product-variation-type.php | 8 - includes/utils/class-ql-session-handler.php | 24 +- tests/_support/Helper/GraphQLE2E.php | 94 ++---- tests/_support/Helper/crud-helpers/order.php | 4 +- .../Helper/crud-helpers/product-variation.php | 6 +- tests/acceptance.suite.dist.yml | 20 +- .../ReturningCustomerSessionCept.php | 296 +++++++++++++++++- tests/functional.suite.dist.yml | 21 +- tests/wpunit.suite.dist.yml | 46 +-- tests/wpunit/CheckoutMutationTest.php | 4 +- tests/wpunit/CoreInterfaceQueriesTest.php | 9 +- tests/wpunit/PaymentGatewayQueriesTest.php | 66 ---- tests/wpunit/ProductVariationQueriesTest.php | 2 +- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +- vendor/composer/autoload_static.php | 8 +- 34 files changed, 667 insertions(+), 375 deletions(-) diff --git a/.env.dist b/.env.dist index 144b9530..6ba22604 100644 --- a/.env.dist +++ b/.env.dist @@ -28,7 +28,5 @@ TESTS_ENVS=tests/_envs CORE_BRANCH=develop JWT_AUTH_BRANCH=develop -STRIPE_GATEWAY=1 GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123 -STRIPE_API_PUBLISHABLE_KEY=test_key -STRIPE_API_SECRET_KEY=test_secret +SKIP_TESTS_CLEANUP=1 diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index 6ecf5148..5d1bcc00 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -35,11 +35,7 @@ jobs: - name: Install dependencies run: | - composer require \ - squizlabs/php_codesniffer \ - phpcompatibility/phpcompatibility-wp wp-coding-standards/wpcs \ - dealerdirect/phpcodesniffer-composer-installer - composer install --no-dev + composer install - name: Cache dependencies uses: actions/cache@v1 @@ -49,4 +45,4 @@ jobs: restore-keys: ${{ runner.os }}-composer - name: Run PHP CodeSniffer - run: vendor/bin/phpcs + run: composer lint diff --git a/.phpcs.xml b/.phpcs.xml index 2830f074..2c973c3e 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,5 +1,6 @@ + Generally-applicable sniffs for WordPress plugins. @@ -19,15 +20,16 @@ - - - + + + + diff --git a/bin/run-docker.sh b/bin/run-docker.sh index 959309d1..406e4d14 100755 --- a/bin/run-docker.sh +++ b/bin/run-docker.sh @@ -3,7 +3,7 @@ set -eu print_usage_instructions() { - echo "Usage: $0 build|run [-a|-t]"; + echo "Usage: $0 build|run [-e=env-file ] [-a|-t]"; exit 1 } @@ -11,6 +11,8 @@ if [ -z "$1" ]; then print_usage_instructions fi +env_file=".env.dist"; + subcommand=$1; shift case "$subcommand" in "build" ) @@ -35,17 +37,24 @@ case "$subcommand" in --build-arg USE_XDEBUG=${USE_XDEBUG-} \ . ;; - \? ) echo "Usage: $0 build [-a|-t]";; - * ) echo "Usage: $0 build [-a|-t]";; + \? ) print_usage_instructions;; + * ) print_usage_instructions;; esac done shift $((OPTIND -1)) ;; "run" ) - while getopts ":at" opt; do + while getopts "e:at" opt; do case ${opt} in - a ) docker-compose up --scale testing=0 --build;; + e ) + env_file=${OPTARG}; + if [ ! -f $env_file ]; then + echo "No file found at $env_file" + fi + ;; + a ) docker-compose up --scale testing=0;; t ) + source ${env_file} docker-compose run --rm \ -e STRIPE_API_PUBLISHABLE_KEY=${STRIPE_API_PUBLISHABLE_KEY-} \ -e STRIPE_API_SECRET_KEY=${STRIPE_API_SECRET_KEY-} \ @@ -55,13 +64,13 @@ case "$subcommand" in -e SKIP_TESTS_CLEANUP=${SKIP_TESTS_CLEANUP-} \ testing --scale app=0 ;; - \? ) echo "Usage: $0 run [-a|-t]";; - * ) echo "Usage: $0 run [-a|-t]";; + \? ) print_usage_instructions;; + * ) print_usage_instructions;; esac done shift $((OPTIND -1)) ;; - \? ) echo "Usage: $0 [-a|-t]";; - * ) echo "Usage: $0 [-a|-t]";; + \? ) print_usage_instructions;; + * ) print_usage_instructions;; esac diff --git a/codeception.dist.yml b/codeception.dist.yml index d503a42f..de59e776 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -1,88 +1,89 @@ paths: - tests: '%TESTS_DIR%' - output: '%TESTS_OUTPUT%' - data: '%TESTS_DATA%' - support: '%TESTS_SUPPORT%' - envs: '%TESTS_ENVS%' + tests: '%TESTS_DIR%' + output: '%TESTS_OUTPUT%' + data: '%TESTS_DATA%' + support: '%TESTS_SUPPORT%' + envs: '%TESTS_ENVS%' params: - - env - - .env.dist + - env + - .env.dist actor_suffix: Tester settings: - colors: true - memory_limit: 1024M + colors: true + memory_limit: 1024M coverage: - enabled: true - remote: false - c3_url: '%WP_URL%/wp-content/plugins/wp-graphql-woocommerce/wp-graphql-woocommerce.php' - include: - - includes/* - exclude: - - wp-graphql-woocommerce.php - - access-functions.php - - class-inflect.php - - vendor/* - show_only_summary: false + enabled: true + remote: false + c3_url: '%WP_URL%/wp-content/plugins/wp-graphql-woocommerce/wp-graphql-woocommerce.php' + include: + - includes/* + exclude: + - wp-graphql-woocommerce.php + - access-functions.php + - class-inflect.php + - vendor/* + show_only_summary: false extensions: - enabled: - - Codeception\Extension\RunFailed - commands: - - Codeception\Command\GenerateWPUnit - - Codeception\Command\GenerateWPRestApi - - Codeception\Command\GenerateWPRestController - - Codeception\Command\GenerateWPRestPostTypeController - - Codeception\Command\GenerateWPAjax - - Codeception\Command\GenerateWPCanonical - - Codeception\Command\GenerateWPXMLRPC + enabled: + - Codeception\Extension\RunFailed + commands: + - Codeception\Command\GenerateWPUnit + - Codeception\Command\GenerateWPRestApi + - Codeception\Command\GenerateWPRestController + - Codeception\Command\GenerateWPRestPostTypeController + - Codeception\Command\GenerateWPAjax + - Codeception\Command\GenerateWPCanonical + - Codeception\Command\GenerateWPXMLRPC modules: - config: - WPDb: - dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%' - user: '%DB_USER%' - password: '%DB_PASSWORD%' - populator: 'mysql -u $user -p$password -h $host $dbname < $dump' - dump: 'tests/_data/dump.sql' - populate: true - cleanup: true - waitlock: 0 - url: '%WP_URL%' - urlReplacement: true - tablePrefix: '%WP_TABLE_PREFIX%' - WPBrowser: - url: '%WP_URL%' - wpRootFolder: '%WP_ROOT_FOLDER%' - adminUsername: '%ADMIN_USERNAME%' - adminPassword: '%ADMIN_PASSWORD%' - adminPath: '/wp-admin' - REST: - depends: WPBrowser - url: '%WP_URL%' - WPFilesystem: - wpRootFolder: '%WP_ROOT_FOLDER%' - plugins: '/wp-content/plugins' - mu-plugins: '/wp-content/mu-plugins' - themes: '/wp-content/themes' - uploads: '/wp-content/uploads' - WPLoader: - wpRootFolder: '%WP_ROOT_FOLDER%' - dbName: '%DB_NAME%' - dbHost: '%DB_HOST%' - dbUser: '%DB_USER%' - dbPassword: '%DB_PASSWORD%' - tablePrefix: '%WP_TABLE_PREFIX%' - domain: '%WP_DOMAIN%' - adminEmail: '%ADMIN_EMAIL%' - title: 'Test' - 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' + config: + WPDb: + dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%' + user: '%DB_USER%' + password: '%DB_PASSWORD%' + populator: 'mysql -u $user -p$password -h $host $dbname < $dump' + dump: 'tests/_data/dump.sql' + populate: false + cleanup: true + waitlock: 0 + url: '%WP_URL%' + urlReplacement: true + tablePrefix: '%WP_TABLE_PREFIX%' + WPBrowser: + url: '%WP_URL%' + wpRootFolder: '%WP_ROOT_FOLDER%' + adminUsername: '%ADMIN_USERNAME%' + adminPassword: '%ADMIN_PASSWORD%' + adminPath: '/wp-admin' + cookies: false + REST: + depends: WPBrowser + url: '%WP_URL%' + WPFilesystem: + wpRootFolder: '%WP_ROOT_FOLDER%' + plugins: '/wp-content/plugins' + mu-plugins: '/wp-content/mu-plugins' + themes: '/wp-content/themes' + uploads: '/wp-content/uploads' + WPLoader: + wpRootFolder: '%WP_ROOT_FOLDER%' + dbName: '%DB_NAME%' + dbHost: '%DB_HOST%' + dbUser: '%DB_USER%' + dbPassword: '%DB_PASSWORD%' + tablePrefix: '%WP_TABLE_PREFIX%' + domain: '%WP_DOMAIN%' + adminEmail: '%ADMIN_EMAIL%' + title: 'Test' + 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' diff --git a/composer.json b/composer.json index 3fc41867..d55527b7 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "require-dev": { "lucatume/wp-browser": ">=2.2.1 <2.2.8", "simpod/php-coveralls-mirror": "^3.0", - "stripe/stripe-php": "^7.28" + "stripe/stripe-php": "^7.28", + "wp-coding-standards/wpcs": "^2.3" }, "config": { "optimize-autoloader": true @@ -51,10 +52,19 @@ }, "scripts": { "install-test-env": "bash bin/install-test-env.sh", - "test": "vendor/bin/codecept run", - "functional-test": "vendor/bin/codecept run functional", - "acceptance-test": "vendor/bin/codecept run acceptance", - "wpunit-test": "vendor/bin/codecept run wpunit" + "docker-build": "bash bin/run-docker.sh build", + "docker-run": [ + "@docker-build", + "bash bin/run-docker.sh run" + ], + "docker-destroy": "docker-compose down", + "local-app": "@docker-run -a", + "local-test": "@docker-run -t", + "test": [ + "composer install --no-dev", + "@local-test" + ], + "lint": "vendor/bin/phpcs" }, "support" : { "issues": "https://github.com/wp-graphql/wp-graphql-woocommerce/issues", diff --git a/docker-compose.yml b/docker-compose.yml index 74a2d46e..7d83631c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,7 @@ services: ADMIN_PASSWORD: password INCLUDE_WPGRAPHIQL: 1 IMPORT_WC_PRODUCTS: 1 + STRIPE_GATEWAY: 1 ports: - '8091:80' networks: diff --git a/includes/class-core-schema-filters.php b/includes/class-core-schema-filters.php index e94eb06d..8289a35e 100644 --- a/includes/class-core-schema-filters.php +++ b/includes/class-core-schema-filters.php @@ -70,6 +70,13 @@ class Core_Schema_Filters { 10, 3 ); + + add_filter( + 'graphql_dataloader_pre_get_model', + array( '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ), + 10, + 3 + ); } /** diff --git a/includes/class-jwt-auth-schema-filters.php b/includes/class-jwt-auth-schema-filters.php index ee5d26fe..77f178c6 100644 --- a/includes/class-jwt-auth-schema-filters.php +++ b/includes/class-jwt-auth-schema-filters.php @@ -79,7 +79,7 @@ class JWT_Auth_Schema_Filters { return $refresh_token; }, - ), + ) ) ); @@ -90,16 +90,24 @@ class JWT_Auth_Schema_Filters { * Adds "customer" field to "login" mutation payload. */ public static function add_customer_to_login_payload() { - register_graphql_field( + register_graphql_fields( 'LoginPayload', - 'customer', array( - 'type' => 'Customer', - 'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { - $id = $payload['id']; - return new Customer( $id ); - }, + 'customer' => array( + 'type' => 'Customer', + 'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ), + 'resolve' => function( $payload ) { + $id = $payload['id']; + return new Customer( $id ); + }, + ), + 'sessionToken' => array( + 'type' => 'String', + 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), + 'resolve' => function( $payload ) { + return apply_filters( 'graphql_customer_session_token', null ); + }, + ) ) ); } diff --git a/includes/connection/class-products.php b/includes/connection/class-products.php index 2afb8329..5b5e229f 100644 --- a/includes/connection/class-products.php +++ b/includes/connection/class-products.php @@ -203,6 +203,28 @@ class Products { ) ); + register_graphql_connection( + array( + 'fromType' => 'ProductVariation', + 'toType' => 'VariableProduct', + 'fromFieldName' => 'parent', + 'description' => __( 'The parent of the node. The parent object can be of various types', 'wp-graphql' ), + 'oneToOne' => true, + 'resolve' => function( $source, $args, AppContext $context, ResolveInfo $info ) { + + if ( empty( $source->parent_id ) ) { + return null; + } + + $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); + $resolver->set_query_arg( 'p', $source->parent_id ); + + return $resolver->one_to_one()->get_connection(); + + }, + ) + ); + // Taxonomy To Product resolver. $resolve_product_from_taxonomy = function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); diff --git a/includes/data/class-factory.php b/includes/data/class-factory.php index 5ac145d7..0360789f 100644 --- a/includes/data/class-factory.php +++ b/includes/data/class-factory.php @@ -46,8 +46,6 @@ class Factory { * @access public */ public static function resolve_session_customer() { - self::maybe_initialize_session(); - return new Customer(); } @@ -163,43 +161,12 @@ class Factory { return new Shipping_Method( $method ); } - /** - * Checks if the WooCommerce Session needs to be (re)initialized. - * - * @return bool True if (re)initialized. - */ - public static function maybe_initialize_session() { - switch ( true ) { - case is_null( WC()->customer ): - case 0 !== get_current_user_id() && get_current_user_id() !== WC()->customer->get_id(): - if ( is_null( WC()->session ) ) { - WC()->initialize_session(); - } else { - WC()->session->init(); - } - - // Set customer and cart to null just to be safe. - WC()->customer = null; - WC()->cart = null; - - // (re)initialize cart. - WC()->initialize_cart(); - - return true; - - default: - return false; - } - } - /** * Resolves the WooCommerce cart instance. * * @return \WC_Cart */ public static function resolve_cart() { - self::maybe_initialize_session(); - return WC()->cart; } diff --git a/includes/data/loader/class-wc-cpt-loader.php b/includes/data/loader/class-wc-cpt-loader.php index 54588b16..b453f597 100644 --- a/includes/data/loader/class-wc-cpt-loader.php +++ b/includes/data/loader/class-wc-cpt-loader.php @@ -34,13 +34,14 @@ class WC_CPT_Loader extends AbstractDataLoader { /** * Returns the Model for a given post-type and ID. * - * @param string $post_type - WordPress post-type. - * @param int $id - Post ID. + * @param string $post_type WordPress post-type. + * @param int $id Post ID. + * @param boolean $fatal Throw if no model found. * * @return mixed * @throws UserError - throws if no corresponding Model is registered to the post-type. */ - public function resolve_model( $post_type, $id ) { + public static function resolve_model( $post_type, $id, $fatal = true ) { switch ( $post_type ) { case 'product': return new Product( $id ); @@ -57,6 +58,12 @@ class WC_CPT_Loader extends AbstractDataLoader { if ( ! empty( $model ) ) { return new $model( $id ); } + + // Bail if not fatal. + if ( ! $fatal ) { + return null; + } + /* translators: no model assigned error message */ throw new UserError( sprintf( __( 'No Model is register to the custom post-type "%s"', 'wp-graphql-woocommerce' ), $post_type ) ); } @@ -192,11 +199,27 @@ class WC_CPT_Loader extends AbstractDataLoader { */ $loaded_posts[ $key ] = $load_dependencies->then( function() use ( $post_type, $key ) { - return $this->resolve_model( $post_type, $key ); + return self::resolve_model( $post_type, $key ); } ); } return ! empty( $loaded_posts ) ? $loaded_posts : []; } + + /** + * Callback for inject the PostObject dataloader with WC_Post models. + * + * @param null $model + * @param mixed $entry + * @param mixed $key + * @return void + */ + public static function inject_post_loader_models( $model, $entry, $key ) { + if ( is_a( $entry, \WP_Post::class ) ) { + $model = self::resolve_model( $entry->post_type, $key, false ); + } + + return $model; + } } diff --git a/includes/model/class-customer.php b/includes/model/class-customer.php index 0bb7d945..b84ee44f 100644 --- a/includes/model/class-customer.php +++ b/includes/model/class-customer.php @@ -63,7 +63,7 @@ class Customer extends Model { 'id' => function() { return ( ! empty( $this->data->get_id() ) ) ? Relay::toGlobalId( 'customer', $this->data->get_id() ) - : 'new_customer'; + : 'guest'; }, 'databaseId' => function() { return $this->ID; diff --git a/includes/model/class-order.php b/includes/model/class-order.php index 98543a64..46cc3431 100644 --- a/includes/model/class-order.php +++ b/includes/model/class-order.php @@ -75,7 +75,7 @@ class Order extends WC_Post { } /** - * Whether or not the owner of the data matches the current user. + * Whether or not the customer of the order matches the current user. * * @return bool */ @@ -87,12 +87,37 @@ class Order extends WC_Post { $customer_id = get_post_meta( '_customer_user', $this->wc_data->get_parent_id(), true ); } + if ( 0 === $customer_id ) { + return $this->guest_order_customer_matches_current_user(); + } + if ( empty( $this->current_user->ID ) || empty( $customer_id ) ) { return false; } + return absint( $customer_id ) === absint( $this->current_user->ID ) ? true : false; } + /** + * Whether or not the customer of the order who is a guest matches the current user. + * + * @return bool + */ + public function guest_order_customer_matches_current_user() { + if ( 'shop_order' === $this->post_type ) { + $customer_email = $this->wc_data->get_billing_email(); + } else { + $customer_email = get_post_meta( '_billing_email', $this->wc_data->get_parent_id(), true ); + } + + $session_customer = new \WC_Customer( 0, true ); + if ( empty( $session_customer->get_billing_email() ) || empty( $customer_email ) ) { + return false; + } + + return $customer_email === $session_customer->get_billing_email() ? true : false ; + } + /** * Determine if the model is private * diff --git a/includes/model/class-refund.php b/includes/model/class-refund.php index b595d3db..83db19e1 100644 --- a/includes/model/class-refund.php +++ b/includes/model/class-refund.php @@ -67,6 +67,5 @@ class Refund extends Order { $this->fields = array_merge( $this->fields, $fields ); } - } } diff --git a/includes/type/interface/class-product.php b/includes/type/interface/class-product.php index a3c32ea3..3ba9b262 100644 --- a/includes/type/interface/class-product.php +++ b/includes/type/interface/class-product.php @@ -115,7 +115,7 @@ class Product { 'description' => __( 'The globally unique identifier for the product', 'wp-graphql-woocommerce' ), ), 'databaseId' => array( - 'type' => 'Int', + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the product in the database', 'wp-graphql-woocommerce' ), ), 'slug' => array( diff --git a/includes/type/object/class-customer-type.php b/includes/type/object/class-customer-type.php index 0f5bd04e..59bc3b73 100644 --- a/includes/type/object/class-customer-type.php +++ b/includes/type/object/class-customer-type.php @@ -20,7 +20,7 @@ use WPGraphQL\WooCommerce\Data\Factory; class Customer_Type { /** - * Registers Customer WPObject type + * Registers Customer WPObject type and related fields. */ public static function register() { register_graphql_object_type( @@ -108,8 +108,38 @@ class Customer_Type { 'type' => 'Boolean', 'description' => __( 'Return the date customer was last updated', 'wp-graphql-woocommerce' ), ), + 'sessionToken' => array( + 'type' => 'String', + 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), + 'resolve' => function( $source ) { + if ( $source->ID === \get_current_user_id() ) { + return apply_filters( 'graphql_customer_session_token', null ); + } + + return null; + }, + ) ), ) ); + + /** + * Register the "sessionToken" field to the "User" type. + */ + register_graphql_field( + 'User', + 'sessionToken', + array( + 'type' => 'String', + 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), + 'resolve' => function( $source ) { + if ( $source->ID === \get_current_user_id() ) { + return apply_filters( 'graphql_customer_session_token', null ); + } + + return null; + }, + ) + ); } } diff --git a/includes/type/object/class-order-type.php b/includes/type/object/class-order-type.php index 43319709..91e51b54 100644 --- a/includes/type/object/class-order-type.php +++ b/includes/type/object/class-order-type.php @@ -286,6 +286,10 @@ class Order_Type { 'type' => 'Customer', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), 'resolve' => function( $order, array $args, AppContext $context ) { + if ( empty( $order->customer_id ) ) { + return Factory::resolve_session_customer(); + } + return Factory::resolve_customer( $order->customer_id, $context ); }, ), diff --git a/includes/type/object/class-product-variation-type.php b/includes/type/object/class-product-variation-type.php index 9736e754..fa38d3a9 100644 --- a/includes/type/object/class-product-variation-type.php +++ b/includes/type/object/class-product-variation-type.php @@ -34,7 +34,6 @@ class Product_Variation_Type { 'NodeWithFeaturedImage', 'ContentNode', 'UniformResourceIdentifiable', - 'HierarchicalContentNode', ), 'fields' => array( 'id' => array( @@ -237,13 +236,6 @@ class Product_Variation_Type { return DataSource::resolve_post_object( $source->image_id, $context ); }, ), - 'parent' => array( - 'type' => 'VariableProduct', - 'description' => __( 'Product variation parent product', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { - return Factory::resolve_crud_object( $source->parent_id, $context ); - }, - ), ), ) ); diff --git a/includes/utils/class-ql-session-handler.php b/includes/utils/class-ql-session-handler.php index 7f6749d3..e0a80bfa 100644 --- a/includes/utils/class-ql-session-handler.php +++ b/includes/utils/class-ql-session-handler.php @@ -213,6 +213,7 @@ class QL_Session_Handler extends WC_Session_Handler { public function init_session_token() { $token = $this->get_session_token(); + // Process existing session. if ( $token && ! is_wp_error( $token ) ) { $this->_customer_id = $token->data->customer_id; $this->_session_issued = $token->iat; @@ -226,6 +227,12 @@ class QL_Session_Handler extends WC_Session_Handler { $guest_session_id = $this->_customer_id; $this->_customer_id = strval( get_current_user_id() ); $this->_dirty = true; + + // If session empty check for previous data associated with customer and assign that to the session. + if ( empty( $this->_data ) ) { + $this->_data = $this->get_session_data(); + } + $this->save_data( $guest_session_id ); $this->set_customer_session_token( true ); } @@ -236,6 +243,8 @@ class QL_Session_Handler extends WC_Session_Handler { $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); } } else { + + // If token invalid throw warning. if ( is_wp_error( $token ) ) { add_filter( 'graphql_woocommerce_session_token_errors', @@ -245,9 +254,14 @@ class QL_Session_Handler extends WC_Session_Handler { } ); } + + // Start new session. $this->set_session_expiration(); - $this->_customer_id = $this->generate_customer_id(); + + // Get Customer ID. + $this->_customer_id = is_user_logged_in() ? get_current_user_id() : $this->generate_customer_id(); $this->_data = $this->get_session_data(); + $this->set_customer_session_token( true ); } } @@ -393,7 +407,7 @@ class QL_Session_Handler extends WC_Session_Handler { } /** - * Sets session token HTTP response header. + * Set session token for use in the HTTP response header and customer/user "sessionToken" field. */ add_filter( 'graphql_response_headers_to_send', @@ -403,6 +417,12 @@ class QL_Session_Handler extends WC_Session_Handler { }, 10 ); + add_filter( + 'graphql_customer_session_token', + function( $_ ) use ( $token ) { + return $token; + } + ); $this->_issuing_new_token = true; } diff --git a/tests/_support/Helper/GraphQLE2E.php b/tests/_support/Helper/GraphQLE2E.php index 5759a4df..2a6640df 100644 --- a/tests/_support/Helper/GraphQLE2E.php +++ b/tests/_support/Helper/GraphQLE2E.php @@ -6,9 +6,9 @@ namespace Helper; class GraphQLE2E extends \Codeception\Module { /** * Asserts existence of and returns an array of HTTP response headers - * + * * @param string|array $headers Headers to be evaluated and returned. - * + * * @return array */ public function wantHTTPResponseHeaders( $headers ) { @@ -41,9 +41,10 @@ class GraphQLE2E extends \Codeception\Module { authToken refreshToken customer { - customerId + databaseId username - } + } + sessionToken } } '; @@ -72,12 +73,7 @@ class GraphQLE2E extends \Codeception\Module { cartItem { key product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } variation { id @@ -152,12 +148,7 @@ class GraphQLE2E extends \Codeception\Module { cartItems { key product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } variation { id @@ -194,12 +185,7 @@ class GraphQLE2E extends \Codeception\Module { cartItems { key product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } variation { id @@ -238,12 +224,7 @@ class GraphQLE2E extends \Codeception\Module { nodes { key product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } variation { id @@ -320,12 +301,7 @@ class GraphQLE2E extends \Codeception\Module { nodes { key product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } quantity subtotal @@ -368,12 +344,7 @@ class GraphQLE2E extends \Codeception\Module { nodes { key product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } quantity subtotal @@ -439,7 +410,7 @@ class GraphQLE2E extends \Codeception\Module { * * @param array $input * @param string $session_header - * + * * @return array */ public function checkout( $input, $request_headers = array() ) { @@ -450,7 +421,7 @@ class GraphQLE2E extends \Codeception\Module { clientMutationId order { id - orderId + databaseId currency orderVersion date @@ -521,7 +492,7 @@ class GraphQLE2E extends \Codeception\Module { downloadsRemaining name product { - productId + databaseId } download { downloadId @@ -532,7 +503,7 @@ class GraphQLE2E extends \Codeception\Module { needsProcessing couponLines { nodes { - itemId + databaseId orderId code discount @@ -544,7 +515,7 @@ class GraphQLE2E extends \Codeception\Module { } feeLines { nodes { - itemId + databaseId orderId amount name @@ -556,7 +527,7 @@ class GraphQLE2E extends \Codeception\Module { } shippingLines { nodes { - itemId + databaseId orderId methodTitle total @@ -572,7 +543,7 @@ class GraphQLE2E extends \Codeception\Module { shippingTaxTotal isCompound taxRate { - rateId + databaseId } } } @@ -588,12 +559,7 @@ class GraphQLE2E extends \Codeception\Module { totalTax taxStatus product { - ... on SimpleProduct { - id - } - ... on VariableProduct { - id - } + id } variation { id @@ -619,12 +585,12 @@ class GraphQLE2E extends \Codeception\Module { /** * Sends GraphQL and returns a response - * + * * @param string $mutation * @param array $input * @param string|null $session_header * @param bool $update_header - * + * * @return array */ public function sendGraphQLRequest( $query, $input, $request_headers = array() ) { @@ -657,7 +623,7 @@ class GraphQLE2E extends \Codeception\Module { $response = json_decode( $rest->grabResponse(), true ); // use --debug flag to view - codecept_debug( $response ); + codecept_debug( json_encode( $response, JSON_PRETTY_PRINT ) ); // Delete request headers foreach( $request_headers as $header => $value ) { @@ -727,13 +693,13 @@ class GraphQLE2E extends \Codeception\Module { * @param AcceptanceTester $I * @return void */ - public function _setupStore() { + public function _setupStore() { // Turn on tax calculations and store shipping countries. Important! update_option( 'woocommerce_ship_to_countries', 'all' ); update_option( 'woocommerce_prices_include_tax', 'no' ); update_option( 'woocommerce_calc_taxes', 'yes' ); update_option( 'woocommerce_tax_round_at_subtotal', 'no' ); - + // Enable payment gateway. update_option( 'woocommerce_bacs_settings', @@ -752,11 +718,11 @@ class GraphQLE2E extends \Codeception\Module { 'woocommerce_cart_calculate_fees', function() { $percentage = 0.01; - $surcharge = ( \WC()->cart->cart_contents_total + \WC()->cart->shipping_total ) * $percentage; + $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' ); @@ -843,7 +809,7 @@ class GraphQLE2E extends \Codeception\Module { '_featured' => false, '_wc_rating_counts' => array(), '_wc_average_rating' => 0, - '_wc_review_count' => 0, + '_wc_review_count' => 0, ), ), $args @@ -852,14 +818,14 @@ class GraphQLE2E extends \Codeception\Module { if ( ! $term_id ) { $term_id = $wpdb->grabTermIdFromDatabase( [ 'name' => $term, 'slug' => $term ] ); - } + } $term_taxonomy_id = $wpdb->grabTermTaxonomyIdFromDatabase( [ 'term_id' => $term_id, 'taxonomy' => 'product_type' ] ); $wpdb->haveTermRelationshipInDatabase( $product_id, $term_id ); } - public function createOldSession() { - $products = $this->getCatalog(); + public function setupStoreAndUsers() { + $this->_setupStore(); $wpdb = $this->getModule( 'WPDb' ); $userId = $wpdb->haveUserInDatabase( diff --git a/tests/_support/Helper/crud-helpers/order.php b/tests/_support/Helper/crud-helpers/order.php index 477d9b54..d9852305 100644 --- a/tests/_support/Helper/crud-helpers/order.php +++ b/tests/_support/Helper/crud-helpers/order.php @@ -204,7 +204,9 @@ class OrderHelper extends WCG_Helper { 'pricesIncludeTax' => $data->get_prices_include_tax(), 'parent' => null, 'customer' => array( - 'id' => Relay::toGlobalId( 'customer', $data->get_customer_id() ) + 'id' => ! empty( $data->get_customer_id() ) + ? Relay::toGlobalId( 'customer', $data->get_customer_id() ) + : 'guest', ), 'customerIpAddress' => ! empty( $data->get_customer_ip_address() ) ? $data->get_customer_ip_address() diff --git a/tests/_support/Helper/crud-helpers/product-variation.php b/tests/_support/Helper/crud-helpers/product-variation.php index c8462386..b22d81ea 100644 --- a/tests/_support/Helper/crud-helpers/product-variation.php +++ b/tests/_support/Helper/crud-helpers/product-variation.php @@ -155,8 +155,10 @@ class ProductVariationHelper extends WCG_Helper { 'hasAttributes' => ! empty( $data->has_attributes() ) ? $data->has_attributes() : null, 'type' => WPEnumType::get_safe_name( $data->get_type() ), 'parent' => array ( - 'id' => Relay::toGlobalId( 'product', $data->get_parent_id() ) - ) + 'node' => array( + 'id' => Relay::toGlobalId( 'product', $data->get_parent_id() ), + ), + ), ); } diff --git a/tests/acceptance.suite.dist.yml b/tests/acceptance.suite.dist.yml index 0a8db34b..79b83eb1 100644 --- a/tests/acceptance.suite.dist.yml +++ b/tests/acceptance.suite.dist.yml @@ -7,13 +7,13 @@ actor: AcceptanceTester modules: - enabled: - - Asserts - - REST - - WPBrowser - - WPDb - - WPLoader - - \Helper\GraphQLE2E - config: - WPDb: - cleanup: false \ No newline at end of file + enabled: + - Asserts + - REST + - WPBrowser + - WPDb + - WPLoader + - \Helper\GraphQLE2E + config: + WPDb: + cleanup: false diff --git a/tests/acceptance/ReturningCustomerSessionCept.php b/tests/acceptance/ReturningCustomerSessionCept.php index 74623c59..49c70476 100644 --- a/tests/acceptance/ReturningCustomerSessionCept.php +++ b/tests/acceptance/ReturningCustomerSessionCept.php @@ -1,6 +1,9 @@ -createOldSession(); +$I->setupStoreAndUsers(); + +// Create products +$product_catalog = $I->getCatalog(); // Begin Tests. $I->wantTo('login'); @@ -12,38 +15,313 @@ $login_input = array( $success = $I->login( $login_input ); +// Validate response. $I->assertArrayNotHasKey( 'errors', $success ); $I->assertArrayHasKey('data', $success ); $I->assertArrayHasKey('login', $success['data'] ); $I->assertArrayHasKey('customer', $success['data']['login'] ); $I->assertArrayHasKey('authToken', $success['data']['login'] ); $I->assertArrayHasKey('refreshToken', $success['data']['login'] ); -$authToken = $success['data']['login']['authToken']; -$customer_id = $success['data']['login']['customer']['customerId']; +$I->assertArrayHasKey('sessionToken', $success['data']['login'] ); + +// Retrieve customer ID for later use. +$customer_id = $success['data']['login']['customer']['databaseId']; + +// Retrieve JWT Authorization Token for later use. +$authToken = $success['data']['login']['authToken']; + +// Retrieve session token. Add as "Session %s" in the woocommerce-session HTTP header to future requests +// so WooCommerce can identify the user session associated with actions made in the GraphQL requests. +// You can also retrieve the token from the "woocommerce-session" HTTP response header. +$initial_session_token = $success['data']['login']['sessionToken']; $I->wantTo('Get current username'); $query = ' query { customer { - customerId + databaseId username } } '; -$success = $I->sendGraphQLRequest( +$response = $I->sendGraphQLRequest( $query, null, - array( 'Authorization' => "Bearer {$authToken}" ) + array( + 'Authorization' => "Bearer {$authToken}", + 'woocommerce-session' => "Session {$initial_session_token}", + ) ); $expected_results = array( 'data' => array( 'customer' => array( - 'customerId' => $customer_id, + 'databaseId' => $customer_id, 'username' => 'jimbo1234' ) ) ); -$I->assertEquals( $expected_results, $success ); \ No newline at end of file +$I->assertEquals( $expected_results, $response ); + +$I->wantTo( 'Put items in the cart' ); + +/** + * Add "T-Shirt" to cart and confirm response data. + */ +$add_to_cart_input = array( + 'clientMutationId' => 'someId', + 'productId' => $product_catalog['t-shirt'], + 'quantity' => 3, +); + +$success = $I->addToCart( + $add_to_cart_input, + array( + 'Authorization' => "Bearer {$authToken}", + 'woocommerce-session' => "Session {$initial_session_token}", + ) +); + +$I->assertArrayNotHasKey( 'errors', $success ); +$I->assertArrayHasKey('data', $success ); +$I->assertArrayHasKey('addToCart', $success['data'] ); +$I->assertArrayHasKey('cartItem', $success['data']['addToCart'] ); +$I->assertArrayHasKey('key', $success['data']['addToCart']['cartItem'] ); +$shirt_key = $success['data']['addToCart']['cartItem']['key']; + +$I->wantTo( 'Check the cart, should contain t-shirts.' ); + +$cart_query = ' + query { + cart { + contents { + nodes { + key + product{ databaseId } + } + } + } + } +'; + +$response = $I->sendGraphQLRequest( + $cart_query, + null, + array( + 'Authorization' => "Bearer {$authToken}", + 'woocommerce-session' => "Session {$initial_session_token}", + ) +); +$expected_results = array( + 'data' => array( + 'cart' => array( + 'contents' => array( + 'nodes' => array( + array( + 'key' => $shirt_key, + 'product' => array( 'databaseId' => $product_catalog['t-shirt'] ), + ), + ), + ), + ), + ), +); + +$I->assertEquals( $expected_results, $response ); + +$I->wantTo( 'End session' ); +/* + Simply not sending the previous Authorization or woocommerce-session headers in the next request does the trick. + ¯\_(ツ)_/¯ +*/ + +$I->wantTo( 'Login and continue previous session.' ); + +$login_input = array( + 'clientMutationId' => 'someId', + 'username' => 'jimbo1234', + 'password' => 'password', +); +$success = $I->login( $login_input ); + +$I->assertArrayNotHasKey( 'errors', $success ); +$I->assertArrayHasKey('data', $success ); +$I->assertArrayHasKey('login', $success['data'] ); +$I->assertArrayHasKey('customer', $success['data']['login'] ); +$I->assertArrayHasKey('authToken', $success['data']['login'] ); +$I->assertArrayHasKey('refreshToken', $success['data']['login'] ); +$I->assertEquals( $customer_id, $success['data']['login']['customer']['databaseId'] ); + +// Retrieve new JWT Authorization Token for later use. +$authToken = $success['data']['login']['authToken']; + +$I->wantTo( 'Check the cart again, should still contain t-shirts.' ); + +$cart_query = ' + query { + cart { + contents { + nodes { + key + product{ databaseId } + } + } + } + } +'; + +$response = $I->sendGraphQLRequest( $cart_query, null, array( 'Authorization' => "Bearer {$authToken}" ) ); +$expected_results = array( + 'data' => array( + 'cart' => array( + 'contents' => array( + 'nodes' => array( + array( + 'key' => $shirt_key, + 'product' => array( 'databaseId' => $product_catalog['t-shirt'] ), + ), + ), + ), + ), + ), +); + +$I->assertEquals( $expected_results, $response ); + +$I->wantTo( 'Put more items in the cart.' ); + +/** + * Add "Belt" to cart and confirm response data. + */ +$add_to_cart_input = array( + 'clientMutationId' => 'someId', + 'productId' => $product_catalog['belt'], + 'quantity' => 2, +); + +$success = $I->addToCart( $add_to_cart_input, array( 'Authorization' => "Bearer {$authToken}" ) ); + +$I->assertArrayNotHasKey( 'errors', $success ); +$I->assertArrayHasKey('data', $success ); +$I->assertArrayHasKey('addToCart', $success['data'] ); +$I->assertArrayHasKey('cartItem', $success['data']['addToCart'] ); +$I->assertArrayHasKey('key', $success['data']['addToCart']['cartItem'] ); +$belt_key = $success['data']['addToCart']['cartItem']['key']; + +// Retrieve refreshed session token created when a new item is added to the cart. +// Use this token to continue previous session. +// Can also retrieve current session token by querying the following "query{ customer { sessionToken } }" +$I->seeHttpHeaderOnce( 'woocommerce-session' ); +$refreshed_session_token = $I->grabHttpHeader( 'woocommerce-session' ); + +$I->wantTo( 'Check the cart again, should contain t-shirts and belts.'); + +$cart_query = ' + query { + cart { + contents { + nodes { + key + product{ databaseId } + } + } + } + } +'; + +$response = $I->sendGraphQLRequest( + $cart_query, + null, + array( + 'Authorization' => "Bearer {$authToken}", + 'woocommerce-session' => "Session {$refreshed_session_token}", + ) +); +$expected_results = array( + 'data' => array( + 'cart' => array( + 'contents' => array( + 'nodes' => array( + array( + 'key' => $shirt_key, + 'product' => array( 'databaseId' => $product_catalog['t-shirt'] ), + ), + array( + 'key' => $belt_key, + 'product' => array( 'databaseId' => $product_catalog['belt'] ), + ), + ), + ), + ), + ), +); + +$I->assertEquals( $expected_results, $response ); + +$I->wantTo( 'End session' ); +/* + Simply not sending the previous Authorization or woocommerce-session headers in the next request does the trick. + ¯\_(ツ)_/¯ +*/ + +$I->wantTo( 'Login and start a new session.' ); + +$login_input = array( + 'clientMutationId' => 'someId', + 'username' => 'jimbo1234', + 'password' => 'password', +); +$success = $I->login( $login_input ); + +$I->assertArrayNotHasKey( 'errors', $success ); +$I->assertArrayHasKey('data', $success ); +$I->assertArrayHasKey('login', $success['data'] ); +$I->assertArrayHasKey('customer', $success['data']['login'] ); +$I->assertArrayHasKey('authToken', $success['data']['login'] ); +$I->assertArrayHasKey('refreshToken', $success['data']['login'] ); +$I->assertArrayHasKey('sessionToken', $success['data']['login'] ); +$I->assertEquals( $customer_id, $success['data']['login']['customer']['databaseId'] ); + +// Retrieve new JWT Authorization Token for later use. +$authToken = $success['data']['login']['authToken']; + +// Retrieve new session token using this in any future requests will destroy +// any existing sessions. +$new_session_token = $success['data']['login']['sessionToken']; + +$I->wantTo( 'Check the cart and should be empty' ); + +$cart_query = ' + query { + cart { + contents { + nodes { + key + product{ databaseId } + } + } + } + } +'; + +$response = $I->sendGraphQLRequest( + $cart_query, + null, + array( + 'Authorization' => "Bearer {$authToken}", + 'woocommerce-session' => "Session {$new_session_token}", + ) +); +$expected_results = array( + 'data' => array( + 'cart' => array( + 'contents' => array( + 'nodes' => array(), + ), + ), + ), +); + +$I->assertEquals( $expected_results, $response ); diff --git a/tests/functional.suite.dist.yml b/tests/functional.suite.dist.yml index 51a591e6..ec141b60 100644 --- a/tests/functional.suite.dist.yml +++ b/tests/functional.suite.dist.yml @@ -5,14 +5,13 @@ actor: FunctionalTester modules: - enabled: - - Asserts - - REST - - WPBrowser - - WPDb - - WPLoader - - \Helper\GraphQLE2E - config: - WPDb: - cleanup: false - \ No newline at end of file + enabled: + - Asserts + - REST + - WPBrowser + - WPDb + - WPLoader + - \Helper\GraphQLE2E + config: + WPDb: + cleanup: false diff --git a/tests/wpunit.suite.dist.yml b/tests/wpunit.suite.dist.yml index 4efc9dfb..e84f0a4f 100644 --- a/tests/wpunit.suite.dist.yml +++ b/tests/wpunit.suite.dist.yml @@ -4,26 +4,26 @@ actor: WpunitTester modules: - enabled: - - WPLoader - - \Helper\Wpunit - disabled: - - WPDb - - WPBrowser - config: - WPDb: - cleanup: false - WPLoader: - 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 -bootstrap: bootstrap.php \ No newline at end of file + enabled: + - WPLoader + - \Helper\Wpunit + disabled: + - WPDb + - WPBrowser + config: + WPDb: + cleanup: false + WPLoader: + 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 +bootstrap: bootstrap.php diff --git a/tests/wpunit/CheckoutMutationTest.php b/tests/wpunit/CheckoutMutationTest.php index cd0ca225..7c5782b6 100644 --- a/tests/wpunit/CheckoutMutationTest.php +++ b/tests/wpunit/CheckoutMutationTest.php @@ -761,7 +761,7 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase { 'checkout' => array( 'clientMutationId' => 'someId', 'order' => array_merge( - $this->order->print_restricted_query( $order->get_id() ), + $this->order->print_query( $order->get_id() ), array( 'metaData' => array( array( @@ -966,7 +966,7 @@ class CheckoutMutationTest extends \Codeception\TestCase\WPTestCase { 'checkout' => array( 'clientMutationId' => 'someId', 'order' => array_merge( - $this->order->print_restricted_query( $order->get_id() ), + $this->order->print_query( $order->get_id() ), array( 'metaData' => array( array( diff --git a/tests/wpunit/CoreInterfaceQueriesTest.php b/tests/wpunit/CoreInterfaceQueriesTest.php index ee85ff61..a1d4b824 100644 --- a/tests/wpunit/CoreInterfaceQueriesTest.php +++ b/tests/wpunit/CoreInterfaceQueriesTest.php @@ -145,6 +145,9 @@ class CoreInterfaceQueriesTest extends \Codeception\TestCase\WPTestCase { $product_id = $this->products->create_simple(); $product = \wc_get_product( $product_id ); + // Authenticate to view RAW content. + wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) ); + // Define query and variables. $query = ' query ( $id: ID!, $format: PostObjectFieldFormatEnum ) { @@ -335,10 +338,6 @@ class CoreInterfaceQueriesTest extends \Codeception\TestCase\WPTestCase { query ( $id: ID! ) { productVariation( id: $id, idType: DATABASE_ID ) { id - ... on HierarchicalContentNode { - parentId - parentDatabaseId - } ... on ContentNode { databaseId date @@ -374,8 +373,6 @@ class CoreInterfaceQueriesTest extends \Codeception\TestCase\WPTestCase { 'data' => array( 'productVariation' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'product_variation', $variation_id ), - 'parentId' => \GraphQLRelay\Relay::toGlobalId( 'post', $wp_product->post_parent ), - 'parentDatabaseId' => $wp_product->post_parent, 'databaseId' => $wp_product->ID, 'date' => (string) $wc_product->get_date_created(), 'dateGmt' => \WPGraphQL\Utils\Utils::prepare_date_response( $wp_product->post_date_gmt ), diff --git a/tests/wpunit/PaymentGatewayQueriesTest.php b/tests/wpunit/PaymentGatewayQueriesTest.php index 4fe978ec..cac1b1c0 100644 --- a/tests/wpunit/PaymentGatewayQueriesTest.php +++ b/tests/wpunit/PaymentGatewayQueriesTest.php @@ -108,12 +108,6 @@ class PaymentGatewayQueriesTest extends \Codeception\TestCase\WPTestCase 'title' => 'Direct bank transfer', 'icon' => null, ), - array( - 'id' => 'stripe', - 'title' => 'Credit Card (Stripe)', - 'description' => 'Pay with your credit card via Stripe', - 'icon' => null, - ), ), ), ), @@ -220,66 +214,6 @@ class PaymentGatewayQueriesTest extends \Codeception\TestCase\WPTestCase 'title' => 'Multibanco', 'icon' => null, ), - array( - 'id' => 'stripe', - 'title' => 'Credit Card (Stripe)', - 'description' => 'Pay with your credit card via Stripe', - 'icon' => null, - ), - array( - 'id' => 'stripe_sepa', - 'title' => 'SEPA Direct Debit', - 'description' => 'Mandate Information.', - 'icon' => null, - ), - array( - 'id' => 'stripe_bancontact', - 'title' => 'Bancontact', - 'description' => 'You will be redirected to Bancontact.', - 'icon' => null, - ), - array( - 'id' => 'stripe_sofort', - 'title' => 'SOFORT', - 'description' => 'You will be redirected to SOFORT.', - 'icon' => null, - ), - array( - 'id' => 'stripe_giropay', - 'title' => 'Giropay', - 'description' => 'You will be redirected to Giropay.', - 'icon' => null, - ), - array( - 'id' => 'stripe_eps', - 'title' => 'EPS', - 'description' => 'You will be redirected to EPS.', - 'icon' => null, - ), - array( - 'id' => 'stripe_ideal', - 'title' => 'iDeal', - 'description' => 'You will be redirected to iDeal.', - 'icon' => null, - ), - array( - 'id' => 'stripe_p24', - 'title' => 'Przelewy24 (P24)', - 'description' => 'You will be redirected to P24.', - 'icon' => null, - ), - array( - 'id' => 'stripe_alipay', - 'title' => 'Alipay', - 'description' => 'You will be redirected to Alipay.', - 'icon' => null, - ), - array( - 'id' => 'stripe_multibanco', - 'title' => 'Multibanco', - 'description' => 'You will be redirected to Multibanco.', - 'icon' => null, - ), ), ), ), diff --git a/tests/wpunit/ProductVariationQueriesTest.php b/tests/wpunit/ProductVariationQueriesTest.php index 7f60e6d1..01715f53 100644 --- a/tests/wpunit/ProductVariationQueriesTest.php +++ b/tests/wpunit/ProductVariationQueriesTest.php @@ -68,7 +68,7 @@ class ProductVariationQueriesTest extends \Codeception\TestCase\WPTestCase { hasAttributes type parent { - id + node { id } } } } diff --git a/vendor/autoload.php b/vendor/autoload.php index 84efe408..7ee55b8a 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitd71d86c43e8ed05b96e37706ed82275d::getLoader(); +return ComposerAutoloaderInita19c98089e83bf1ea084032a65b4d4fa::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 3f71a1b9..9566aee2 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitd71d86c43e8ed05b96e37706ed82275d +class ComposerAutoloaderInita19c98089e83bf1ea084032a65b4d4fa { private static $loader; @@ -22,15 +22,15 @@ class ComposerAutoloaderInitd71d86c43e8ed05b96e37706ed82275d return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitd71d86c43e8ed05b96e37706ed82275d', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInita19c98089e83bf1ea084032a65b4d4fa', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInitd71d86c43e8ed05b96e37706ed82275d', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInita19c98089e83bf1ea084032a65b4d4fa', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInita19c98089e83bf1ea084032a65b4d4fa::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -51,19 +51,19 @@ class ComposerAutoloaderInitd71d86c43e8ed05b96e37706ed82275d $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d::$files; + $includeFiles = Composer\Autoload\ComposerStaticInita19c98089e83bf1ea084032a65b4d4fa::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequired71d86c43e8ed05b96e37706ed82275d($fileIdentifier, $file); + composerRequirea19c98089e83bf1ea084032a65b4d4fa($fileIdentifier, $file); } return $loader; } } -function composerRequired71d86c43e8ed05b96e37706ed82275d($fileIdentifier, $file) +function composerRequirea19c98089e83bf1ea084032a65b4d4fa($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 4eac7679..4ff1edd4 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d +class ComposerStaticInita19c98089e83bf1ea084032a65b4d4fa { public static $files = array ( '944484f100dc1864a5320474d49ebd5a' => __DIR__ . '/../..' . '/includes/connection/wc-cpt-connection-args.php', @@ -176,9 +176,9 @@ class ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitd71d86c43e8ed05b96e37706ed82275d::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInita19c98089e83bf1ea084032a65b4d4fa::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInita19c98089e83bf1ea084032a65b4d4fa::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInita19c98089e83bf1ea084032a65b4d4fa::$classMap; }, null, ClassLoader::class); }