diff --git a/.env.testing b/.env.testing index 3215134bc..578c92153 100644 --- a/.env.testing +++ b/.env.testing @@ -11,15 +11,13 @@ MUPLUGINS_DIR= THEMES_DIR= # WordPress database configurations -DB_NAME=wordpress -DB_HOST=app_db -DB_PORT=3306 -DB_USER=wordpress -DB_PASSWORD=password -ROOT_PASSWORD=password -WP_TABLE_PREFIX=wp_ -SKIP_DB_CREATE=true -SKIP_WP_SETUP=true +DB_NAME=wordpress_test +DB_USER=root +DB_PASSWORD= +DB_HOST=127.0.0.1 +DB_PORT=3308 +DB_PREFIX=wp_ + # Extra environmental variables/constants. GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123 diff --git a/access-functions.php b/access-functions.php index dd785bb0a..12b1a9eba 100644 --- a/access-functions.php +++ b/access-functions.php @@ -51,11 +51,11 @@ function str_ends_with( $haystack, $needle ) { * @return array */ function wc_graphql_map_tax_statements( $raw_taxes ) { - $taxes = []; + $taxes = array(); foreach ( $raw_taxes as $field => $values ) { foreach ( $values as $id => $amount ) { if ( empty( $taxes[ $id ] ) ) { - $taxes[ $id ] = []; + $taxes[ $id ] = array(); } $taxes[ $id ]['ID'] = $id; $taxes[ $id ][ $field ] = $amount; @@ -73,7 +73,7 @@ function wc_graphql_map_tax_statements( $raw_taxes ) { * @return array */ function wc_graphql_get_order_statuses() { - $order_statuses = []; + $order_statuses = array(); foreach ( array_keys( wc_get_order_statuses() ) as $status ) { $order_statuses[] = str_replace( 'wc-', '', $status ); } @@ -103,19 +103,19 @@ function wc_graphql_get_order_statuses() { * } * @return string */ - function wc_graphql_price( $price, $args = [] ) { + function wc_graphql_price( $price, $args = array() ) { $price = floatval( $price ); $args = apply_filters( 'wc_price_args', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound wp_parse_args( $args, - [ + array( 'currency' => '', 'decimal_separator' => wc_get_price_decimal_separator(), 'thousand_separator' => wc_get_price_thousand_separator(), 'decimals' => wc_get_price_decimals(), 'price_format' => get_woocommerce_price_format(), - ] + ) ) ); diff --git a/codeception.dist.yml b/codeception.dist.yml index 283cbaf9f..7a3598767 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -5,8 +5,8 @@ paths: support: tests/_support envs: tests/_envs params: - - env - - .env.docker + - .env + # - .env.docker actor_suffix: Tester settings: colors: true diff --git a/composer.json b/composer.json index 3f839603b..1558b275e 100644 --- a/composer.json +++ b/composer.json @@ -28,11 +28,23 @@ "axepress/wp-graphql-cs": "^2.0.0-beta", "axepress/wp-graphql-stubs": "^1.27.1", "brainmaestro/composer-git-hooks": "^2.8.5", + "codeception/codeception": "*", + "codeception/module-asserts": "*", + "codeception/module-phpbrowser": "*", + "codeception/module-rest": "*", + "lucatume/wp-browser": "*", "php-stubs/woocommerce-stubs": "9.1.0", + "phpcsstandards/phpcsutils": "^1.0", "phpstan/extension-installer": "^1.3", "phpstan/phpdoc-parser": "^1.22.0", "phpstan/phpstan": "^1.10", - "szepeviktor/phpstan-wordpress": "^1.3" + "squizlabs/php_codesniffer": "^3.7", + "szepeviktor/phpstan-wordpress": "^1.3", + "wp-coding-standards/wpcs": "^3.1", + "phpunit/phpunit": "^9.6 || ^10.0 || ^11.0", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "phpcompatibility/phpcompatibility-wp": "^2.1", + "sirbrillig/phpcs-variable-analysis": "^2.11" }, "config": { "optimize-autoloader": true, @@ -73,8 +85,8 @@ ], "dRunTestStandalone": "env $(sed -e '/^#/d' .env.testing) docker compose run --rm run_tests", "dDestroy": "docker compose down -v", - "lint": "vendor/bin/phpcs -vp .", - "fix": "vendor/bin/phpcbf -vp .", + "lint": "phpcs -p --standard=WordPress --extensions=php .", + "lint:fix": "phpcbf -p --standard=WordPress --extensions=php .", "stan": "phpstan analyze --ansi --memory-limit=1G", "strauss": [ "test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.14.0/strauss.phar", @@ -92,7 +104,8 @@ "post-update-cmd": [ "@strauss", "[ $COMPOSER_DEV_MODE -eq 0 ] || composer cghooks update" - ] + ], + "test": "phpunit" }, "support": { "issues": "https://github.com/wp-graphql/wp-graphql-woocommerce/issues", @@ -121,14 +134,14 @@ ] }, "extra": { - "strauss" : { + "strauss": { "target_directory": "vendor-prefixed", "namespace_prefix": "WPGraphQL\\WooCommerce\\Vendor\\", "classmap_prefix": "WP_GraphQL_WooCommerce_Vendor", "constant_prefix": "WPGRAPHQL_WOOCOMMERCE_VENDOR", "delete_vendor_files": true, "include_modified_date": false, - "packages" : [ + "packages": [ "firebase/php-jwt" ], "exclude_from_prefix": { @@ -144,4 +157,4 @@ ] } } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 802e32e71..f47cadac8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "775e640cc122cba00a8653eb87c9dcf8", + "content-hash": "dbc71d75624058b7033dc21b0eb9ad55", "packages": [ { "name": "firebase/php-jwt", - "version": "v6.11.0", + "version": "v6.11.1", "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "8f718f4dfc9c5d5f0c994cdfd103921b43592712" + "reference": "d1e91ecf8c598d073d0995afa8cd5c75c6e19e66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/8f718f4dfc9c5d5f0c994cdfd103921b43592712", - "reference": "8f718f4dfc9c5d5f0c994cdfd103921b43592712", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/d1e91ecf8c598d073d0995afa8cd5c75c6e19e66", + "reference": "d1e91ecf8c598d073d0995afa8cd5c75c6e19e66", "shasum": "" }, "require": { @@ -65,9 +65,9 @@ ], "support": { "issues": "https://github.com/firebase/php-jwt/issues", - "source": "https://github.com/firebase/php-jwt/tree/v6.11.0" + "source": "https://github.com/firebase/php-jwt/tree/v6.11.1" }, - "time": "2025-01-23T05:11:06+00:00" + "time": "2025-04-09T20:32:01+00:00" } ], "packages-dev": [ @@ -127,16 +127,16 @@ }, { "name": "axepress/wp-graphql-cs", - "version": "2.0.0-beta.3", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/AxeWP/WPGraphQL-Coding-Standards.git", - "reference": "764056aacbf67fd9a318d8dc7a3b9107102f974e" + "reference": "2107d7ae6d05759820b57d0b00125b43eeb7c2d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/AxeWP/WPGraphQL-Coding-Standards/zipball/764056aacbf67fd9a318d8dc7a3b9107102f974e", - "reference": "764056aacbf67fd9a318d8dc7a3b9107102f974e", + "url": "https://api.github.com/repos/AxeWP/WPGraphQL-Coding-Standards/zipball/2107d7ae6d05759820b57d0b00125b43eeb7c2d2", + "reference": "2107d7ae6d05759820b57d0b00125b43eeb7c2d2", "shasum": "" }, "require": { @@ -149,8 +149,7 @@ "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9", - "phpcsstandards/phpcsdevtools": "^1.0", - "phpunit/phpunit": "^8.5 || ^9" + "phpcsstandards/phpcsdevtools": "^1.0" }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -181,20 +180,20 @@ "issues": "https://github.com/AxeWP/WPGraphQL-Coding-Standards/issues", "source": "https://github.com/AxeWP/WPGraphQL-Coding-Standards" }, - "time": "2024-04-05T17:27:39+00:00" + "time": "2025-05-03T00:30:19+00:00" }, { "name": "axepress/wp-graphql-stubs", - "version": "v1.29.0", + "version": "v1.31.1", "source": { "type": "git", "url": "https://github.com/AxeWP/wp-graphql-stubs.git", - "reference": "79bc096361b1bf65a6b367a382fa90407d8952ba" + "reference": "55296773a7537e0dbc008010959718c7c796e170" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/AxeWP/wp-graphql-stubs/zipball/79bc096361b1bf65a6b367a382fa90407d8952ba", - "reference": "79bc096361b1bf65a6b367a382fa90407d8952ba", + "url": "https://api.github.com/repos/AxeWP/wp-graphql-stubs/zipball/55296773a7537e0dbc008010959718c7c796e170", + "reference": "55296773a7537e0dbc008010959718c7c796e170", "shasum": "" }, "require": { @@ -225,7 +224,7 @@ ], "support": { "issues": "https://github.com/AxeWP/wp-graphql-stubs/issues", - "source": "https://github.com/AxeWP/wp-graphql-stubs/tree/v1.29.0" + "source": "https://github.com/AxeWP/wp-graphql-stubs/tree/v1.31.1" }, "funding": [ { @@ -233,7 +232,76 @@ "type": "github" } ], - "time": "2024-09-20T01:43:19+00:00" + "time": "2025-01-29T12:41:14+00:00" + }, + { + "name": "behat/gherkin", + "version": "v4.14.0", + "source": { + "type": "git", + "url": "https://github.com/Behat/Gherkin.git", + "reference": "34c9b59c59355a7b4c53b9f041c8dbd1c8acc3b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Behat/Gherkin/zipball/34c9b59c59355a7b4c53b9f041c8dbd1c8acc3b4", + "reference": "34c9b59c59355a7b4c53b9f041c8dbd1c8acc3b4", + "shasum": "" + }, + "require": { + "composer-runtime-api": "^2.2", + "php": "8.1.* || 8.2.* || 8.3.* || 8.4.*" + }, + "require-dev": { + "cucumber/gherkin-monorepo": "dev-gherkin-v32.1.1", + "friendsofphp/php-cs-fixer": "^3.65", + "mikey179/vfsstream": "^1.6", + "phpstan/extension-installer": "^1", + "phpstan/phpstan": "^2", + "phpstan/phpstan-phpunit": "^2", + "phpunit/phpunit": "^10.5", + "symfony/yaml": "^5.4 || ^6.4 || ^7.0" + }, + "suggest": { + "symfony/yaml": "If you want to parse features, represented in YAML files" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Gherkin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "https://everzet.com" + } + ], + "description": "Gherkin DSL parser for PHP", + "homepage": "https://behat.org/", + "keywords": [ + "BDD", + "Behat", + "Cucumber", + "DSL", + "gherkin", + "parser" + ], + "support": { + "issues": "https://github.com/Behat/Gherkin/issues", + "source": "https://github.com/Behat/Gherkin/tree/v4.14.0" + }, + "time": "2025-05-23T15:06:40+00:00" }, { "name": "brainmaestro/composer-git-hooks", @@ -264,7 +332,6 @@ "type": "library", "extra": { "hooks": { - "pre-commit": "composer check-style", "pre-push": [ "composer test", "appver=$(grep -o -E '\\d.\\d.\\d' cghooks)", @@ -275,7 +342,8 @@ "sed -i -E \"s/$appver/$tag/\" cghooks", "exit 1", "fi" - ] + ], + "pre-commit": "composer check-style" } }, "autoload": { @@ -309,40 +377,99 @@ "time": "2021-02-08T15:59:11+00:00" }, { - "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v1.0.0", + "name": "codeception/codeception", + "version": "5.3.2", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/composer-installer.git", - "reference": "4be43904336affa5c2f70744a348312336afd0da" + "url": "https://github.com/Codeception/Codeception.git", + "reference": "582112d7a603d575e41638df1e96900b10ae91b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", - "reference": "4be43904336affa5c2f70744a348312336afd0da", + "url": "https://api.github.com/repos/Codeception/Codeception/zipball/582112d7a603d575e41638df1e96900b10ae91b8", + "reference": "582112d7a603d575e41638df1e96900b10ae91b8", "shasum": "" }, "require": { - "composer-plugin-api": "^1.0 || ^2.0", - "php": ">=5.4", - "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + "behat/gherkin": "^4.12", + "codeception/lib-asserts": "^2.2", + "codeception/stub": "^4.1", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": "^8.2", + "phpunit/php-code-coverage": "^9.2 | ^10.0 | ^11.0 | ^12.0", + "phpunit/php-text-template": "^2.0 | ^3.0 | ^4.0 | ^5.0", + "phpunit/php-timer": "^5.0.3 | ^6.0 | ^7.0 | ^8.0", + "phpunit/phpunit": "^9.5.20 | ^10.0 | ^11.0 | ^12.0", + "psy/psysh": "^0.11.2 | ^0.12", + "sebastian/comparator": "^4.0.5 | ^5.0 | ^6.0 | ^7.0", + "sebastian/diff": "^4.0.3 | ^5.0 | ^6.0 | ^7.0", + "symfony/console": ">=5.4.24 <8.0", + "symfony/css-selector": ">=5.4.24 <8.0", + "symfony/event-dispatcher": ">=5.4.24 <8.0", + "symfony/finder": ">=5.4.24 <8.0", + "symfony/var-dumper": ">=5.4.24 <8.0", + "symfony/yaml": ">=5.4.24 <8.0" + }, + "conflict": { + "codeception/lib-innerbrowser": "<3.1.3", + "codeception/module-filesystem": "<3.0", + "codeception/module-phpbrowser": "<2.5" + }, + "replace": { + "codeception/phpunit-wrapper": "*" }, "require-dev": { - "composer/composer": "*", - "ext-json": "*", - "ext-zip": "*", - "php-parallel-lint/php-parallel-lint": "^1.3.1", - "phpcompatibility/php-compatibility": "^9.0", - "yoast/phpunit-polyfills": "^1.0" + "codeception/lib-innerbrowser": "*@dev", + "codeception/lib-web": "*@dev", + "codeception/module-asserts": "*@dev", + "codeception/module-cli": "*@dev", + "codeception/module-db": "*@dev", + "codeception/module-filesystem": "*@dev", + "codeception/module-phpbrowser": "*@dev", + "codeception/module-webdriver": "*@dev", + "codeception/util-universalframework": "*@dev", + "doctrine/orm": "^3.3", + "ext-simplexml": "*", + "jetbrains/phpstorm-attributes": "^1.0", + "laravel-zero/phar-updater": "^1.4", + "php-webdriver/webdriver": "^1.15", + "stecman/symfony-console-completion": "^0.14", + "symfony/dotenv": ">=5.4.24 <8.0", + "symfony/error-handler": ">=5.4.24 <8.0", + "symfony/process": ">=5.4.24 <8.0", + "vlucas/phpdotenv": "^5.1" }, - "type": "composer-plugin", + "suggest": { + "codeception/specify": "BDD-style code blocks", + "codeception/verify": "BDD-style assertions", + "ext-simplexml": "For loading params from XML files", + "stecman/symfony-console-completion": "For BASH autocompletion", + "symfony/dotenv": "For loading params from .env files", + "symfony/phpunit-bridge": "For phpunit-bridge support", + "vlucas/phpdotenv": "For loading params from .env files" + }, + "bin": [ + "codecept" + ], + "type": "library", "extra": { - "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + "branch-alias": { + "dev-main": "5.2.x-dev" + } }, "autoload": { + "files": [ + "functions.php" + ], "psr-4": { - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" - } + "Codeception\\": "src/Codeception", + "Codeception\\Extension\\": "ext" + }, + "classmap": [ + "src/PHPUnit/TestCase.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -350,683 +477,726 @@ ], "authors": [ { - "name": "Franck Nijhof", - "email": "franck.nijhof@dealerdirect.com", - "homepage": "http://www.frenck.nl", - "role": "Developer / IT Manager" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + "name": "Michael Bodnarchuk", + "email": "davert.ua@gmail.com", + "homepage": "https://codeception.com" } ], - "description": "PHP_CodeSniffer Standards Composer Installer Plugin", - "homepage": "http://www.dealerdirect.com", + "description": "BDD-style testing framework", + "homepage": "https://codeception.com/", "keywords": [ - "PHPCodeSniffer", - "PHP_CodeSniffer", - "code quality", - "codesniffer", - "composer", - "installer", - "phpcbf", - "phpcs", - "plugin", - "qa", - "quality", - "standard", - "standards", - "style guide", - "stylecheck", - "tests" + "BDD", + "TDD", + "acceptance testing", + "functional testing", + "unit testing" ], "support": { - "issues": "https://github.com/PHPCSStandards/composer-installer/issues", - "source": "https://github.com/PHPCSStandards/composer-installer" + "issues": "https://github.com/Codeception/Codeception/issues", + "source": "https://github.com/Codeception/Codeception/tree/5.3.2" }, - "time": "2023-01-05T11:28:13+00:00" + "funding": [ + { + "url": "https://opencollective.com/codeception", + "type": "open_collective" + } + ], + "time": "2025-05-26T07:47:39+00:00" }, { - "name": "php-stubs/woocommerce-stubs", - "version": "v9.1.0", + "name": "codeception/lib-asserts", + "version": "2.2.0", "source": { "type": "git", - "url": "https://github.com/php-stubs/woocommerce-stubs.git", - "reference": "2c95c633362d1f4f531f69e5db63bb19399d8b58" + "url": "https://github.com/Codeception/lib-asserts.git", + "reference": "06750a60af3ebc66faab4313981accec1be4eefc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/2c95c633362d1f4f531f69e5db63bb19399d8b58", - "reference": "2c95c633362d1f4f531f69e5db63bb19399d8b58", + "url": "https://api.github.com/repos/Codeception/lib-asserts/zipball/06750a60af3ebc66faab4313981accec1be4eefc", + "reference": "06750a60af3ebc66faab4313981accec1be4eefc", "shasum": "" }, "require": { - "php-stubs/wordpress-stubs": "^5.3 || ^6.0" - }, - "require-dev": { - "php": "~7.1 || ~8.0", - "php-stubs/generator": "^0.8.0" - }, - "suggest": { - "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", - "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + "codeception/phpunit-wrapper": "^7.7.1 | ^8.0.3 | ^9.0", + "ext-dom": "*", + "php": "^7.4 | ^8.0" }, "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "WooCommerce function and class declaration stubs for static analysis.", - "homepage": "https://github.com/php-stubs/woocommerce-stubs", + "authors": [ + { + "name": "Michael Bodnarchuk", + "email": "davert@mail.ua", + "homepage": "http://codegyre.com" + }, + { + "name": "Gintautas Miselis" + }, + { + "name": "Gustavo Nieves", + "homepage": "https://medium.com/@ganieves" + } + ], + "description": "Assertion methods used by Codeception core and Asserts module", + "homepage": "https://codeception.com/", "keywords": [ - "PHPStan", - "static analysis", - "woocommerce", - "wordpress" + "codeception" ], "support": { - "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", - "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v9.1.0" + "issues": "https://github.com/Codeception/lib-asserts/issues", + "source": "https://github.com/Codeception/lib-asserts/tree/2.2.0" }, - "time": "2024-07-11T10:55:02+00:00" + "time": "2025-03-10T20:41:33+00:00" }, { - "name": "php-stubs/wordpress-stubs", - "version": "v6.6.2", + "name": "codeception/lib-innerbrowser", + "version": "4.0.6", "source": { "type": "git", - "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "f50fd7ed45894d036e4fef9ab7e5bbbaff6a30cc" + "url": "https://github.com/Codeception/lib-innerbrowser.git", + "reference": "74476dd019ec7900b26b7dca91a42fdcb04e549f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/f50fd7ed45894d036e4fef9ab7e5bbbaff6a30cc", - "reference": "f50fd7ed45894d036e4fef9ab7e5bbbaff6a30cc", + "url": "https://api.github.com/repos/Codeception/lib-innerbrowser/zipball/74476dd019ec7900b26b7dca91a42fdcb04e549f", + "reference": "74476dd019ec7900b26b7dca91a42fdcb04e549f", "shasum": "" }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "nikic/php-parser": "^4.13", - "php": "^7.4 || ^8.0", - "php-stubs/generator": "^0.8.3", - "phpdocumentor/reflection-docblock": "^5.4.1", - "phpstan/phpstan": "^1.10.49", - "phpunit/phpunit": "^9.5", - "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.0", - "wp-coding-standards/wpcs": "3.1.0 as 2.3.0" + "require": { + "codeception/codeception": "^5.0.8", + "codeception/lib-web": "^1.0.1", + "ext-dom": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": "^8.1", + "phpunit/phpunit": "^10.0 || ^11.0 || ^12.0", + "symfony/browser-kit": "^4.4.24 || ^5.4 || ^6.0 || ^7.0", + "symfony/dom-crawler": "^4.4.30 || ^5.4 || ^6.0 || ^7.0" }, - "suggest": { - "paragonie/sodium_compat": "Pure PHP implementation of libsodium", - "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + "require-dev": { + "codeception/util-universalframework": "^1.0" }, "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "WordPress function and class declaration stubs for static analysis.", - "homepage": "https://github.com/php-stubs/wordpress-stubs", + "authors": [ + { + "name": "Michael Bodnarchuk", + "email": "davert@mail.ua", + "homepage": "https://codegyre.com" + }, + { + "name": "Gintautas Miselis" + } + ], + "description": "Parent library for all Codeception framework modules and PhpBrowser", + "homepage": "https://codeception.com/", "keywords": [ - "PHPStan", - "static analysis", - "wordpress" + "codeception" ], "support": { - "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.6.2" + "issues": "https://github.com/Codeception/lib-innerbrowser/issues", + "source": "https://github.com/Codeception/lib-innerbrowser/tree/4.0.6" }, - "time": "2024-09-30T07:10:48+00:00" + "time": "2025-02-14T07:02:48+00:00" }, { - "name": "phpcompatibility/php-compatibility", - "version": "9.3.5", + "name": "codeception/lib-web", + "version": "1.0.7", "source": { "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", - "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + "url": "https://github.com/Codeception/lib-web.git", + "reference": "1444ccc9b1d6721f3ced8703c8f4a9041b80df93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", - "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "url": "https://api.github.com/repos/Codeception/lib-web/zipball/1444ccc9b1d6721f3ced8703c8f4a9041b80df93", + "reference": "1444ccc9b1d6721f3ced8703c8f4a9041b80df93", "shasum": "" }, "require": { - "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + "ext-mbstring": "*", + "guzzlehttp/psr7": "^2.0", + "php": "^8.1", + "phpunit/phpunit": "^9.5 | ^10.0 | ^11.0 | ^12", + "symfony/css-selector": ">=4.4.24 <8.0" }, "conflict": { - "squizlabs/php_codesniffer": "2.6.2" + "codeception/codeception": "<5.0.0-alpha3" }, "require-dev": { - "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + "php-webdriver/webdriver": "^1.12" }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] }, - "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0-or-later" + "MIT" ], "authors": [ { - "name": "Wim Godden", - "homepage": "https://github.com/wimg", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", - "role": "lead" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + "name": "Gintautas Miselis" } ], - "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", - "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "description": "Library containing files used by module-webdriver and lib-innerbrowser or module-phpbrowser", + "homepage": "https://codeception.com/", "keywords": [ - "compatibility", - "phpcs", - "standards" + "codeception" ], "support": { - "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", - "source": "https://github.com/PHPCompatibility/PHPCompatibility" + "issues": "https://github.com/Codeception/lib-web/issues", + "source": "https://github.com/Codeception/lib-web/tree/1.0.7" }, - "time": "2019-12-27T09:44:58+00:00" + "time": "2025-02-09T12:05:55+00:00" }, { - "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.3", + "name": "codeception/lib-xml", + "version": "1.1.0", "source": { "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac" + "url": "https://github.com/Codeception/lib-xml.git", + "reference": "da6559647c1e0f3839335d401e383ae3e61aafaa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/293975b465e0e709b571cbf0c957c6c0a7b9a2ac", - "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac", + "url": "https://api.github.com/repos/Codeception/lib-xml/zipball/da6559647c1e0f3839335d401e383ae3e61aafaa", + "reference": "da6559647c1e0f3839335d401e383ae3e61aafaa", "shasum": "" }, "require": { - "phpcompatibility/php-compatibility": "^9.0" + "codeception/lib-web": "^1.0.6 || ^2", + "ext-dom": "*", + "php": "^8.2", + "symfony/css-selector": ">=4.4.24 <8.0" }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "paragonie/random_compat": "dev-master", - "paragonie/sodium_compat": "dev-master" + "conflict": { + "codeception/codeception": "<5.0.0-alpha3" }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] }, - "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0-or-later" + "MIT" ], "authors": [ { - "name": "Wim Godden", - "role": "lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "lead" + "name": "Gintautas Miselis" } ], - "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", - "homepage": "http://phpcompatibility.com/", + "description": "Files used by module-rest and module-soap", + "homepage": "https://codeception.com/", "keywords": [ - "compatibility", - "paragonie", - "phpcs", - "polyfill", - "standards", - "static analysis" + "codeception" ], "support": { - "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", - "security": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/security/policy", - "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + "issues": "https://github.com/Codeception/lib-xml/issues", + "source": "https://github.com/Codeception/lib-xml/tree/1.1.0" }, - "funding": [ - { - "url": "https://github.com/PHPCompatibility", - "type": "github" - }, - { - "url": "https://github.com/jrfnl", - "type": "github" - }, - { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" - } - ], - "time": "2024-04-24T21:30:46+00:00" + "time": "2025-09-21T18:33:44+00:00" }, { - "name": "phpcompatibility/phpcompatibility-wp", - "version": "2.1.5", + "name": "codeception/module-asserts", + "version": "3.2.0", "source": { "type": "git", - "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", - "reference": "01c1ff2704a58e46f0cb1ca9d06aee07b3589082" + "url": "https://github.com/Codeception/module-asserts.git", + "reference": "eb1f7c980423888f3def5116635754ae4a75bd47" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/01c1ff2704a58e46f0cb1ca9d06aee07b3589082", - "reference": "01c1ff2704a58e46f0cb1ca9d06aee07b3589082", + "url": "https://api.github.com/repos/Codeception/module-asserts/zipball/eb1f7c980423888f3def5116635754ae4a75bd47", + "reference": "eb1f7c980423888f3def5116635754ae4a75bd47", "shasum": "" }, "require": { - "phpcompatibility/php-compatibility": "^9.0", - "phpcompatibility/phpcompatibility-paragonie": "^1.0" + "codeception/codeception": "*@dev", + "codeception/lib-asserts": "^2.2", + "php": "^8.2" }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0" + "conflict": { + "codeception/codeception": "<5.0" }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", - "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] }, - "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0-or-later" + "MIT" ], "authors": [ { - "name": "Wim Godden", - "role": "lead" + "name": "Michael Bodnarchuk" }, { - "name": "Juliette Reinders Folmer", - "role": "lead" + "name": "Gintautas Miselis" + }, + { + "name": "Gustavo Nieves", + "homepage": "https://medium.com/@ganieves" } ], - "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", - "homepage": "http://phpcompatibility.com/", + "description": "Codeception module containing various assertions", + "homepage": "https://codeception.com/", "keywords": [ - "compatibility", - "phpcs", - "standards", - "static analysis", - "wordpress" + "assertions", + "asserts", + "codeception" ], "support": { - "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", - "security": "https://github.com/PHPCompatibility/PHPCompatibilityWP/security/policy", - "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + "issues": "https://github.com/Codeception/module-asserts/issues", + "source": "https://github.com/Codeception/module-asserts/tree/3.2.0" }, - "funding": [ - { - "url": "https://github.com/PHPCompatibility", - "type": "github" - }, - { - "url": "https://github.com/jrfnl", - "type": "github" - }, - { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" - } - ], - "time": "2024-04-24T21:37:59+00:00" + "time": "2025-05-02T02:33:11+00:00" }, { - "name": "phpcsstandards/phpcsextra", - "version": "1.2.1", + "name": "codeception/module-cli", + "version": "2.0.1", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", - "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + "url": "https://github.com/Codeception/module-cli.git", + "reference": "a3a101fae4049fa2f810107f7bd5db3b3266ce63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", - "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "url": "https://api.github.com/repos/Codeception/module-cli/zipball/a3a101fae4049fa2f810107f7bd5db3b3266ce63", + "reference": "a3a101fae4049fa2f810107f7bd5db3b3266ce63", "shasum": "" }, "require": { - "php": ">=5.4", - "phpcsstandards/phpcsutils": "^1.0.9", - "squizlabs/php_codesniffer": "^3.8.0" + "codeception/codeception": "*@dev", + "codeception/module-asserts": "*", + "php": "^7.4 || ^8.0" }, - "require-dev": { - "php-parallel-lint/php-console-highlighter": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", - "phpcsstandards/phpcsdevcs": "^1.1.6", - "phpcsstandards/phpcsdevtools": "^1.2.1", - "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "conflict": { + "codeception/codeception": "<4.0" }, - "type": "phpcodesniffer-standard", - "extra": { - "branch-alias": { - "dev-stable": "1.x-dev", - "dev-develop": "1.x-dev" - } + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0-or-later" + "MIT" ], "authors": [ { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", - "role": "lead" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + "name": "Michael Bodnarchuk" } ], - "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "description": "Codeception module for testing basic shell commands and shell output", + "homepage": "https://codeception.com/", "keywords": [ - "PHP_CodeSniffer", - "phpcbf", - "phpcodesniffer-standard", - "phpcs", - "standards", - "static analysis" + "codeception" ], "support": { - "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", - "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", - "source": "https://github.com/PHPCSStandards/PHPCSExtra" + "issues": "https://github.com/Codeception/module-cli/issues", + "source": "https://github.com/Codeception/module-cli/tree/2.0.1" }, - "funding": [ - { - "url": "https://github.com/PHPCSStandards", - "type": "github" - }, - { - "url": "https://github.com/jrfnl", - "type": "github" - }, - { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" - } - ], - "time": "2023-12-08T16:49:07+00:00" + "time": "2023-01-13T18:41:03+00:00" }, { - "name": "phpcsstandards/phpcsutils", - "version": "1.0.12", + "name": "codeception/module-db", + "version": "3.2.2", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", - "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c" + "url": "https://github.com/Codeception/module-db.git", + "reference": "0ac08372c13f72c33745050e396317c8456a5f7b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/87b233b00daf83fb70f40c9a28692be017ea7c6c", - "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c", + "url": "https://api.github.com/repos/Codeception/module-db/zipball/0ac08372c13f72c33745050e396317c8456a5f7b", + "reference": "0ac08372c13f72c33745050e396317c8456a5f7b", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", - "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.10.0 || 4.0.x-dev@dev" + "codeception/codeception": "*@dev", + "ext-json": "*", + "ext-mbstring": "*", + "ext-pdo": "*", + "php": "^8.0" }, - "require-dev": { - "ext-filter": "*", - "php-parallel-lint/php-console-highlighter": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", - "phpcsstandards/phpcsdevcs": "^1.1.6", - "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + "conflict": { + "codeception/codeception": "<5.0" }, - "type": "phpcodesniffer-standard", - "extra": { - "branch-alias": { - "dev-stable": "1.x-dev", - "dev-develop": "1.x-dev" - } + "require-dev": { + "behat/gherkin": "~4.10.0", + "squizlabs/php_codesniffer": "*" }, + "type": "library", "autoload": { "classmap": [ - "PHPCSUtils/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0-or-later" + "MIT" ], "authors": [ { - "name": "Juliette Reinders Folmer", - "homepage": "https://github.com/jrfnl", - "role": "lead" + "name": "Michael Bodnarchuk" }, { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + "name": "Gintautas Miselis" } ], - "description": "A suite of utility functions for use with PHP_CodeSniffer", - "homepage": "https://phpcsutils.com/", + "description": "DB module for Codeception", + "homepage": "https://codeception.com/", "keywords": [ - "PHP_CodeSniffer", - "phpcbf", - "phpcodesniffer-standard", - "phpcs", - "phpcs3", - "standards", - "static analysis", - "tokens", - "utility" + "codeception", + "database-testing", + "db-testing" ], "support": { - "docs": "https://phpcsutils.com/", - "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", - "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", - "source": "https://github.com/PHPCSStandards/PHPCSUtils" + "issues": "https://github.com/Codeception/module-db/issues", + "source": "https://github.com/Codeception/module-db/tree/3.2.2" }, - "funding": [ - { - "url": "https://github.com/PHPCSStandards", - "type": "github" - }, - { - "url": "https://github.com/jrfnl", - "type": "github" - }, - { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" - } - ], - "time": "2024-05-20T13:34:27+00:00" + "time": "2025-03-03T08:10:27+00:00" }, { - "name": "phpstan/extension-installer", - "version": "1.4.3", + "name": "codeception/module-filesystem", + "version": "3.0.1", "source": { "type": "git", - "url": "https://github.com/phpstan/extension-installer.git", - "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + "url": "https://github.com/Codeception/module-filesystem.git", + "reference": "0fd78cf941cb72dc2a650c6132c5999c26ad4f9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", - "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "url": "https://api.github.com/repos/Codeception/module-filesystem/zipball/0fd78cf941cb72dc2a650c6132c5999c26ad4f9a", + "reference": "0fd78cf941cb72dc2a650c6132c5999c26ad4f9a", "shasum": "" }, "require": { - "composer-plugin-api": "^2.0", - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.9.0 || ^2.0" - }, - "require-dev": { - "composer/composer": "^2.0", - "php-parallel-lint/php-parallel-lint": "^1.2.0", - "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + "codeception/codeception": "*@dev", + "php": "^8.0", + "symfony/finder": "^4.4 || ^5.4 || ^6.0 || ^7.0" }, - "type": "composer-plugin", - "extra": { - "class": "PHPStan\\ExtensionInstaller\\Plugin" + "conflict": { + "codeception/codeception": "<5.0" }, + "type": "library", "autoload": { - "psr-4": { - "PHPStan\\ExtensionInstaller\\": "src/" - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "Composer plugin for automatic installation of PHPStan extensions", + "authors": [ + { + "name": "Michael Bodnarchuk" + }, + { + "name": "Gintautas Miselis" + } + ], + "description": "Codeception module for testing local filesystem", + "homepage": "https://codeception.com/", "keywords": [ - "dev", - "static analysis" + "codeception", + "filesystem" ], "support": { - "issues": "https://github.com/phpstan/extension-installer/issues", - "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + "issues": "https://github.com/Codeception/module-filesystem/issues", + "source": "https://github.com/Codeception/module-filesystem/tree/3.0.1" }, - "time": "2024-09-04T20:21:43+00:00" + "time": "2023-12-08T19:23:28+00:00" }, { - "name": "phpstan/phpdoc-parser", - "version": "1.33.0", + "name": "codeception/module-phpbrowser", + "version": "3.0.2", "source": { "type": "git", - "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" + "url": "https://github.com/Codeception/module-phpbrowser.git", + "reference": "460e392c77370f7836012b16e06071eb1607876a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", - "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "url": "https://api.github.com/repos/Codeception/module-phpbrowser/zipball/460e392c77370f7836012b16e06071eb1607876a", + "reference": "460e392c77370f7836012b16e06071eb1607876a", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "codeception/codeception": "*@dev", + "codeception/lib-innerbrowser": "*@dev", + "ext-json": "*", + "guzzlehttp/guzzle": "^7.4", + "php": "^8.1", + "symfony/browser-kit": "^5.4 | ^6.0 | ^7.0" + }, + "conflict": { + "codeception/codeception": "<5.0", + "codeception/lib-innerbrowser": "<3.0" }, "require-dev": { - "doctrine/annotations": "^2.0", - "nikic/php-parser": "^4.15", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.5", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^9.5", - "symfony/process": "^5.2" + "aws/aws-sdk-php": "^3.199", + "codeception/module-rest": "^2.0 | *@dev", + "ext-curl": "*", + "phpstan/phpstan": "^1.10", + "squizlabs/php_codesniffer": "^3.10" + }, + "suggest": { + "codeception/phpbuiltinserver": "Start and stop PHP built-in web server for your tests" }, "type": "library", "autoload": { - "psr-4": { - "PHPStan\\PhpDocParser\\": [ - "src/" - ] - } + "classmap": [ + "src/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "PHPDoc parser with support for nullable, intersection and generic types", + "authors": [ + { + "name": "Michael Bodnarchuk" + }, + { + "name": "Gintautas Miselis" + } + ], + "description": "Codeception module for testing web application over HTTP", + "homepage": "https://codeception.com/", + "keywords": [ + "codeception", + "functional-testing", + "http" + ], "support": { - "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" + "issues": "https://github.com/Codeception/module-phpbrowser/issues", + "source": "https://github.com/Codeception/module-phpbrowser/tree/3.0.2" }, - "time": "2024-10-13T11:25:22+00:00" + "time": "2025-09-04T10:45:58+00:00" }, { - "name": "phpstan/phpstan", - "version": "1.12.8", + "name": "codeception/module-rest", + "version": "3.4.1", "source": { "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c" + "url": "https://github.com/Codeception/module-rest.git", + "reference": "5db3a2e62ce6948d1822709c034a22fa1b1f2309" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f6a60a4d66142b8156c9da923f1972657bc4748c", - "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c", + "url": "https://api.github.com/repos/Codeception/module-rest/zipball/5db3a2e62ce6948d1822709c034a22fa1b1f2309", + "reference": "5db3a2e62ce6948d1822709c034a22fa1b1f2309", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "codeception/codeception": "^5.0.8", + "codeception/lib-xml": "^1.0", + "ext-dom": "*", + "ext-json": "*", + "justinrainbow/json-schema": "^5.2.9 || ^6", + "php": "^8.1", + "softcreatr/jsonpath": "^0.8 || ^0.9 || ^0.10" }, - "conflict": { - "phpstan/phpstan-shim": "*" + "require-dev": { + "codeception/lib-innerbrowser": "^3.0 | ^4.0", + "codeception/stub": "^4.0", + "codeception/util-universalframework": "^1.0", + "ext-libxml": "*", + "ext-simplexml": "*" + }, + "suggest": { + "aws/aws-sdk-php": "For using AWS Auth" }, - "bin": [ - "phpstan", - "phpstan.phar" - ], "type": "library", "autoload": { - "files": [ - "bootstrap.php" + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "PHPStan - PHP Static Analysis Tool", + "authors": [ + { + "name": "Gintautas Miselis" + } + ], + "description": "REST module for Codeception", + "homepage": "https://codeception.com/", "keywords": [ - "dev", - "static analysis" + "codeception", + "rest" ], "support": { - "docs": "https://phpstan.org/user-guide/getting-started", - "forum": "https://github.com/phpstan/phpstan/discussions", - "issues": "https://github.com/phpstan/phpstan/issues", - "security": "https://github.com/phpstan/phpstan/security/policy", - "source": "https://github.com/phpstan/phpstan-src" + "issues": "https://github.com/Codeception/module-rest/issues", + "source": "https://github.com/Codeception/module-rest/tree/3.4.1" }, - "funding": [ + "time": "2025-03-25T23:04:38+00:00" + }, + { + "name": "codeception/module-webdriver", + "version": "4.0.3", + "source": { + "type": "git", + "url": "https://github.com/Codeception/module-webdriver.git", + "reference": "551d214ddd57a9539acf1123d7c56ec82b1004df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Codeception/module-webdriver/zipball/551d214ddd57a9539acf1123d7c56ec82b1004df", + "reference": "551d214ddd57a9539acf1123d7c56ec82b1004df", + "shasum": "" + }, + "require": { + "codeception/codeception": "^5.0.8", + "codeception/lib-web": "^1.0.1", + "codeception/stub": "^4.0", + "ext-json": "*", + "ext-mbstring": "*", + "php": "^8.1", + "php-webdriver/webdriver": "^1.14.0", + "phpunit/phpunit": "^10.0 || ^11.0 || ^12.0" + }, + "suggest": { + "codeception/phpbuiltinserver": "Start and stop PHP built-in web server for your tests" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ { - "url": "https://github.com/ondrejmirtes", - "type": "github" + "name": "Michael Bodnarchuk" }, { - "url": "https://github.com/phpstan", - "type": "github" + "name": "Gintautas Miselis" + }, + { + "name": "Zaahid Bateson" } ], - "time": "2024-11-06T19:06:49+00:00" + "description": "WebDriver module for Codeception", + "homepage": "https://codeception.com/", + "keywords": [ + "acceptance-testing", + "browser-testing", + "codeception" + ], + "support": { + "issues": "https://github.com/Codeception/module-webdriver/issues", + "source": "https://github.com/Codeception/module-webdriver/tree/4.0.3" + }, + "time": "2025-02-14T07:10:05+00:00" }, { - "name": "psr/container", - "version": "2.0.2", + "name": "codeception/stub", + "version": "4.2.0", "source": { "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + "url": "https://github.com/Codeception/Stub.git", + "reference": "19014cec368cefc0579499779c451551cd288557" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", - "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "url": "https://api.github.com/repos/Codeception/Stub/zipball/19014cec368cefc0579499779c451551cd288557", + "reference": "19014cec368cefc0579499779c451551cd288557", "shasum": "" }, "require": { - "php": ">=7.4.0" + "php": "^8.1", + "phpunit/phpunit": "^8.4 | ^9.0 | ^10.0 | ^11 | ^12" + }, + "conflict": { + "codeception/codeception": "<5.0.6" + }, + "require-dev": { + "consolidation/robo": "^3.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" + "autoload": { + "psr-4": { + "Codeception\\": "src/" } }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Flexible Stub wrapper for PHPUnit's Mock Builder", + "support": { + "issues": "https://github.com/Codeception/Stub/issues", + "source": "https://github.com/Codeception/Stub/tree/4.2.0" + }, + "time": "2025-08-01T08:15:29+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.1.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.2", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "^2.2", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, "autoload": { "psr-4": { - "Psr\\Container\\": "src/" + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1035,281 +1205,4535 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "name": "Franck Nijhof", + "email": "opensource@frenck.dev", + "homepage": "https://frenck.dev", + "role": "Open source developer" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" } ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" ], "support": { - "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/2.0.2" + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "security": "https://github.com/PHPCSStandards/composer-installer/security/policy", + "source": "https://github.com/PHPCSStandards/composer-installer" }, - "time": "2021-11-05T16:47:00+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-07-17T20:45:56+00:00" }, { - "name": "sirbrillig/phpcs-variable-analysis", - "version": "v2.11.19", + "name": "druidfi/mysqldump-php", + "version": "1.1.0", "source": { "type": "git", - "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", - "reference": "bc8d7e30e2005bce5c59018b7cdb08e9fb45c0d1" + "url": "https://github.com/druidfi/mysqldump-php.git", + "reference": "df0e3bc3f8a47ea79c5c8e14594a8720034ae24f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/bc8d7e30e2005bce5c59018b7cdb08e9fb45c0d1", - "reference": "bc8d7e30e2005bce5c59018b7cdb08e9fb45c0d1", + "url": "https://api.github.com/repos/druidfi/mysqldump-php/zipball/df0e3bc3f8a47ea79c5c8e14594a8720034ae24f", + "reference": "df0e3bc3f8a47ea79c5c8e14594a8720034ae24f", "shasum": "" }, "require": { - "php": ">=5.4.0", - "squizlabs/php_codesniffer": "^3.5.6" + "composer-runtime-api": "^2", + "ext-pdo": "*", + "php": "^7.4 || ^8.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", - "phpcsstandards/phpcsdevcs": "^1.1", - "phpstan/phpstan": "^1.7", - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", - "sirbrillig/phpcs-import-detection": "^1.1", - "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" + "phpunit/phpunit": "^8.5.15 || ^9", + "squizlabs/php_codesniffer": "3.*" }, - "type": "phpcodesniffer-standard", + "type": "library", "autoload": { "psr-4": { - "VariableAnalysis\\": "VariableAnalysis/" + "Druidfi\\Mysqldump\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-2-Clause" + "GPL-3.0-or-later" ], "authors": [ { - "name": "Sam Graham", - "email": "php-codesniffer-variableanalysis@illusori.co.uk" + "name": "Druid.fi", + "homepage": "https://github.com/druidfi" }, { - "name": "Payton Swick", - "email": "payton@foolord.com" + "name": "Diego Torres", + "homepage": "https://github.com/ifsnop", + "role": "Developer" } ], - "description": "A PHPCS sniff to detect problems with variables.", + "description": "PHP version of mysqldump cli that comes with MySQL", + "homepage": "https://github.com/druidfi/mysqldump-php", "keywords": [ - "phpcs", - "static analysis" + "PHP7", + "database", + "mariadb", + "mysql", + "mysql-backup", + "mysqldump", + "pdo", + "php", + "php8", + "sql" ], "support": { - "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", - "source": "https://github.com/sirbrillig/phpcs-variable-analysis", - "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + "issues": "https://github.com/druidfi/mysqldump-php/issues", + "source": "https://github.com/druidfi/mysqldump-php/tree/1.1.0" }, - "time": "2024-06-26T20:08:34+00:00" + "time": "2024-03-03T10:20:17+00:00" }, { - "name": "slevomat/coding-standard", - "version": "8.15.0", + "name": "graham-campbell/result-type", + "version": "v1.1.3", "source": { "type": "git", - "url": "https://github.com/slevomat/coding-standard.git", - "reference": "7d1d957421618a3803b593ec31ace470177d7817" + "url": "https://github.com/GrahamCampbell/Result-Type.git", + "reference": "3ba905c11371512af9d9bdd27d99b782216b6945" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/7d1d957421618a3803b593ec31ace470177d7817", - "reference": "7d1d957421618a3803b593ec31ace470177d7817", + "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/3ba905c11371512af9d9bdd27d99b782216b6945", + "reference": "3ba905c11371512af9d9bdd27d99b782216b6945", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", - "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.23.1", - "squizlabs/php_codesniffer": "^3.9.0" + "php": "^7.2.5 || ^8.0", + "phpoption/phpoption": "^1.9.3" }, "require-dev": { - "phing/phing": "2.17.4", - "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.10.60", - "phpstan/phpstan-deprecation-rules": "1.1.4", - "phpstan/phpstan-phpunit": "1.3.16", - "phpstan/phpstan-strict-rules": "1.5.2", - "phpunit/phpunit": "8.5.21|9.6.8|10.5.11" + "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28" }, - "type": "phpcodesniffer-standard", + "type": "library", + "autoload": { + "psr-4": { + "GrahamCampbell\\ResultType\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + } + ], + "description": "An Implementation Of The Result Type", + "keywords": [ + "Graham Campbell", + "GrahamCampbell", + "Result Type", + "Result-Type", + "result" + ], + "support": { + "issues": "https://github.com/GrahamCampbell/Result-Type/issues", + "source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.3" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type", + "type": "tidelift" + } + ], + "time": "2024-07-20T21:45:45+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "7.10.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b51ac707cfa420b7bfd4e4d5e510ba8008e822b4", + "reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^2.3", + "guzzlehttp/psr7": "^2.8", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-curl": "*", + "guzzle/client-integration-tests": "3.0.2", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", "extra": { - "branch-alias": { - "dev-master": "8.x-dev" + "bamarni-bin": { + "bin-links": true, + "forward-command": false } }, "autoload": { + "files": [ + "src/functions_include.php" + ], "psr-4": { - "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", "keywords": [ - "dev", - "phpcs" + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.10.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2025-08-23T22:36:01+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "481557b130ef3790cf82b713667b43030dc9c957" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/481557b130ef3790cf82b713667b43030dc9c957", + "reference": "481557b130ef3790cf82b713667b43030dc9c957", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.44 || ^9.6.25" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.3.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2025-08-22T14:34:08+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.8.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "21dc724a0583619cd1652f673303492272778051" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/21dc724a0583619cd1652f673303492272778051", + "reference": "21dc724a0583619cd1652f673303492272778051", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.44 || ^9.6.25" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.8.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2025-08-23T21:21:41+00:00" + }, + { + "name": "justinrainbow/json-schema", + "version": "6.5.2", + "source": { + "type": "git", + "url": "https://github.com/jsonrainbow/json-schema.git", + "reference": "ac0d369c09653cf7af561f6d91a705bc617a87b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jsonrainbow/json-schema/zipball/ac0d369c09653cf7af561f6d91a705bc617a87b8", + "reference": "ac0d369c09653cf7af561f6d91a705bc617a87b8", + "shasum": "" + }, + "require": { + "ext-json": "*", + "marc-mabe/php-enum": "^4.0", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.3.0", + "json-schema/json-schema-test-suite": "^23.2", + "marc-mabe/php-enum-phpstan": "^2.0", + "phpspec/prophecy": "^1.19", + "phpstan/phpstan": "^1.12", + "phpunit/phpunit": "^8.5" + }, + "bin": [ + "bin/validate-json" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + } + }, + "autoload": { + "psr-4": { + "JsonSchema\\": "src/JsonSchema/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bruno Prieto Reis", + "email": "bruno.p.reis@gmail.com" + }, + { + "name": "Justin Rainbow", + "email": "justin.rainbow@gmail.com" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Robert Schönthal", + "email": "seroscho@googlemail.com" + } + ], + "description": "A library to validate a json schema.", + "homepage": "https://github.com/jsonrainbow/json-schema", + "keywords": [ + "json", + "schema" + ], + "support": { + "issues": "https://github.com/jsonrainbow/json-schema/issues", + "source": "https://github.com/jsonrainbow/json-schema/tree/6.5.2" + }, + "time": "2025-09-09T09:42:27+00:00" + }, + { + "name": "lucatume/wp-browser", + "version": "4.5.7", + "source": { + "type": "git", + "url": "https://github.com/lucatume/wp-browser.git", + "reference": "9c8bb63c26fe76ee5cfd06fac26d9b400a8216ef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lucatume/wp-browser/zipball/9c8bb63c26fe76ee5cfd06fac26d9b400a8216ef", + "reference": "9c8bb63c26fe76ee5cfd06fac26d9b400a8216ef", + "shasum": "" + }, + "require": { + "codeception/codeception": "^5.0", + "codeception/module-asserts": "^2.0 || ^3.0", + "codeception/module-cli": "^2.0 || ^3.0", + "codeception/module-db": "^2.0 || ^3.0", + "codeception/module-filesystem": "^2.0 || ^3.0", + "codeception/module-phpbrowser": "^2.0 || ^3.0", + "codeception/module-webdriver": "^2.0 || ^3.0 || ^4.0", + "composer-runtime-api": "^2.2", + "druidfi/mysqldump-php": "^1.1", + "ext-curl": "*", + "ext-fileinfo": "*", + "ext-json": "*", + "ext-mysqli": "*", + "ext-pdo": "*", + "ext-zip": "*", + "php": "^8.0", + "phpunit/phpunit": "<12.0.0", + "symfony/filesystem": ">=4.4.24 <8.0", + "symfony/process": ">=4.4.24 <8.0", + "vlucas/phpdotenv": "^5.0" + }, + "require-dev": { + "gumlet/php-image-resize": "^1.6", + "lucatume/codeception-snapshot-assertions": "^1.3.0", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "1.10.56", + "phpstan/phpstan-symfony": "^1.3", + "rector/rector": "0.19.8", + "squizlabs/php_codesniffer": "^3.7", + "szepeviktor/phpstan-wordpress": "^1.3" + }, + "suggest": { + "ext-pdo_sqlite": "For SQLite database support.", + "ext-sqlite3": "For SQLite database support." + }, + "type": "library", + "extra": { + "_hash": "484f861f69198089cab0e642f27e5653" + }, + "autoload": { + "files": [ + "src/version-4-aliases.php", + "src/deprecated-functions.php", + "src/functions.php" + ], + "psr-4": { + "Hautelook\\Phpass\\": "includes/Hautelook/Phpass", + "lucatume\\WPBrowser\\": [ + "src/", + "src/Deprecated" + ], + "Codeception\\Extension\\": "src/Extension", + "lucatume\\WPBrowser\\Opis\\Closure\\": "includes/opis/closure/src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "theAverageDev (Luca Tumedei)", + "email": "luca@theaveragedev.com", + "homepage": "https://theaveragedev.com", + "role": "Developer" + } + ], + "description": "A set of Codeception modules to test WordPress projects.", + "homepage": "https://github.com/lucatume/wp-browser", + "keywords": [ + "codeception", + "wordpress" + ], + "support": { + "issues": "https://github.com/lucatume/wp-browser/issues", + "source": "https://github.com/lucatume/wp-browser/tree/4.5.7" + }, + "funding": [ + { + "url": "https://github.com/lucatume", + "type": "github" + } + ], + "time": "2025-09-09T12:20:53+00:00" + }, + { + "name": "marc-mabe/php-enum", + "version": "v4.7.2", + "source": { + "type": "git", + "url": "https://github.com/marc-mabe/php-enum.git", + "reference": "bb426fcdd65c60fb3638ef741e8782508fda7eef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/marc-mabe/php-enum/zipball/bb426fcdd65c60fb3638ef741e8782508fda7eef", + "reference": "bb426fcdd65c60fb3638ef741e8782508fda7eef", + "shasum": "" + }, + "require": { + "ext-reflection": "*", + "php": "^7.1 | ^8.0" + }, + "require-dev": { + "phpbench/phpbench": "^0.16.10 || ^1.0.4", + "phpstan/phpstan": "^1.3.1", + "phpunit/phpunit": "^7.5.20 | ^8.5.22 | ^9.5.11", + "vimeo/psalm": "^4.17.0 | ^5.26.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-3.x": "3.2-dev", + "dev-master": "4.7-dev" + } + }, + "autoload": { + "psr-4": { + "MabeEnum\\": "src/" + }, + "classmap": [ + "stubs/Stringable.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Marc Bennewitz", + "email": "dev@mabe.berlin", + "homepage": "https://mabe.berlin/", + "role": "Lead" + } + ], + "description": "Simple and fast implementation of enumerations with native PHP", + "homepage": "https://github.com/marc-mabe/php-enum", + "keywords": [ + "enum", + "enum-map", + "enum-set", + "enumeration", + "enumerator", + "enummap", + "enumset", + "map", + "set", + "type", + "type-hint", + "typehint" + ], + "support": { + "issues": "https://github.com/marc-mabe/php-enum/issues", + "source": "https://github.com/marc-mabe/php-enum/tree/v4.7.2" + }, + "time": "2025-09-14T11:18:39+00:00" + }, + { + "name": "masterminds/html5", + "version": "2.10.0", + "source": { + "type": "git", + "url": "https://github.com/Masterminds/html5-php.git", + "reference": "fcf91eb64359852f00d921887b219479b4f21251" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/fcf91eb64359852f00d921887b219479b4f21251", + "reference": "fcf91eb64359852f00d921887b219479b4f21251", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Masterminds\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Butcher", + "email": "technosophos@gmail.com" + }, + { + "name": "Matt Farina", + "email": "matt@mattfarina.com" + }, + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" + } + ], + "description": "An HTML5 parser and serializer.", + "homepage": "http://masterminds.github.io/html5-php", + "keywords": [ + "HTML5", + "dom", + "html", + "parser", + "querypath", + "serializer", + "xml" + ], + "support": { + "issues": "https://github.com/Masterminds/html5-php/issues", + "source": "https://github.com/Masterminds/html5-php/tree/2.10.0" + }, + "time": "2025-07-25T09:04:22+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.13.4", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a", + "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.4" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2025-08-01T08:46:24+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v5.6.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2", + "reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": ">=7.4" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v5.6.1" + }, + "time": "2025-08-13T20:13:15+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "php-stubs/woocommerce-stubs", + "version": "v9.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/woocommerce-stubs.git", + "reference": "2c95c633362d1f4f531f69e5db63bb19399d8b58" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/2c95c633362d1f4f531f69e5db63bb19399d8b58", + "reference": "2c95c633362d1f4f531f69e5db63bb19399d8b58", + "shasum": "" + }, + "require": { + "php-stubs/wordpress-stubs": "^5.3 || ^6.0" + }, + "require-dev": { + "php": "~7.1 || ~8.0", + "php-stubs/generator": "^0.8.0" + }, + "suggest": { + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WooCommerce function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/woocommerce-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "woocommerce", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v9.1.0" + }, + "time": "2024-07-11T10:55:02+00:00" + }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v6.8.2", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "9c8e22e437463197c1ec0d5eaa9ddd4a0eb6d7f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/9c8e22e437463197c1ec0d5eaa9ddd4a0eb6d7f8", + "reference": "9c8e22e437463197c1ec0d5eaa9ddd4a0eb6d7f8", + "shasum": "" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "5.6.1" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "nikic/php-parser": "^5.5", + "php": "^7.4 || ^8.0", + "php-stubs/generator": "^0.8.3", + "phpdocumentor/reflection-docblock": "^5.4.1", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.1.1", + "wp-coding-standards/wpcs": "3.1.0 as 2.3.0" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.8.2" + }, + "time": "2025-07-16T06:41:00+00:00" + }, + { + "name": "php-webdriver/webdriver", + "version": "1.15.2", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "998e499b786805568deaf8cbf06f4044f05d91bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/998e499b786805568deaf8cbf06f4044f05d91bf", + "reference": "998e499b786805568deaf8cbf06f4044f05d91bf", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^7.3 || ^8.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^5.0 || ^6.0 || ^7.0" + }, + "replace": { + "facebook/webdriver": "*" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.20.0", + "ondram/ci-detector": "^4.0", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpunit/phpunit": "^9.3", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Exception/TimeoutException.php" + ], + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.", + "homepage": "https://github.com/php-webdriver/php-webdriver", + "keywords": [ + "Chromedriver", + "geckodriver", + "php", + "selenium", + "webdriver" + ], + "support": { + "issues": "https://github.com/php-webdriver/php-webdriver/issues", + "source": "https://github.com/php-webdriver/php-webdriver/tree/1.15.2" + }, + "time": "2024-11-21T15:12:59+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "244d7b04fc4bc2117c15f5abe23eb933b5f02bbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/244d7b04fc4bc2117c15f5abe23eb933b5f02bbf", + "reference": "244d7b04fc4bc2117c15f5abe23eb933b5f02bbf", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/security/policy", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcompatibility", + "type": "thanks_dev" + } + ], + "time": "2025-09-19T17:43:28+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.7", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "5bfbbfbabb3df2b9a83e601de9153e4a7111962c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/5bfbbfbabb3df2b9a83e601de9153e4a7111962c", + "reference": "5bfbbfbabb3df2b9a83e601de9153e4a7111962c", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0", + "squizlabs/php_codesniffer": "^3.3" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibilityWP/security/policy", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcompatibility", + "type": "thanks_dev" + } + ], + "time": "2025-05-12T16:38:37+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "882b8c947ada27eb002870fe77fee9ce0a454cdb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/882b8c947ada27eb002870fe77fee9ce0a454cdb", + "reference": "882b8c947ada27eb002870fe77fee9ce0a454cdb", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.1.2", + "squizlabs/php_codesniffer": "^3.13.4 || ^4.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-09-05T06:54:52+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "b22b59e3d9ec8fe4953e42c7d59117c6eae70eae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/b22b59e3d9ec8fe4953e42c7d59117c6eae70eae", + "reference": "b22b59e3d9ec8fe4953e42c7d59117c6eae70eae", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.13.3 || ^4.0" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0 || ^3.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "phpcs4", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-09-05T00:00:03+00:00" + }, + { + "name": "phpoption/phpoption", + "version": "1.9.4", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-option.git", + "reference": "638a154f8d4ee6a5cfa96d6a34dfbe0cffa9566d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/638a154f8d4ee6a5cfa96d6a34dfbe0cffa9566d", + "reference": "638a154f8d4ee6a5cfa96d6a34dfbe0cffa9566d", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.44 || ^9.6.25 || ^10.5.53 || ^11.5.34" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + }, + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpOption\\": "src/PhpOption/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com", + "homepage": "https://github.com/schmittjoh" + }, + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + } + ], + "description": "Option Type for PHP", + "keywords": [ + "language", + "option", + "php", + "type" + ], + "support": { + "issues": "https://github.com/schmittjoh/php-option/issues", + "source": "https://github.com/schmittjoh/php-option/tree/1.9.4" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", + "type": "tidelift" + } + ], + "time": "2025-08-21T11:53:16+00:00" + }, + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.33.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" + }, + "time": "2024-10-13T11:25:22+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.12.32", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2770dcdf5078d0b0d53f94317e06affe88419aa8", + "reference": "2770dcdf5078d0b0d53f94317e06affe88419aa8", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2025-09-30T10:16:31+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "11.0.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4", + "reference": "4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^5.4.0", + "php": ">=8.2", + "phpunit/php-file-iterator": "^5.1.0", + "phpunit/php-text-template": "^4.0.1", + "sebastian/code-unit-reverse-lookup": "^4.0.1", + "sebastian/complexity": "^4.0.1", + "sebastian/environment": "^7.2.0", + "sebastian/lines-of-code": "^3.0.1", + "sebastian/version": "^5.0.2", + "theseer/tokenizer": "^1.2.3" + }, + "require-dev": { + "phpunit/phpunit": "^11.5.2" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.11" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/php-code-coverage", + "type": "tidelift" + } + ], + "time": "2025-08-27T14:37:49+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "5.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6", + "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-08-27T05:02:59+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2", + "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "security": "https://github.com/sebastianbergmann/php-invoker/security/policy", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:07:44+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964", + "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:08:43+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "7.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3", + "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "security": "https://github.com/sebastianbergmann/php-timer/security/policy", + "source": "https://github.com/sebastianbergmann/php-timer/tree/7.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:09:35+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "11.5.42", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "1c6cb5dfe412af3d0dfd414cfd110e3b9cfdbc3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c6cb5dfe412af3d0dfd414cfd110e3b9cfdbc3c", + "reference": "1c6cb5dfe412af3d0dfd414cfd110e3b9cfdbc3c", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.13.4", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", + "php": ">=8.2", + "phpunit/php-code-coverage": "^11.0.11", + "phpunit/php-file-iterator": "^5.1.0", + "phpunit/php-invoker": "^5.0.1", + "phpunit/php-text-template": "^4.0.1", + "phpunit/php-timer": "^7.0.1", + "sebastian/cli-parser": "^3.0.2", + "sebastian/code-unit": "^3.0.3", + "sebastian/comparator": "^6.3.2", + "sebastian/diff": "^6.0.2", + "sebastian/environment": "^7.2.1", + "sebastian/exporter": "^6.3.2", + "sebastian/global-state": "^7.0.2", + "sebastian/object-enumerator": "^6.0.1", + "sebastian/type": "^5.1.3", + "sebastian/version": "^5.0.2", + "staabm/side-effects-detector": "^1.0.5" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.5-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.42" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2025-09-28T12:09:13+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "psr/event-dispatcher", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/event-dispatcher.git", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", + "shasum": "" + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\EventDispatcher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Standard interfaces for event handling.", + "keywords": [ + "events", + "psr", + "psr-14" + ], + "support": { + "issues": "https://github.com/php-fig/event-dispatcher/issues", + "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" + }, + "time": "2019-01-08T18:20:26+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory" + }, + "time": "2024-04-15T12:06:14+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "psy/psysh", + "version": "v0.12.12", + "source": { + "type": "git", + "url": "https://github.com/bobthecow/psysh.git", + "reference": "cd23863404a40ccfaf733e3af4db2b459837f7e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/cd23863404a40ccfaf733e3af4db2b459837f7e7", + "reference": "cd23863404a40ccfaf733e3af4db2b459837f7e7", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-tokenizer": "*", + "nikic/php-parser": "^5.0 || ^4.0", + "php": "^8.0 || ^7.4", + "symfony/console": "^7.0 || ^6.0 || ^5.0 || ^4.0 || ^3.4", + "symfony/var-dumper": "^7.0 || ^6.0 || ^5.0 || ^4.0 || ^3.4" + }, + "conflict": { + "symfony/console": "4.4.37 || 5.3.14 || 5.3.15 || 5.4.3 || 5.4.4 || 6.0.3 || 6.0.4" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.2" + }, + "suggest": { + "ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)", + "ext-pdo-sqlite": "The doc command requires SQLite to work.", + "ext-posix": "If you have PCNTL, you'll want the POSIX extension as well." + }, + "bin": [ + "bin/psysh" + ], + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": false, + "forward-command": false + }, + "branch-alias": { + "dev-main": "0.12.x-dev" + } + }, + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Psy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Justin Hileman", + "email": "justin@justinhileman.info" + } + ], + "description": "An interactive shell for modern PHP.", + "homepage": "https://psysh.org", + "keywords": [ + "REPL", + "console", + "interactive", + "shell" + ], + "support": { + "issues": "https://github.com/bobthecow/psysh/issues", + "source": "https://github.com/bobthecow/psysh/tree/v0.12.12" + }, + "time": "2025-09-20T13:46:31+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180", + "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "security": "https://github.com/sebastianbergmann/cli-parser/security/policy", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:41:36+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "54391c61e4af8078e5b276ab082b6d3c54c9ad64" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/54391c61e4af8078e5b276ab082b6d3c54c9ad64", + "reference": "54391c61e4af8078e5b276ab082b6d3c54c9ad64", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "security": "https://github.com/sebastianbergmann/code-unit/security/policy", + "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2025-03-19T07:56:08+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "183a9b2632194febd219bb9246eee421dad8d45e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e", + "reference": "183a9b2632194febd219bb9246eee421dad8d45e", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:45:54+00:00" + }, + { + "name": "sebastian/comparator", + "version": "6.3.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "85c77556683e6eee4323e4c5468641ca0237e2e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/85c77556683e6eee4323e4c5468641ca0237e2e8", + "reference": "85c77556683e6eee4323e4c5468641ca0237e2e8", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.2", + "sebastian/diff": "^6.0", + "sebastian/exporter": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.4" + }, + "suggest": { + "ext-bcmath": "For comparing BcMath\\Number objects" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/6.3.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/comparator", + "type": "tidelift" + } + ], + "time": "2025-08-10T08:07:46+00:00" + }, + { + "name": "sebastian/complexity", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "ee41d384ab1906c68852636b6de493846e13e5a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0", + "reference": "ee41d384ab1906c68852636b6de493846e13e5a0", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^5.0", + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "security": "https://github.com/sebastianbergmann/complexity/security/policy", + "source": "https://github.com/sebastianbergmann/complexity/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:49:50+00:00" + }, + { + "name": "sebastian/diff", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:53:05+00:00" + }, + { + "name": "sebastian/environment", + "version": "7.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "a5c75038693ad2e8d4b6c15ba2403532647830c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/a5c75038693ad2e8d4b6c15ba2403532647830c4", + "reference": "a5c75038693ad2e8d4b6c15ba2403532647830c4", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.3" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/7.2.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/environment", + "type": "tidelift" + } + ], + "time": "2025-05-21T11:55:47+00:00" + }, + { + "name": "sebastian/exporter", + "version": "6.3.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "70a298763b40b213ec087c51c739efcaa90bcd74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/70a298763b40b213ec087c51c739efcaa90bcd74", + "reference": "70a298763b40b213ec087c51c739efcaa90bcd74", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.2", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/6.3.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/exporter", + "type": "tidelift" + } + ], + "time": "2025-09-24T06:12:51+00:00" + }, + { + "name": "sebastian/global-state", + "version": "7.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "3be331570a721f9a4b5917f4209773de17f747d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7", + "reference": "3be331570a721f9a4b5917f4209773de17f747d7", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "sebastian/object-reflector": "^4.0", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "https://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/7.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:57:36+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a", + "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^5.0", + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:58:38+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "f5b498e631a74204185071eb41f33f38d64608aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa", + "reference": "f5b498e631a74204185071eb41f33f38d64608aa", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "sebastian/object-reflector": "^4.0", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "security": "https://github.com/sebastianbergmann/object-enumerator/security/policy", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:00:13+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9", + "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "security": "https://github.com/sebastianbergmann/object-reflector/security/policy", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:01:32+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "6.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "f6458abbf32a6c8174f8f26261475dc133b3d9dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/f6458abbf32a6c8174f8f26261475dc133b3d9dc", + "reference": "f6458abbf32a6c8174f8f26261475dc133b3d9dc", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "security": "https://github.com/sebastianbergmann/recursion-context/security/policy", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/6.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/recursion-context", + "type": "tidelift" + } + ], + "time": "2025-08-13T04:42:22+00:00" + }, + { + "name": "sebastian/type", + "version": "5.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "f77d2d4e78738c98d9a68d2596fe5e8fa380f449" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/f77d2d4e78738c98d9a68d2596fe5e8fa380f449", + "reference": "f77d2d4e78738c98d9a68d2596fe5e8fa380f449", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "security": "https://github.com/sebastianbergmann/type/security/policy", + "source": "https://github.com/sebastianbergmann/type/tree/5.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/type", + "type": "tidelift" + } + ], + "time": "2025-08-09T06:55:48+00:00" + }, + { + "name": "sebastian/version", + "version": "5.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c687e3387b99f5b03b6caa64c74b63e2936ff874" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874", + "reference": "c687e3387b99f5b03b6caa64c74b63e2936ff874", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "security": "https://github.com/sebastianbergmann/version/security/policy", + "source": "https://github.com/sebastianbergmann/version/tree/5.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-10-09T05:16:32+00:00" + }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.13.0", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "a15e970b8a0bf64cfa5e86d941f5e6b08855f369" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/a15e970b8a0bf64cfa5e86d941f5e6b08855f369", + "reference": "a15e970b8a0bf64cfa5e86d941f5e6b08855f369", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.7 || ^4.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpstan/phpstan": "^1.7 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2025-09-30T22:22:48+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "8.15.0", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "7d1d957421618a3803b593ec31ace470177d7817" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/7d1d957421618a3803b593ec31ace470177d7817", + "reference": "7d1d957421618a3803b593ec31ace470177d7817", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.23.1", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.60", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.16", + "phpstan/phpstan-strict-rules": "1.5.2", + "phpunit/phpunit": "8.5.21|9.6.8|10.5.11" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.15.0" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2024-03-09T15:20:58+00:00" + }, + { + "name": "softcreatr/jsonpath", + "version": "0.10.0", + "source": { + "type": "git", + "url": "https://github.com/SoftCreatR/JSONPath.git", + "reference": "74f0b330a98135160db947ba7bc65216b64a0c86" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SoftCreatR/JSONPath/zipball/74f0b330a98135160db947ba7bc65216b64a0c86", + "reference": "74f0b330a98135160db947ba7bc65216b64a0c86", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "8.1 - 8.4" + }, + "replace": { + "flow/jsonpath": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.58", + "phpunit/phpunit": "10 - 12", + "squizlabs/php_codesniffer": "^3.10" + }, + "type": "library", + "autoload": { + "psr-4": { + "Flow\\JSONPath\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stephen Frank", + "email": "stephen@flowsa.com", + "homepage": "https://prismaticbytes.com", + "role": "Developer" + }, + { + "name": "Sascha Greuel", + "email": "hello@1-2.dev", + "homepage": "https://1-2.dev", + "role": "Developer" + } + ], + "description": "JSONPath implementation for parsing, searching and flattening arrays", + "support": { + "email": "hello@1-2.dev", + "forum": "https://github.com/SoftCreatR/JSONPath/discussions", + "issues": "https://github.com/SoftCreatR/JSONPath/issues", + "source": "https://github.com/SoftCreatR/JSONPath" + }, + "funding": [ + { + "url": "https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4", + "type": "custom" + }, + { + "url": "https://github.com/softcreatr", + "type": "github" + } + ], + "time": "2025-03-22T00:28:17+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.13.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "ad545ea9c1b7d270ce0fc9cbfb884161cd706119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/ad545ea9c1b7d270ce0fc9cbfb884161cd706119", + "reference": "ad545ea9c1b7d270ce0fc9cbfb884161cd706119", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-09-05T05:47:09+00:00" + }, + { + "name": "staabm/side-effects-detector", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/staabm/side-effects-detector.git", + "reference": "d8334211a140ce329c13726d4a715adbddd0a163" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163", + "reference": "d8334211a140ce329c13726d4a715adbddd0a163", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^1.12.6", + "phpunit/phpunit": "^9.6.21", + "symfony/var-dumper": "^5.4.43", + "tomasvotruba/type-coverage": "1.0.0", + "tomasvotruba/unused-public": "1.0.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "lib/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A static analysis tool to detect side effects in PHP code", + "keywords": [ + "static analysis" + ], + "support": { + "issues": "https://github.com/staabm/side-effects-detector/issues", + "source": "https://github.com/staabm/side-effects-detector/tree/1.0.5" + }, + "funding": [ + { + "url": "https://github.com/staabm", + "type": "github" + } + ], + "time": "2024-10-20T05:08:20+00:00" + }, + { + "name": "symfony/browser-kit", + "version": "v7.3.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/browser-kit.git", + "reference": "f0b889b73a845cddef1d25fe207b37fd04cb5419" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/f0b889b73a845cddef1d25fe207b37fd04cb5419", + "reference": "f0b889b73a845cddef1d25fe207b37fd04cb5419", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/dom-crawler": "^6.4|^7.0" + }, + "require-dev": { + "symfony/css-selector": "^6.4|^7.0", + "symfony/http-client": "^6.4|^7.0", + "symfony/mime": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\BrowserKit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/browser-kit/tree/v7.3.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-07-10T08:47:49+00:00" + }, + { + "name": "symfony/console", + "version": "v5.4.47", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "^1.9", + "symfony/polyfill-php80": "^1.16", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/string": "^5.1|^6.0" + }, + "conflict": { + "psr/log": ">=3", + "symfony/dependency-injection": "<4.4", + "symfony/dotenv": "<5.1", + "symfony/event-dispatcher": "<4.4", + "symfony/lock": "<4.4", + "symfony/process": "<4.4" + }, + "provide": { + "psr/log-implementation": "1.0|2.0" + }, + "require-dev": { + "psr/log": "^1|^2", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/event-dispatcher": "^4.4|^5.0|^6.0", + "symfony/lock": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/var-dumper": "^4.4|^5.0|^6.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Eases the creation of beautiful and testable command line interfaces", + "homepage": "https://symfony.com", + "keywords": [ + "cli", + "command-line", + "console", + "terminal" + ], + "support": { + "source": "https://github.com/symfony/console/tree/v5.4.47" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-11-06T11:30:55+00:00" + }, + { + "name": "symfony/css-selector", + "version": "v7.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "601a5ce9aaad7bf10797e3663faefce9e26c24e2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/601a5ce9aaad7bf10797e3663faefce9e26c24e2", + "reference": "601a5ce9aaad7bf10797e3663faefce9e26c24e2", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Converts CSS selectors to XPath expressions", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/css-selector/tree/v7.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-25T14:21:43+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.6.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62", + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, + "branch-alias": { + "dev-main": "3.6-dev" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-25T14:21:43+00:00" + }, + { + "name": "symfony/dom-crawler", + "version": "v7.3.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "efa076ea0eeff504383ff0dcf827ea5ce15690ba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/efa076ea0eeff504383ff0dcf827ea5ce15690ba", + "reference": "efa076ea0eeff504383ff0dcf827ea5ce15690ba", + "shasum": "" + }, + "require": { + "masterminds/html5": "^2.6", + "php": ">=8.2", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/css-selector": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Eases DOM navigation for HTML and XML documents", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/dom-crawler/tree/v7.3.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-08-06T20:13:54+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v7.3.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "b7dc69e71de420ac04bc9ab830cf3ffebba48191" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b7dc69e71de420ac04bc9ab830cf3ffebba48191", + "reference": "b7dc69e71de420ac04bc9ab830cf3ffebba48191", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/event-dispatcher-contracts": "^2.5|^3" + }, + "conflict": { + "symfony/dependency-injection": "<6.4", + "symfony/service-contracts": "<2.5" + }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "2.0|3.0" + }, + "require-dev": { + "psr/log": "^1|^2|^3", + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0", + "symfony/expression-language": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/stopwatch": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } ], + "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", + "homepage": "https://symfony.com", "support": { - "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.15.0" + "source": "https://github.com/symfony/event-dispatcher/tree/v7.3.3" }, "funding": [ { - "url": "https://github.com/kukulich", + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", "type": "github" }, { - "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-03-09T15:20:58+00:00" + "time": "2025-08-13T11:49:31+00:00" }, { - "name": "squizlabs/php_codesniffer", - "version": "3.10.3", + "name": "symfony/event-dispatcher-contracts", + "version": "v3.6.0", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "62d32998e820bddc40f99f8251958aed187a5c9c" + "url": "https://github.com/symfony/event-dispatcher-contracts.git", + "reference": "59eb412e93815df44f05f342958efa9f46b1e586" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/62d32998e820bddc40f99f8251958aed187a5c9c", - "reference": "62d32998e820bddc40f99f8251958aed187a5c9c", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586", + "reference": "59eb412e93815df44f05f342958efa9f46b1e586", "shasum": "" }, "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + "php": ">=8.1", + "psr/event-dispatcher": "^1" }, - "bin": [ - "bin/phpcbf", - "bin/phpcs" - ], "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { - "dev-master": "3.x-dev" + "dev-main": "3.6-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\EventDispatcher\\": "" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Greg Sherwood", - "role": "Former lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "Current lead" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" }, { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "description": "Generic abstractions related to dispatching event", + "homepage": "https://symfony.com", "keywords": [ - "phpcs", - "standards", - "static analysis" + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" ], "support": { - "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", - "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", - "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", - "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.6.0" }, "funding": [ { - "url": "https://github.com/PHPCSStandards", - "type": "github" + "url": "https://symfony.com/sponsor", + "type": "custom" }, { - "url": "https://github.com/jrfnl", + "url": "https://github.com/fabpot", "type": "github" }, { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" } ], - "time": "2024-09-18T10:38:58+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { - "name": "symfony/console", - "version": "v5.4.47", + "name": "symfony/filesystem", + "version": "v7.3.2", "source": { "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed" + "url": "https://github.com/symfony/filesystem.git", + "reference": "edcbb768a186b5c3f25d0643159a787d3e63b7fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/edcbb768a186b5c3f25d0643159a787d3e63b7fd", + "reference": "edcbb768a186b5c3f25d0643159a787d3e63b7fd", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.16", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/string": "^5.1|^6.0" - }, - "conflict": { - "psr/log": ">=3", - "symfony/dependency-injection": "<4.4", - "symfony/dotenv": "<5.1", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" - }, - "provide": { - "psr/log-implementation": "1.0|2.0" + "php": ">=8.2", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "psr/log": "^1|^2", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/event-dispatcher": "^4.4|^5.0|^6.0", - "symfony/lock": "^4.4|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0", - "symfony/var-dumper": "^4.4|^5.0|^6.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" + "symfony/process": "^6.4|^7.0" }, "type": "library", "autoload": { "psr-4": { - "Symfony\\Component\\Console\\": "" + "Symfony\\Component\\Filesystem\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -1329,16 +5753,10 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Eases the creation of beautiful and testable command line interfaces", + "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", - "keywords": [ - "cli", - "command-line", - "console", - "terminal" - ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.47" + "source": "https://github.com/symfony/filesystem/tree/v7.3.2" }, "funding": [ { @@ -1349,43 +5767,44 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-06T11:30:55+00:00" + "time": "2025-07-07T08:17:47+00:00" }, { - "name": "symfony/deprecation-contracts", - "version": "v3.5.1", + "name": "symfony/finder", + "version": "v7.3.2", "source": { "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6" + "url": "https://github.com/symfony/finder.git", + "reference": "2a6614966ba1074fa93dae0bc804227422df4dfe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", - "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", + "url": "https://api.github.com/repos/symfony/finder/zipball/2a6614966ba1074fa93dae0bc804227422df4dfe", + "reference": "2a6614966ba1074fa93dae0bc804227422df4dfe", "shasum": "" }, "require": { - "php": ">=8.1" + "php": ">=8.2" }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/contracts", - "name": "symfony/contracts" - }, - "branch-alias": { - "dev-main": "3.5-dev" - } + "require-dev": { + "symfony/filesystem": "^6.4|^7.0" }, + "type": "library", "autoload": { - "files": [ - "function.php" + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1394,18 +5813,18 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "A generic function and convention to trigger deprecation notices", + "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/finder/tree/v7.3.2" }, "funding": [ { @@ -1416,16 +5835,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2025-07-15T13:41:35+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -1484,7 +5907,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.33.0" }, "funding": [ { @@ -1495,6 +5918,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -1504,16 +5931,16 @@ }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" + "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/380872130d3a5dd3ace2f4010d95125fde5d5c70", + "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70", "shasum": "" }, "require": { @@ -1562,7 +5989,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.33.0" }, "funding": [ { @@ -1573,16 +6000,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-06-27T09:58:17+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -1643,7 +6074,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.33.0" }, "funding": [ { @@ -1654,6 +6085,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -1663,19 +6098,20 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" + "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493", + "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493", "shasum": "" }, "require": { + "ext-iconv": "*", "php": ">=7.2" }, "provide": { @@ -1723,7 +6159,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.33.0" }, "funding": [ { @@ -1734,16 +6170,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-12-23T08:48:59+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", @@ -1790,7 +6230,91 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.33.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-09T11:45:10+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.33.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "homepage": "https://symfony.com", "keywords": [ "compatibility", @@ -1799,7 +6323,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.33.0" }, "funding": [ { @@ -1810,46 +6334,41 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-01-02T08:10:11+00:00" }, { - "name": "symfony/polyfill-php80", - "version": "v1.31.0", + "name": "symfony/process", + "version": "v7.3.4", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" + "url": "https://github.com/symfony/process.git", + "reference": "f24f8f316367b30810810d4eb30c543d7003ff3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "url": "https://api.github.com/repos/symfony/process/zipball/f24f8f316367b30810810d4eb30c543d7003ff3b", + "reference": "f24f8f316367b30810810d4eb30c543d7003ff3b", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=8.2" }, "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, "autoload": { - "files": [ - "bootstrap.php" - ], "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" + "Symfony\\Component\\Process\\": "" }, - "classmap": [ - "Resources/stubs" + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1858,28 +6377,18 @@ ], "authors": [ { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" + "source": "https://github.com/symfony/process/tree/v7.3.4" }, "funding": [ { @@ -1890,25 +6399,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-09-11T10:12:26+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "e53260aabf78fb3d63f8d79d69ece59f80d5eda0" + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/e53260aabf78fb3d63f8d79d69ece59f80d5eda0", - "reference": "e53260aabf78fb3d63f8d79d69ece59f80d5eda0", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4", + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4", "shasum": "" }, "require": { @@ -1926,7 +6439,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -1962,7 +6475,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.6.0" }, "funding": [ { @@ -1978,20 +6491,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2025-04-25T09:37:31+00:00" }, { "name": "symfony/string", - "version": "v6.4.15", + "version": "v6.4.26", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f" + "reference": "5621f039a71a11c87c106c1c598bdcd04a19aeea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f", - "reference": "73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f", + "url": "https://api.github.com/repos/symfony/string/zipball/5621f039a71a11c87c106c1c598bdcd04a19aeea", + "reference": "5621f039a71a11c87c106c1c598bdcd04a19aeea", "shasum": "" }, "require": { @@ -2005,7 +6518,6 @@ "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/error-handler": "^5.4|^6.0|^7.0", "symfony/http-client": "^5.4|^6.0|^7.0", "symfony/intl": "^6.2|^7.0", "symfony/translation-contracts": "^2.5|^3.0", @@ -2048,7 +6560,171 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.4.15" + "source": "https://github.com/symfony/string/tree/v6.4.26" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-09-11T14:32:46+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v6.4.26", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "cfae1497a2f1eaad78dbc0590311c599c7178d4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/cfae1497a2f1eaad78dbc0590311c599c7178d4a", + "reference": "cfae1497a2f1eaad78dbc0590311c599c7178d4a", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/console": "<5.4" + }, + "require-dev": { + "symfony/console": "^5.4|^6.0|^7.0", + "symfony/error-handler": "^6.3|^7.0", + "symfony/http-kernel": "^5.4|^6.0|^7.0", + "symfony/process": "^5.4|^6.0|^7.0", + "symfony/uid": "^5.4|^6.0|^7.0", + "twig/twig": "^2.13|^3.0.4" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides mechanisms for walking through any arbitrary PHP variable", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "support": { + "source": "https://github.com/symfony/var-dumper/tree/v6.4.26" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-09-25T15:37:27+00:00" + }, + { + "name": "symfony/yaml", + "version": "v6.4.26", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "0fc8b966fd0dcaab544ae59bfc3a433f048c17b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/0fc8b966fd0dcaab544ae59bfc3a433f048c17b0", + "reference": "0fc8b966fd0dcaab544ae59bfc3a433f048c17b0", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "symfony/console": "<5.4" + }, + "require-dev": { + "symfony/console": "^5.4|^6.0|^7.0" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v6.4.26" }, "funding": [ { @@ -2059,12 +6735,16 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-13T13:31:12+00:00" + "time": "2025-09-26T15:07:38+00:00" }, { "name": "szepeviktor/phpstan-wordpress", @@ -2129,18 +6809,152 @@ }, "time": "2024-06-28T22:27:19+00:00" }, + { + "name": "theseer/tokenizer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:36:25+00:00" + }, + { + "name": "vlucas/phpdotenv", + "version": "v5.6.2", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "24ac4c74f91ee2c193fa1aaa5c249cb0822809af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/24ac4c74f91ee2c193fa1aaa5c249cb0822809af", + "reference": "24ac4c74f91ee2c193fa1aaa5c249cb0822809af", + "shasum": "" + }, + "require": { + "ext-pcre": "*", + "graham-campbell/result-type": "^1.1.3", + "php": "^7.2.5 || ^8.0", + "phpoption/phpoption": "^1.9.3", + "symfony/polyfill-ctype": "^1.24", + "symfony/polyfill-mbstring": "^1.24", + "symfony/polyfill-php80": "^1.24" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-filter": "*", + "phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2" + }, + "suggest": { + "ext-filter": "Required to use the boolean validator." + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + }, + "branch-alias": { + "dev-master": "5.6-dev" + } + }, + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "https://github.com/vlucas" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "support": { + "issues": "https://github.com/vlucas/phpdotenv/issues", + "source": "https://github.com/vlucas/phpdotenv/tree/v5.6.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", + "type": "tidelift" + } + ], + "time": "2025-04-30T23:37:27+00:00" + }, { "name": "wp-coding-standards/wpcs", - "version": "3.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7" + "reference": "d2421de7cec3274ae622c22c744de9a62c7925af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/9333efcbff231f10dfd9c56bb7b65818b4733ca7", - "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/d2421de7cec3274ae622c22c744de9a62c7925af", + "reference": "d2421de7cec3274ae622c22c744de9a62c7925af", "shasum": "" }, "require": { @@ -2149,13 +6963,13 @@ "ext-tokenizer": "*", "ext-xmlreader": "*", "php": ">=5.4", - "phpcsstandards/phpcsextra": "^1.2.1", - "phpcsstandards/phpcsutils": "^1.0.10", - "squizlabs/php_codesniffer": "^3.9.0" + "phpcsstandards/phpcsextra": "^1.4.0", + "phpcsstandards/phpcsutils": "^1.1.0", + "squizlabs/php_codesniffer": "^3.13.0" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", + "php-parallel-lint/php-parallel-lint": "^1.4.0", "phpcompatibility/php-compatibility": "^9.0", "phpcsstandards/phpcsdevtools": "^1.2.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" @@ -2193,7 +7007,7 @@ "type": "custom" } ], - "time": "2024-03-25T16:39:00+00:00" + "time": "2025-07-24T20:08:31+00:00" } ], "aliases": [], diff --git a/fix-phpcs.bat b/fix-phpcs.bat new file mode 100644 index 000000000..0be0522ea --- /dev/null +++ b/fix-phpcs.bat @@ -0,0 +1,22 @@ +@echo off +REM Increase PHP memory for this session +SET PHP_MEMORY_LIMIT=4096M + +REM Directories to scan +SET DIRS=includes tests vendor-prefixed + +REM Loop through each directory and fix PHPCS issues +FOR %%D IN (%DIRS%) DO ( + echo ============================================== + echo Running PHPCBF on directory: %%D + php -d memory_limit=%PHP_MEMORY_LIMIT% vendor\bin\phpcbf -p --standard=WordPress %%D +) + +REM Fix the root files +echo ============================================== +echo Running PHPCBF on root files +php -d memory_limit=%PHP_MEMORY_LIMIT% vendor\bin\phpcbf -p --standard=WordPress *.php + +echo ============================================== +echo PHPCS auto-fix complete! +pause diff --git a/includes/admin/class-general.php b/includes/admin/class-general.php index eb27e307b..16ed81c6f 100644 --- a/includes/admin/class-general.php +++ b/includes/admin/class-general.php @@ -21,15 +21,15 @@ class General extends Section { public static function get_other_nonce_values( $excluded ) { $nonce_values = apply_filters( 'woographql_authorizing_url_nonce_values', - [ + array( 'cart_url' => woographql_setting( 'cart_url_nonce_param', '_wc_cart' ), 'checkout_url' => woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ), 'account_url' => woographql_setting( 'account_url_nonce_param', '_wc_account' ), 'add_payment_method_url' => woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ), - ] + ) ); - return array_values( array_diff_key( $nonce_values, [ $excluded => '' ] ) ); + return array_values( array_diff_key( $nonce_values, array( $excluded => '' ) ) ); } /** @@ -40,12 +40,12 @@ public static function get_other_nonce_values( $excluded ) { public static function enabled_authorizing_url_fields_value() { return apply_filters( 'woographql_enabled_authorizing_url_fields', - [ + array( 'cart_url' => 'cart_url', 'checkout_url' => 'checkout_url', 'account_url' => 'account_url', 'add_payment_method_url' => 'add_payment_method_url', - ] + ) ); } @@ -56,8 +56,8 @@ public static function enabled_authorizing_url_fields_value() { */ public static function get_fields() { $custom_endpoint = apply_filters( 'woographql_authorizing_url_endpoint', null ); - $enabled_authorizing_url_fields = woographql_setting( 'enable_authorizing_url_fields', [] ); - $enabled_authorizing_url_fields = ! empty( $enabled_authorizing_url_fields ) ? array_keys( $enabled_authorizing_url_fields ) : []; + $enabled_authorizing_url_fields = woographql_setting( 'enable_authorizing_url_fields', array() ); + $enabled_authorizing_url_fields = ! empty( $enabled_authorizing_url_fields ) ? array_keys( $enabled_authorizing_url_fields ) : array(); $all_urls_checked = self::enabled_authorizing_url_fields_value(); $cart_url_hardcoded = defined( 'CART_URL_NONCE_PARAM' ) && ! empty( constant( 'CART_URL_NONCE_PARAM' ) ); @@ -67,8 +67,8 @@ public static function get_fields() { $enable_auth_urls_hardcoded = defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) && ! empty( constant( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) ); - return [ - [ + return array( + array( 'name' => 'disable_ql_session_handler', 'label' => __( 'Disable QL Session Handler', 'wp-graphql-woocommerce' ), 'desc' => __( 'The QL Session Handler takes over management of WooCommerce Session Management on WPGraphQL request replacing the usage of HTTP Cookies with JSON Web Tokens.', 'wp-graphql-woocommerce' ) @@ -76,8 +76,8 @@ public static function get_fields() { 'type' => 'checkbox', 'value' => defined( 'NO_QL_SESSION_HANDLER' ) ? 'on' : woographql_setting( 'disable_ql_session_handler', 'off' ), 'disabled' => defined( 'NO_QL_SESSION_HANDLER' ), - ], - [ + ), + array( 'name' => 'enable_ql_session_handler_on_ajax', 'label' => __( 'Enable QL Session Handler on WC AJAX requests.', 'wp-graphql-woocommerce' ), 'desc' => __( 'Enabling this will enable JSON Web Tokens usage on WC AJAX requests.', 'wp-graphql-woocommerce' ) @@ -85,8 +85,8 @@ public static function get_fields() { 'type' => 'checkbox', 'value' => defined( 'NO_QL_SESSION_HANDLER' ) ? 'off' : woographql_setting( 'enable_ql_session_handler_on_ajax', 'off' ), 'disabled' => defined( 'NO_QL_SESSION_HANDLER' ), - ], - [ + ), + array( 'name' => 'enable_ql_session_handler_on_rest', 'label' => __( 'Enable QL Session Handler on WP REST requests.', 'wp-graphql-woocommerce' ), 'desc' => __( 'Enabling this will enable JSON Web Tokens usage on WP REST requests.', 'wp-graphql-woocommerce' ) @@ -94,15 +94,15 @@ public static function get_fields() { 'type' => 'checkbox', 'value' => defined( 'NO_QL_SESSION_HANDLER' ) ? 'off' : woographql_setting( 'enable_ql_session_handler_on_rest', 'off' ), 'disabled' => defined( 'NO_QL_SESSION_HANDLER' ), - ], - [ + ), + array( 'name' => 'enable_unsupported_product_type', 'label' => __( 'Enable Unsupported types', 'wp-graphql-woocommerce' ), 'desc' => __( 'Substitute unsupported product types with SimpleProduct', 'wp-graphql-woocommerce' ), 'type' => 'checkbox', 'default' => 'off', - ], - [ + ), + array( 'name' => 'enable_authorizing_url_fields', 'label' => __( 'Enable User Session transferring URLs', 'wp-graphql-woocommerce' ), 'desc' => __( 'URL fields to add to the Customer type.', 'wp-graphql-woocommerce' ) @@ -110,24 +110,24 @@ public static function get_fields() { 'type' => 'multicheck', 'options' => apply_filters( 'woographql_settings_enable_authorizing_url_options', - [ + array( 'cart_url' => __( 'Cart URL. Field name: cartUrl', 'wp-graphql-woocommerce' ), 'checkout_url' => __( 'Checkout URL. Field name: checkoutUrl', 'wp-graphql-woocommerce' ), 'account_url' => __( 'Account URL. Field name: accountUrl', 'wp-graphql-woocommerce' ), 'add_payment_method_url' => __( 'Add Payment Method URL. Field name: addPaymentMethodUrl', 'wp-graphql-woocommerce' ), - ] + ) ), - 'value' => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ), + 'value' => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', array() ), 'disabled' => $enable_auth_urls_hardcoded, 'sanitize_callback' => static function ( $value ) { if ( empty( $value ) ) { - return []; + return array(); } return $value; }, - ], - [ + ), + array( 'name' => 'authorizing_url_endpoint', 'label' => __( 'Endpoint for Authorizing URLs', 'wp-graphql-woocommerce' ), 'desc' => sprintf( @@ -139,8 +139,8 @@ public static function get_fields() { 'type' => 'text', 'default' => ! empty( $custom_endpoint ) ? $custom_endpoint : 'transfer-session', 'disabled' => empty( $enabled_authorizing_url_fields ), - ], - [ + ), + array( 'name' => 'cart_url_nonce_param', 'label' => __( 'Cart URL nonce name', 'wp-graphql-woocommerce' ), 'desc' => __( 'Query parameter name of the nonce included in the "cartUrl" field', 'wp-graphql-woocommerce' ) @@ -163,8 +163,8 @@ public static function get_fields() { return $value; }, - ], - [ + ), + array( 'name' => 'checkout_url_nonce_param', 'label' => __( 'Checkout URL nonce name', 'wp-graphql-woocommerce' ), 'desc' => __( 'Query parameter name of the nonce included in the "checkoutUrl" field', 'wp-graphql-woocommerce' ) @@ -187,8 +187,8 @@ public static function get_fields() { return $value; }, - ], - [ + ), + array( 'name' => 'account_url_nonce_param', 'label' => __( 'Account URL nonce name', 'wp-graphql-woocommerce' ), 'desc' => __( 'Query parameter name of the nonce included in the "accountUrl" field', 'wp-graphql-woocommerce' ) @@ -211,8 +211,8 @@ public static function get_fields() { return $value; }, - ], - [ + ), + array( 'name' => 'add_payment_method_url_nonce_param', 'label' => __( 'Add Payment Method URL nonce name', 'wp-graphql-woocommerce' ), 'desc' => __( 'Query parameter name of the nonce included in the "addPaymentMethodUrl" field', 'wp-graphql-woocommerce' ) @@ -235,7 +235,7 @@ public static function get_fields() { return $value; }, - ], - ]; + ), + ); } } diff --git a/includes/class-acf-schema-filters.php b/includes/class-acf-schema-filters.php index 2141f2fa1..08401d597 100644 --- a/includes/class-acf-schema-filters.php +++ b/includes/class-acf-schema-filters.php @@ -19,8 +19,8 @@ class ACF_Schema_Filters { */ public static function add_filters() { // Registers WooCommerce CPTs && taxonomies. - add_filter( 'graphql_acf_get_root_id', [ self::class, 'resolve_crud_root_id' ], 10, 2 ); - add_filter( 'graphql_acf_post_object_source', [ self::class, 'resolve_post_object_source' ], 10, 2 ); + add_filter( 'graphql_acf_get_root_id', array( self::class, 'resolve_crud_root_id' ), 10, 2 ); + add_filter( 'graphql_acf_post_object_source', array( self::class, 'resolve_post_object_source' ), 10, 2 ); } /** diff --git a/includes/class-admin.php b/includes/class-admin.php index 5cd54877c..25726886f 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -19,7 +19,7 @@ class Admin { * Admin constructor */ public function __construct() { - add_action( 'graphql_register_settings', [ $this, 'register_settings' ] ); + add_action( 'graphql_register_settings', array( $this, 'register_settings' ) ); } /** @@ -31,7 +31,7 @@ public function __construct() { public function register_settings( Settings $manager ) { $manager->settings_api->register_section( 'woographql_settings', - [ 'title' => __( 'WooCommerce', 'wp-graphql-woocommerce' ) ] + array( 'title' => __( 'WooCommerce', 'wp-graphql-woocommerce' ) ) ); $manager->settings_api->register_fields( diff --git a/includes/class-core-schema-filters.php b/includes/class-core-schema-filters.php index 0a69ee36b..1404ec975 100644 --- a/includes/class-core-schema-filters.php +++ b/includes/class-core-schema-filters.php @@ -26,25 +26,25 @@ class Core_Schema_Filters { */ public static function add_filters() { // Registers WooCommerce CPTs. - add_filter( 'register_post_type_args', [ self::class, 'register_post_types' ], 10, 2 ); - add_filter( 'graphql_post_entities_allowed_post_types', [ self::class, 'skip_type_registry' ], 10 ); + add_filter( 'register_post_type_args', array( self::class, 'register_post_types' ), 10, 2 ); + add_filter( 'graphql_post_entities_allowed_post_types', array( self::class, 'skip_type_registry' ), 10 ); // Registers WooCommerce taxonomies. - add_filter( 'register_taxonomy_args', [ self::class, 'register_taxonomy_args' ], 10, 2 ); + add_filter( 'register_taxonomy_args', array( self::class, 'register_taxonomy_args' ), 10, 2 ); // Add data-loaders to AppContext. - add_filter( 'graphql_data_loaders', [ self::class, 'graphql_data_loaders' ], 10, 2 ); + add_filter( 'graphql_data_loaders', array( self::class, 'graphql_data_loaders' ), 10, 2 ); // Add node resolvers. add_filter( 'graphql_resolve_node', - [ '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node' ], + array( '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node' ), 10, 4 ); add_filter( 'graphql_resolve_node_type', - [ '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node_type' ], + array( '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node_type' ), 10, 2 ); @@ -52,63 +52,63 @@ public static function add_filters() { // Filter Unions. add_filter( 'graphql_wp_union_type_config', - [ self::class, 'inject_union_types' ], + array( self::class, 'inject_union_types' ), 10, 2 ); add_filter( 'graphql_union_resolve_type', - [ self::class, 'inject_type_resolver' ], + array( self::class, 'inject_type_resolver' ), 10, 2 ); add_filter( 'graphql_interface_resolve_type', - [ self::class, 'inject_type_resolver' ], + array( self::class, 'inject_type_resolver' ), 10, 2 ); add_filter( 'graphql_dataloader_pre_get_model', - [ '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ], + array( '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ), 10, 3 ); add_filter( 'graphql_dataloader_get_model', - [ '\WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader', 'inject_user_loader_models' ], + array( '\WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader', 'inject_user_loader_models' ), 10, 3 ); add_filter( 'graphql_map_input_fields_to_wp_query', - [ '\WPGraphQL\WooCommerce\Connection\Coupons', 'map_input_fields_to_wp_query' ], + array( '\WPGraphQL\WooCommerce\Connection\Coupons', 'map_input_fields_to_wp_query' ), 10, 7 ); add_filter( 'graphql_map_input_fields_to_wp_user_query', - [ '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ], + array( '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ), 10, 6 ); add_filter( 'graphql_connection', - [ '\WPGraphQL\WooCommerce\Connection\Customers', 'upgrade_models' ], + array( '\WPGraphQL\WooCommerce\Connection\Customers', 'upgrade_models' ), 10, 2 ); add_filter( 'graphql_wp_connection_type_config', - [ '\WPGraphQL\WooCommerce\Connection\Products', 'set_connection_config' ] + array( '\WPGraphQL\WooCommerce\Connection\Products', 'set_connection_config' ) ); } @@ -127,10 +127,10 @@ public static function register_post_types( $args, $post_type ) { $args['graphql_single_name'] = 'Product'; $args['graphql_plural_name'] = 'Products'; $args['graphql_kind'] = 'interface'; - $args['graphql_interfaces'] = [ 'ContentNode', 'ProductUnion' ]; + $args['graphql_interfaces'] = array( 'ContentNode', 'ProductUnion' ); $args['graphql_register_root_field'] = false; $args['graphql_register_root_connection'] = false; - $args['graphql_resolve_type'] = [ self::class, 'resolve_product_type' ]; + $args['graphql_resolve_type'] = array( self::class, 'resolve_product_type' ); } if ( 'product_variation' === $post_type ) { $args['show_in_graphql'] = true; @@ -139,7 +139,7 @@ public static function register_post_types( $args, $post_type ) { $args['graphql_plural_name'] = 'ProductVariations'; $args['publicly_queryable'] = true; $args['graphql_kind'] = 'interface'; - $args['graphql_interfaces'] = [ + $args['graphql_interfaces'] = array( 'Node', 'NodeWithFeaturedImage', 'ContentNode', @@ -149,10 +149,10 @@ public static function register_post_types( $args, $post_type ) { 'ProductWithDimensions', 'InventoriedProduct', 'DownloadableProduct', - ]; + ); $args['graphql_register_root_field'] = false; $args['graphql_register_root_connection'] = false; - $args['graphql_resolve_type'] = [ self::class, 'resolve_product_variation_type' ]; + $args['graphql_resolve_type'] = array( self::class, 'resolve_product_variation_type' ); } if ( 'shop_coupon' === $post_type ) { $args['show_in_graphql'] = true; @@ -188,10 +188,10 @@ public static function skip_type_registry( $post_types ) { return array_diff( $post_types, get_post_types( - [ + array( 'show_in_graphql' => true, 'skip_graphql_type_registry' => true, - ] + ) ) ); } @@ -302,7 +302,7 @@ static function ( $type ) { } ), array_values( WooGraphQL::get_enabled_product_types() ), - [ WooGraphQL::get_supported_product_type() ] + array( WooGraphQL::get_supported_product_type() ) ); $refresh_callback = true; } @@ -310,7 +310,7 @@ static function ( $type ) { // Update 'types' callback. if ( $refresh_callback ) { $config['types'] = static function () use ( $config, $wp_union ) { - $prepared_types = []; + $prepared_types = array(); foreach ( $config['typeNames'] as $type_name ) { $prepared_types[] = $wp_union->type_registry->get_type( $type_name ); } diff --git a/includes/class-jwt-auth-schema-filters.php b/includes/class-jwt-auth-schema-filters.php index 763be8a9e..aa8d90b48 100644 --- a/includes/class-jwt-auth-schema-filters.php +++ b/includes/class-jwt-auth-schema-filters.php @@ -104,10 +104,10 @@ public static function add_filters() { // Confirm WPGraphQL JWT Authentication is installed. $auth_class = self::get_auth_class(); if ( ! is_null( $auth_class ) ) { - add_filter( 'graphql_jwt_user_types', [ self::class, 'add_customer_to_jwt_user_types' ], 10 ); - add_filter( 'graphql_registerCustomerPayload_fields', [ self::class, 'add_jwt_output_fields' ], 10, 3 ); - add_filter( 'graphql_updateCustomerPayload_fields', [ self::class, 'add_jwt_output_fields' ], 10, 3 ); - add_action( 'graphql_register_types', [ self::class, 'add_customer_to_login_payload' ], 10 ); + add_filter( 'graphql_jwt_user_types', array( self::class, 'add_customer_to_jwt_user_types' ), 10 ); + add_filter( 'graphql_registerCustomerPayload_fields', array( self::class, 'add_jwt_output_fields' ), 10, 3 ); + add_filter( 'graphql_updateCustomerPayload_fields', array( self::class, 'add_jwt_output_fields' ), 10, 3 ); + add_action( 'graphql_register_types', array( self::class, 'add_customer_to_login_payload' ), 10 ); } } @@ -135,8 +135,8 @@ public static function add_customer_to_jwt_user_types( array $types ) { public static function add_jwt_output_fields( $fields, $object_type, $type_registry ): array { $fields = array_merge( $fields, - [ - 'authToken' => [ + array( + 'authToken' => array( 'type' => $type_registry->get_type( 'String' ), 'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { @@ -148,8 +148,8 @@ public static function add_jwt_output_fields( $fields, $object_type, $type_regis return self::get_auth_token( $user ); }, - ], - 'refreshToken' => [ + ), + 'refreshToken' => array( 'type' => $type_registry->get_type( 'String' ), 'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { @@ -161,8 +161,8 @@ public static function add_jwt_output_fields( $fields, $object_type, $type_regis return self::get_refresh_token( $user ); }, - ], - ] + ), + ) ); return $fields; @@ -177,21 +177,21 @@ public static function add_customer_to_login_payload() { register_graphql_field( 'LoginPayload', 'customer', - [ + array( 'type' => 'Customer', 'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { $id = $payload['id']; return new Customer( $id ); }, - ] + ) ); if ( ! WooCommerce_Filters::is_session_handler_disabled() ) { register_graphql_field( 'LoginPayload', 'sessionToken', - [ + array( 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), 'resolve' => static function () { @@ -204,7 +204,7 @@ public static function add_customer_to_login_payload() { return apply_filters( 'graphql_customer_session_token', $session->build_token() ); }, - ] + ) ); } } diff --git a/includes/class-woocommerce-filters.php b/includes/class-woocommerce-filters.php index 60ff76824..50b38e8d0 100644 --- a/includes/class-woocommerce-filters.php +++ b/includes/class-woocommerce-filters.php @@ -31,17 +31,17 @@ public static function setup() { // Check if request is a GraphQL POST request. if ( ! self::is_session_handler_disabled() ) { - add_filter( 'woocommerce_session_handler', [ self::class, 'woocommerce_session_handler' ] ); - add_filter( 'graphql_response_headers_to_send', [ self::class, 'add_session_header_to_expose_headers' ] ); - add_filter( 'graphql_access_control_allow_headers', [ self::class, 'add_session_header_to_allow_headers' ] ); + add_filter( 'woocommerce_session_handler', array( self::class, 'woocommerce_session_handler' ) ); + add_filter( 'graphql_response_headers_to_send', array( self::class, 'add_session_header_to_expose_headers' ) ); + add_filter( 'graphql_access_control_allow_headers', array( self::class, 'add_session_header_to_allow_headers' ) ); } // Add better support for Stripe payment gateway. - add_filter( 'graphql_stripe_process_payment_args', [ self::class, 'woographql_stripe_gateway_args' ], 10, 2 ); + add_filter( 'graphql_stripe_process_payment_args', array( self::class, 'woographql_stripe_gateway_args' ), 10, 2 ); // WPGraphQL Reset password -> Use woocommerce email password template when requested. - add_filter( 'retrieve_password_message', [ self::class, 'get_reset_password_message' ], 10, 3 ); - add_filter( 'retrieve_password_title', [ self::class, 'get_reset_password_title' ] ); + add_filter( 'retrieve_password_message', array( self::class, 'get_reset_password_message' ), 10, 3 ); + add_filter( 'retrieve_password_title', array( self::class, 'get_reset_password_title' ) ); } /** @@ -62,7 +62,7 @@ public static function enabled_authorizing_url_fields() { if ( defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) ) { return \WPGraphQL\WooCommerce\Admin\General::enabled_authorizing_url_fields_value(); } - return woographql_setting( 'enable_authorizing_url_fields', [] ); + return woographql_setting( 'enable_authorizing_url_fields', array() ); } /** @@ -165,13 +165,13 @@ public static function woographql_stripe_gateway_args( $gateway_args, $payment_m $stripe_source_id = $order->get_meta( '_stripe_source_id' ); if ( 'stripe' === $payment_method && ! empty( $stripe_source_id ) ) { - $gateway_args = [ + $gateway_args = array( $gateway_args[0], true, false, false, true, - ]; + ); } return $gateway_args; @@ -196,7 +196,7 @@ public static function get_reset_password_message( $message, $key, $user_login ) $wc_reset_email = \WC()->mailer()->emails['WC_Email_Customer_Reset_Password']; if ( $wc_reset_email && $wc_reset_email->is_enabled() ) { - add_filter( 'wp_mail_content_type', [ $wc_reset_email, 'get_content_type' ] ); + add_filter( 'wp_mail_content_type', array( $wc_reset_email, 'get_content_type' ) ); $wc_reset_email->user_login = $user_login; $wc_reset_email->reset_key = $key; diff --git a/includes/class-wp-graphql-woocommerce.php b/includes/class-wp-graphql-woocommerce.php index 7156baeb1..f3573441c 100644 --- a/includes/class-wp-graphql-woocommerce.php +++ b/includes/class-wp-graphql-woocommerce.php @@ -55,13 +55,13 @@ public static function instance() { public static function get_post_types() { return apply_filters( 'graphql_woocommerce_post_types', - [ + array( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund', - ] + ) ); } @@ -73,12 +73,12 @@ public static function get_post_types() { public static function get_enabled_product_types() { return apply_filters( 'graphql_woocommerce_product_types', - [ + array( 'simple' => 'SimpleProduct', 'variable' => 'VariableProduct', 'external' => 'ExternalProduct', 'grouped' => 'GroupProduct', - ] + ) ); } @@ -88,7 +88,7 @@ public static function get_enabled_product_types() { * @return array */ public static function get_enabled_product_variation_types() { - return apply_filters( 'graphql_woocommerce_product_variation_types', [ 'variation' => 'SimpleProductVariation' ] ); + return apply_filters( 'graphql_woocommerce_product_variation_types', array( 'variation' => 'SimpleProductVariation' ) ); } /** @@ -113,7 +113,7 @@ public static function get_product_attribute_taxonomies() { $attribute_taxonomies = \wc_get_attribute_taxonomies(); // Get taxonomy names. - $attributes = []; + $attributes = array(); foreach ( $attribute_taxonomies as $tax ) { $attributes[] = 'pa_' . $tax->attribute_name; } @@ -439,7 +439,7 @@ static function () { * @return array */ public static function get_enabled_auth_urls() { - return woographql_setting( 'enable_authorizing_url_fields', [] ); + return woographql_setting( 'enable_authorizing_url_fields', array() ); } /** @@ -459,7 +459,7 @@ public static function auth_router_is_enabled() { */ public static function load_auth_router() { require get_includes_directory() . 'utils/class-protected-router.php'; - add_action( 'after_setup_theme', [ Utils\Protected_Router::class, 'initialize' ] ); + add_action( 'after_setup_theme', array( Utils\Protected_Router::class, 'initialize' ) ); } /** @@ -491,7 +491,7 @@ private function setup() { // Initialize WPGraphQL for WooCommerce TypeRegistry. $registry = new Type_Registry(); - add_action( 'graphql_register_types', [ $registry, 'init' ] ); + add_action( 'graphql_register_types', array( $registry, 'init' ) ); } } diff --git a/includes/connection/class-comments.php b/includes/connection/class-comments.php index 968fd3b53..8003f51f1 100644 --- a/includes/connection/class-comments.php +++ b/includes/connection/class-comments.php @@ -25,12 +25,12 @@ public static function register_connections() { // From Products. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Product', 'toType' => 'Comment', 'fromFieldName' => 'reviews', - 'connectionFields' => [ - 'averageRating' => [ + 'connectionFields' => array( + 'averageRating' => array( 'type' => 'Float', 'description' => __( 'Average review rating for this product.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -40,10 +40,10 @@ public static function register_connections() { $product = $source['edges'][0]['source']; return $product->averageRating; // @codingStandardsIgnoreLine }, - ], - ], - 'edgeFields' => [ - 'rating' => [ + ), + ), + 'edgeFields' => array( + 'rating' => array( 'type' => 'Float', 'description' => __( 'Review rating', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -52,8 +52,8 @@ public static function register_connections() { $rating = get_comment_meta( $review->commentId, 'rating', true ); return $rating ? $rating : 0; }, - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); @@ -62,19 +62,19 @@ public static function register_connections() { return $resolver->get_connection(); }, - ] + ) ) ); // From Orders. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Order', 'toType' => 'Comment', 'fromFieldName' => 'orderNotes', - 'edgeFields' => [ - 'isCustomerNote' => [ + 'edgeFields' => array( + 'isCustomerNote' => array( 'type' => 'Boolean', 'description' => __( 'Is this a customer note?', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -82,8 +82,8 @@ public static function register_connections() { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return get_comment_meta( $note->commentId, 'is_customer_note', true ); }, - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); @@ -96,15 +96,15 @@ public static function register_connections() { $resolver->set_query_arg( 'meta_value', true ); } - remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); + remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); $connection = $resolver->get_connection(); - add_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); + add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); return $connection; }, - ] + ) ) ); } diff --git a/includes/connection/class-coupons.php b/includes/connection/class-coupons.php index a05e66616..763cb00ec 100644 --- a/includes/connection/class-coupons.php +++ b/includes/connection/class-coupons.php @@ -32,9 +32,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'Coupon', 'fromFieldName' => 'coupons', @@ -43,15 +43,15 @@ public static function get_connection_config( $args = [] ): array { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'shop_coupon' ); if ( ! self::should_execute() ) { - return [ - 'edges' => [], - 'nodes' => [], - ]; + return array( + 'edges' => array(), + 'nodes' => array(), + ); } return $resolver->get_connection(); }, - ], + ), $args ); } @@ -84,12 +84,12 @@ public static function should_execute() { public static function get_connection_args(): array { return array_merge( get_wc_cpt_connection_args(), - [ - 'code' => [ + array( + 'code' => array( 'type' => 'String', 'description' => __( 'Limit result set to resources with a specific code.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -122,7 +122,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ if ( ! empty( $where_args['code'] ) ) { $id = \wc_get_coupon_id_by_code( $where_args['code'] ); - $ids = $id ? [ $id ] : [ '0' ]; + $ids = $id ? array( $id ) : array( '0' ); $query_args['post__in'] = ! empty( $query_args['post__in'] ) ? array_intersect( $ids, $query_args['post__in'] ) : $ids; diff --git a/includes/connection/class-customers.php b/includes/connection/class-customers.php index 55707260f..d97bb0230 100644 --- a/includes/connection/class-customers.php +++ b/includes/connection/class-customers.php @@ -25,7 +25,7 @@ class Customers { */ public static function register_connections() { register_graphql_connection( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'Customer', 'fromFieldName' => 'customers', @@ -34,21 +34,21 @@ public static function register_connections() { $resolver = new UserConnectionResolver( $source, $args, $context, $info ); if ( ! self::should_execute() ) { - return [ - 'nodes' => [], - 'edges' => [], - ]; + return array( + 'nodes' => array(), + 'edges' => array(), + ); } $resolver->set_query_arg( 'role', 'customer' ); return $resolver->get_connection(); }, - ] + ) ); register_graphql_connection( - [ + array( 'fromType' => 'Coupon', 'toType' => 'Customer', 'fromFieldName' => 'usedBy', @@ -60,15 +60,15 @@ public static function register_connections() { $resolver->set_query_arg( 'role', 'customer' ); if ( ! self::should_execute() ) { - return [ - 'nodes' => [], - 'edges' => [], - ]; + return array( + 'nodes' => array(), + 'edges' => array(), + ); } return $resolver->get_connection(); }, - ] + ) ); } @@ -92,32 +92,32 @@ public static function should_execute() { * @return array */ public static function get_connection_args(): array { - return [ - 'search' => [ + return array( + 'search' => array( 'type' => 'String', 'description' => __( 'Limit results to those matching a string.', 'wp-graphql-woocommerce' ), - ], - 'exclude' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'exclude' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Ensure result set excludes specific IDs.', 'wp-graphql-woocommerce' ), - ], - 'include' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'include' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to specific ids.', 'wp-graphql-woocommerce' ), - ], - 'email' => [ + ), + 'email' => array( 'type' => 'String', 'description' => __( 'Limit result set to resources with a specific email.', 'wp-graphql-woocommerce' ), - ], - 'orderby' => [ + ), + 'orderby' => array( 'type' => 'CustomerConnectionOrderbyEnum', 'description' => __( 'Order results by a specific field.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'OrderEnum', 'description' => __( 'Order of results.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -134,11 +134,11 @@ public static function get_connection_args(): array { * @return array Query arguments. */ public static function map_input_fields_to_wp_query( $query_args, $where_args, $source, $args, $context, $info ) { - $key_mapping = [ + $key_mapping = array( 'search' => 'search', 'exclude' => 'exclude', 'include' => 'include', - ]; + ); foreach ( $key_mapping as $key => $field ) { if ( ! empty( $where_args[ $key ] ) ) { @@ -149,7 +149,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ // Filter by email. if ( ! empty( $where_args['email'] ) ) { $query_args['search'] = $where_args['email']; - $query_args['search_columns'] = [ 'user_email' ]; + $query_args['search_columns'] = array( 'user_email' ); } /** @@ -202,8 +202,8 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ */ public static function upgrade_models( $connection, $resolver ) { if ( 'customers' === $resolver->get_info()->fieldName ) { - $nodes = []; - $edges = []; + $nodes = array(); + $edges = array(); foreach ( $connection['nodes'] as $node ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $nodes[] = new Customer( $node->databaseId ); @@ -213,7 +213,7 @@ public static function upgrade_models( $connection, $resolver ) { $edges[] = array_merge( $edge, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - [ 'node' => new Customer( $edge['node']->databaseId ) ] + array( 'node' => new Customer( $edge['node']->databaseId ) ) ); } diff --git a/includes/connection/class-orders.php b/includes/connection/class-orders.php index c270c33fc..61c51a46c 100644 --- a/includes/connection/class-orders.php +++ b/includes/connection/class-orders.php @@ -31,7 +31,7 @@ public static function register_connections() { // From Customer To Orders. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Customer', 'fromFieldName' => 'orders', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -39,25 +39,25 @@ public static function register_connections() { return self::get_customer_order_connection( $resolver, $source ); }, - ] + ) ) ); // From RootQuery To Refunds. register_graphql_connection( self::get_connection_config( - [ + array( 'toType' => 'Refund', 'fromFieldName' => 'refunds', 'connectionArgs' => self::get_refund_connection_args(), - ], + ), 'shop_order_refund' ) ); // From Order To Refunds. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Order', 'toType' => 'Refund', 'fromFieldName' => 'refunds', @@ -70,14 +70,14 @@ public static function register_connections() { return $resolver->get_connection(); }, - ], + ), 'shop_order_refund' ) ); // From Customer To Refunds. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Customer', 'toType' => 'Refund', 'fromFieldName' => 'refunds', @@ -87,7 +87,7 @@ public static function register_connections() { return self::get_customer_refund_connection( $resolver, $source ); }, - ], + ), 'shop_order_refund' ) ); @@ -104,10 +104,10 @@ public static function register_connections() { private static function get_customer_order_connection( $resolver, $customer ) { // If not "billing email" or "ID" set bail early by returning an empty connection. if ( empty( $customer->get_billing_email() ) && empty( $customer->get_id() ) ) { - return [ - 'nodes' => [], - 'edges' => [], - ]; + return array( + 'nodes' => array(), + 'edges' => array(), + ); } $customer_id = $customer->get_id(); @@ -132,24 +132,24 @@ private static function get_customer_order_connection( $resolver, $customer ) { * @return array|\GraphQL\Deferred */ private static function get_customer_refund_connection( $resolver, $customer ) { - $empty_results = [ + $empty_results = array( 'pageInfo' => null, - 'nodes' => [], - 'edges' => [], - ]; + 'nodes' => array(), + 'edges' => array(), + ); // If not "billing email" or "ID" set bail early by returning an empty connection. if ( empty( $customer->get_billing_email() ) && empty( $customer->get_id() ) ) { return $empty_results; } - $order_ids = []; + $order_ids = array(); $customer_id = $customer->get_id(); $billing_email = $customer->get_billing_email(); if ( ! empty( $customer_id ) ) { - $args = [ + $args = array( 'customer_id' => $customer_id, 'return' => 'ids', - ]; + ); /** @var array $order_ids_by_customer_id */ $order_ids_by_customer_id = wc_get_orders( $args ); @@ -159,10 +159,10 @@ private static function get_customer_refund_connection( $resolver, $customer ) { } if ( ! empty( $billing_email ) ) { - $args = [ + $args = array( 'billing_email' => $billing_email, 'return' => 'ids', - ]; + ); /** @var array $order_ids_by_email */ $order_ids_by_email = wc_get_orders( $args ); // Merge the arrays of order IDs. @@ -200,7 +200,7 @@ private static function get_customer_refund_connection( $resolver, $customer ) { * * @return array */ - public static function get_connection_config( $args = [], $post_type = 'shop_order' ): array { + public static function get_connection_config( $args = array(), $post_type = 'shop_order' ): array { // Get Post type object for use in connection resolve function. /** * Get connection post type. @@ -210,7 +210,7 @@ public static function get_connection_config( $args = [], $post_type = 'shop_ord $post_object = get_post_type_object( $post_type ); return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'Order', 'fromFieldName' => 'orders', @@ -239,7 +239,7 @@ public static function get_connection_config( $args = [], $post_type = 'shop_ord return $resolver->get_connection(); }, - ], + ), $args ); } @@ -255,58 +255,58 @@ public static function get_connection_args( $access = 'public' ): array { case 'private': return array_merge( get_wc_cpt_connection_args(), - [ - 'statuses' => [ - 'type' => [ 'list_of' => 'OrderStatusEnum' ], + array( + 'statuses' => array( + 'type' => array( 'list_of' => 'OrderStatusEnum' ), 'description' => __( 'Limit result set to orders assigned a specific status.', 'wp-graphql-woocommerce' ), - ], - 'customerId' => [ + ), + 'customerId' => array( 'type' => 'Int', 'description' => __( 'Limit result set to orders assigned a specific customer.', 'wp-graphql-woocommerce' ), - ], - 'customersIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'customersIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to orders assigned a specific group of customers.', 'wp-graphql-woocommerce' ), - ], - 'productId' => [ + ), + 'productId' => array( 'type' => 'Int', 'description' => __( 'Limit result set to orders assigned a specific product.', 'wp-graphql-woocommerce' ), - ], - 'orderby' => [ - 'type' => [ 'list_of' => 'OrdersOrderbyInput' ], + ), + 'orderby' => array( + 'type' => array( 'list_of' => 'OrdersOrderbyInput' ), 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ], - 'billingEmail' => [ + ), + 'billingEmail' => array( 'type' => 'String', 'description' => __( 'Limit result set to orders assigned a specific billing email.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); case 'public': default: - return [ - 'statuses' => [ - 'type' => [ 'list_of' => 'OrderStatusEnum' ], + return array( + 'statuses' => array( + 'type' => array( 'list_of' => 'OrderStatusEnum' ), 'description' => __( 'Limit result set to orders assigned a specific status.', 'wp-graphql-woocommerce' ), - ], - 'productId' => [ + ), + 'productId' => array( 'type' => 'Int', 'description' => __( 'Limit result set to orders assigned a specific product.', 'wp-graphql-woocommerce' ), - ], - 'orderby' => [ - 'type' => [ 'list_of' => 'OrdersOrderbyInput' ], + ), + 'orderby' => array( + 'type' => array( 'list_of' => 'OrdersOrderbyInput' ), 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ], - 'search' => [ + ), + 'search' => array( 'type' => 'String', 'description' => __( 'Limit results to those matching a string.', 'wp-graphql-woocommerce' ), - ], - 'dateQuery' => [ + ), + 'dateQuery' => array( 'type' => 'DateQueryInput', 'description' => __( 'Filter the connection based on dates.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); }//end switch } @@ -318,16 +318,16 @@ public static function get_connection_args( $access = 'public' ): array { public static function get_refund_connection_args(): array { return array_merge( get_wc_cpt_connection_args(), - [ - 'statuses' => [ - 'type' => [ 'list_of' => 'String' ], + array( + 'statuses' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to refunds assigned a specific status.', 'wp-graphql-woocommerce' ), - ], - 'orderIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'orderIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to refunds from a specific group of order IDs.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } } diff --git a/includes/connection/class-payment-gateways.php b/includes/connection/class-payment-gateways.php index 6dcd3766c..1440528d8 100644 --- a/includes/connection/class-payment-gateways.php +++ b/includes/connection/class-payment-gateways.php @@ -33,9 +33,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'PaymentGateway', 'fromFieldName' => 'paymentGateways', @@ -45,7 +45,7 @@ public static function get_connection_config( $args = [] ): array { return $resolver->resolve( $source, $args, $context, $info ); }, - ], + ), $args ); } @@ -56,11 +56,11 @@ public static function get_connection_config( $args = [] ): array { * @return array */ public static function get_connection_args(): array { - return [ - 'all' => [ + return array( + 'all' => array( 'type' => 'Boolean', 'description' => __( 'Include disabled payment gateways?', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } } diff --git a/includes/connection/class-posts.php b/includes/connection/class-posts.php index 6a530bec6..1e44178bc 100644 --- a/includes/connection/class-posts.php +++ b/includes/connection/class-posts.php @@ -25,7 +25,7 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config( get_post_type_object( 'attachment' ), - [ + array( 'fromType' => 'Product', 'toType' => 'MediaItem', 'fromFieldName' => 'galleryImages', @@ -41,7 +41,7 @@ public static function register_connections() { return $resolver->get_connection(); }, - ] + ) ) ); } diff --git a/includes/connection/class-product-attributes.php b/includes/connection/class-product-attributes.php index d7f89a7e9..7d781899c 100644 --- a/includes/connection/class-product-attributes.php +++ b/includes/connection/class-product-attributes.php @@ -28,24 +28,24 @@ public static function register_connections() { // From Product to LocalProductAttribute. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Product', 'toType' => 'LocalProductAttribute', 'fromFieldName' => 'localAttributes', - 'connectionArgs' => [], - ] + 'connectionArgs' => array(), + ) ) ); // From Product to GlobalProductAttribute. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Product', 'toType' => 'GlobalProductAttribute', 'fromFieldName' => 'globalAttributes', - 'connectionArgs' => [], - ] + 'connectionArgs' => array(), + ) ) ); } @@ -59,7 +59,7 @@ public static function register_connections() { * * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { if ( ! isset( $args['fromType'] ) ) { throw new Error( __( 'The "fromType" is required for the ProductAttributes connection.', 'wp-graphql-woocommerce' ) ); } @@ -69,9 +69,9 @@ public static function get_connection_config( $args = [] ): array { } return array_merge( - [ + array( 'fromFieldName' => 'attributes', - 'connectionArgs' => [], + 'connectionArgs' => array(), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Attribute_Connection_Resolver(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase @@ -84,7 +84,7 @@ public static function get_connection_config( $args = [] ): array { return $resolver->resolve( $source, $args, $context, $info ); } }, - ], + ), $args ); } diff --git a/includes/connection/class-products.php b/includes/connection/class-products.php index 17894114d..7048945fe 100644 --- a/includes/connection/class-products.php +++ b/includes/connection/class-products.php @@ -30,7 +30,7 @@ public static function register_connections() { // From Coupon. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Coupon', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); @@ -38,12 +38,12 @@ public static function register_connections() { return $resolver->get_connection(); }, - ] + ) ) ); register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProducts', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -57,23 +57,23 @@ public static function register_connections() { return $resolver->get_connection(); }, - ] + ) ) ); // Connections from all product types to related and upsell. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Product', 'fromFieldName' => 'related', 'connectionArgs' => self::get_connection_args( - [ - 'shuffle' => [ + array( + 'shuffle' => array( 'type' => 'Boolean', 'description' => __( 'Shuffle results? (Pagination currently not support by this argument)', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); @@ -93,12 +93,12 @@ static function () { return $resolver->get_connection(); }, - ] + ) ) ); register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'Product', 'fromFieldName' => 'upsell', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -107,14 +107,14 @@ static function () { return $resolver->get_connection(); }, - ] + ) ) ); // Group product children connection. register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => 'GroupProduct', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); @@ -122,32 +122,32 @@ static function () { return $resolver->get_connection(); }, - ] + ) ) ); // Product cross-sell connections. - $cross_sell_config = [ + $cross_sell_config = array( 'fromFieldName' => 'crossSell', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'post__in', $source->cross_sell_ids ); return $resolver->get_connection(); }, - ]; + ); register_graphql_connection( self::get_connection_config( - array_merge( [ 'fromType' => 'SimpleProduct' ], $cross_sell_config ) + array_merge( array( 'fromType' => 'SimpleProduct' ), $cross_sell_config ) ) ); register_graphql_connection( self::get_connection_config( - array_merge( [ 'fromType' => 'VariableProduct' ], $cross_sell_config ) + array_merge( array( 'fromType' => 'VariableProduct' ), $cross_sell_config ) ) ); register_graphql_connection( - [ + array( 'fromType' => 'Product', 'toType' => 'Product', 'fromFieldName' => 'parent', @@ -164,7 +164,7 @@ static function () { return $resolver->one_to_one()->get_connection(); }, - ] + ) ); // From WooCommerce product attributes. @@ -172,17 +172,17 @@ static function () { foreach ( $attributes as $attribute ) { register_graphql_connection( self::get_connection_config( - [ + array( 'fromType' => ucfirst( graphql_format_field_name( $attribute ) ), 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $attribute_meta_key = 'attribute_' . strtolower( preg_replace( '/([A-Z])/', '_$1', $source->taxonomyName ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - $meta_query = [ + $meta_query = array( 'key' => $attribute_meta_key, 'value' => $source->slug, 'compare' => '=', - ]; + ); $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'post_type', 'product_variation' ); @@ -190,7 +190,7 @@ static function () { return $resolver->get_connection(); }, - ] + ) ) ); }//end foreach @@ -202,7 +202,7 @@ static function () { * @return array */ private static function get_product_connected_taxonomies() { - $taxonomies = []; + $taxonomies = array(); $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies( 'objects' ); foreach ( $allowed_taxonomies as $tax_object ) { @@ -232,14 +232,14 @@ public static function set_connection_config( $config ) { $taxonomies = self::get_product_connected_taxonomies(); if ( 'Product' === $to_type && in_array( $from_type, $taxonomies, true ) ) { $config['resolve'] = static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { - $tax_query = [ - [ + $tax_query = array( + array( 'taxonomy' => $source->taxonomyName, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 'field' => 'term_id', 'terms' => $source->term_id, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 'operator' => 'IN', - ], - ]; + ), + ); $resolver = new Product_Connection_Resolver( $source, $args, $context, $info ); $resolver->add_tax_query( $tax_query ); @@ -257,9 +257,9 @@ public static function set_connection_config( $config ) { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'ProductUnion', 'fromFieldName' => 'products', @@ -270,7 +270,7 @@ public static function get_connection_config( $args = [] ): array { return $resolver->get_connection(); }, - ], + ), $args ); } @@ -281,15 +281,15 @@ public static function get_connection_config( $args = [] ): array { * @return array */ public static function get_connection_fields(): array { - return [ - 'found' => [ + return array( + 'found' => array( 'type' => 'Integer', 'description' => __( 'Total products founds', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['pageInfo']['found'] ) ? $source['pageInfo']['found'] : null; }, - ], - ]; + ), + ); } /** @@ -299,153 +299,153 @@ public static function get_connection_fields(): array { * * @return array */ - public static function get_connection_args( $extra_args = [] ): array { - $args = [ - 'slugIn' => [ - 'type' => [ 'list_of' => 'String' ], + public static function get_connection_args( $extra_args = array() ): array { + $args = array( + 'slugIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products with specific slugs.', 'wp-graphql-woocommerce' ), - ], - 'status' => [ + ), + 'status' => array( 'type' => 'String', 'description' => __( 'Limit result set to products assigned a specific status.', 'wp-graphql-woocommerce' ), - ], - 'type' => [ + ), + 'type' => array( 'type' => 'ProductTypesEnum', 'description' => __( 'Limit result set to products assigned a specific type.', 'wp-graphql-woocommerce' ), - ], - 'typeIn' => [ - 'type' => [ 'list_of' => 'ProductTypesEnum' ], + ), + 'typeIn' => array( + 'type' => array( 'list_of' => 'ProductTypesEnum' ), 'description' => __( 'Limit result set to products assigned to a group of specific types.', 'wp-graphql-woocommerce' ), - ], - 'typeNotIn' => [ - 'type' => [ 'list_of' => 'ProductTypesEnum' ], + ), + 'typeNotIn' => array( + 'type' => array( 'list_of' => 'ProductTypesEnum' ), 'description' => __( 'Limit result set to products not assigned to a group of specific types.', 'wp-graphql-woocommerce' ), - ], - 'sku' => [ + ), + 'sku' => array( 'type' => 'String', 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'wp-graphql-woocommerce' ), - ], - 'featured' => [ + ), + 'featured' => array( 'type' => 'Boolean', 'description' => __( 'Limit result set to featured products.', 'wp-graphql-woocommerce' ), - ], - 'category' => [ + ), + 'category' => array( 'type' => 'String', 'description' => __( 'Limit result set to products assigned a specific category name.', 'wp-graphql-woocommerce' ), - ], - 'categoryIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'categoryIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products assigned to a group of specific categories by name.', 'wp-graphql-woocommerce' ), - ], - 'categoryNotIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'categoryNotIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products not assigned to a group of specific categories by name.', 'wp-graphql-woocommerce' ), - ], - 'categoryId' => [ + ), + 'categoryId' => array( 'type' => 'Int', 'description' => __( 'Limit result set to products assigned a specific category name.', 'wp-graphql-woocommerce' ), - ], - 'categoryIdIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'categoryIdIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to products assigned to a specific group of category IDs.', 'wp-graphql-woocommerce' ), - ], - 'categoryIdNotIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'categoryIdNotIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to products not assigned to a specific group of category IDs.', 'wp-graphql-woocommerce' ), - ], - 'tag' => [ + ), + 'tag' => array( 'type' => 'String', 'description' => __( 'Limit result set to products assigned a specific tag name.', 'wp-graphql-woocommerce' ), - ], - 'tagIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'tagIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products assigned to a specific group of tags by name.', 'wp-graphql-woocommerce' ), - ], - 'tagNotIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'tagNotIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products not assigned to a specific group of tags by name.', 'wp-graphql-woocommerce' ), - ], - 'tagId' => [ + ), + 'tagId' => array( 'type' => 'Int', 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'wp-graphql-woocommerce' ), - ], - 'tagIdIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'tagIdIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to products assigned to a specific group of tag IDs.', 'wp-graphql-woocommerce' ), - ], - 'tagIdNotIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'tagIdNotIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to products not assigned to a specific group of tag IDs.', 'wp-graphql-woocommerce' ), - ], - 'shippingClassId' => [ + ), + 'shippingClassId' => array( 'type' => 'Int', 'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'wp-graphql-woocommerce' ), - ], - 'attributes' => [ + ), + 'attributes' => array( 'type' => 'ProductAttributeQueryInput', 'description' => __( 'Limit result set to products with selected global attribute queries.', 'wp-graphql-woocommerce' ), - ], - 'attribute' => [ + ), + 'attribute' => array( 'type' => 'String', 'description' => __( 'Limit result set to products with a specific global product attribute', 'wp-graphql-woocommerce' ), 'deprecationReason' => 'Use attributes instead.', - ], - 'attributeTerm' => [ + ), + 'attributeTerm' => array( 'type' => 'String', 'description' => __( 'Limit result set to products with a specific global product attribute term ID (required an assigned attribute).', 'wp-graphql-woocommerce' ), 'deprecationReason' => 'Use attributes instead.', - ], - 'stockStatus' => [ - 'type' => [ 'list_of' => 'StockStatusEnum' ], + ), + 'stockStatus' => array( + 'type' => array( 'list_of' => 'StockStatusEnum' ), 'description' => __( 'Limit result set to products in stock or out of stock.', 'wp-graphql-woocommerce' ), - ], - 'onSale' => [ + ), + 'onSale' => array( 'type' => 'Boolean', 'description' => __( 'Limit result set to products on sale.', 'wp-graphql-woocommerce' ), - ], - 'minPrice' => [ + ), + 'minPrice' => array( 'type' => 'Float', 'description' => __( 'Limit result set to products based on a minimum price.', 'wp-graphql-woocommerce' ), - ], - 'maxPrice' => [ + ), + 'maxPrice' => array( 'type' => 'Float', 'description' => __( 'Limit result set to products based on a maximum price.', 'wp-graphql-woocommerce' ), - ], - 'search' => [ + ), + 'search' => array( 'type' => 'String', 'description' => __( 'Limit result set to products based on a keyword search.', 'wp-graphql-woocommerce' ), - ], - 'visibility' => [ + ), + 'visibility' => array( 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Limit result set to products with a specific visibility level.', 'wp-graphql-woocommerce' ), - ], - 'taxonomyFilter' => [ + ), + 'taxonomyFilter' => array( 'type' => 'ProductTaxonomyInput', 'description' => __( 'Limit result set with complex set of taxonomy filters.', 'wp-graphql-woocommerce' ), - ], - 'orderby' => [ - 'type' => [ 'list_of' => 'ProductsOrderbyInput' ], + ), + 'orderby' => array( + 'type' => array( 'list_of' => 'ProductsOrderbyInput' ), 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ], - 'supportedTypesOnly' => [ + ), + 'supportedTypesOnly' => array( 'type' => 'Boolean', 'description' => __( 'Limit result types to types supported by WooGraphQL.', 'wp-graphql-woocommerce' ), - ], - 'includeVariations' => [ + ), + 'includeVariations' => array( 'type' => 'Boolean', 'description' => __( 'Include variations in the result set.', 'wp-graphql-woocommerce' ), - ], - 'rating' => [ - 'type' => [ 'list_of' => 'Integer' ], + ), + 'rating' => array( + 'type' => array( 'list_of' => 'Integer' ), 'description' => __( 'Limit result set to products with a specific average rating. Must be between 1 and 5', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); if ( wc_tax_enabled() ) { - $args['taxClass'] = [ + $args['taxClass'] = array( 'type' => 'TaxClassEnum', 'description' => __( 'Limit result set to products with a specific tax class.', 'wp-graphql-woocommerce' ), - ]; + ); } return array_merge( get_wc_cpt_connection_args(), $args, $extra_args ); diff --git a/includes/connection/class-shipping-methods.php b/includes/connection/class-shipping-methods.php index 732dc528c..eba68dcda 100644 --- a/includes/connection/class-shipping-methods.php +++ b/includes/connection/class-shipping-methods.php @@ -35,19 +35,19 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'ShippingMethod', 'fromFieldName' => 'shippingMethods', - 'connectionArgs' => [], + 'connectionArgs' => array(), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], + ), $args ); } diff --git a/includes/connection/class-shipping-zones.php b/includes/connection/class-shipping-zones.php index 33801a8e9..8d60ff4f8 100644 --- a/includes/connection/class-shipping-zones.php +++ b/includes/connection/class-shipping-zones.php @@ -35,19 +35,19 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'ShippingZone', 'fromFieldName' => 'shippingZones', - 'connectionArgs' => [], + 'connectionArgs' => array(), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Shipping_Zone_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], + ), $args ); } @@ -58,6 +58,6 @@ public static function get_connection_config( $args = [] ): array { * @return array */ public static function get_connection_args(): array { - return []; + return array(); } } diff --git a/includes/connection/class-tax-classes.php b/includes/connection/class-tax-classes.php index bb92fe2e6..0d161b95f 100644 --- a/includes/connection/class-tax-classes.php +++ b/includes/connection/class-tax-classes.php @@ -35,19 +35,19 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'TaxClass', 'fromFieldName' => 'taxClasses', - 'connectionArgs' => [], + 'connectionArgs' => array(), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Tax_Class_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], + ), $args ); } @@ -58,6 +58,6 @@ public static function get_connection_config( $args = [] ): array { * @return array */ public static function get_connection_args(): array { - return []; + return array(); } } diff --git a/includes/connection/class-tax-rates.php b/includes/connection/class-tax-rates.php index be9f22535..3a5838350 100644 --- a/includes/connection/class-tax-rates.php +++ b/includes/connection/class-tax-rates.php @@ -35,9 +35,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = [] ): array { + public static function get_connection_config( $args = array() ): array { return array_merge( - [ + array( 'fromType' => 'RootQuery', 'toType' => 'TaxRate', 'fromFieldName' => 'taxRates', @@ -47,7 +47,7 @@ public static function get_connection_config( $args = [] ): array { return $resolver->get_connection(); }, - ], + ), $args ); } @@ -58,23 +58,23 @@ public static function get_connection_config( $args = [] ): array { * @return array */ public static function get_connection_args(): array { - return [ - 'class' => [ + return array( + 'class' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Sort by tax class.', 'wp-graphql-woocommerce' ), - ], - 'postCode' => [ + ), + 'postCode' => array( 'type' => 'String', 'description' => __( 'Filter results by a post code.', 'wp-graphql-woocommerce' ), - ], - 'postCodeIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'postCodeIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Filter results by a group of post codes.', 'wp-graphql-woocommerce' ), - ], - 'orderby' => [ - 'type' => [ 'list_of' => 'TaxRateConnectionOrderbyInput' ], + ), + 'orderby' => array( + 'type' => array( 'list_of' => 'TaxRateConnectionOrderbyInput' ), 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } } diff --git a/includes/connection/class-wc-terms.php b/includes/connection/class-wc-terms.php index 3df79ee87..2c7f65fa7 100644 --- a/includes/connection/class-wc-terms.php +++ b/includes/connection/class-wc-terms.php @@ -55,7 +55,7 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config( $tax_object, - [ + array( 'fromType' => $post_type_object->graphql_single_name, 'toType' => $tax_object->graphql_single_name, 'fromFieldName' => $tax_object->graphql_plural_name, @@ -64,11 +64,11 @@ public static function register_connections() { $term_ids = \wc_get_object_terms( $source->ID, $tax_object->name, 'term_id' ); - $resolver->set_query_arg( 'term_taxonomy_id', ! empty( $term_ids ) ? $term_ids : [ '0' ] ); + $resolver->set_query_arg( 'term_taxonomy_id', ! empty( $term_ids ) ? $term_ids : array( '0' ) ); return $resolver->get_connection(); }, - ] + ) ) ); }//end if @@ -84,7 +84,7 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config( $tax_object, - [ + array( 'fromType' => 'Coupon', 'fromFieldName' => 'productCategories', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { @@ -93,13 +93,13 @@ public static function register_connections() { return $resolver->get_connection(); }, - ] + ) ) ); register_graphql_connection( self::get_connection_config( $tax_object, - [ + array( 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProductCategories', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { @@ -108,23 +108,23 @@ public static function register_connections() { return $resolver->get_connection(); }, - ] + ) ) ); register_graphql_connection( - [ + array( 'fromType' => 'GlobalProductAttribute', 'toType' => 'TermNode', 'queryClass' => 'WP_Term_Query', 'fromFieldName' => 'terms', 'connectionArgs' => self::get_connection_args( - [ - 'orderby' => [ + array( + 'orderby' => array( 'type' => 'ProductAttributesConnectionOrderbyEnum', 'description' => __( 'Field(s) to order terms by. Defaults to \'name\'.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { if ( ! $source->is_taxonomy() ) { @@ -135,7 +135,7 @@ public static function register_connections() { $resolver->set_query_arg( 'slug', $source->get_slugs() ); return $resolver->get_connection(); }, - ] + ) ); } } diff --git a/includes/connection/wc-cpt-connection-args.php b/includes/connection/wc-cpt-connection-args.php index 3a1c38d9d..eefd81f94 100644 --- a/includes/connection/wc-cpt-connection-args.php +++ b/includes/connection/wc-cpt-connection-args.php @@ -14,40 +14,40 @@ * @return array */ function get_wc_cpt_connection_args(): array { - return [ - 'search' => [ + return array( + 'search' => array( 'type' => 'String', 'description' => __( 'Limit results to those matching a string.', 'wp-graphql-woocommerce' ), - ], - 'exclude' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'exclude' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Ensure result set excludes specific IDs.', 'wp-graphql-woocommerce' ), - ], - 'include' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'include' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to specific ids.', 'wp-graphql-woocommerce' ), - ], - 'orderby' => [ - 'type' => [ 'list_of' => 'PostTypeOrderbyInput' ], + ), + 'orderby' => array( + 'type' => array( 'list_of' => 'PostTypeOrderbyInput' ), 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ], - 'dateQuery' => [ + ), + 'dateQuery' => array( 'type' => 'DateQueryInput', 'description' => __( 'Filter the connection based on dates.', 'wp-graphql-woocommerce' ), - ], - 'parent' => [ + ), + 'parent' => array( 'type' => 'Int', 'description' => __( 'Use ID to return only children. Use 0 to return only top-level items.', 'wp-graphql-woocommerce' ), - ], - 'parentIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'parentIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Specify objects whose parent is in an array.', 'wp-graphql-woocommerce' ), - ], - 'parentNotIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'parentNotIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Specify objects whose parent is not in an array.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -58,8 +58,8 @@ function get_wc_cpt_connection_args(): array { * * @return array */ -function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = [] ) { - $args = []; +function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = array() ) { + $args = array(); if ( ! empty( $input['include'] ) ) { $args['post__in'] = $input['include']; } @@ -88,7 +88,7 @@ function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = [] * Map the orderby inputArgs to the WP_Query */ if ( ! empty( $input['orderby'] ) && is_array( $input['orderby'] ) ) { - $args['orderby'] = []; + $args['orderby'] = array(); foreach ( $input['orderby'] as $orderby_input ) { /** @@ -113,7 +113,7 @@ function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = [] /** * These orderby options should not include the order parameter. */ - $post_fields = [ 'post__in', 'post_name__in', 'post_parent__in' ]; + $post_fields = array( 'post__in', 'post_name__in', 'post_parent__in' ); if ( in_array( $orderby_field, $post_fields, true ) ) { $args['orderby'][ $orderby_field ] = $orderby_order; diff --git a/includes/data/class-db-hooks.php b/includes/data/class-db-hooks.php index a3892c67c..9ef3d8e6b 100644 --- a/includes/data/class-db-hooks.php +++ b/includes/data/class-db-hooks.php @@ -18,7 +18,7 @@ class DB_Hooks { * DB_Hooks constructor. */ public function __construct() { - add_filter( 'woocommerce_orders_table_query_clauses', [ $this, 'add_cursor' ], 10, 3 ); + add_filter( 'woocommerce_orders_table_query_clauses', array( $this, 'add_cursor' ), 10, 3 ); } /** diff --git a/includes/data/connection/class-cart-item-connection-resolver.php b/includes/data/connection/class-cart-item-connection-resolver.php index c176062f1..43e5cfebf 100644 --- a/includes/data/connection/class-cart-item-connection-resolver.php +++ b/includes/data/connection/class-cart-item-connection-resolver.php @@ -44,7 +44,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = [ 'filters' => [] ]; + $query_args = array( 'filters' => array() ); if ( ! empty( $this->args['where'] ) ) { $where_args = $this->args['where']; if ( isset( $where_args['needsShipping'] ) ) { @@ -102,7 +102,7 @@ public function get_query() { * {@inheritDoc} */ public function get_ids_from_query() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** diff --git a/includes/data/connection/class-coupon-connection-resolver.php b/includes/data/connection/class-coupon-connection-resolver.php index 16d4ddd2b..f3e188c62 100644 --- a/includes/data/connection/class-coupon-connection-resolver.php +++ b/includes/data/connection/class-coupon-connection-resolver.php @@ -104,7 +104,7 @@ public function get_query_args() { $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; // Set the $query_args based on various defaults and primary input $args. - $query_args = [ + $query_args = array( 'post_type' => 'shop_coupon', 'post_status' => 'any', 'perm' => 'readable', @@ -113,7 +113,7 @@ public function get_query_args() { // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'posts_per_page' => min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1, 'post_parent' => 0, - ]; + ); /** * Set the cursor args. @@ -140,7 +140,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = []; + $input_fields = array(); if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -195,7 +195,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query->posts ) ? $this->query->posts : []; + return ! empty( $this->query->posts ) ? $this->query->posts : array(); } /** @@ -207,10 +207,10 @@ public function get_ids() { */ public function ordering_meta( $is_numeric = true ) { if ( ! $is_numeric ) { - return apply_filters( 'woographql_coupon_connection_orderby_meta_keys', [] ); + return apply_filters( 'woographql_coupon_connection_orderby_meta_keys', array() ); } - return apply_filters( 'woographql_coupon_connection_orderby_numeric_meta_keys', [] ); + return apply_filters( 'woographql_coupon_connection_orderby_numeric_meta_keys', array() ); } /** @@ -228,7 +228,7 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $where_args['code'] ) ) { $id = \wc_get_coupon_id_by_code( $where_args['code'] ); - $ids = $id ? [ $id ] : [ '0' ]; + $ids = $id ? array( $id ) : array( '0' ); $args['post__in'] = isset( $args['post__in'] ) ? array_intersect( $ids, $args['post__in'] ) : $ids; diff --git a/includes/data/connection/class-customer-connection-resolver.php b/includes/data/connection/class-customer-connection-resolver.php index 5b3d9ee8e..f82c0a5c6 100644 --- a/includes/data/connection/class-customer-connection-resolver.php +++ b/includes/data/connection/class-customer-connection-resolver.php @@ -50,7 +50,7 @@ public function get_query_args() { * Prepare for later use */ $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; - $query_args = []; + $query_args = array(); /** * Set the $query_args based on various defaults and primary input $args @@ -69,7 +69,7 @@ public function get_query_args() { $query_args['graphql_before_cursor'] = $this->get_before_offset(); $query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<'; - $input_fields = []; + $input_fields = array(); if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -97,15 +97,15 @@ public function get_query_args() { * Map the orderby inputArgs to the WP_User_Query */ if ( ! empty( $this->args['where']['orderby'] ) && is_array( $this->args['where']['orderby'] ) ) { - $query_args['orderby'] = []; + $query_args['orderby'] = array(); foreach ( $this->args['where']['orderby'] as $orderby_input ) { /** * These orderby options should not include the order parameter. */ - if ( in_array( $orderby_input['field'], [ 'login__in', 'nicename__in' ], true ) ) { + if ( in_array( $orderby_input['field'], array( 'login__in', 'nicename__in' ), true ) ) { $query_args['orderby'] = esc_sql( $orderby_input['field'] ); } elseif ( ! empty( $orderby_input['field'] ) ) { - $query_args['orderby'] = [ $orderby_input['field'] => $orderby_input['order'] ]; + $query_args['orderby'] = array( $orderby_input['field'] => $orderby_input['order'] ); } } } @@ -115,10 +115,10 @@ public function get_query_args() { * graphql_wp_term_query_cursor_pagination_support knowns how to handle */ if ( isset( $query_args['orderby'] ) && 'meta_value_num' === $query_args['orderby'] ) { - $query_args['orderby'] = [ + $query_args['orderby'] = array( //phpcs:ignore WordPress.DB.SlowDBQuery 'meta_value' => empty( $query_args['order'] ) ? 'DESC' : $query_args['order'], - ]; + ); unset( $query_args['order'] ); $query_args['meta_type'] = 'NUMERIC'; } @@ -166,7 +166,7 @@ public function get_query() { */ public function get_ids() { $results = $this->get_query()->get_results(); - return ! empty( $results ) ? $results : []; + return ! empty( $results ) ? $results : array(); } /** @@ -180,16 +180,16 @@ public function get_ids() { * @return array */ public function sanitize_input_fields( array $where_args ) { - $args = []; + $args = array(); - $key_mapping = [ + $key_mapping = array( 'search' => 'search', 'exclude' => 'exclude', 'include' => 'include', 'role' => 'role', 'roleIn' => 'role__in', 'roleNotIn' => 'role__not_in', - ]; + ); foreach ( $key_mapping as $key => $field ) { if ( ! empty( $where_args[ $key ] ) ) { @@ -200,7 +200,7 @@ public function sanitize_input_fields( array $where_args ) { // Filter by email. if ( ! empty( $where_args['email'] ) ) { $args['search'] = $where_args['email']; - $args['search_columns'] = [ 'user_email' ]; + $args['search_columns'] = array( 'user_email' ); } /** diff --git a/includes/data/connection/class-downloadable-item-connection-resolver.php b/includes/data/connection/class-downloadable-item-connection-resolver.php index a21496026..d44140c1f 100644 --- a/includes/data/connection/class-downloadable-item-connection-resolver.php +++ b/includes/data/connection/class-downloadable-item-connection-resolver.php @@ -45,7 +45,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = [ 'filters' => [] ]; + $query_args = array( 'filters' => array() ); if ( ! empty( $this->args['where'] ) ) { $where_args = $this->args['where']; if ( isset( $where_args['active'] ) ) { @@ -116,7 +116,7 @@ public function get_query() { } if ( empty( $items ) ) { - return []; + return array(); } if ( ! empty( $this->query_args['filters'] ) && is_array( $this->query_args['filters'] ) ) { @@ -139,7 +139,7 @@ public function get_query() { * @return array */ public function get_ids_from_query() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** diff --git a/includes/data/connection/class-order-connection-resolver.php b/includes/data/connection/class-order-connection-resolver.php index 716336670..f6fcace55 100644 --- a/includes/data/connection/class-order-connection-resolver.php +++ b/includes/data/connection/class-order-connection-resolver.php @@ -127,12 +127,12 @@ public function get_query_args() { $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; // Set the $query_args based on various defaults and primary input $args. - $query_args = [ + $query_args = array( 'post_type' => $this->post_type, 'no_rows_found' => true, 'return' => 'ids', 'limit' => min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1, - ]; + ); /** * Set posts_per_page the highest value of $first and $last, with a (filterable) max of 100 @@ -162,7 +162,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = []; + $input_fields = array(); if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -176,7 +176,7 @@ public function get_query_args() { */ if ( empty( $query_args['orderby'] ) ) { $query_args['order'] = ! empty( $last ) ? 'ASC' : 'DESC'; - $query_args['orderby'] = [ 'date' => $query_args['order'] ]; + $query_args['orderby'] = array( 'date' => $query_args['order'] ); } /** @@ -216,7 +216,7 @@ public function get_query() { * {@inheritDoc} */ public function get_ids_from_query() { - $ids = ! empty( $this->query->get_orders() ) ? $this->query->get_orders() : []; + $ids = ! empty( $this->query->get_orders() ) ? $this->query->get_orders() : array(); // If we're going backwards, we need to reverse the array. if ( ! empty( $this->args['last'] ) ) { @@ -237,21 +237,21 @@ public function ordering_meta( $is_numeric = true ) { if ( ! $is_numeric ) { return apply_filters( 'woographql_order_connection_orderby_meta_keys', - [ + array( '_order_key', '_date_paid', '_date_completed', - ] + ) ); } return apply_filters( 'woographql_order_connection_orderby_numeric_meta_keys', - [ + array( '_cart_discount', '_order_total', '_order_tax', - ] + ) ); } @@ -269,11 +269,11 @@ public function sanitize_input_fields( array $where_args ) { global $wpdb; $args = $this->sanitize_common_inputs( $where_args ); - $key_mapping = [ + $key_mapping = array( 'post_parent' => 'parent', 'post_parent__not_in' => 'parent_exclude', 'post__not_in' => 'exclude', - ]; + ); foreach ( $key_mapping as $key => $field ) { if ( isset( $args[ $key ] ) ) { @@ -300,7 +300,7 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $where_args['billingEmail'] ) ) { $billing_email = $where_args['billingEmail']; $args['customer'] = ! empty( $args['customer'] ) - ? array_merge( $args['customer'], [ $billing_email ] ) + ? array_merge( $args['customer'], array( $billing_email ) ) : $billing_email; } @@ -318,7 +318,7 @@ public function sanitize_input_fields( array $where_args ) { ); // Force WP_Query return empty if don't found any order. - $args['post__in'] = ! empty( $order_ids ) ? $order_ids : [ 0 ]; + $args['post__in'] = ! empty( $order_ids ) ? $order_ids : array( 0 ); } // Search. diff --git a/includes/data/connection/class-order-item-connection-resolver.php b/includes/data/connection/class-order-item-connection-resolver.php index 93f47c9f8..d47c2fc9d 100644 --- a/includes/data/connection/class-order-item-connection-resolver.php +++ b/includes/data/connection/class-order-item-connection-resolver.php @@ -40,7 +40,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = [ 'filters' => [] ]; + $query_args = array( 'filters' => array() ); /** * Filter the $query_args to allow folks to customize queries programmatically. @@ -97,13 +97,13 @@ public function get_query() { break; }//end switch - $items = []; + $items = array(); foreach ( $this->source->get_items( $type ) as $item ) { $items[] = $item; } if ( empty( $items ) ) { - return []; + return array(); } if ( ! empty( $this->query_args['filters'] ) && is_array( $this->query_args['filters'] ) ) { @@ -158,7 +158,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** diff --git a/includes/data/connection/class-payment-gateway-connection-resolver.php b/includes/data/connection/class-payment-gateway-connection-resolver.php index b7be294dc..0e2447f04 100644 --- a/includes/data/connection/class-payment-gateway-connection-resolver.php +++ b/includes/data/connection/class-payment-gateway-connection-resolver.php @@ -41,7 +41,7 @@ public function resolve( $source, array $args, AppContext $context, ResolveInfo } $connection = Relay::connectionFromArray( array_values( $gateways ), $args ); - $nodes = []; + $nodes = array(); if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; diff --git a/includes/data/connection/class-product-attribute-connection-resolver.php b/includes/data/connection/class-product-attribute-connection-resolver.php index 5b3af9b83..23d39cd1d 100644 --- a/includes/data/connection/class-product-attribute-connection-resolver.php +++ b/includes/data/connection/class-product-attribute-connection-resolver.php @@ -35,7 +35,7 @@ class Product_Attribute_Connection_Resolver { * @return array */ private function get_items( $attributes, $source, $args, $context, $info, $type = null ) { - $items = []; + $items = array(); foreach ( $attributes as $attribute_name => $data ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $data->_relay_id = base64_encode( @@ -91,7 +91,7 @@ public function resolve( $source, array $args, AppContext $context, ResolveInfo $attributes = $this->get_items( $source->attributes, $source, $args, $context, $info, $type ); $connection = Relay::connectionFromArray( $attributes, $args ); - $nodes = []; + $nodes = array(); if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; diff --git a/includes/data/connection/class-product-connection-resolver.php b/includes/data/connection/class-product-connection-resolver.php index 8a7c44460..91d21928d 100644 --- a/includes/data/connection/class-product-connection-resolver.php +++ b/includes/data/connection/class-product-connection-resolver.php @@ -88,7 +88,7 @@ public function get_query_args() { $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; - $query_args = []; + $query_args = array(); /** * Ignore sticky posts by default */ @@ -107,7 +107,7 @@ public function get_query_args() { /** * Set the post_status */ - $query_args['post_status'] = [ 'draft', 'pending', 'private', 'publish' ]; + $query_args['post_status'] = array( 'draft', 'pending', 'private', 'publish' ); $query_args['perm'] = 'readable'; /** @@ -140,7 +140,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = []; + $input_fields = array(); if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -208,10 +208,10 @@ public function get_query_args() { $query_args['graphql_cursor_compare_by_rating_value'] = $offset_product->get_average_rating(); $query_args['graphql_cursor_compare_by_rating_key'] = 'wc_product_meta_lookup.average_rating'; } elseif ( $offset_product && 'menu_order title' === $query_args['orderby'] ) { - $query_args['orderby'] = [ + $query_args['orderby'] = array( 'menu_order' => $query_args['order'], 'post_title' => isset( $this->args['last'] ) ? 'ASC' : 'DESC', - ]; + ); unset( $query_args['order'] ); } @@ -237,13 +237,13 @@ public function get_query_args() { * {@inheritDoc} */ public function get_query() { - add_filter( 'posts_clauses', [ $this->products_query, 'add_query_clauses' ], 10, 2 ); + add_filter( 'posts_clauses', array( $this->products_query, 'add_query_clauses' ), 10, 2 ); // Temporary fix for the search query. if ( ! empty( $this->query_args['search'] ) ) { $this->query_args['fulltext_search'] = $this->query_args['search']; unset( $this->query_args['search'] ); - add_filter( 'posts_clauses', [ $this, 'add_search_query_clause' ], 10, 2 ); + add_filter( 'posts_clauses', array( $this, 'add_search_query_clause' ), 10, 2 ); } return new \WP_Query(); @@ -257,10 +257,10 @@ public function get_ids_from_query() { $ids = $this->query->query( $this->query_args ); if ( ! empty( $this->query_args['fulltext_search'] ) ) { - remove_filter( 'posts_clauses', [ $this, 'add_search_query_clause' ], 10 ); + remove_filter( 'posts_clauses', array( $this, 'add_search_query_clause' ), 10 ); } - remove_filter( 'posts_clauses', [ $this->products_query, 'add_query_clauses' ], 10 ); + remove_filter( 'posts_clauses', array( $this->products_query, 'add_query_clauses' ), 10 ); // If we're going backwards, we need to reverse the array. if ( ! empty( $this->args['last'] ) ) { @@ -281,17 +281,17 @@ public function ordering_meta( $is_numeric = true ) { if ( ! $is_numeric ) { return apply_filters( 'woographql_product_connection_orderby_meta_keys', - [] + array() ); } return apply_filters( 'woographql_product_connection_orderby_numeric_meta_keys', - [ + array( '_sale_price_dates_from', '_sale_price_dates_to', 'total_sales', - ] + ) ); } @@ -332,7 +332,7 @@ public function add_search_query_clause( $args, $wp_query ) { public function sanitize_input_fields( array $where_args ) { $query_args = Utils::map_input( $where_args, - [ + array( 'slugIn' => 'post_name__in', 'minPrice' => 'min_price', 'maxPrice' => 'max_price', @@ -345,7 +345,7 @@ public function sanitize_input_fields( array $where_args ) { 'parentNotIn' => 'post_parent__not_in', 'search' => 'search', - ] + ) ); if ( ! empty( $where_args['orderby'] ) ) { @@ -362,11 +362,11 @@ public function sanitize_input_fields( array $where_args ) { } if ( isset( $where_args['includeVariations'] ) && $where_args['includeVariations'] ) { - $query_args['post_type'] = [ 'product', 'product_variation' ]; + $query_args['post_type'] = array( 'product', 'product_variation' ); } - $tax_query = []; - $taxonomy_args = [ + $tax_query = array(); + $taxonomy_args = array( 'type' => 'product_type', 'typeIn' => 'product_type', 'typeNotIn' => 'product_type', @@ -382,7 +382,7 @@ public function sanitize_input_fields( array $where_args ) { 'tagId' => 'product_tag', 'tagIdIn' => 'product_tag', 'tagIdNotIn' => 'product_tag', - ]; + ); foreach ( $taxonomy_args as $field => $taxonomy ) { if ( ! empty( $where_args[ $field ] ) ) { @@ -401,27 +401,27 @@ public function sanitize_input_fields( array $where_args ) { case 'type': // If the type is variation, we only need to set the post_type arg. if ( 'variation' === $where_args[ $field ] ) { - $query_args['post_type'] = [ 'product_variation' ]; + $query_args['post_type'] = array( 'product_variation' ); break; } // Otherwise continue to create a tax query. case 'typeIn': if ( is_array( $where_args[ $field ] ) && in_array( 'variation', $where_args[ $field ], true ) ) { - $query_args['post_type'] = array_merge( $this->post_type, [ 'product_variation' ] ); + $query_args['post_type'] = array_merge( $this->post_type, array( 'product_variation' ) ); } - $tax_query[] = [ // phpcs:ignore SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed.DisallowedPartiallyKeyed + $tax_query[] = array( // phpcs:ignore SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed.DisallowedPartiallyKeyed 'relation' => 'OR', - [ + array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $where_args[ $field ], - ], - [ + ), + array( 'taxonomy' => 'product_type', 'field' => 'id', 'operator' => 'NOT EXISTS', - ], - ]; + ), + ); break; case 'typeNotIn': case 'category': @@ -433,11 +433,11 @@ public function sanitize_input_fields( array $where_args ) { // Get terms. $terms = $where_args[ $field ]; if ( ! is_array( $terms ) ) { - $terms = [ $terms ]; + $terms = array( $terms ); } // Get term taxonomy IDs for complex tax queries. - $term_taxonomy_ids = []; + $term_taxonomy_ids = array(); foreach ( $terms as $term_slug ) { $term = get_term_by( 'slug', $term_slug, $taxonomy ); if ( ! $term || is_wp_error( $term ) ) { @@ -445,12 +445,12 @@ public function sanitize_input_fields( array $where_args ) { } $term_taxonomy_ids[] = $term->term_taxonomy_id; } - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => $taxonomy, 'field' => 'term_taxonomy_id', 'terms' => $term_taxonomy_ids, 'operator' => $operator, - ]; + ); break; case 'categoryId': case 'categoryIdIn': @@ -458,12 +458,12 @@ public function sanitize_input_fields( array $where_args ) { case 'tagId': case 'tagIdIn': case 'tagIdNotIn': - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $where_args[ $field ], 'operator' => $operator, - ]; + ); break; }//end switch }//end if @@ -475,18 +475,18 @@ public function sanitize_input_fields( array $where_args ) { __( 'The "attribute" and "attributeTerm" arguments have been deprecated. Please use the "attributes" argument instead.', 'wp-graphql-woocommerce' ), ); if ( in_array( $where_args['attribute'], \wc_get_attribute_taxonomy_names(), true ) ) { - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => $where_args['attribute'], 'field' => 'slug', 'terms' => $where_args['attributeTerm'], - ]; + ); } } // Filter by attributes. if ( ! empty( $where_args['attributes'] ) && ! empty( $where_args['attributes']['queries'] ) ) { $attributes = $where_args['attributes']['queries']; - $att_queries = []; + $att_queries = array(); foreach ( $attributes as $attribute ) { if ( empty( $attribute['ids'] ) && empty( $attribute['terms'] ) ) { @@ -501,23 +501,23 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $attribute['terms'] ) ) { foreach ( $attribute['terms'] as $term ) { - $att_queries[] = [ + $att_queries[] = array( 'taxonomy' => $attribute['taxonomy'], 'field' => 'slug', 'terms' => $term, 'operator' => $operator, - ]; + ); } } if ( ! empty( $attribute['ids'] ) ) { foreach ( $attribute['ids'] as $id ) { - $att_queries[] = [ + $att_queries[] = array( 'taxonomy' => $attribute['taxonomy'], 'field' => 'term_id', 'terms' => $id, 'operator' => $operator, - ]; + ); } } } @@ -530,7 +530,7 @@ public function sanitize_input_fields( array $where_args ) { } $tax_query[] = array_merge( - [ 'relation' => $relation ], + array( 'relation' => $relation ), $att_queries ); } else { @@ -544,34 +544,34 @@ public function sanitize_input_fields( array $where_args ) { $terms = ! empty( $where_args['typeNotIn'] ) ? array_diff( $supported_types, $where_args['typeNotIn'] ) : $supported_types; - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $terms, - ]; + ); } if ( isset( $where_args['featured'] ) ) { $product_visibility_term_ids = wc_get_product_visibility_term_ids(); if ( $where_args['featured'] ) { - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => [ $product_visibility_term_ids['featured'] ], - ]; - $tax_query[] = [ + 'terms' => array( $product_visibility_term_ids['featured'] ), + ); + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => [ $product_visibility_term_ids['exclude-from-catalog'] ], + 'terms' => array( $product_visibility_term_ids['exclude-from-catalog'] ), 'operator' => 'NOT IN', - ]; + ); } else { - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => [ $product_visibility_term_ids['featured'] ], + 'terms' => array( $product_visibility_term_ids['featured'] ), 'operator' => 'NOT IN', - ]; + ); } }//end if @@ -579,84 +579,84 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $where_args['visibility'] ) ) { switch ( $where_args['visibility'] ) { case 'search': - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => [ 'exclude-from-search' ], + 'terms' => array( 'exclude-from-search' ), 'operator' => 'NOT IN', - ]; + ); break; case 'catalog': - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => [ 'exclude-from-catalog' ], + 'terms' => array( 'exclude-from-catalog' ), 'operator' => 'NOT IN', - ]; + ); break; case 'visible': - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], + 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), 'operator' => 'NOT IN', - ]; + ); break; case 'hidden': - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], + 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), 'operator' => 'AND', - ]; + ); break; }//end switch }//end if if ( ! empty( $where_args['rating'] ) ) { $rating = $where_args['rating']; - $rating_terms = []; + $rating_terms = array(); foreach ( $rating as $value ) { $rating_terms[] = 'rated-' . $value; } - $tax_query[] = [ + $tax_query[] = array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => $rating_terms, - ]; + ); } // Process "taxonomyFilter". - $tax_filter_query = []; + $tax_filter_query = array(); if ( ! empty( $where_args['taxonomyFilter'] ) ) { $taxonomy_query = $where_args['taxonomyFilter']; $relation = ! empty( $taxonomy_query['relation'] ) ? $taxonomy_query['relation'] : 'AND'; if ( ! empty( $taxonomy_query['filters'] ) ) { - $tax_groups = []; + $tax_groups = array(); foreach ( $taxonomy_query['filters'] as $filter ) { - $common = [ + $common = array( 'taxonomy' => $filter['taxonomy'], 'operator' => ! empty( $filter['operator'] ) ? $filter['operator'] : 'IN', - ]; + ); if ( ! empty( $filter['ids'] ) ) { $tax_groups[] = array_merge( $common, - [ + array( 'field' => 'ID', 'terms' => $filter['ids'], - ] + ) ); } if ( ! empty( $filter['terms'] ) ) { $tax_groups[] = array_merge( $common, - [ + array( 'field' => 'slug', 'terms' => $filter['terms'], - ] + ) ); } }//end foreach @@ -684,13 +684,13 @@ public function sanitize_input_fields( array $where_args ) { $query_args['tax_query'] = $tax_query; } - $meta_query = []; + $meta_query = array(); if ( ! empty( $where_args['sku'] ) ) { - $meta_query[] = [ + $meta_query[] = array( 'key' => '_sku', 'value' => $where_args['sku'], 'compare' => 'LIKE', - ]; + ); } if ( ! empty( $where_args['minPrice'] ) ) { $query_args['min_price'] = number_format( $where_args['minPrice'], 2, '', '' ); @@ -701,11 +701,11 @@ public function sanitize_input_fields( array $where_args ) { } if ( isset( $where_args['stockStatus'] ) ) { - $meta_query[] = [ + $meta_query[] = array( 'key' => '_stock_status', 'value' => $where_args['stockStatus'], 'compare' => is_array( $where_args['stockStatus'] ) ? 'IN' : '=', - ]; + ); } if ( ! empty( $meta_query ) ) { @@ -717,7 +717,7 @@ public function sanitize_input_fields( array $where_args ) { $on_sale_key = $where_args['onSale'] ? 'post__in' : 'post__not_in'; $on_sale_ids = \wc_get_product_ids_on_sale(); - $on_sale_ids = empty( $on_sale_ids ) ? [ 0 ] : $on_sale_ids; + $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; $query_args[ $on_sale_key ] = $on_sale_ids; } @@ -750,7 +750,7 @@ public function sanitize_input_fields( array $where_args ) { */ $query_args = apply_filters_deprecated( 'graphql_map_input_fields_to_product_query', - [ + array( $query_args, $where_args, $this->source, @@ -758,7 +758,7 @@ public function sanitize_input_fields( array $where_args ) { $this->context, $this->info, $this->post_type, - ], + ), '0.9.0', 'graphql_map_input_fields_to_wp_query' ); diff --git a/includes/data/connection/class-shipping-method-connection-resolver.php b/includes/data/connection/class-shipping-method-connection-resolver.php index 0d8b2829b..69291e52f 100644 --- a/includes/data/connection/class-shipping-method-connection-resolver.php +++ b/includes/data/connection/class-shipping-method-connection-resolver.php @@ -47,7 +47,7 @@ public function should_execute() { */ public function get_query_args() { // TODO: Implement get_query_args() method. - return []; + return array(); } /** @@ -79,7 +79,7 @@ public function get_query() { * @return array */ public function get_ids_from_query() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** diff --git a/includes/data/connection/class-shipping-zone-connection-resolver.php b/includes/data/connection/class-shipping-zone-connection-resolver.php index 80f6b6e1a..6bb664290 100644 --- a/includes/data/connection/class-shipping-zone-connection-resolver.php +++ b/includes/data/connection/class-shipping-zone-connection-resolver.php @@ -50,7 +50,7 @@ public function should_execute() { * @return array|void */ public function get_query_args() { - return []; + return array(); } /** @@ -80,7 +80,7 @@ public function get_query() { * @return array */ public function get_ids_from_query() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** diff --git a/includes/data/connection/class-tax-class-connection-resolver.php b/includes/data/connection/class-tax-class-connection-resolver.php index b04f382c3..da818ee57 100644 --- a/includes/data/connection/class-tax-class-connection-resolver.php +++ b/includes/data/connection/class-tax-class-connection-resolver.php @@ -46,7 +46,7 @@ public function should_execute() { * @return array|void */ public function get_query_args() { - return []; + return array(); } /** @@ -55,21 +55,21 @@ public function get_query_args() { * @return array|mixed|string[] */ public function get_query() { - $tax_classes = []; + $tax_classes = array(); // Add standard class. - $tax_classes[] = [ + $tax_classes[] = array( 'slug' => 'standard', 'name' => __( 'Standard rate', 'wp-graphql-woocommerce' ), - ]; + ); $classes = \WC_Tax::get_tax_classes(); foreach ( $classes as $class ) { - $tax_classes[] = [ + $tax_classes[] = array( 'slug' => sanitize_title( $class ), 'name' => $class, - ]; + ); } // Cache cart items for later. @@ -86,7 +86,7 @@ public function get_query() { * @return array */ public function get_ids_from_query() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** diff --git a/includes/data/connection/class-tax-rate-connection-resolver.php b/includes/data/connection/class-tax-rate-connection-resolver.php index 59205ea2e..3ea3afa01 100644 --- a/includes/data/connection/class-tax-rate-connection-resolver.php +++ b/includes/data/connection/class-tax-rate-connection-resolver.php @@ -50,7 +50,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = []; + $query_args = array(); // Prepare for later use. $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; @@ -59,7 +59,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = []; + $input_fields = array(); if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -160,7 +160,7 @@ static function ( $rate ) { * @return array */ public function get_ids() { - return ! empty( $this->query ) ? $this->query : []; + return ! empty( $this->query ) ? $this->query : array(); } /** @@ -174,13 +174,13 @@ public function get_ids() { * @return array */ public function sanitize_input_fields( array $where_args ) { - $args = []; + $args = array(); if ( ! empty( $where_args['orderby'] ) ) { if ( ! empty( $where_args['orderby']['field'] ) ) { - $orderby_possibles = [ + $orderby_possibles = array( 'id' => 'tax_rate_id', 'order' => 'tax_rate_order', - ]; + ); $args['orderby'] = $orderby_possibles[ $where_args['orderby']['field'] ]; } diff --git a/includes/data/connection/class-variation-attribute-connection-resolver.php b/includes/data/connection/class-variation-attribute-connection-resolver.php index 1a975c89d..f1fdd9059 100644 --- a/includes/data/connection/class-variation-attribute-connection-resolver.php +++ b/includes/data/connection/class-variation-attribute-connection-resolver.php @@ -29,7 +29,7 @@ class Variation_Attribute_Connection_Resolver { * @return array */ public static function product_attributes_to_data_array( $attrs, $product_id ) { - $attributes = []; + $attributes = array(); foreach ( $attrs as $attribute ) { if ( ! is_a( $attribute, 'WC_Product_Attribute' ) ) { @@ -39,26 +39,26 @@ public static function product_attributes_to_data_array( $attrs, $product_id ) { if ( $attribute->is_taxonomy() ) { $attribute_taxonomy = $attribute->get_taxonomy_object(); - $attribute_values = wc_get_product_terms( $product_id, $attribute->get_name(), [ 'fields' => 'all' ] ); + $attribute_values = wc_get_product_terms( $product_id, $attribute->get_name(), array( 'fields' => 'all' ) ); foreach ( $attribute_values as $attribute_value ) { $id = base64_encode( $product_id . '|' . $name . '|' . $attribute_value->name ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode - $attributes[] = [ + $attributes[] = array( 'id' => $id, 'attributeId' => $attribute_value->term_id, 'name' => $name, 'value' => $attribute_value->name, - ]; + ); } } else { $values = $attribute->get_options(); foreach ( $values as $attribute_value ) { $id = base64_encode( $product_id . '|' . $name . '|' . $attribute_value ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode - $attributes[] = [ + $attributes[] = array( 'id' => $id, 'attributeId' => 0, 'name' => $name, 'value' => $attribute_value, - ]; + ); } }//end if }//end foreach @@ -75,10 +75,10 @@ public static function product_attributes_to_data_array( $attrs, $product_id ) { * @return array */ public static function variation_attributes_to_data_array( $attrs, $variation_id ) { - $attributes = []; + $attributes = array(); // Bail early if explicitly '0' attributes. - if ( [ '0' ] === $attrs ) { + if ( array( '0' ) === $attrs ) { return $attributes; } @@ -90,19 +90,19 @@ public static function variation_attributes_to_data_array( $attrs, $variation_id $id = base64_encode( $variation_id . '||' . $name . '||' . $value ); if ( ! $term instanceof \WP_Term ) { - $attributes[] = [ + $attributes[] = array( 'id' => $id, 'attributeId' => 0, 'name' => $name, 'value' => $value, - ]; + ); } else { - $attributes[] = [ + $attributes[] = array( 'id' => $id, 'attributeId' => $term->term_id, 'name' => $term->taxonomy, 'value' => $term->slug, - ]; + ); } }//end foreach @@ -130,7 +130,7 @@ public function resolve( $source, array $args, AppContext $context, ResolveInfo } $connection = Relay::connectionFromArray( $attributes, $args ); - $nodes = []; + $nodes = array(); if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; diff --git a/includes/data/connection/trait-wc-cpt-loader-common.php b/includes/data/connection/trait-wc-cpt-loader-common.php index 88846d01e..1d38bf96a 100644 --- a/includes/data/connection/trait-wc-cpt-loader-common.php +++ b/includes/data/connection/trait-wc-cpt-loader-common.php @@ -45,21 +45,21 @@ public function is_valid_post_offset( $offset ) { public function sanitize_common_inputs( array $input ) { $args = Utils::map_input( $input, - [ + array( 'include' => 'post__in', 'exclude' => 'post__not_in', 'parent' => 'post_parent', 'parentIn' => 'post_parent__in', 'parentNotIn' => 'post_parent__not_in', 'search' => 's', - ] + ) ); /** * Map the orderby inputArgs to the WP_Query */ if ( ! empty( $input['orderby'] ) && is_array( $input['orderby'] ) ) { - $args['orderby'] = []; + $args['orderby'] = array(); foreach ( $input['orderby'] as $orderby_input ) { /** * Stores orderby field @@ -83,7 +83,7 @@ public function sanitize_common_inputs( array $input ) { /** * These orderby options should not include the order parameter. */ - $post_fields = [ 'post__in', 'post_name__in', 'post_parent__in' ]; + $post_fields = array( 'post__in', 'post_name__in', 'post_parent__in' ); if ( in_array( $orderby_field, $post_fields, true ) ) { $args['orderby'][ $orderby_field ] = $orderby_order; diff --git a/includes/data/cursor/class-cot-cursor.php b/includes/data/cursor/class-cot-cursor.php index 18f0c8da5..9dddbdd97 100644 --- a/includes/data/cursor/class-cot-cursor.php +++ b/includes/data/cursor/class-cot-cursor.php @@ -79,7 +79,7 @@ public function __construct( $query_vars, $query, $cursor = 'after' ) { $order_datastore = wc_get_container()->get( OrdersTableDataStore::class ); $this->tables = $order_datastore::get_all_table_names_with_id(); $mappings = $order_datastore->get_all_order_column_mappings(); - $this->column_mappings = []; + $this->column_mappings = array(); foreach ( $mappings['orders'] as $column => $meta_value ) { $this->column_mappings[ "{$this->tables['orders']}.{$column}" ] = $meta_value['name']; } @@ -114,11 +114,11 @@ public function to_sql() { $orderby_should_not_convert_to_sql = isset( $orderby ) && in_array( $orderby, - [ + array( 'include', 'id', 'parent_order_id', - ], + ), true ); @@ -188,7 +188,7 @@ private function compare_with( $by, $order ) { return; } - $meta_orderby_keys = $this->meta_query ? $this->meta_query->get_orderby_keys() : []; + $meta_orderby_keys = $this->meta_query ? $this->meta_query->get_orderby_keys() : array(); if ( in_array( $by, $meta_orderby_keys, true ) && null !== $this->meta_query ) { $orderby = $this->meta_query->get_orderby_clause_for_key( $by ); @@ -198,7 +198,7 @@ private function compare_with( $by, $order ) { $getter_name = $this->column_mappings[ $orderby ]; $method = "get_{$getter_name}"; - $value = is_callable( [ $this->cursor_node, $method ] ) ? $this->cursor_node->$method() : null; + $value = is_callable( array( $this->cursor_node, $method ) ) ? $this->cursor_node->$method() : null; } if ( ! empty( $value ) && is_a( $value, '\WC_DateTime' ) ) { diff --git a/includes/data/loader/class-wc-cpt-loader.php b/includes/data/loader/class-wc-cpt-loader.php index 01feb5b89..162b5f9cf 100644 --- a/includes/data/loader/class-wc-cpt-loader.php +++ b/includes/data/loader/class-wc-cpt-loader.php @@ -88,7 +88,7 @@ public function loadKeys( array $keys ) { * to the count of the keys provided. The query must also return results * in the same order the keys were provided in. */ - $args = [ + $args = array( 'post_type' => $wc_post_types, 'post_status' => 'any', //phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page @@ -98,7 +98,7 @@ public function loadKeys( array $keys ) { 'no_found_rows' => true, 'split_the_query' => false, 'ignore_sticky_posts' => true, - ]; + ); /** * Ensure that WP_Query doesn't first ask for IDs since we already have them. @@ -116,7 +116,7 @@ static function ( $split, \WP_Query $query ) { ); new \WP_Query( $args ); - $loaded_posts = []; + $loaded_posts = array(); /** * Loop over the posts and return an array of all_posts, diff --git a/includes/data/loader/class-wc-customer-loader.php b/includes/data/loader/class-wc-customer-loader.php index 014425521..21891a6d6 100644 --- a/includes/data/loader/class-wc-customer-loader.php +++ b/includes/data/loader/class-wc-customer-loader.php @@ -28,7 +28,7 @@ public function loadKeys( array $keys ) { if ( empty( $keys ) ) { return $keys; } - $all_customers = []; + $all_customers = array(); /** * Prepare the args for the query. We're provided a specific @@ -38,13 +38,13 @@ public function loadKeys( array $keys ) { * to the count of the keys provided. The query must also return results * in the same order the keys were provided in. */ - $args = [ + $args = array( 'include' => $keys, 'number' => count( $keys ), 'orderby' => 'include', 'count_total' => false, 'fields' => 'ids', - ]; + ); /** * Query for the users and get the results @@ -56,7 +56,7 @@ public function loadKeys( array $keys ) { * If no users are returned, return an empty array */ if ( empty( $customers ) || ! is_array( $customers ) ) { - return []; + return array(); } foreach ( $keys as $key ) { diff --git a/includes/data/loader/class-wc-db-loader.php b/includes/data/loader/class-wc-db-loader.php index 37fe30e6c..d613e2b63 100644 --- a/includes/data/loader/class-wc-db-loader.php +++ b/includes/data/loader/class-wc-db-loader.php @@ -60,25 +60,25 @@ public function loadKeys( array $keys ) { $loader = null; switch ( $this->loader_type ) { case 'CART_ITEM': - $loader = [ $this, 'load_cart_item_from_key' ]; + $loader = array( $this, 'load_cart_item_from_key' ); break; case 'DOWNLOADABLE_ITEM': - $loader = [ $this, 'load_downloadable_item_from_id' ]; + $loader = array( $this, 'load_downloadable_item_from_id' ); break; case 'TAX_CLASS': - $loader = [ $this, 'load_tax_class_from_slug' ]; + $loader = array( $this, 'load_tax_class_from_slug' ); break; case 'TAX_RATE': - $loader = [ $this, 'load_tax_rate_from_id' ]; + $loader = array( $this, 'load_tax_rate_from_id' ); break; case 'ORDER_ITEM': - $loader = [ $this, 'load_order_item_from_id' ]; + $loader = array( $this, 'load_order_item_from_id' ); break; case 'SHIPPING_METHOD': - $loader = [ $this, 'load_shipping_method_from_id' ]; + $loader = array( $this, 'load_shipping_method_from_id' ); break; case 'SHIPPING_ZONE': - $loader = [ $this, 'load_shipping_zone_from_id' ]; + $loader = array( $this, 'load_shipping_zone_from_id' ); break; default: /** @@ -97,7 +97,7 @@ public function loadKeys( array $keys ) { } }//end switch - $loaded_items = []; + $loaded_items = array(); /** * Loop over the keys and return an array of items. @@ -106,7 +106,7 @@ public function loadKeys( array $keys ) { $loaded_items[ $key ] = call_user_func( $loader, $key ); } - return ! empty( $loaded_items ) ? $loaded_items : []; + return ! empty( $loaded_items ) ? $loaded_items : array(); } /** @@ -142,10 +142,10 @@ public function load_downloadable_item_from_id( $id ) { */ public function load_tax_class_from_slug( $slug ) { if ( 'standard' === $slug ) { - return [ + return array( 'slug' => 'standard', 'name' => __( 'Standard rate', 'wp-graphql-woocommerce' ), - ]; + ); } else { $tax_class = \WC_Tax::get_tax_class_by( 'slug', $slug ); return is_array( $tax_class ) && ! empty( $tax_class ) ? $tax_class : null; @@ -202,8 +202,8 @@ public function load_tax_rate_from_id( $id ) { ) ); - $cities = []; - $postcodes = []; + $cities = array(); + $postcodes = array(); foreach ( $locales as $locale ) { if ( 'city' === $locale->location_type ) { $cities[] = $locale->location_code; diff --git a/includes/data/mutation/class-cart-mutation.php b/includes/data/mutation/class-cart-mutation.php index c1392af32..395b1aa00 100644 --- a/includes/data/mutation/class-cart-mutation.php +++ b/includes/data/mutation/class-cart-mutation.php @@ -22,7 +22,7 @@ class Cart_Mutation { * @return array */ public static function get_cart_field( $fallback = false ) { - return [ + return array( 'type' => 'Cart', 'resolve' => static function ( $payload ) use ( $fallback ) { $cart = ! empty( $payload['cart'] ) ? $payload['cart'] : null; @@ -32,7 +32,7 @@ public static function get_cart_field( $fallback = false ) { } return $cart; }, - ]; + ); } /** @@ -55,13 +55,13 @@ public static function prepare_cart_item( $input, $context, $info ) { throw new UserError( __( 'No product found matching the ID provided', 'wp-graphql-woocommerce' ) ); } - $cart_item_args = [ $input['productId'] ]; + $cart_item_args = array( $input['productId'] ); $cart_item_args[] = ! empty( $input['quantity'] ) ? $input['quantity'] : 1; $cart_item_args[] = ! empty( $input['variationId'] ) ? $input['variationId'] : 0; - $cart_item_args[] = ! empty( $input['variation'] ) ? self::prepare_attributes( $input['productId'], $input['variation'] ) : []; + $cart_item_args[] = ! empty( $input['variation'] ) ? self::prepare_attributes( $input['productId'], $input['variation'] ) : array(); $cart_item_args[] = ! empty( $input['extraData'] ) ? json_decode( $input['extraData'], true ) - : []; + : array(); return apply_filters( 'graphql_woocommerce_new_cart_item_data', $cart_item_args, $input, $context, $info ); } @@ -76,7 +76,7 @@ public static function prepare_cart_item( $input, $context, $info ) { * * @throws \GraphQL\Error\UserError Invalid cart attribute provided. */ - public static function prepare_attributes( $product_id, array $variation_data = [] ) { + public static function prepare_attributes( $product_id, array $variation_data = array() ) { $product = wc_get_product( $product_id ); // Bail if bad product ID. @@ -92,7 +92,7 @@ public static function prepare_attributes( $product_id, array $variation_data = $attribute_names = array_keys( $product->get_attributes() ); - $attributes = []; + $attributes = array(); foreach ( $variation_data as $attribute ) { $attribute_name = $attribute['attributeName']; if ( in_array( "pa_{$attribute_name}", $attribute_names, true ) ) { @@ -138,7 +138,7 @@ public static function retrieve_cart_items( $input, $context, $info, $mutation = // If keys are provided and cart items haven't been retrieve yet, // retrieve the cart items by key. if ( ! empty( $input['keys'] ) && null === $items ) { - $items = []; + $items = array(); foreach ( $input['keys'] as $key ) { $item = \WC()->cart->get_cart_item( $key ); if ( empty( $item ) ) { @@ -162,12 +162,12 @@ public static function retrieve_cart_items( $input, $context, $info, $mutation = * @return array */ public static function prepare_cart_fee( $input, $context, $info ) { - $cart_item_args = [ + $cart_item_args = array( $input['name'], $input['amount'], ! empty( $input['taxable'] ) ? $input['taxable'] : false, ! empty( $input['taxClass'] ) ? $input['taxClass'] : '', - ]; + ); return apply_filters( 'graphql_woocommerce_new_cart_fee_data', $cart_item_args, $input, $context, $info ); } @@ -218,7 +218,7 @@ public static function validate_shipping_method( $shipping_method, $index, &$rea // Get available shipping packages. $available_packages = \WC()->cart->needs_shipping() ? \WC()->shipping()->calculate_shipping( \WC()->cart->get_shipping_packages() ) - : []; + : array(); if ( ! isset( $available_packages[ $index ] ) ) { $reason = sprintf( @@ -237,7 +237,7 @@ public static function validate_shipping_method( $shipping_method, $index, &$rea return true; } - $product_names = []; + $product_names = array(); foreach ( $package['contents'] as $item_id => $values ) { $product_names[ $item_id ] = \html_entity_decode( $values['data']->get_name() . ' ×' . $values['quantity'] ); } diff --git a/includes/data/mutation/class-checkout-mutation.php b/includes/data/mutation/class-checkout-mutation.php index fd339dbee..f7142c71b 100644 --- a/includes/data/mutation/class-checkout-mutation.php +++ b/includes/data/mutation/class-checkout-mutation.php @@ -65,15 +65,15 @@ protected static function maybe_skip_fieldset( $fieldset_key, $data ) { * @return array */ public static function prepare_checkout_args( $input, $context, $info ) { - $data = [ + $data = array( 'terms' => (int) isset( $input['terms'] ), 'createaccount' => (int) ! empty( $input['account'] ), '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(), - ]; + ); - $skipped = []; + $skipped = array(); foreach ( self::get_checkout_fields() as $fieldset_key => $fieldset ) { if ( self::maybe_skip_fieldset( $fieldset_key, $data ) ) { $skipped[] = $fieldset_key; @@ -115,8 +115,8 @@ public static function prepare_checkout_args( $input, $context, $info ) { * @return array */ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) { - $fields = [ - 'billing' => [ + $fields = array( + 'billing' => array( 'first_name' => 'firstName', 'last_name' => 'lastName', 'company' => 'company', @@ -128,8 +128,8 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) 'country' => 'country', 'phone' => 'phone', 'email' => 'email', - ], - 'shipping' => [ + ), + 'shipping' => array( 'first_name' => 'firstName', 'last_name' => 'lastName', 'company' => 'company', @@ -139,15 +139,15 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) 'postcode' => 'postcode', 'state' => 'state', 'country' => 'country', - ], - 'account' => [ + ), + 'account' => array( 'username' => 'username', 'password' => 'password', - ], - 'order' => [ + ), + 'order' => array( 'comments' => 'customerNote', - ], - ]; + ), + ); if ( $prefixed ) { foreach ( $fields as $prefix => $values ) { @@ -158,7 +158,7 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) } if ( ! empty( $fieldset ) ) { - return ! empty( $fields[ $fieldset ] ) ? $fields[ $fieldset ] : []; + return ! empty( $fields[ $fieldset ] ) ? $fields[ $fieldset ] : array(); } return $fields; @@ -173,7 +173,7 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) */ protected static function update_session( $data ) { // Update both shipping and billing to the passed billing address first if set. - $address_fields = [ + $address_fields = array( 'first_name', 'last_name', 'company', @@ -185,7 +185,7 @@ protected static function update_session( $data ) { 'postcode', 'state', 'country', - ]; + ); foreach ( $address_fields as $field ) { self::set_customer_address_fields( $field, $data ); @@ -220,7 +220,7 @@ protected static function clear_customer_address( $type = 'billing' ) { return false; } - $address = [ + $address = array( 'first_name' => '', 'last_name' => '', 'company' => '', @@ -230,15 +230,15 @@ protected static function clear_customer_address( $type = 'billing' ) { 'state' => '', 'postcode' => '', 'country' => '', - ]; + ); if ( 'billing' === $type ) { $address = array_merge( $address, - [ + array( 'email' => '', 'phone' => '', - ] + ) ); } @@ -270,10 +270,10 @@ protected static function process_customer( $data ) { $data['billing_email'], $username, $password, - [ + array( 'first_name' => ! empty( $data['billing_first_name'] ) ? $data['billing_first_name'] : '', 'last_name' => ! empty( $data['billing_last_name'] ) ? $data['billing_last_name'] : '', - ] + ) ); if ( is_wp_error( $customer_id ) ) { @@ -314,7 +314,7 @@ protected static function process_customer( $data ) { foreach ( $data as $key => $value ) { // Use setters where available. - if ( is_callable( [ $customer, "set_{$key}" ] ) ) { + if ( is_callable( array( $customer, "set_{$key}" ) ) ) { $customer->{"set_{$key}"}( $value ); // Store custom fields prefixed with wither shipping_ or billing_. @@ -346,20 +346,20 @@ protected static function set_customer_address_fields( $field, $data ) { $billing_value = null; $shipping_value = null; - if ( isset( $data[ "billing_{$field}" ] ) && is_callable( [ WC()->customer, "set_billing_{$field}" ] ) ) { + if ( isset( $data[ "billing_{$field}" ] ) && is_callable( array( WC()->customer, "set_billing_{$field}" ) ) ) { $billing_value = $data[ "billing_{$field}" ]; $shipping_value = $data[ "billing_{$field}" ]; } - if ( isset( $data[ "shipping_{$field}" ] ) && is_callable( [ WC()->customer, "set_shipping_{$field}" ] ) ) { + if ( isset( $data[ "shipping_{$field}" ] ) && is_callable( array( WC()->customer, "set_shipping_{$field}" ) ) ) { $shipping_value = $data[ "shipping_{$field}" ]; } - if ( ! is_null( $billing_value ) && is_callable( [ WC()->customer, "set_billing_{$field}" ] ) ) { + if ( ! is_null( $billing_value ) && is_callable( array( WC()->customer, "set_billing_{$field}" ) ) ) { WC()->customer->{"set_billing_{$field}"}( $billing_value ); } - if ( ! is_null( $shipping_value ) && is_callable( [ WC()->customer, "set_shipping_{$field}" ] ) ) { + if ( ! is_null( $shipping_value ) && is_callable( array( WC()->customer, "set_shipping_{$field}" ) ) ) { WC()->customer->{"set_shipping_{$field}"}( $shipping_value ); } } @@ -525,7 +525,7 @@ protected static function process_order_payment( $order_id, $payment_method ) { $process_payment_args = apply_filters( "graphql_{$payment_method}_process_payment_args", - [ $order_id ], + array( $order_id ), $payment_method ); @@ -552,11 +552,11 @@ protected static function process_order_without_payment( $order_id, $transaction $order->payment_complete( $transaction_id ); - return [ + return array( 'result' => 'success', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'redirect' => apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', $order->get_checkout_order_received_url(), $order ), - ]; + ); } /** @@ -649,7 +649,7 @@ public static function process_checkout( $data, $input, $context, $info, &$resul if ( $valid ) { $results = self::process_order_without_payment( $order_id, $transaction_id ); } else { - $results = [ + $results = array( 'result' => 'failed', 'redirect' => apply_filters( 'graphql_woocommerce_checkout_payment_failed_redirect', @@ -658,7 +658,7 @@ public static function process_checkout( $data, $input, $context, $info, &$resul $order_id, $transaction_id ), - ]; + ); } }//end if @@ -701,7 +701,7 @@ public static function get_value( $input ) { $customer_object = WC()->customer; } - if ( is_callable( [ $customer_object, "get_$input" ] ) ) { + if ( is_callable( array( $customer_object, "get_$input" ) ) ) { $value = $customer_object->{"get_$input"}(); } elseif ( $customer_object->meta_exists( $input ) ) { $value = $customer_object->get_meta( $input, true ); diff --git a/includes/data/mutation/class-coupon-mutation.php b/includes/data/mutation/class-coupon-mutation.php index 6175e2a46..2f71318ce 100644 --- a/includes/data/mutation/class-coupon-mutation.php +++ b/includes/data/mutation/class-coupon-mutation.php @@ -20,7 +20,7 @@ class Coupon_Mutation { * @return array */ public static function prepare_args( array $input ) { - $data_keys = [ + $data_keys = array( 'code' => 'code', 'amount' => 'amount', 'discountType' => 'discount_type', @@ -41,9 +41,9 @@ public static function prepare_args( array $input ) { 'maximumAmount' => 'maximum_amount', 'emailRestrictions' => 'email_restrictions', 'metaData' => 'meta_data', - ]; + ); - $args = []; + $args = array(); foreach ( $input as $input_field => $value ) { if ( empty( $data_keys[ $input_field ] ) ) { continue; diff --git a/includes/data/mutation/class-customer-mutation.php b/includes/data/mutation/class-customer-mutation.php index 2f4bf713f..23880f2a9 100644 --- a/includes/data/mutation/class-customer-mutation.php +++ b/includes/data/mutation/class-customer-mutation.php @@ -22,7 +22,7 @@ class Customer_Mutation { * @return array */ public static function prepare_customer_props( $input, $mutation ) { - $customer_args = []; + $customer_args = array(); if ( ! empty( $input['billing'] ) ) { $customer_args['billing'] = self::address_input_mapping( $input['billing'], 'billing' ); @@ -54,19 +54,19 @@ public static function prepare_customer_props( $input, $mutation ) { */ public static function address_input_mapping( $input, $type = 'billing' ) { // Map GQL input to address props array. - $key_mapping = [ + $key_mapping = array( 'firstName' => 'first_name', 'lastName' => 'last_name', 'address1' => 'address_1', 'address2' => 'address_2', - ]; + ); - $skip = apply_filters( 'graphql_woocommerce_customer_address_input_mapping_skipped', [ 'overwrite' ] ); + $skip = apply_filters( 'graphql_woocommerce_customer_address_input_mapping_skipped', array( 'overwrite' ) ); $type = 'empty_' . $type; $address = ! empty( $input['overwrite'] ) && true === $input['overwrite'] ? self::{$type}() - : []; + : array(); foreach ( $input as $input_field => $value ) { if ( in_array( $input_field, array_keys( $key_mapping ), true ) ) { $address[ $key_mapping[ $input_field ] ] = $value; @@ -86,7 +86,7 @@ public static function address_input_mapping( $input, $type = 'billing' ) { * @return array */ public static function empty_shipping() { - return [ + return array( 'first_name' => '', 'last_name' => '', 'company' => '', @@ -97,7 +97,7 @@ public static function empty_shipping() { 'postcode' => '', 'country' => '', 'phone' => '', - ]; + ); } /** @@ -108,7 +108,7 @@ public static function empty_shipping() { public static function empty_billing() { return array_merge( self::empty_shipping(), - [ 'email' => '' ] + array( 'email' => '' ) ); } diff --git a/includes/data/mutation/class-order-mutation.php b/includes/data/mutation/class-order-mutation.php index 53b89ceb0..8d8c73b0d 100644 --- a/includes/data/mutation/class-order-mutation.php +++ b/includes/data/mutation/class-order-mutation.php @@ -91,15 +91,15 @@ public static function create_order( $input, $context, $info ) { $order_id = $order->save(); - $order_keys = [ + $order_keys = array( 'status' => 'status', 'customerId' => 'customer_id', 'customerNote' => 'customer_note', 'parent' => 'parent', 'createdVia' => 'created_via', - ]; + ); - $args = [ 'order_id' => $order_id ]; + $args = array( 'order_id' => $order_id ); foreach ( $input as $key => $value ) { if ( array_key_exists( $key, $order_keys ) ) { $args[ $order_keys[ $key ] ] = $value; @@ -152,17 +152,17 @@ public static function add_items( $input, $order_id, $context, $info ) { throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) ); } - $item_group_keys = [ + $item_group_keys = array( 'lineItems' => 'line_item', 'shippingLines' => 'shipping', 'feeLines' => 'fee', - ]; + ); - $order_items = []; + $order_items = array(); foreach ( $input as $key => $group_items ) { if ( array_key_exists( $key, $item_group_keys ) ) { $type = $item_group_keys[ $key ]; - $order_items[ $type ] = []; + $order_items[ $type ] = array(); /** * Action called before an item group is added to an order. @@ -321,7 +321,7 @@ public static function get_order_item_classname( $type, $id = 0 ) { protected static function map_input_to_item( &$item, $input, $type ) { $item_keys = self::get_order_item_keys( $type ); - $args = []; + $args = array(); $meta_data = null; foreach ( $input as $key => $value ) { if ( array_key_exists( $key, $item_keys ) ) { @@ -342,14 +342,14 @@ protected static function map_input_to_item( &$item, $input, $type ) { throw new \Exception( __( 'Failed to retrieve product connected to order item.', 'wp-graphql-woocommerce' ) ); } - $total = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ] ); + $total = wc_get_price_excluding_tax( $product, array( 'qty' => $args['quantity'] ) ); $args['subtotal'] = ! empty( $args['subtotal'] ) ? $args['subtotal'] : $total; $args['total'] = ! empty( $args['total'] ) ? $args['total'] : $total; } // Set item props. foreach ( $args as $key => $value ) { - if ( is_callable( [ $item, "set_{$key}" ] ) ) { + if ( is_callable( array( $item, "set_{$key}" ) ) ) { $item->{"set_{$key}"}( $value ); } } @@ -379,26 +379,26 @@ protected static function map_input_to_item( &$item, $input, $type ) { protected static function get_order_item_keys( $type ) { switch ( $type ) { case 'line_item': - return [ + return array( 'productId' => 'product_id', 'variationId' => 'variation_id', 'taxClass' => 'tax_class', - ]; + ); case 'shipping': - return [ + return array( 'name' => 'order_item_name', 'methodTitle' => 'method_title', 'methodId' => 'method_id', 'instanceId' => 'instance_id', - ]; + ); case 'fee': - return [ + return array( 'name' => 'name', 'taxClass' => 'tax_class', 'taxStatus' => 'tax_status', - ]; + ); default: /** * Allow filtering of order item keys for unknown item types. @@ -406,7 +406,7 @@ protected static function get_order_item_keys( $type ) { * @param array $item_keys Order item keys. * @param string $type Order item type slug. */ - return apply_filters( 'woographql_get_order_item_keys', [], $type ); + return apply_filters( 'woographql_get_order_item_keys', array(), $type ); }//end switch } @@ -500,7 +500,7 @@ public static function add_order_meta( $order_id, $input, $context, $info ) { break; default: $prop = \wc_graphql_camel_case_to_underscore( $key ); - if ( is_callable( [ $order, "set_{$prop}" ] ) ) { + if ( is_callable( array( $order, "set_{$prop}" ) ) ) { $order->{"set_{$prop}"}( $value ); } break; @@ -540,7 +540,7 @@ protected static function update_address( $address, $order_id, $type = 'billing' $formatted_address = Customer_Mutation::address_input_mapping( $address, $type ); foreach ( $formatted_address as $key => $value ) { - if ( is_callable( [ $order, "set_{$type}_{$key}" ] ) ) { + if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) { $order->{"set_{$type}_{$key}"}( $value ); } } diff --git a/includes/data/mutation/class-settings-mutation.php b/includes/data/mutation/class-settings-mutation.php index be6dbdf89..321d8c16f 100644 --- a/includes/data/mutation/class-settings-mutation.php +++ b/includes/data/mutation/class-settings-mutation.php @@ -56,14 +56,14 @@ public static function validate_setting_select_field( $value, $setting ) { */ public static function validate_setting_multiselect_field( $values, $setting ) { if ( empty( $values ) ) { - return []; + return array(); } if ( ! is_array( $values ) ) { throw new UserError( __( 'An invalid setting value was passed.', 'wp-graphql-woocommerce' ), 400 ); } - $final_values = []; + $final_values = array(); foreach ( $values as $value ) { if ( array_key_exists( $value, $setting['options'] ) ) { $final_values[] = $value; @@ -126,7 +126,7 @@ public static function validate_setting_radio_field( $value, $setting ) { * @return string */ public function validate_setting_checkbox_field( $value, $setting ) { - if ( in_array( $value, [ 'yes', 'no' ], true ) ) { + if ( in_array( $value, array( 'yes', 'no' ), true ) ) { return $value; } elseif ( empty( $value ) ) { $value = isset( $setting['default'] ) ? $setting['default'] : 'no'; @@ -149,14 +149,14 @@ public static function validate_setting_textarea_field( $value, $setting ) { return wp_kses( trim( stripslashes( $value ) ), array_merge( - [ - 'iframe' => [ + array( + 'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true, - ], - ], + ), + ), wp_kses_allowed_html( 'post' ) ) ); diff --git a/includes/data/mutation/class-shipping-mutation.php b/includes/data/mutation/class-shipping-mutation.php index d6d75562c..47ab0c2b1 100644 --- a/includes/data/mutation/class-shipping-mutation.php +++ b/includes/data/mutation/class-shipping-mutation.php @@ -20,7 +20,7 @@ class Shipping_Mutation { * @return array */ private static function flatten_settings_input( $settings_input ) { - $settings = []; + $settings = array(); foreach ( $settings_input as $setting ) { $settings[ $setting['id'] ] = $setting['value']; } @@ -43,7 +43,7 @@ public static function set_shipping_zone_method_settings( $instance_id, $method, $errors_found = false; foreach ( $method->get_instance_form_fields() as $key => $field ) { if ( isset( $settings[ $key ] ) ) { - if ( is_callable( [ Settings_Mutation::class, 'validate_setting_' . $field['type'] . '_field' ] ) ) { + if ( is_callable( array( Settings_Mutation::class, 'validate_setting_' . $field['type'] . '_field' ) ) ) { $value = Settings_Mutation::{'validate_setting_' . $field['type'] . '_field'}( $settings[ $key ], $field ); } else { $value = Settings_Mutation::validate_setting_text_field( $settings[ $key ], $field ); @@ -79,8 +79,8 @@ public static function set_shipping_zone_method_order( $instance_id, $method, $o $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "{$wpdb->prefix}woocommerce_shipping_zone_methods", - [ 'method_order' => $order ], - [ 'instance_id' => $instance_id ] + array( 'method_order' => $order ), + array( 'instance_id' => $instance_id ) ); $method->method_order = $order; @@ -100,7 +100,7 @@ public static function set_shipping_zone_method_order( $instance_id, $method, $o public static function set_shipping_zone_method_enabled( $zone_id, $instance_id, $method, $enabled ) { global $wpdb; - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", [ 'is_enabled' => $enabled ], [ 'instance_id' => $instance_id ] ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery + if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $enabled ), array( 'instance_id' => $instance_id ) ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $zone_id, $enabled ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $method->enabled = ( true === $enabled ? 'yes' : 'no' ); } diff --git a/includes/functions.php b/includes/functions.php index 7cc4e9971..b39b16d32 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -41,12 +41,12 @@ static function ( $type_name ) { return 'Product' !== $type_name; } ), - [ + array( 'SimpleProduct', 'VariableProduct', 'GroupProduct', 'ExternalProduct', - ] + ) ); } diff --git a/includes/model/class-coupon.php b/includes/model/class-coupon.php index e5cc56707..aa6d749f7 100644 --- a/includes/model/class-coupon.php +++ b/includes/model/class-coupon.php @@ -64,7 +64,7 @@ protected function init() { if ( empty( $this->fields ) ) { parent::init(); - $fields = [ + $fields = array( 'ID' => function () { return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null; }, @@ -129,21 +129,21 @@ protected function init() { * Note: underscore naming style is used as a quick identifier */ 'product_ids' => function () { - return ! empty( $this->wc_data->get_product_ids() ) ? $this->wc_data->get_product_ids() : [ '0' ]; + return ! empty( $this->wc_data->get_product_ids() ) ? $this->wc_data->get_product_ids() : array( '0' ); }, 'excluded_product_ids' => function () { - return ! empty( $this->wc_data->get_excluded_product_ids() ) ? $this->wc_data->get_excluded_product_ids() : [ '0' ]; + return ! empty( $this->wc_data->get_excluded_product_ids() ) ? $this->wc_data->get_excluded_product_ids() : array( '0' ); }, 'product_category_ids' => function () { - return ! empty( $this->wc_data->get_product_categories() ) ? $this->wc_data->get_product_categories() : [ '0' ]; + return ! empty( $this->wc_data->get_product_categories() ) ? $this->wc_data->get_product_categories() : array( '0' ); }, 'excluded_product_category_ids' => function () { - return ! empty( $this->wc_data->get_excluded_product_categories() ) ? $this->wc_data->get_excluded_product_categories() : [ '0' ]; + return ! empty( $this->wc_data->get_excluded_product_categories() ) ? $this->wc_data->get_excluded_product_categories() : array( '0' ); }, 'used_by_ids' => function () { - return ! empty( $this->wc_data->get_used_by() ) ? $this->wc_data->get_used_by() : [ '0' ]; + return ! empty( $this->wc_data->get_used_by() ) ? $this->wc_data->get_used_by() : array( '0' ); }, - ]; + ); $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-customer.php b/includes/model/class-customer.php index 6abe9c83b..b44e3d670 100644 --- a/includes/model/class-customer.php +++ b/includes/model/class-customer.php @@ -51,13 +51,13 @@ class Customer extends Model { */ public function __construct( $id = 'session', $is_session = false ) { $this->data = 'session' === $id ? \WC()->customer : new WC_Customer( absint( $id ), $is_session ); - $allowed_restricted_fields = [ + $allowed_restricted_fields = array( 'isRestricted', 'isPrivate', 'isPublic', 'id', 'customerId', - ]; + ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'customer_restricted_cap', 'session' === $id ? '' : 'list_users' ); @@ -81,7 +81,7 @@ public function __call( $method, $args ) { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = [ + $this->fields = array( 'ID' => function () { return ( ! empty( $this->data->get_id() ) ) ? $this->data->get_id() : \WC()->session->get_customer_id(); }, @@ -150,7 +150,7 @@ protected function init() { 'last_order_id' => function () { return ( ! empty( $this->data->get_last_order() ) ) ? $this->data->get_last_order()->get_id() : null; }, - ]; + ); }//end if parent::prepare_fields(); diff --git a/includes/model/class-order-item.php b/includes/model/class-order-item.php index a46c306dc..177ef6c45 100644 --- a/includes/model/class-order-item.php +++ b/includes/model/class-order-item.php @@ -90,13 +90,13 @@ public function __construct( $item, $cached_order = null ) { $this->item_type = $item->get_type(); $order_id = $item->get_order_id(); $this->order = ! empty( $cached_order ) ? $cached_order : new Order( $order_id ); - $allowed_restricted_fields = [ + $allowed_restricted_fields = array( 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ]; + ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'order_item_restricted_cap', '' ); @@ -120,7 +120,7 @@ public function __call( $method, $args ) { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = [ + $this->fields = array( 'ID' => function () { return $this->data->get_id(); }, @@ -139,13 +139,13 @@ protected function init() { 'type' => function () { return ! empty( $this->data->get_type() ) ? $this->data->get_type() : null; }, - ]; + ); switch ( $this->item_type ) { case 'coupon': $this->fields = array_merge( $this->fields, - [ + array( 'code' => function () { return ! empty( $this->data->get_code() ) ? $this->data->get_code() : null; }, @@ -155,21 +155,21 @@ protected function init() { 'discountTax' => function () { return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : null; }, - 'coupon_id' => [ + 'coupon_id' => array( 'callback' => function () { $coupon_id = \wc_get_coupon_id_by_code( $this->data->get_code() ); return ! empty( $coupon_id ) ? $coupon_id : null; }, 'capability' => 'edit_shop_orders', - ], - ] + ), + ) ); break; case 'fee': $this->fields = array_merge( $this->fields, - [ + array( 'amount' => function () { return ! empty( $this->data->get_amount() ) ? $this->data->get_amount() : null; }, @@ -198,14 +198,14 @@ protected function init() { ? \wc_graphql_map_tax_statements( $this->data->get_taxes() ) : null; }, - ] + ) ); break; case 'shipping': $this->fields = array_merge( $this->fields, - [ + array( 'name' => function () { return ! empty( $this->data->get_name() ) ? $this->data->get_name() : null; }, @@ -229,14 +229,14 @@ protected function init() { 'method_id' => function () { return ! empty( $this->data->get_method_id() ) ? $this->data->get_method_id() : null; }, - ] + ) ); break; case 'tax': $this->fields = array_merge( $this->fields, - [ + array( 'rateCode' => function () { return ! empty( $this->data->get_rate_code() ) ? $this->data->get_rate_code() : null; }, @@ -255,13 +255,13 @@ protected function init() { 'rate_id' => function () { return ! empty( $this->data->get_rate_id() ) ? $this->data->get_rate_id() : null; }, - ] + ) ); break; default: $this->fields = array_merge( $this->fields, - [ + array( 'productId' => function () { return ! empty( $this->data->get_product_id() ) ? $this->data->get_product_id() : null; }, @@ -302,7 +302,7 @@ protected function init() { } return null; }, - ] + ) ); break; }//end switch diff --git a/includes/model/class-order.php b/includes/model/class-order.php index 3b95a7860..3cb7fec49 100644 --- a/includes/model/class-order.php +++ b/includes/model/class-order.php @@ -119,7 +119,7 @@ public function __construct( $id ) { $this->post_type = $this->get_post_type(); $this->post_type_object = ! empty( $this->post_type ) ? get_post_type_object( $this->post_type ) : null; $this->current_user = wp_get_current_user(); - $allowed_restricted_fields = [ + $allowed_restricted_fields = array( 'isRestricted', 'isPrivate', 'isPublic', @@ -151,7 +151,7 @@ public function __construct( $id ) { 'downloadable_items', 'commentCount', 'commentStatus', - ]; + ); $restricted_cap = $this->get_restricted_cap(); @@ -193,7 +193,7 @@ public function get_post_type() { * @return mixed */ public function __call( $method, $args ) { - if ( \is_callable( [ $this->data, $method ] ) ) { + if ( \is_callable( array( $this->data, $method ) ) ) { return $this->data->$method( ...$args ); } @@ -364,7 +364,7 @@ public function delete( $force_delete = false ) { * @return array */ protected function abstract_order_fields() { - return [ + return array( 'ID' => function () { return ! empty( $this->data->get_id() ) ? $this->data->get_id() : null; }, @@ -397,42 +397,42 @@ protected function abstract_order_fields() { }, 'discountTotal' => function () { $price = ! is_null( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0; - return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); + return wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) ); }, 'discountTotalRaw' => function () { return ! empty( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0; }, 'discountTax' => function () { $price = ! is_null( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0; - return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); + return wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) ); }, 'discountTaxRaw' => function () { return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0; }, 'shippingTotal' => function () { $price = ! is_null( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0; - return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); + return wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) ); }, 'shippingTotalRaw' => function () { return ! empty( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0; }, 'shippingTax' => function () { $price = ! is_null( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0; - return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); + return wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) ); }, 'shippingTaxRaw' => function () { return ! empty( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0; }, 'cartTax' => function () { $price = ! is_null( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0; - return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); + return wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) ); }, 'cartTaxRaw' => function () { return ! empty( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0; }, 'total' => function () { return ! is_null( $this->data->get_total() ) - ? wc_graphql_price( $this->data->get_total(), [ 'currency' => $this->data->get_currency() ] ) + ? wc_graphql_price( $this->data->get_total(), array( 'currency' => $this->data->get_currency() ) ) : null; }, 'totalRaw' => function () { @@ -440,13 +440,13 @@ protected function abstract_order_fields() { }, 'totalTax' => function () { return ! is_null( $this->data->get_total_tax() ) - ? wc_graphql_price( $this->data->get_total_tax(), [ 'currency' => $this->data->get_currency() ] ) + ? wc_graphql_price( $this->data->get_total_tax(), array( 'currency' => $this->data->get_currency() ) ) : null; }, 'totalTaxRaw' => function () { return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : 0; }, - ]; + ); } /** @@ -455,7 +455,7 @@ protected function abstract_order_fields() { * @return array */ protected function order_fields() { - return [ + return array( 'date' => function () { return ! empty( $this->data->get_date_created() ) ? $this->data->get_date_created() : null; }, @@ -498,7 +498,7 @@ protected function order_fields() { }, 'subtotal' => function () { return ! is_null( $this->data->get_subtotal() ) - ? wc_graphql_price( $this->data->get_subtotal(), [ 'currency' => $this->data->get_currency() ] ) + ? wc_graphql_price( $this->data->get_subtotal(), array( 'currency' => $this->data->get_currency() ) ) : null; }, 'subtotalRaw' => function () { @@ -604,31 +604,31 @@ protected function order_fields() { * and some fields act as aliases/decorator for existing fields. */ 'commentCount' => function () { - remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); + remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); - $args = [ + $args = array( 'post_id' => $this->ID, 'approve' => 'approve', 'fields' => 'ids', 'type' => '', - ]; + ); $is_allowed_to_edit = null !== $this->post_type_object ? current_user_can( $this->post_type_object->cap->edit_posts, $this->ID ) : current_user_can( 'manage_woocommerce' ); if ( ! $is_allowed_to_edit ) { - $args += [ + $args += array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'meta_key' => 'is_customer_note', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value 'meta_value' => '1', - ]; + ); } $notes = get_comments( $args ); - add_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); + add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); return is_array( $notes ) ? count( $notes ) : 0; }, @@ -638,7 +638,7 @@ protected function order_fields() { : current_user_can( 'manage_woocommerce' ); return $is_allowed_to_comment ? 'open' : 'closed'; }, - ]; + ); } /** @@ -647,7 +647,7 @@ protected function order_fields() { * @return array */ protected function refund_fields() { - return [ + return array( 'title' => function () { $post_title = method_exists( $this->data, 'get_post_title' ) ? $this->data->get_post_title() : null; return ! empty( $post_title ) ? $post_title : null; @@ -660,17 +660,17 @@ protected function refund_fields() { $reason = method_exists( $this->data, 'get_reason' ) ? $this->data->get_reason() : null; return ! empty( $reason ) ? $reason : null; }, - 'refunded_by_id' => [ + 'refunded_by_id' => array( 'callback' => function () { $refunded_by = method_exists( $this->data, 'get_refunded_by' ) ? $this->data->get_refunded_by() : null; return ! empty( $refunded_by ) ? $refunded_by : null; }, 'capability' => 'list_users', - ], + ), 'date' => function () { return ! empty( $this->data->get_date_modified() ) ? $this->data->get_date_modified() : null; }, - ]; + ); } /** diff --git a/includes/model/class-product-variation.php b/includes/model/class-product-variation.php index f0d22668e..fb62f6349 100644 --- a/includes/model/class-product-variation.php +++ b/includes/model/class-product-variation.php @@ -99,7 +99,7 @@ protected function init() { if ( empty( $this->fields ) ) { parent::init(); - $fields = [ + $fields = array( 'ID' => function () { return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null; }, @@ -123,17 +123,17 @@ protected function init() { }, 'price' => function () { return ! empty( $this->wc_data->get_price() ) - ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_price() ] ) ) + ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, array( 'price' => $this->wc_data->get_price() ) ) ) : null; }, 'regularPrice' => function () { return ! empty( $this->wc_data->get_regular_price() ) - ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_regular_price() ] ) ) + ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, array( 'price' => $this->wc_data->get_regular_price() ) ) ) : null; }, 'salePrice' => function () { return ! empty( $this->wc_data->get_sale_price() ) - ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_sale_price() ] ) ) + ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, array( 'price' => $this->wc_data->get_sale_price() ) ) ) : null; }, 'dateOnSaleFrom' => function () { @@ -246,7 +246,7 @@ protected function init() { 'attributes' => function () { return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : null; }, - ]; + ); $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-product.php b/includes/model/class-product.php index 25e369e1e..2614df3ee 100644 --- a/includes/model/class-product.php +++ b/includes/model/class-product.php @@ -131,10 +131,10 @@ public function __construct( $id ) { /** * {@inheritDoc} */ - protected static function get_allowed_restricted_fields( $allowed_restricted_fields = [] ) { + protected static function get_allowed_restricted_fields( $allowed_restricted_fields = array() ) { return array_merge( parent::get_allowed_restricted_fields(), - [ 'type' ] + array( 'type' ) ); } @@ -201,7 +201,7 @@ protected function init() { parent::init(); $type = $this->wc_data->get_type(); - $fields = [ + $fields = array( 'ID' => function () { return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null; }, @@ -288,18 +288,18 @@ protected function init() { /** * Editor/Shop Manager only fields */ - 'catalogVisibility' => [ + 'catalogVisibility' => array( 'callback' => function () { return ! empty( $this->wc_data->get_catalog_visibility() ) ? $this->wc_data->get_catalog_visibility() : null; }, 'capability' => $this->post_type_object->cap->edit_posts, - ], - 'totalSales' => [ + ), + 'totalSales' => array( 'callback' => function () { return $this->wc_data->get_total_sales(); }, 'capability' => $this->post_type_object->cap->edit_posts, - ], + ), /** * Connection resolvers fields @@ -310,25 +310,25 @@ protected function init() { 'upsell_ids' => function () { return ! empty( $this->wc_data->get_upsell_ids() ) ? array_map( 'absint', $this->wc_data->get_upsell_ids() ) - : [ '0' ]; + : array( '0' ); }, 'attributes' => function () { - return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : []; + return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : array(); }, 'default_attributes' => function () { - return ! empty( $this->wc_data->get_default_attributes() ) ? $this->wc_data->get_default_attributes() : [ '0' ]; + return ! empty( $this->wc_data->get_default_attributes() ) ? $this->wc_data->get_default_attributes() : array( '0' ); }, 'image_id' => function () { return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null; }, 'gallery_image_ids' => function () { - return ! empty( $this->wc_data->get_gallery_image_ids() ) ? $this->wc_data->get_gallery_image_ids() : [ '0' ]; + return ! empty( $this->wc_data->get_gallery_image_ids() ) ? $this->wc_data->get_gallery_image_ids() : array( '0' ); }, 'category_ids' => function () { - return ! empty( $this->wc_data->get_category_ids() ) ? $this->wc_data->get_category_ids() : [ '0' ]; + return ! empty( $this->wc_data->get_category_ids() ) ? $this->wc_data->get_category_ids() : array( '0' ); }, 'tag_ids' => function () { - return ! empty( $this->wc_data->get_tag_ids() ) ? $this->wc_data->get_tag_ids() : [ '0' ]; + return ! empty( $this->wc_data->get_tag_ids() ) ? $this->wc_data->get_tag_ids() : array( '0' ); }, 'parent_id' => function () { return ! empty( $this->wc_data->get_parent_id() ) ? $this->wc_data->get_parent_id() : null; @@ -336,7 +336,7 @@ protected function init() { 'post' => function () { return ! empty( $this->wc_data->post ) ? $this->wc_data->post : null; }, - ]; + ); if ( apply_filters( @@ -344,7 +344,7 @@ protected function init() { 'grouped' !== $this->wc_data->get_type() ) ) { - $fields += [ + $fields += array( 'price' => function () { return ! empty( $this->wc_data->get_price() ) ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data ) ) @@ -355,7 +355,7 @@ protected function init() { }, 'regularPrice' => function () { return ! empty( $this->wc_data->get_regular_price() ) - ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_regular_price() ] ) ) + ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, array( 'price' => $this->wc_data->get_regular_price() ) ) ) : null; }, 'regularPriceRaw' => function () { @@ -366,9 +366,9 @@ protected function init() { ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, - [ + array( 'price' => $this->wc_data->get_sale_price(), - ] + ) ) ) : null; @@ -382,7 +382,7 @@ protected function init() { 'taxClass' => function () { return $this->wc_data->get_tax_class(); }, - ]; + ); }//end if if ( @@ -391,7 +391,7 @@ protected function init() { 'simple' === $type || 'variable' === $type ) ) { - $fields += [ + $fields += array( 'manageStock' => function () { return ! empty( $this->wc_data->get_manage_stock() ) ? $this->wc_data->get_manage_stock() : null; }, @@ -434,17 +434,17 @@ protected function init() { 'cross_sell_ids' => function () { return ! empty( $this->wc_data->get_cross_sell_ids() ) ? array_map( 'absint', $this->wc_data->get_cross_sell_ids() ) - : [ '0' ]; + : array( '0' ); }, 'stockStatus' => function () { return ! empty( $this->wc_data->get_stock_status() ) ? $this->wc_data->get_stock_status() : null; }, - ]; + ); }//end if switch ( true ) { case apply_filters( "graphql_{$type}_product_model_use_virtual_data_fields", 'simple' === $type ): - $fields += [ + $fields += array( 'virtual' => function () { return $this->wc_data->is_virtual(); }, @@ -460,10 +460,10 @@ protected function init() { 'downloads' => function () { return ! empty( $this->wc_data->get_downloads() ) ? $this->wc_data->get_downloads() : null; }, - ]; + ); break; case apply_filters( "graphql_{$type}_product_model_use_variation_pricing_fields", 'variable' === $type ): - $fields = [ + $fields = array( 'price' => function () { return $this->get_variation_price(); }, @@ -476,7 +476,7 @@ protected function init() { 'variation_ids' => function () { return ! empty( $this->wc_data->get_children() ) ? array_map( 'absint', $this->wc_data->get_children() ) - : [ '0' ]; + : array( '0' ); }, 'priceRaw' => function () { return $this->get_variation_price( '', true ); @@ -487,10 +487,10 @@ protected function init() { 'salePriceRaw' => function () { return $this->get_variation_price( 'sale', true ); }, - ] + $fields; + ) + $fields; break; case apply_filters( "graphql_{$type}_product_model_use_external_fields", 'external' === $type ): - $fields += [ + $fields += array( 'externalUrl' => function () { /** * External product @@ -509,10 +509,10 @@ protected function init() { $data = $this->wc_data; return ! empty( $data->get_button_text() ) ? $data->get_button_text() : null; }, - ]; + ); break; case apply_filters( "graphql_{$type}_product_model_use_grouped_fields", 'grouped' === $type ): - $fields += [ + $fields += array( 'addToCartText' => function () { return ! empty( $this->wc_data->add_to_cart_text() ) ? $this->wc_data->add_to_cart_text() : null; }, @@ -524,9 +524,9 @@ protected function init() { 'grouped_ids' => function () { return ! empty( $this->wc_data->get_children() ) ? array_map( 'absint', $this->wc_data->get_children() ) - : [ '0' ]; + : array( '0' ); }, - ]; + ); break; }//end switch @@ -536,7 +536,7 @@ protected function init() { * These fields are used primarily by WPGraphQL core Node* interfaces * and some fields act as aliases/decorator for existing fields. */ - $fields += [ + $fields += array( 'commentCount' => function () { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return ! empty( $this->reviewCount ) ? $this->reviewCount : null; @@ -545,7 +545,7 @@ protected function init() { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return isset( $this->reviewsAllowed ) && $this->reviewsAllowed ? 'open' : 'closed'; }, - ]; + ); $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-shipping-method.php b/includes/model/class-shipping-method.php index 4346420f9..6af43356b 100644 --- a/includes/model/class-shipping-method.php +++ b/includes/model/class-shipping-method.php @@ -34,13 +34,13 @@ class Shipping_Method extends Model { */ public function __construct( $method ) { $this->data = $method; - $allowed_restricted_fields = [ + $allowed_restricted_fields = array( 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ]; + ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'shipping_method_restricted_cap', '' ); @@ -62,7 +62,7 @@ protected function is_private() { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = [ + $this->fields = array( 'ID' => function () { return $this->data->id; }, @@ -78,7 +78,7 @@ protected function init() { 'description' => function () { return ! empty( $this->data->method_description ) ? $this->data->method_description : null; }, - ]; + ); } } @@ -93,7 +93,7 @@ protected function init() { * @throws \BadMethodCallException Method not found on WC data object. */ public function __call( $method, $args ) { - if ( \is_callable( [ $this->data, $method ] ) ) { + if ( \is_callable( array( $this->data, $method ) ) ) { return $this->data->$method( ...$args ); } diff --git a/includes/model/class-shipping-zone.php b/includes/model/class-shipping-zone.php index 67ae28401..cf85fe799 100644 --- a/includes/model/class-shipping-zone.php +++ b/includes/model/class-shipping-zone.php @@ -36,13 +36,13 @@ class Shipping_Zone extends Model { */ public function __construct( $zone ) { $this->data = $zone; - $allowed_restricted_fields = [ + $allowed_restricted_fields = array( 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ]; + ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'shipping_zone_restricted_cap', '' ); @@ -64,7 +64,7 @@ protected function is_private() { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = [ + $this->fields = array( 'ID' => function () { return $this->data->get_id(); }, @@ -86,7 +86,7 @@ protected function init() { 'methods' => function () { return $this->data->get_shipping_methods(); }, - ]; + ); } } @@ -101,7 +101,7 @@ protected function init() { * @throws \BadMethodCallException Method not found on WC data object. */ public function __call( $method, $args ) { - if ( \is_callable( [ $this->data, $method ] ) ) { + if ( \is_callable( array( $this->data, $method ) ) ) { return $this->data->$method( ...$args ); } diff --git a/includes/model/class-tax-rate.php b/includes/model/class-tax-rate.php index 672acc1bc..863b94892 100644 --- a/includes/model/class-tax-rate.php +++ b/includes/model/class-tax-rate.php @@ -60,13 +60,13 @@ class Tax_Rate extends Model { */ public function __construct( $rate ) { $this->data = $rate; - $allowed_restricted_fields = [ + $allowed_restricted_fields = array( 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ]; + ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'tax_rate_restricted_cap', '' ); @@ -88,7 +88,7 @@ protected function is_private() { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = [ + $this->fields = array( 'ID' => function () { return $this->data->tax_rate_id; }, @@ -111,10 +111,10 @@ protected function init() { return ! empty( $this->data->tax_rate_postcode ) ? $this->data->tax_rate_postcode : '*'; }, 'postcodes' => function () { - return ! empty( $this->data->tax_rate_postcodes ) ? explode( ';', $this->data->tax_rate_postcodes ) : [ '*' ]; + return ! empty( $this->data->tax_rate_postcodes ) ? explode( ';', $this->data->tax_rate_postcodes ) : array( '*' ); }, 'cities' => function () { - return ! empty( $this->data->tax_rate_cities ) ? explode( ';', $this->data->tax_rate_cities ) : [ '*' ]; + return ! empty( $this->data->tax_rate_cities ) ? explode( ';', $this->data->tax_rate_cities ) : array( '*' ); }, 'rate' => function () { return ! empty( $this->data->tax_rate ) ? $this->data->tax_rate : null; @@ -137,7 +137,7 @@ protected function init() { 'class' => function () { return ! is_null( $this->data->tax_rate_class ) ? $this->data->tax_rate_class : ''; }, - ]; + ); }//end if } } diff --git a/includes/model/class-wc-post.php b/includes/model/class-wc-post.php index b420fc643..47c08d23e 100644 --- a/includes/model/class-wc-post.php +++ b/includes/model/class-wc-post.php @@ -49,8 +49,8 @@ public function __construct( $data ) { } // Add $allowed_restricted_fields. - if ( ! has_filter( 'graphql_allowed_fields_on_restricted_type', [ static::class, 'add_allowed_restricted_fields' ] ) ) { - add_filter( 'graphql_allowed_fields_on_restricted_type', [ static::class, 'add_allowed_restricted_fields' ], 10, 2 ); + if ( ! has_filter( 'graphql_allowed_fields_on_restricted_type', array( static::class, 'add_allowed_restricted_fields' ) ) ) { + add_filter( 'graphql_allowed_fields_on_restricted_type', array( static::class, 'add_allowed_restricted_fields' ), 10, 2 ); } // Execute Post Model constructor. @@ -81,8 +81,8 @@ public static function add_allowed_restricted_fields( $allowed_restricted_fields * * @return array */ - protected static function get_allowed_restricted_fields( $allowed_restricted_fields = [] ) { - return [ + protected static function get_allowed_restricted_fields( $allowed_restricted_fields = array() ) { + return array( 'isRestricted', 'isPrivate', 'isPublic', @@ -96,7 +96,7 @@ protected static function get_allowed_restricted_fields( $allowed_restricted_fie 'isFrontPage', 'hasPassword', 'status', - ]; + ); } /** @@ -110,7 +110,7 @@ protected static function get_allowed_restricted_fields( $allowed_restricted_fie * @throws \BadMethodCallException Method not found on WC data object. */ public function __call( $method, $args ) { - if ( \is_callable( [ $this->wc_data, $method ] ) ) { + if ( \is_callable( array( $this->wc_data, $method ) ) ) { return $this->wc_data->$method( ...$args ); } diff --git a/includes/mutation/class-cart-add-fee.php b/includes/mutation/class-cart-add-fee.php index a986eb79d..a3e7db321 100644 --- a/includes/mutation/class-cart-add-fee.php +++ b/includes/mutation/class-cart-add-fee.php @@ -27,11 +27,11 @@ class Cart_Add_Fee { public static function register_mutation() { register_graphql_mutation( 'addFee', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,24 +41,24 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'name' => [ - 'type' => [ 'non_null' => 'String' ], + return array( + 'name' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Unique name for the fee.', 'wp-graphql-woocommerce' ), - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'Float', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), - ], - 'taxable' => [ + ), + 'taxable' => array( 'type' => 'Boolean', 'description' => __( 'Is the fee taxable?', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'The tax class for the fee if taxable.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -67,16 +67,16 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'cartFee' => [ + return array( + 'cartFee' => array( 'type' => 'CartFee', 'resolve' => static function ( $payload ) { $fees = \WC()->cart->get_fees(); return $fees[ $payload['id'] ]; }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -109,7 +109,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_update_session', true ); // Return payload. - return [ 'id' => \sanitize_title( $input['name'] ) ]; + return array( 'id' => \sanitize_title( $input['name'] ) ); }; } } diff --git a/includes/mutation/class-cart-add-item.php b/includes/mutation/class-cart-add-item.php index 3e8cb3c6a..ec74bbe94 100644 --- a/includes/mutation/class-cart-add-item.php +++ b/includes/mutation/class-cart-add-item.php @@ -27,11 +27,11 @@ class Cart_Add_Item { public static function register_mutation() { register_graphql_mutation( 'addToCart', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,28 +41,28 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'productId' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'productId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), - ], - 'quantity' => [ + ), + 'quantity' => array( 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - ], - 'variationId' => [ + ), + 'variationId' => array( 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), - ], - 'variation' => [ - 'type' => [ 'list_of' => 'ProductAttributeInput' ], + ), + 'variation' => array( + 'type' => array( 'list_of' => 'ProductAttributeInput' ), 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), - ], - 'extraData' => [ + ), + 'extraData' => array( 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -71,15 +71,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'cartItem' => [ + return array( + 'cartItem' => array( 'type' => 'CartItem', 'resolve' => static function ( $payload ) { return \WC()->cart->get_cart_item( $payload['key'] ); }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -104,7 +104,7 @@ public static function mutate_and_get_payload() { // If cart item key valid return payload. if ( false !== $cart_item_key ) { - return [ 'key' => $cart_item_key ]; + return array( 'key' => $cart_item_key ); } // Process errors. diff --git a/includes/mutation/class-cart-add-items.php b/includes/mutation/class-cart-add-items.php index 5e2a6ae92..d59af568e 100644 --- a/includes/mutation/class-cart-add-items.php +++ b/includes/mutation/class-cart-add-items.php @@ -27,11 +27,11 @@ class Cart_Add_Items { public static function register_mutation() { register_graphql_mutation( 'addCartItems', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,12 +41,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'items' => [ - 'type' => [ 'list_of' => 'CartItemInput' ], + return array( + 'items' => array( + 'type' => array( 'list_of' => 'CartItemInput' ), 'description' => __( 'Cart items to be added', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -55,22 +55,22 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'added' => [ - 'type' => [ 'list_of' => 'CartItem' ], + return array( + 'added' => array( + 'type' => array( 'list_of' => 'CartItem' ), 'resolve' => static function ( $payload ) { - $items = []; + $items = array(); foreach ( $payload['added'] as $key ) { $items[] = \WC()->cart->get_cart_item( $key ); } return $items; }, - ], - 'cartErrors' => [ - 'type' => [ 'list_of' => 'CartItemError' ], + ), + 'cartErrors' => array( + 'type' => array( 'list_of' => 'CartItemError' ), 'resolve' => static function ( $payload ) { - $errors = []; + $errors = array(); foreach ( $payload['failure'] as $error_data ) { $cart_error = $error_data['cart_item_data']; $cart_error['type'] = 'INVALID_CART_ITEM'; @@ -78,7 +78,7 @@ public static function get_output_fields() { if ( ! empty( $error_data['reasons'] ) ) { $cart_error['reasons'] = $error_data['reasons']; } elseif ( $error_data['reason'] ) { - $cart_error['reasons'] = [ $error_data['reason'] ]; + $cart_error['reasons'] = array( $error_data['reason'] ); } $errors[] = $cart_error; @@ -86,9 +86,9 @@ public static function get_output_fields() { return $errors; }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -106,8 +106,8 @@ public static function mutate_and_get_payload() { } // Validate cart item input. - $added = []; - $failure = []; + $added = array(); + $failure = array(); foreach ( $input['items'] as $cart_item_data ) { try { // Prepare args for "add_to_cart" from input data. @@ -144,7 +144,7 @@ public static function mutate_and_get_payload() { // Log captured errors. if ( ! empty( $failure ) ) { - graphql_debug( $failure, [ 'type' => 'INVALID_CART_ITEMS' ] ); + graphql_debug( $failure, array( 'type' => 'INVALID_CART_ITEMS' ) ); } // Throw error, if no items added. diff --git a/includes/mutation/class-cart-apply-coupon.php b/includes/mutation/class-cart-apply-coupon.php index b136d41dd..bcb78c249 100644 --- a/includes/mutation/class-cart-apply-coupon.php +++ b/includes/mutation/class-cart-apply-coupon.php @@ -25,11 +25,11 @@ class Cart_Apply_Coupon { public static function register_mutation() { register_graphql_mutation( 'applyCoupon', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -39,12 +39,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'code' => [ - 'type' => [ 'non_null' => 'String' ], + return array( + 'code' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Code of coupon being applied', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -53,15 +53,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'applied' => [ + return array( + 'applied' => array( 'type' => 'AppliedCoupon', 'resolve' => static function ( $payload ) { return $payload['code']; }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -78,7 +78,7 @@ public static function mutate_and_get_payload() { if ( Cart_Mutation::validate_coupon( $input['code'], $reason ) && \WC()->cart->apply_coupon( $input['code'] ) ) { do_action( 'woographql_update_session', true ); - return [ 'code' => $input['code'] ]; + return array( 'code' => $input['code'] ); } // If any session error notices, capture them. diff --git a/includes/mutation/class-cart-empty.php b/includes/mutation/class-cart-empty.php index 3d634d404..b742888d1 100644 --- a/includes/mutation/class-cart-empty.php +++ b/includes/mutation/class-cart-empty.php @@ -27,13 +27,13 @@ class Cart_Empty { public static function register_mutation() { register_graphql_mutation( 'emptyCart', - [ - 'inputFields' => [ - 'clearPersistentCart' => [ 'type' => 'Boolean' ], - ], + array( + 'inputFields' => array( + 'clearPersistentCart' => array( 'type' => 'Boolean' ), + ), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -43,15 +43,15 @@ public static function register_mutation() { * @return array */ public static function get_output_fields() { - return [ + return array( 'deletedCart' => Cart_Mutation::get_cart_field(), - 'cart' => [ + 'cart' => array( 'type' => 'Cart', 'resolve' => static function () { return \WC()->cart; }, - ], - ]; + ), + ); } /** @@ -96,7 +96,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_update_session', true ); - return [ 'cart' => $cloned_cart ]; + return array( 'cart' => $cloned_cart ); }; } } diff --git a/includes/mutation/class-cart-fill.php b/includes/mutation/class-cart-fill.php index 9df21193a..f7df219ee 100644 --- a/includes/mutation/class-cart-fill.php +++ b/includes/mutation/class-cart-fill.php @@ -28,11 +28,11 @@ class Cart_Fill { public static function register_mutation() { register_graphql_mutation( 'fillCart', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -42,20 +42,20 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'shippingMethods' => [ - 'type' => [ 'list_of' => 'String' ], + return array( + 'shippingMethods' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Shipping methods to be used.', 'wp-graphql-woocommerce' ), - ], - 'coupons' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'coupons' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Coupons to be applied to the cart', 'wp-graphql-woocommerce' ), - ], - 'items' => [ - 'type' => [ 'list_of' => 'CartItemInput' ], + ), + 'items' => array( + 'type' => array( 'list_of' => 'CartItemInput' ), 'description' => __( 'Cart items to be added', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -64,36 +64,36 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'added' => [ - 'type' => [ 'list_of' => 'CartItem' ], + return array( + 'added' => array( + 'type' => array( 'list_of' => 'CartItem' ), 'resolve' => static function ( $payload ) { - $items = []; + $items = array(); foreach ( $payload['added'] as $key ) { $items[] = \WC()->cart->get_cart_item( $key ); } return $items; }, - ], - 'applied' => [ - 'type' => [ 'list_of' => 'AppliedCoupon' ], + ), + 'applied' => array( + 'type' => array( 'list_of' => 'AppliedCoupon' ), 'resolve' => static function ( $payload ) { $codes = $payload['applied']; return ! empty( $codes ) ? $codes : null; }, - ], - 'chosenShippingMethods' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'chosenShippingMethods' => array( + 'type' => array( 'list_of' => 'String' ), 'resolve' => static function ( $payload ) { $methods = $payload['chosen_shipping_methods']; return ! empty( $methods ) ? $methods : null; }, - ], - 'cartErrors' => [ - 'type' => [ 'list_of' => 'CartError' ], + ), + 'cartErrors' => array( + 'type' => array( 'list_of' => 'CartError' ), 'resolve' => static function ( $payload ) { - $errors = []; + $errors = array(); $all_error_data = array_merge( $payload['invalid_cart_items'], $payload['invalid_coupons'], @@ -101,37 +101,37 @@ public static function get_output_fields() { ); foreach ( $all_error_data as $error_data ) { - $cart_error = []; + $cart_error = array(); switch ( true ) { case isset( $error_data['cart_item_data'] ): $cart_error = $error_data['cart_item_data']; $cart_error['type'] = 'INVALID_CART_ITEM'; break; case isset( $error_data['code'] ): - $cart_error = [ + $cart_error = array( 'code' => $error_data['code'], 'type' => 'INVALID_COUPON', - ]; + ); break; case isset( $error_data['package'] ): - $cart_error = [ + $cart_error = array( 'package' => $error_data['package'], 'chosen_method' => $error_data['chosen_method'], 'type' => 'INVALID_SHIPPING_METHOD', - ]; + ); break; default: - $cart_error = [ - 'reasons' => [ 'Unknown error occurred.' ], + $cart_error = array( + 'reasons' => array( 'Unknown error occurred.' ), 'type' => 'UNKNOWN', - ]; + ); break; }//end switch if ( ! empty( $error_data['reasons'] ) ) { $cart_error['reasons'] = $error_data['reasons']; } elseif ( $error_data['reason'] ) { - $cart_error['reasons'] = [ $error_data['reason'] ]; + $cart_error['reasons'] = array( $error_data['reason'] ); } $errors[] = $cart_error; @@ -139,9 +139,9 @@ public static function get_output_fields() { return $errors; }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -159,8 +159,8 @@ public static function mutate_and_get_payload() { } // Validate cart item input. - $added = []; - $invalid_cart_items = []; + $added = array(); + $invalid_cart_items = array(); foreach ( $input['items'] as $cart_item_data ) { try { // Prepare args for "add_to_cart" from input data. @@ -197,7 +197,7 @@ public static function mutate_and_get_payload() { // Log captured errors. if ( ! empty( $invalid_cart_items ) ) { - graphql_debug( $invalid_cart_items, [ 'type' => 'INVALID_CART_ITEMS' ] ); + graphql_debug( $invalid_cart_items, array( 'type' => 'INVALID_CART_ITEMS' ) ); } // Throw error, if no items added. @@ -205,8 +205,8 @@ public static function mutate_and_get_payload() { throw new UserError( __( 'Failed to add any cart items. Please check input.', 'wp-graphql-woocommerce' ) ); } - $applied = []; - $invalid_coupons = []; + $applied = array(); + $invalid_coupons = array(); if ( ! empty( $input['coupons'] ) ) { foreach ( $input['coupons'] as $code ) { $reason = ''; @@ -232,12 +232,12 @@ public static function mutate_and_get_payload() { }//end foreach if ( ! empty( $invalid_coupons ) ) { - graphql_debug( $invalid_coupons, [ 'type' => 'INVALID_COUPONS' ] ); + graphql_debug( $invalid_coupons, array( 'type' => 'INVALID_COUPONS' ) ); } }//end if - $chosen_shipping_methods = []; - $invalid_shipping_methods = []; + $chosen_shipping_methods = array(); + $invalid_shipping_methods = array(); if ( ! empty( $input['shippingMethods'] ) ) { $posted_shipping_methods = $input['shippingMethods']; @@ -263,7 +263,7 @@ public static function mutate_and_get_payload() { \WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); if ( ! empty( $invalid_shipping_methods ) ) { - graphql_debug( $invalid_shipping_methods, [ 'type' => 'INVALID_SHIPPING_METHODS' ] ); + graphql_debug( $invalid_shipping_methods, array( 'type' => 'INVALID_SHIPPING_METHODS' ) ); } }//end if diff --git a/includes/mutation/class-cart-remove-coupons.php b/includes/mutation/class-cart-remove-coupons.php index 6be66f5f6..6d32e9c49 100644 --- a/includes/mutation/class-cart-remove-coupons.php +++ b/includes/mutation/class-cart-remove-coupons.php @@ -25,11 +25,11 @@ class Cart_Remove_Coupons { public static function register_mutation() { register_graphql_mutation( 'removeCoupons', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -39,12 +39,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'codes' => [ - 'type' => [ 'list_of' => 'String' ], + return array( + 'codes' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Code of coupon being applied', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -53,9 +53,9 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ + return array( 'cart' => Cart_Mutation::get_cart_field(), - ]; + ); } /** @@ -89,7 +89,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_update_session', true ); // Return payload. - return [ 'cart' => \WC()->cart ]; + return array( 'cart' => \WC()->cart ); }; } } diff --git a/includes/mutation/class-cart-remove-items.php b/includes/mutation/class-cart-remove-items.php index 1c03dd39e..bc8d0773f 100644 --- a/includes/mutation/class-cart-remove-items.php +++ b/includes/mutation/class-cart-remove-items.php @@ -27,11 +27,11 @@ class Cart_Remove_Items { public static function register_mutation() { register_graphql_mutation( 'removeItemsFromCart', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,16 +41,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'keys' => [ - 'type' => [ 'list_of' => 'ID' ], + return array( + 'keys' => array( + 'type' => array( 'list_of' => 'ID' ), 'description' => __( 'Item keys of the items being removed', 'wp-graphql-woocommerce' ), - ], - 'all' => [ + ), + 'all' => array( 'type' => 'Boolean', 'description' => __( 'Remove all cart items', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -59,15 +59,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'cartItems' => [ - 'type' => [ 'list_of' => 'CartItem' ], + return array( + 'cartItems' => array( + 'type' => array( 'list_of' => 'CartItem' ), 'resolve' => static function ( $payload ) { return $payload['items']; }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -99,7 +99,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_update_session', true ); // Return payload. - return [ 'items' => $cart_items ]; + return array( 'items' => $cart_items ); }; } } diff --git a/includes/mutation/class-cart-restore-items.php b/includes/mutation/class-cart-restore-items.php index aa57476a2..6282a2843 100644 --- a/includes/mutation/class-cart-restore-items.php +++ b/includes/mutation/class-cart-restore-items.php @@ -27,11 +27,11 @@ class Cart_Restore_Items { public static function register_mutation() { register_graphql_mutation( 'restoreCartItems', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,12 +41,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'keys' => [ - 'type' => [ 'list_of' => 'ID' ], + return array( + 'keys' => array( + 'type' => array( 'list_of' => 'ID' ), 'description' => __( 'Cart item key of the item being removed', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -85,7 +85,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_update_session', true ); // Return payload. - return [ 'items' => $cart_items ]; + return array( 'items' => $cart_items ); }; } } diff --git a/includes/mutation/class-cart-update-item-quantities.php b/includes/mutation/class-cart-update-item-quantities.php index a85219988..8a91ec015 100644 --- a/includes/mutation/class-cart-update-item-quantities.php +++ b/includes/mutation/class-cart-update-item-quantities.php @@ -28,11 +28,11 @@ class Cart_Update_Item_Quantities { public static function register_mutation() { register_graphql_mutation( 'updateItemQuantities', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -42,12 +42,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'items' => [ - 'type' => [ 'list_of' => 'CartItemQuantityInput' ], + return array( + 'items' => array( + 'type' => array( 'list_of' => 'CartItemQuantityInput' ), 'description' => __( 'Cart item being updated', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -56,37 +56,37 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'updated' => [ - 'type' => [ 'list_of' => 'CartItem' ], + return array( + 'updated' => array( + 'type' => array( 'list_of' => 'CartItem' ), 'resolve' => static function ( $payload ) { - $items = []; + $items = array(); foreach ( $payload['updated'] as $key ) { $items[] = WC()->cart->get_cart_item( $key ); } return $items; }, - ], - 'removed' => [ - 'type' => [ 'list_of' => 'CartItem' ], + ), + 'removed' => array( + 'type' => array( 'list_of' => 'CartItem' ), 'resolve' => static function ( $payload ) { return $payload['removed']; }, - ], - 'items' => [ - 'type' => [ 'list_of' => 'CartItem' ], + ), + 'items' => array( + 'type' => array( 'list_of' => 'CartItem' ), 'resolve' => static function ( $payload ) { - $updated = []; + $updated = array(); foreach ( $payload['updated'] as $key ) { $updated[] = \WC()->cart->get_cart_item( $key ); } return array_merge( $updated, $payload['removed'] ); }, - ], + ), 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -111,9 +111,9 @@ public static function mutate_and_get_payload() { do_action( 'graphql_woocommerce_before_set_item_quantities', $input['items'], $input, $context, $info ); // Update quantities. If quantity set to 0, the items in removed. - $removed = []; - $updated = []; - $removed_items = []; + $removed = array(); + $updated = array(); + $removed_items = array(); foreach ( $input['items'] as $item ) { if ( Cart_Mutation::item_is_valid( $item ) ) { $key = $item['key']; @@ -167,10 +167,10 @@ static function ( $value ) { do_action( 'woographql_update_session', true ); - return [ + return array( 'removed' => $removed_items, 'updated' => array_keys( $updated ), - ]; + ); }; } } diff --git a/includes/mutation/class-cart-update-shipping-method.php b/includes/mutation/class-cart-update-shipping-method.php index 4a897a8d6..fd286b8ec 100644 --- a/includes/mutation/class-cart-update-shipping-method.php +++ b/includes/mutation/class-cart-update-shipping-method.php @@ -25,11 +25,11 @@ class Cart_Update_Shipping_Method { public static function register_mutation() { register_graphql_mutation( 'updateShippingMethod', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -39,11 +39,11 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'shippingMethods' => [ - 'type' => [ 'list_of' => 'String' ], - ], - ]; + return array( + 'shippingMethods' => array( + 'type' => array( 'list_of' => 'String' ), + ), + ); } /** @@ -52,9 +52,9 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ + return array( 'cart' => Cart_Mutation::get_cart_field( true ), - ]; + ); } /** @@ -80,7 +80,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_update_session', true ); - return []; + return array(); }; } } diff --git a/includes/mutation/class-checkout.php b/includes/mutation/class-checkout.php index f8e9d0d36..0b047b4b5 100644 --- a/includes/mutation/class-checkout.php +++ b/includes/mutation/class-checkout.php @@ -30,11 +30,11 @@ class Checkout { public static function register_mutation() { register_graphql_mutation( 'checkout', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -44,48 +44,48 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'paymentMethod' => [ + return array( + 'paymentMethod' => array( 'type' => 'String', 'description' => __( 'Payment method ID.', 'wp-graphql-woocommerce' ), - ], - 'shippingMethod' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'shippingMethod' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Order shipping method', 'wp-graphql-woocommerce' ), - ], - 'shipToDifferentAddress' => [ + ), + 'shipToDifferentAddress' => array( 'type' => 'Boolean', 'description' => __( 'Ship to a separate address', 'wp-graphql-woocommerce' ), - ], - 'billing' => [ + ), + 'billing' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Order billing address', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Order shipping address', 'wp-graphql-woocommerce' ), - ], - 'account' => [ + ), + 'account' => array( 'type' => 'CreateAccountInput', 'description' => __( 'Create new customer account', 'wp-graphql-woocommerce' ), - ], - 'transactionId' => [ + ), + 'transactionId' => array( 'type' => 'String', 'description' => __( 'Order transaction ID', 'wp-graphql-woocommerce' ), - ], - 'isPaid' => [ + ), + 'isPaid' => array( 'type' => 'Boolean', 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ - 'type' => [ 'list_of' => 'MetaDataInput' ], + ), + 'metaData' => array( + 'type' => array( 'list_of' => 'MetaDataInput' ), 'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ), - ], - 'customerNote' => [ + ), + 'customerNote' => array( 'type' => 'String', 'description' => __( 'Order customer note', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -94,32 +94,32 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'order' => [ + return array( + 'order' => array( 'type' => 'Order', 'resolve' => static function ( $payload ) { return new Order( $payload['id'] ); }, - ], - 'customer' => [ + ), + 'customer' => array( 'type' => 'Customer', 'resolve' => static function () { return is_user_logged_in() ? new Customer( get_current_user_id() ) : new Customer(); }, - ], - 'result' => [ + ), + 'result' => array( 'type' => 'String', 'resolve' => static function ( $payload ) { return $payload['result']; }, - ], - 'redirect' => [ + ), + 'redirect' => array( 'type' => 'String', 'resolve' => static function ( $payload ) { return $payload['redirect']; }, - ], - ]; + ), + ); } /** @@ -145,7 +145,7 @@ public static function mutate_and_get_payload() { do_action( 'graphql_woocommerce_before_checkout', $args, $input, $context, $info ); // We define this now and pass it as a reference. - $results = []; + $results = array(); $order_id = Checkout_Mutation::process_checkout( $args, $input, $context, $info, $results ); @@ -165,7 +165,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_checkout', $order, $input, $context, $info ); - return array_merge( [ 'id' => $order_id ], $results ); + return array_merge( array( 'id' => $order_id ), $results ); } catch ( \Throwable $e ) { // Delete order if it was created. if ( is_object( $order ) ) { diff --git a/includes/mutation/class-coupon-create.php b/includes/mutation/class-coupon-create.php index fce437720..db7633c10 100644 --- a/includes/mutation/class-coupon-create.php +++ b/includes/mutation/class-coupon-create.php @@ -29,11 +29,11 @@ class Coupon_Create { public static function register_mutation() { register_graphql_mutation( 'createCoupon', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => [ self::class, 'mutate_and_get_payload' ], - ] + 'mutateAndGetPayload' => array( self::class, 'mutate_and_get_payload' ), + ) ); } @@ -43,88 +43,88 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'code' => [ - 'type' => [ 'non_null' => 'String' ], + return array( + 'code' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Coupon code.', 'wp-graphql-woocommerce' ), - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'Float', 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'wp-graphql-woocommerce' ), - ], - 'discountType' => [ + ), + 'discountType' => array( 'type' => 'DiscountTypeEnum', 'description' => __( 'Determines the type of discount that will be applied.', 'wp-graphql-woocommerce' ), - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Coupon description.', 'wp-graphql-woocommerce' ), - ], - 'dateExpires' => [ + ), + 'dateExpires' => array( 'type' => 'String', 'description' => __( 'The date the coupon expires, in the site\'s timezone.', 'wp-graphql-woocommerce' ), - ], - 'dateExpiresGmt' => [ + ), + 'dateExpiresGmt' => array( 'type' => 'String', 'description' => __( 'The date the coupon expires, as GMT.', 'wp-graphql-woocommerce' ), - ], - 'individualUse' => [ + ), + 'individualUse' => array( 'type' => 'Boolean', 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'wp-graphql-woocommerce' ), - ], - 'productIds' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'productIds' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'List of product IDs the coupon can be used on.', 'wp-graphql-woocommerce' ), - ], - 'excludedProductIds' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'excludedProductIds' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'List of product IDs the coupon cannot be used on.', 'wp-graphql-woocommerce' ), - ], - 'usageLimit' => [ + ), + 'usageLimit' => array( 'type' => 'Int', 'description' => __( 'How many times the coupon can be used in total.', 'wp-graphql-woocommerce' ), - ], - 'usageLimitPerUser' => [ + ), + 'usageLimitPerUser' => array( 'type' => 'Int', 'description' => __( 'How many times the coupon can be used per customer.', 'wp-graphql-woocommerce' ), - ], - 'limitUsageToXItems' => [ + ), + 'limitUsageToXItems' => array( 'type' => 'Int', 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'wp-graphql-woocommerce' ), - ], - 'freeShipping' => [ + ), + 'freeShipping' => array( 'type' => 'Boolean', 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'wp-graphql-woocommerce' ), - ], - 'productCategories' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'productCategories' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'List of category IDs the coupon applies to.', 'wp-graphql-woocommerce' ), - ], - 'excludedProductCategories' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'excludedProductCategories' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'List of category IDs the coupon does not apply to.', 'wp-graphql-woocommerce' ), - ], - 'excludeSaleItems' => [ + ), + 'excludeSaleItems' => array( 'type' => 'Boolean', 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'wp-graphql-woocommerce' ), - ], - 'minimumAmount' => [ + ), + 'minimumAmount' => array( 'type' => 'String', 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'wp-graphql-woocommerce' ), - ], - 'maximumAmount' => [ + ), + 'maximumAmount' => array( 'type' => 'String', 'description' => __( 'Maximum order amount allowed when using the coupon.', 'wp-graphql-woocommerce' ), - ], - 'emailRestrictions' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'emailRestrictions' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'List of email addresses that can use this coupon.', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ - 'type' => [ 'list_of' => 'MetaDataInput' ], + ), + 'metaData' => array( + 'type' => array( 'list_of' => 'MetaDataInput' ), 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -133,20 +133,20 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'coupon' => [ + return array( + 'coupon' => array( 'type' => 'Coupon', 'resolve' => static function ( $payload ) { return new Coupon( $payload['id'] ); }, - ], - 'code' => [ + ), + 'code' => array( 'type' => 'String', 'resolve' => static function ( $payload ) { return $payload['code']; }, - ], - ]; + ), + ); } /** @@ -209,13 +209,13 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso $coupon->set_description( wp_filter_post_kses( $value ) ); break; default: - if ( is_callable( [ $coupon, "set_{$key}" ] ) ) { + if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { $coupon->{"set_{$key}"}( $value ); } break; }//end switch }//end foreach - return [ 'id' => $coupon->save() ]; + return array( 'id' => $coupon->save() ); } } diff --git a/includes/mutation/class-coupon-delete.php b/includes/mutation/class-coupon-delete.php index 9e74fe8f4..b5eed19c7 100644 --- a/includes/mutation/class-coupon-delete.php +++ b/includes/mutation/class-coupon-delete.php @@ -28,11 +28,11 @@ class Coupon_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteCoupon', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => [ self::class, 'mutate_and_get_payload' ], - ] + 'mutateAndGetPayload' => array( self::class, 'mutate_and_get_payload' ), + ) ); } @@ -42,16 +42,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Unique identifier for the object.', 'wp-graphql-woocommerce' ), - ], - 'forceDelete' => [ + ), + 'forceDelete' => array( 'type' => 'Boolean', 'description' => __( 'Delete the object. Set to "false" by default.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -62,14 +62,14 @@ public static function get_input_fields() { public static function get_output_fields() { return array_merge( Coupon_Create::get_output_fields(), - [ - 'coupon' => [ + array( + 'coupon' => array( 'type' => 'Coupon', 'resolve' => static function ( $payload ) { return ! empty( $payload['coupon'] ) ? $payload['coupon'] : null; }, - ], - ] + ), + ) ); } diff --git a/includes/mutation/class-coupon-update.php b/includes/mutation/class-coupon-update.php index 6670ce968..a94d163a2 100644 --- a/includes/mutation/class-coupon-update.php +++ b/includes/mutation/class-coupon-update.php @@ -22,11 +22,11 @@ class Coupon_Update { public static function register_mutation() { register_graphql_mutation( 'updateCoupon', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => Coupon_Create::get_output_fields(), - 'mutateAndGetPayload' => [ Coupon_Create::class, 'mutate_and_get_payload' ], - ] + 'mutateAndGetPayload' => array( Coupon_Create::class, 'mutate_and_get_payload' ), + ) ); } @@ -38,16 +38,16 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Coupon_Create::get_input_fields(), - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Unique identifier for the object.', 'wp-graphql-woocommerce' ), - ], - 'code' => [ + ), + 'code' => array( 'type' => 'String', 'description' => __( 'Coupon code.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } } diff --git a/includes/mutation/class-customer-register.php b/includes/mutation/class-customer-register.php index 2a28f1509..9a116b754 100644 --- a/includes/mutation/class-customer-register.php +++ b/includes/mutation/class-customer-register.php @@ -30,11 +30,11 @@ class Customer_Register { public static function register_mutation() { register_graphql_mutation( 'registerCustomer', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -46,24 +46,24 @@ public static function register_mutation() { public static function get_input_fields() { $result = array_merge( UserRegister::get_input_fields(), - [ - 'billing' => [ + array( + 'billing' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Customer billing information', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Customer shipping address', 'wp-graphql-woocommerce' ), - ], - 'shippingSameAsBilling' => [ + ), + 'shippingSameAsBilling' => array( 'type' => 'Boolean', 'description' => __( 'Customer shipping is identical to billing address', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ + ), + 'metaData' => array( 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'type' => [ 'list_of' => 'MetaDataInput' ], - ], - ] + 'type' => array( 'list_of' => 'MetaDataInput' ), + ), + ) ); // Make the username field optional. @@ -78,21 +78,21 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'customer' => [ + return array( + 'customer' => array( 'type' => 'Customer', 'resolve' => static function ( $payload ) { return new Customer( $payload['id'] ); }, - ], - 'viewer' => [ + ), + 'viewer' => array( 'type' => 'User', 'resolve' => static function ( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); return false !== $user ? new User( $user ) : null; }, - ], - ]; + ), + ); } /** @@ -191,7 +191,7 @@ public static function mutate_and_get_payload() { } // Return payload. - return [ 'id' => $user_id ]; + return array( 'id' => $user_id ); }; } } diff --git a/includes/mutation/class-customer-update.php b/includes/mutation/class-customer-update.php index 0f18b2080..03d253757 100644 --- a/includes/mutation/class-customer-update.php +++ b/includes/mutation/class-customer-update.php @@ -29,11 +29,11 @@ class Customer_Update { public static function register_mutation() { register_graphql_mutation( 'updateCustomer', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -45,32 +45,32 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( UserCreate::get_input_fields(), - [ - 'id' => [ + array( + 'id' => array( 'type' => 'ID', 'description' => __( 'The ID of the user', 'wp-graphql-woocommerce' ), - ], - 'billing' => [ + ), + 'billing' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Customer billing information', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Customer shipping address', 'wp-graphql-woocommerce' ), - ], - 'shippingSameAsBilling' => [ + ), + 'shippingSameAsBilling' => array( 'type' => 'Boolean', 'description' => __( 'Customer shipping is identical to billing address', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ + ), + 'metaData' => array( 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'type' => [ 'list_of' => 'MetaDataInput' ], - ], - 'isSession' => [ + 'type' => array( 'list_of' => 'MetaDataInput' ), + ), + 'isSession' => array( 'type' => 'Boolean', 'description' => __( 'Whether to save changes on the session or in the database', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -80,14 +80,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'customer' => [ + return array( + 'customer' => array( 'type' => 'Customer', 'resolve' => static function ( $payload ) { return new Customer( $payload['id'] ); }, - ], - ]; + ), + ); } /** @@ -139,13 +139,13 @@ public static function mutate_and_get_payload() { // Check if group field has set function and assigns new value. foreach ( $value as $field => $field_value ) { - if ( is_callable( [ $customer, "set_{$prop}_{$field}" ] ) ) { + if ( is_callable( array( $customer, "set_{$prop}_{$field}" ) ) ) { $customer->{"set_{$prop}_{$field}"}( $field_value ); } } // If field has set function and assigns new value. - } elseif ( is_callable( [ $customer, "set_{$prop}" ] ) ) { + } elseif ( is_callable( array( $customer, "set_{$prop}" ) ) ) { $customer->{"set_{$prop}"}( $value ); } } @@ -163,7 +163,7 @@ public static function mutate_and_get_payload() { } // Return payload. - return ! empty( $payload ) ? $payload : [ 'id' => 'session' ]; + return ! empty( $payload ) ? $payload : array( 'id' => 'session' ); }; } } diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index 72f065486..fa8b6f294 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -29,11 +29,11 @@ class Order_Create { public static function register_mutation() { register_graphql_mutation( 'createOrder', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -43,72 +43,72 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'parentId' => [ + return array( + 'parentId' => array( 'type' => 'Int', 'description' => __( 'Parent order ID.', 'wp-graphql-woocommerce' ), - ], - 'currency' => [ + ), + 'currency' => array( 'type' => 'CurrencyEnum', 'description' => __( 'Currency the order was created with, in ISO format.', 'wp-graphql-woocommerce' ), - ], - 'customerId' => [ + ), + 'customerId' => array( 'type' => 'Int', 'description' => __( 'Order customer ID', 'wp-graphql-woocommerce' ), - ], - 'customerNote' => [ + ), + 'customerNote' => array( 'type' => 'String', 'description' => __( 'Note left by customer during checkout.', 'wp-graphql-woocommerce' ), - ], - 'coupons' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'coupons' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Coupons codes to be applied to order', 'wp-graphql-woocommerce' ), - ], - 'status' => [ + ), + 'status' => array( 'type' => 'OrderStatusEnum', 'description' => __( 'Order status', 'wp-graphql-woocommerce' ), - ], - 'paymentMethod' => [ + ), + 'paymentMethod' => array( 'type' => 'String', 'description' => __( 'Payment method ID.', 'wp-graphql-woocommerce' ), - ], - 'paymentMethodTitle' => [ + ), + 'paymentMethodTitle' => array( 'type' => 'String', 'description' => __( 'Payment method title.', 'wp-graphql-woocommerce' ), - ], - 'transactionId' => [ + ), + 'transactionId' => array( 'type' => 'String', 'description' => __( 'Order transaction ID', 'wp-graphql-woocommerce' ), - ], - 'billing' => [ + ), + 'billing' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Order billing address', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'CustomerAddressInput', 'description' => __( 'Order shipping address', 'wp-graphql-woocommerce' ), - ], - 'lineItems' => [ - 'type' => [ 'list_of' => 'LineItemInput' ], + ), + 'lineItems' => array( + 'type' => array( 'list_of' => 'LineItemInput' ), 'description' => __( 'Order line items', 'wp-graphql-woocommerce' ), - ], - 'shippingLines' => [ - 'type' => [ 'list_of' => 'ShippingLineInput' ], + ), + 'shippingLines' => array( + 'type' => array( 'list_of' => 'ShippingLineInput' ), 'description' => __( 'Order shipping lines', 'wp-graphql-woocommerce' ), - ], - 'feeLines' => [ - 'type' => [ 'list_of' => 'FeeLineInput' ], + ), + 'feeLines' => array( + 'type' => array( 'list_of' => 'FeeLineInput' ), 'description' => __( 'Order shipping lines', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ - 'type' => [ 'list_of' => 'MetaDataInput' ], + ), + 'metaData' => array( + 'type' => array( 'list_of' => 'MetaDataInput' ), 'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ), - ], - 'isPaid' => [ + ), + 'isPaid' => array( 'type' => 'Boolean', 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -117,20 +117,20 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'order' => [ + return array( + 'order' => array( 'type' => 'Order', 'resolve' => static function ( $payload ) { return new Order( $payload['id'] ); }, - ], - 'orderId' => [ + ), + 'orderId' => array( 'type' => 'Int', 'resolve' => static function ( $payload ) { return $payload['id']; }, - ], - ]; + ), + ); } /** @@ -197,7 +197,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_create', $order, $input, $context, $info ); - return [ 'id' => $order->get_id() ]; + return array( 'id' => $order->get_id() ); } catch ( \Throwable $e ) { // Delete order if it was created. if ( is_object( $order ) ) { diff --git a/includes/mutation/class-order-delete-items.php b/includes/mutation/class-order-delete-items.php index 9b7b17866..bf1153d75 100644 --- a/includes/mutation/class-order-delete-items.php +++ b/includes/mutation/class-order-delete-items.php @@ -29,11 +29,11 @@ class Order_Delete_Items { public static function register_mutation() { register_graphql_mutation( 'deleteOrderItems', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -44,21 +44,21 @@ public static function register_mutation() { */ public static function get_input_fields() { return array_merge( - [ - 'id' => [ + array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Database ID or global ID of the order', 'wp-graphql-woocommerce' ), - ], - 'orderId' => [ + ), + 'orderId' => array( 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'Use "id" field instead.', 'wp-graphql-woocommerce' ), - ], - 'itemIds' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'itemIds' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'ID Order items being deleted', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -68,14 +68,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'order' => [ + return array( + 'order' => array( 'type' => 'Order', 'resolve' => static function ( $payload ) { return $payload['order']; }, - ], - ]; + ), + ); } /** @@ -166,7 +166,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_delete', $ids, $working_order, $input, $context, $info ); - return [ 'order' => $order ]; + return array( 'order' => $order ); }; } } diff --git a/includes/mutation/class-order-delete.php b/includes/mutation/class-order-delete.php index 74b43293d..ec1fb0728 100644 --- a/includes/mutation/class-order-delete.php +++ b/includes/mutation/class-order-delete.php @@ -30,11 +30,11 @@ class Order_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteOrder', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -45,21 +45,21 @@ public static function register_mutation() { */ public static function get_input_fields() { return array_merge( - [ - 'id' => [ + array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Database ID or global ID of the order', 'wp-graphql-woocommerce' ), - ], - 'orderId' => [ + ), + 'orderId' => array( 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'Use "id" field instead.', 'wp-graphql-woocommerce' ), - ], - 'forceDelete' => [ + ), + 'forceDelete' => array( 'type' => 'Boolean', 'description' => __( 'Delete or simply place in trash.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -69,14 +69,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'order' => [ + return array( + 'order' => array( 'type' => 'Order', 'resolve' => static function ( $payload ) { return $payload['order']; }, - ], - ]; + ), + ); } /** @@ -166,7 +166,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_delete', $order, $input, $context, $info ); - return [ 'order' => $order ]; + return array( 'order' => $order ); }; } } diff --git a/includes/mutation/class-order-update.php b/includes/mutation/class-order-update.php index 2fc8cf715..4017492a4 100644 --- a/includes/mutation/class-order-update.php +++ b/includes/mutation/class-order-update.php @@ -30,11 +30,11 @@ class Order_Update { public static function register_mutation() { register_graphql_mutation( 'updateOrder', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -46,21 +46,21 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Order_Create::get_input_fields(), - [ - 'id' => [ + array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Database ID or global ID of the order', 'wp-graphql-woocommerce' ), - ], - 'orderId' => [ + ), + 'orderId' => array( 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'Use "id" field instead.', 'wp-graphql-woocommerce' ), - ], - 'customerId' => [ + ), + 'customerId' => array( 'type' => 'ID', 'description' => __( 'Database ID or global ID of the customer for the order', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -70,14 +70,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'order' => [ + return array( + 'order' => array( 'type' => 'Order', 'resolve' => static function ( $payload ) { return new Order( $payload['id'] ); }, - ], - ]; + ), + ); } /** @@ -166,7 +166,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_update', $order, $input, $context, $info ); - return [ 'id' => $order->get_id() ]; + return array( 'id' => $order->get_id() ); }; } } diff --git a/includes/mutation/class-payment-method-delete.php b/includes/mutation/class-payment-method-delete.php index 35425f0a9..7a3bb54db 100644 --- a/includes/mutation/class-payment-method-delete.php +++ b/includes/mutation/class-payment-method-delete.php @@ -25,11 +25,11 @@ class Payment_Method_Delete { public static function register_mutation() { register_graphql_mutation( 'deletePaymentMethod', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -39,13 +39,13 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'tokenId' => [ - 'type' => [ 'non_null' => 'Integer' ], + return array( + 'tokenId' => array( + 'type' => array( 'non_null' => 'Integer' ), 'description' => __( 'Token ID of the payment token being deleted.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -54,15 +54,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'status' => [ + return array( + 'status' => array( 'type' => 'String', 'description' => __( 'Status of the request', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { return ! empty( $payload['status'] ) ? $payload['status'] : 'FAILED'; }, - ], - ]; + ), + ); } /** @@ -87,7 +87,7 @@ public static function mutate_and_get_payload() { WC_Payment_Tokens::delete( $token_id ); wc_add_notice( __( 'Payment method deleted.', 'wp-graphql-woocommerce' ) ); - return [ 'status' => 'SUCCESS' ]; + return array( 'status' => 'SUCCESS' ); }; } } diff --git a/includes/mutation/class-payment-method-set-default.php b/includes/mutation/class-payment-method-set-default.php index 6b77d2e0c..947baad26 100644 --- a/includes/mutation/class-payment-method-set-default.php +++ b/includes/mutation/class-payment-method-set-default.php @@ -25,11 +25,11 @@ class Payment_Method_Set_Default { public static function register_mutation() { register_graphql_mutation( 'setDefaultPaymentMethod', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -39,12 +39,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'tokenId' => [ - 'type' => [ 'non_null' => 'Integer' ], + return array( + 'tokenId' => array( + 'type' => array( 'non_null' => 'Integer' ), 'description' => __( 'Token ID of the payment token being deleted.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -53,22 +53,22 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'status' => [ + return array( + 'status' => array( 'type' => 'String', 'description' => __( 'Status of the request', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { return ! empty( $payload['status'] ) ? $payload['status'] : 'FAILED'; }, - ], - 'token' => [ + ), + 'token' => array( 'type' => 'PaymentToken', 'description' => __( 'Preferred payment method token', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { return ! empty( $payload['token'] ) ? $payload['token'] : null; }, - ], - ]; + ), + ); } /** @@ -93,10 +93,10 @@ public static function mutate_and_get_payload() { WC_Payment_Tokens::set_users_default( $token->get_user_id(), intval( $token_id ) ); wc_add_notice( __( 'This payment method was successfully set as your default.', 'wp-graphql-woocommerce' ) ); - return [ + return array( 'status' => 'SUCCESS', 'token' => WC_Payment_Tokens::get( $token_id ), - ]; + ); }; } } diff --git a/includes/mutation/class-review-delete-restore.php b/includes/mutation/class-review-delete-restore.php index 0fa1312f4..ddce8369c 100644 --- a/includes/mutation/class-review-delete-restore.php +++ b/includes/mutation/class-review-delete-restore.php @@ -29,21 +29,21 @@ public static function register_mutation() { // Trash/Delete mutation. register_graphql_mutation( 'deleteReview', - [ + array( 'inputFields' => self::get_input_fields( true ), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); // Restore mutation. register_graphql_mutation( 'restoreReview', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields( true ), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -55,20 +55,20 @@ public static function register_mutation() { * @return array */ public static function get_input_fields( $delete = false ) { - $fields = [ - 'id' => [ - 'type' => [ + $fields = array( + 'id' => array( + 'type' => array( 'non_null' => 'ID', - ], + ), 'description' => __( 'The ID of the target product review', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); if ( $delete ) { - $fields['forceDelete'] = [ + $fields['forceDelete'] = array( 'type' => 'Boolean', 'description' => __( 'Whether the product review should be force deleted instead of being moved to the trash', 'wp-graphql-woocommerce' ), - ]; + ); } return $fields; @@ -82,8 +82,8 @@ public static function get_input_fields( $delete = false ) { * @return array */ public static function get_output_fields( $restore = false ) { - return [ - 'rating' => [ + return array( + 'rating' => array( 'type' => 'Float', 'description' => __( 'The product rating of the affected product review', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { @@ -93,8 +93,8 @@ public static function get_output_fields( $restore = false ) { return floatval( $payload['rating'] ); }, - ], - 'affectedId' => [ + ), + 'affectedId' => array( 'type' => 'Id', 'description' => __( 'The affected product review ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { @@ -102,8 +102,8 @@ public static function get_output_fields( $restore = false ) { return ! empty( $deleted->comment_ID ) ? Relay::toGlobalId( 'comment', (string) $deleted->comment_ID ) : null; }, - ], - 'review' => [ + ), + 'review' => array( 'type' => 'Comment', 'description' => __( 'The affected product review', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload, $args, AppContext $context ) use ( $restore ) { @@ -119,8 +119,8 @@ public static function get_output_fields( $restore = false ) { return $payload['commentObject']; }, - ], - ]; + ), + ); } /** diff --git a/includes/mutation/class-review-update.php b/includes/mutation/class-review-update.php index 1c290ab76..edc003860 100644 --- a/includes/mutation/class-review-update.php +++ b/includes/mutation/class-review-update.php @@ -28,11 +28,11 @@ class Review_Update { public static function register_mutation() { register_graphql_mutation( 'updateReview', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -44,12 +44,12 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Review_Write::get_input_fields(), - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The ID of the review being updated.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -72,14 +72,14 @@ public static function mutate_and_get_payload() { // Set comment type to "review". $input['type'] = 'review'; - $skip = [ + $skip = array( 'type' => 'review', 'id' => 1, 'rating' => 1, 'clientMutationId' => 1, - ]; + ); - $payload = []; + $payload = array(); $id = Utils::get_database_id_from_id( $input['id'] ); if ( ! $id ) { throw new UserError( __( 'Provided review ID missing or invalid ', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-review-write.php b/includes/mutation/class-review-write.php index 46ff5d290..bbf592471 100644 --- a/includes/mutation/class-review-write.php +++ b/includes/mutation/class-review-write.php @@ -27,11 +27,11 @@ class Review_Write { public static function register_mutation() { register_graphql_mutation( 'writeReview', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -46,12 +46,12 @@ public static function get_input_fields() { return array_merge( $comment_input_fields, - [ - 'rating' => [ - 'type' => [ 'non_null' => 'Int' ], + array( + 'rating' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product rating', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -61,8 +61,8 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'rating' => [ + return array( + 'rating' => array( 'type' => 'Float', 'description' => __( 'The product rating of the review that was created', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { @@ -71,8 +71,8 @@ public static function get_output_fields() { } return (float) get_comment_meta( $payload['id'], 'rating', true ); }, - ], - 'review' => [ + ), + 'review' => array( 'type' => 'Comment', 'description' => __( 'The product review that was created', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $payload ) { @@ -87,8 +87,8 @@ public static function get_output_fields() { return new Comment( $comment ); }, - ], - ]; + ), + ); } /** diff --git a/includes/mutation/class-session-delete.php b/includes/mutation/class-session-delete.php index a2f5678c0..b732da912 100644 --- a/includes/mutation/class-session-delete.php +++ b/includes/mutation/class-session-delete.php @@ -24,11 +24,11 @@ class Session_Delete { public static function register_mutation() { register_graphql_mutation( 'forgetSession', - [ - 'inputFields' => [], + array( + 'inputFields' => array(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -38,17 +38,17 @@ public static function register_mutation() { * @return array */ public static function get_output_fields() { - return [ - 'session' => [ - 'type' => [ 'list_of' => 'MetaData' ], + return array( + 'session' => array( + 'type' => array( 'list_of' => 'MetaData' ), 'resolve' => static function ( $payload ) { // Guard against missing session data. if ( empty( $payload['session'] ) ) { - return []; + return array(); } // Prepare session data. - $session = []; + $session = array(); foreach ( $payload['session'] as $key => $value ) { $meta = new \stdClass(); $meta->id = null; @@ -59,8 +59,8 @@ public static function get_output_fields() { return $session; }, - ], - ]; + ), + ); } /** @@ -89,7 +89,7 @@ public static function mutate_and_get_payload() { do_action( 'woographql_after_forget_session', $session_data, $input, $session ); // Return payload. - return [ 'session' => $session_data ]; + return array( 'session' => $session_data ); }; } } diff --git a/includes/mutation/class-session-update.php b/includes/mutation/class-session-update.php index a1040be60..2c05dcd31 100644 --- a/includes/mutation/class-session-update.php +++ b/includes/mutation/class-session-update.php @@ -26,11 +26,11 @@ class Session_Update { public static function register_mutation() { register_graphql_mutation( 'updateSession', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,12 +40,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'sessionData' => [ - 'type' => [ 'list_of' => 'MetaDataInput' ], + return array( + 'sessionData' => array( + 'type' => array( 'list_of' => 'MetaDataInput' ), 'description' => __( 'Data to be persisted in the session.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -54,9 +54,9 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'session' => [ - 'type' => [ 'list_of' => 'MetaData' ], + return array( + 'session' => array( + 'type' => array( 'list_of' => 'MetaData' ), 'resolve' => static function () { /** * Session handler. @@ -65,7 +65,7 @@ public static function get_output_fields() { */ $session = \WC()->session; $session_data = $session->get_session_data(); - $session = []; + $session = array(); foreach ( $session_data as $key => $value ) { $meta = new \stdClass(); $meta->id = null; @@ -76,14 +76,14 @@ public static function get_output_fields() { return $session; }, - ], - 'customer' => [ + ), + 'customer' => array( 'type' => 'Customer', 'resolve' => static function () { return new Customer( 'session' ); }, - ], - ]; + ), + ); } /** @@ -126,7 +126,7 @@ public static function mutate_and_get_payload() { \wc_clear_notices(); throw new UserError( $error_messages ); } else { - return [ 'status' => 'SUCCESS' ]; + return array( 'status' => 'SUCCESS' ); } }; } diff --git a/includes/mutation/class-shipping-zone-create.php b/includes/mutation/class-shipping-zone-create.php index 2ea636f6f..db16c6506 100644 --- a/includes/mutation/class-shipping-zone-create.php +++ b/includes/mutation/class-shipping-zone-create.php @@ -26,11 +26,11 @@ class Shipping_Zone_Create { public static function register_mutation() { register_graphql_mutation( 'createShippingZone', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,16 +40,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'name' => [ - 'type' => [ 'non_null' => 'String' ], + return array( + 'name' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Name of the shipping zone.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'Order of the shipping zone.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -58,14 +58,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - ]; + ), + ); } /** @@ -104,7 +104,7 @@ public static function mutate_and_get_payload() { throw new UserError( __( 'Failed to create shipping zone.', 'wp-graphql-woocommerce' ) ); } - return [ 'zone_id' => $zone_id ]; + return array( 'zone_id' => $zone_id ); }; } } diff --git a/includes/mutation/class-shipping-zone-delete.php b/includes/mutation/class-shipping-zone-delete.php index 81aa9dbc8..69275b92f 100644 --- a/includes/mutation/class-shipping-zone-delete.php +++ b/includes/mutation/class-shipping-zone-delete.php @@ -26,11 +26,11 @@ class Shipping_Zone_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteShippingZone', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,12 +40,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to delete.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -54,14 +54,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload ) { return $payload['shippingZone']; }, - ], - ]; + ), + ); } /** @@ -108,7 +108,7 @@ public static function mutate_and_get_payload() { $zone->delete(); - return [ 'shippingZone' => $object ]; + return array( 'shippingZone' => $object ); }; } } diff --git a/includes/mutation/class-shipping-zone-locations-clear.php b/includes/mutation/class-shipping-zone-locations-clear.php index 1a14780da..a24acf467 100644 --- a/includes/mutation/class-shipping-zone-locations-clear.php +++ b/includes/mutation/class-shipping-zone-locations-clear.php @@ -26,11 +26,11 @@ class Shipping_Zone_Locations_Clear { public static function register_mutation() { register_graphql_mutation( 'clearShippingZoneLocations', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,16 +40,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'zoneId' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'zoneId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to delete.', 'wp-graphql-woocommerce' ), - ], - 'type' => [ + ), + 'type' => array( 'type' => 'ShippingLocationTypeEnum', 'description' => __( 'The type of location to remove.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -58,15 +58,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - 'removedLocations' => [ - 'type' => [ 'list_of' => 'ShippingLocation' ], + ), + 'removedLocations' => array( + 'type' => array( 'list_of' => 'ShippingLocation' ), 'resolve' => static function ( $payload ) { return ! empty( $payload['removedLocations'] ) ? array_map( @@ -75,10 +75,10 @@ static function ( $location ) { }, $payload['removedLocations'], ) - : []; + : array(); }, - ], - ]; + ), + ); } /** @@ -108,9 +108,9 @@ public static function mutate_and_get_payload() { throw new UserError( __( 'Invalid shipping zone ID.', 'wp-graphql-woocommerce' ) ); } - $types = [ 'postcode', 'state', 'country', 'continent' ]; + $types = array( 'postcode', 'state', 'country', 'continent' ); if ( ! empty( $input['type'] ) ) { - $types = [ $input['type'] ]; + $types = array( $input['type'] ); } $all_locations = $zone->get_zone_locations(); @@ -133,10 +133,10 @@ static function ( $location ) use ( $types ) { $zone->clear_locations( $types ); $zone->save(); - return [ + return array( 'zone_id' => $zone_id, 'removedLocations' => $locations, - ]; + ); }; } } diff --git a/includes/mutation/class-shipping-zone-locations-update.php b/includes/mutation/class-shipping-zone-locations-update.php index cee85222d..12c6be34a 100644 --- a/includes/mutation/class-shipping-zone-locations-update.php +++ b/includes/mutation/class-shipping-zone-locations-update.php @@ -26,11 +26,11 @@ class Shipping_Zone_Locations_Update { public static function register_mutation() { register_graphql_mutation( 'updateShippingZoneLocations', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,16 +40,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'zoneId' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'zoneId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to delete.', 'wp-graphql-woocommerce' ), - ], - 'locations' => [ - 'type' => [ 'list_of' => 'ShippingLocationInput' ], + ), + 'locations' => array( + 'type' => array( 'list_of' => 'ShippingLocationInput' ), 'description' => __( 'The locations to add to the shipping zone.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -58,15 +58,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - 'locations' => [ - 'type' => [ 'list_of' => 'ShippingLocation' ], + ), + 'locations' => array( + 'type' => array( 'list_of' => 'ShippingLocation' ), 'resolve' => static function ( $payload ) { return ! empty( $payload['locations'] ) ? array_map( @@ -75,10 +75,10 @@ static function ( $location ) { }, $payload['locations'], ) - : []; + : array(); }, - ], - ]; + ), + ); } /** @@ -108,15 +108,15 @@ public static function mutate_and_get_payload() { throw new UserError( __( 'Invalid shipping zone ID.', 'wp-graphql-woocommerce' ) ); } - $raw_locations = ! empty( $input['locations'] ) ? $input['locations'] : []; - $locations = []; + $raw_locations = ! empty( $input['locations'] ) ? $input['locations'] : array(); + $locations = array(); foreach ( $raw_locations as $location ) { $type = ! empty( $location['type'] ) ? $location['type'] : 'country'; - $locations[] = [ + $locations[] = array( 'type' => $type, 'code' => $location['code'], - ]; + ); } /** @@ -131,10 +131,10 @@ public static function mutate_and_get_payload() { $zone->set_locations( $locations ); $zone->save(); - return [ + return array( 'zone_id' => $zone_id, 'locations' => $locations, - ]; + ); }; } } diff --git a/includes/mutation/class-shipping-zone-method-add.php b/includes/mutation/class-shipping-zone-method-add.php index 8fe62c2c6..4d7fd69b2 100644 --- a/includes/mutation/class-shipping-zone-method-add.php +++ b/includes/mutation/class-shipping-zone-method-add.php @@ -28,11 +28,11 @@ class Shipping_Zone_Method_Add { public static function register_mutation() { register_graphql_mutation( 'addMethodToShippingZone', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -42,28 +42,28 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'zoneId' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'zoneId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to delete.', 'wp-graphql-woocommerce' ), - ], - 'methodId' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'methodId' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'The ID of the shipping method to add.', 'wp-graphql-woocommerce' ), - ], - 'enabled' => [ + ), + 'enabled' => array( 'type' => 'Boolean', 'description' => __( 'Whether the shipping method is enabled or not.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'The order of the shipping method.', 'wp-graphql-woocommerce' ), - ], - 'settings' => [ - 'type' => [ 'list_of' => 'WCSettingInput' ], + ), + 'settings' => array( + 'type' => array( 'list_of' => 'WCSettingInput' ), 'description' => __( 'The settings for the shipping method.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -72,24 +72,24 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - 'method' => [ + ), + 'method' => array( 'type' => 'ShippingZoneToShippingMethodConnectionEdge', 'resolve' => static function ( $payload, array $args, AppContext $context ) { - return [ + return array( // Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value. 'node' => new Shipping_Method( $payload['method'] ), 'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ), - ]; + ); }, - ], - ]; + ), + ); } /** @@ -158,11 +158,11 @@ public static function mutate_and_get_payload() { */ $method = apply_filters( 'graphql_woocommerce_shipping_zone_method_add', $method, $zone, $input ); - return [ + return array( 'zone_id' => $zone_id, 'zone' => $zone, 'method' => $method, - ]; + ); }; } } diff --git a/includes/mutation/class-shipping-zone-method-remove.php b/includes/mutation/class-shipping-zone-method-remove.php index 8b30d8d83..b50795352 100644 --- a/includes/mutation/class-shipping-zone-method-remove.php +++ b/includes/mutation/class-shipping-zone-method-remove.php @@ -27,11 +27,11 @@ class Shipping_Zone_Method_Remove { public static function register_mutation() { register_graphql_mutation( 'removeMethodFromShippingZone', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,16 +41,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'zoneId' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'zoneId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to delete.', 'wp-graphql-woocommerce' ), - ], - 'instanceId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'instanceId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Shipping method instance ID', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -59,24 +59,24 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - 'removedMethod' => [ + ), + 'removedMethod' => array( 'type' => 'ShippingZoneToShippingMethodConnectionEdge', 'resolve' => static function ( $payload, array $args, AppContext $context ) { - return [ + return array( // Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value. 'node' => new Shipping_Method( $payload['method'] ), 'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ), - ]; + ); }, - ], - ]; + ), + ); } /** @@ -132,11 +132,11 @@ public static function mutate_and_get_payload() { $zone->delete_shipping_method( $instance_id ); - return [ + return array( 'zone_id' => $zone_id, 'zone' => $zone, 'method' => $method, - ]; + ); }; } } diff --git a/includes/mutation/class-shipping-zone-method-update.php b/includes/mutation/class-shipping-zone-method-update.php index b7e1f21e0..b6a2e20ad 100644 --- a/includes/mutation/class-shipping-zone-method-update.php +++ b/includes/mutation/class-shipping-zone-method-update.php @@ -28,11 +28,11 @@ class Shipping_Zone_Method_Update { public static function register_mutation() { register_graphql_mutation( 'updateMethodOnShippingZone', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -42,28 +42,28 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'zoneId' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'zoneId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to delete.', 'wp-graphql-woocommerce' ), - ], - 'instanceId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'instanceId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Shipping method instance ID', 'wp-graphql-woocommerce' ), - ], - 'enabled' => [ + ), + 'enabled' => array( 'type' => 'Boolean', 'description' => __( 'Whether the shipping method is enabled or not.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'The order of the shipping method.', 'wp-graphql-woocommerce' ), - ], - 'settings' => [ - 'type' => [ 'list_of' => 'WCSettingInput' ], + ), + 'settings' => array( + 'type' => array( 'list_of' => 'WCSettingInput' ), 'description' => __( 'The settings for the shipping method.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -72,24 +72,24 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - 'method' => [ + ), + 'method' => array( 'type' => 'ShippingZoneToShippingMethodConnectionEdge', 'resolve' => static function ( $payload, array $args, AppContext $context ) { - return [ + return array( // Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value. 'node' => new Shipping_Method( $payload['method'] ), 'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ), - ]; + ); }, - ], - ]; + ), + ); } /** @@ -157,11 +157,11 @@ public static function mutate_and_get_payload() { */ $method = apply_filters( 'graphql_woocommerce_shipping_zone_method_update', $method, $zone, $input ); - return [ + return array( 'zone_id' => $zone_id, 'zone' => $zone, 'method' => $method, - ]; + ); }; } } diff --git a/includes/mutation/class-shipping-zone-update.php b/includes/mutation/class-shipping-zone-update.php index d75d63288..7077d8bf7 100644 --- a/includes/mutation/class-shipping-zone-update.php +++ b/includes/mutation/class-shipping-zone-update.php @@ -26,11 +26,11 @@ class Shipping_Zone_Update { public static function register_mutation() { register_graphql_mutation( 'updateShippingZone', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,20 +40,20 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the shipping zone to update.', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Name of the shipping zone.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'Order of the shipping zone.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -62,14 +62,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'shippingZone' => [ + return array( + 'shippingZone' => array( 'type' => 'ShippingZone', 'resolve' => static function ( $payload, array $args, AppContext $context ) { return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ); }, - ], - ]; + ), + ); } /** @@ -122,7 +122,7 @@ public static function mutate_and_get_payload() { $zone->save(); } - return [ 'zone_id' => $zone_id ]; + return array( 'zone_id' => $zone_id ); }; } } diff --git a/includes/mutation/class-tax-class-create.php b/includes/mutation/class-tax-class-create.php index f98e6544c..5f41b1dea 100644 --- a/includes/mutation/class-tax-class-create.php +++ b/includes/mutation/class-tax-class-create.php @@ -26,11 +26,11 @@ class Tax_Class_Create { public static function register_mutation() { register_graphql_mutation( 'createTaxClass', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,16 +40,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'name' => [ - 'type' => [ 'non_null' => 'String' ], + return array( + 'name' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Name of the tax class.', 'wp-graphql-woocommerce' ), - ], - 'slug' => [ + ), + 'slug' => array( 'type' => 'String', 'description' => __( 'Slug of the tax class.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -58,14 +58,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'taxClass' => [ + return array( + 'taxClass' => array( 'type' => 'TaxClass', 'resolve' => static function ( $payload ) { return ! empty( $payload['taxClass'] ) ? $payload['taxClass'] : null; }, - ], - ]; + ), + ); } /** @@ -95,7 +95,7 @@ public static function mutate_and_get_payload() { */ $tax_class = apply_filters( 'graphql_woocommerce_tax_class_create', $tax_class, $input ); - return [ 'taxClass' => $tax_class ]; + return array( 'taxClass' => $tax_class ); }; } } diff --git a/includes/mutation/class-tax-class-delete.php b/includes/mutation/class-tax-class-delete.php index d47487d8d..93020aca9 100644 --- a/includes/mutation/class-tax-class-delete.php +++ b/includes/mutation/class-tax-class-delete.php @@ -26,11 +26,11 @@ class Tax_Class_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteTaxClass', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -40,12 +40,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'slug' => [ - 'type' => [ 'non_null' => 'String' ], + return array( + 'slug' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Slug of the tax class.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -54,14 +54,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'taxClass' => [ + return array( + 'taxClass' => array( 'type' => 'TaxClass', 'resolve' => static function ( $payload ) { return ! empty( $payload['taxClass'] ) ? $payload['taxClass'] : null; }, - ], - ]; + ), + ); } /** @@ -103,7 +103,7 @@ public static function mutate_and_get_payload() { */ $tax_class = apply_filters( 'graphql_woocommerce_tax_class_delete', $tax_class, $input ); - return [ 'taxClass' => $tax_class ]; + return array( 'taxClass' => $tax_class ); }; } } diff --git a/includes/mutation/class-tax-rate-create.php b/includes/mutation/class-tax-rate-create.php index 355677777..e087e72a4 100644 --- a/includes/mutation/class-tax-rate-create.php +++ b/includes/mutation/class-tax-rate-create.php @@ -27,11 +27,11 @@ class Tax_Rate_Create { public static function register_mutation() { register_graphql_mutation( 'createTaxRate', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => [ self::class, 'mutate_and_get_payload' ], - ] + 'mutateAndGetPayload' => array( self::class, 'mutate_and_get_payload' ), + ) ); } @@ -41,52 +41,52 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'country' => [ + return array( + 'country' => array( 'type' => 'String', 'description' => __( 'Country code for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'state' => [ + ), + 'state' => array( 'type' => 'String', 'description' => __( 'State code for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'postcodes' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'postcodes' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Postcodes for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'cities' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'cities' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Cities for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'rate' => [ + ), + 'rate' => array( 'type' => 'String', 'description' => __( 'Tax rate.', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Tax rate name.', 'wp-graphql-woocommerce' ), - ], - 'priority' => [ + ), + 'priority' => array( 'type' => 'Int', 'description' => __( 'Tax rate priority.', 'wp-graphql-woocommerce' ), - ], - 'compound' => [ + ), + 'compound' => array( 'type' => 'Boolean', 'description' => __( 'Whether the tax rate is compound.', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'Boolean', 'description' => __( 'Whether the tax rate is applied to shipping.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'Tax rate order.', 'wp-graphql-woocommerce' ), - ], - 'class' => [ + ), + 'class' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Tax rate class.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -95,14 +95,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'taxRate' => [ + return array( + 'taxRate' => array( 'type' => 'TaxRate', 'resolve' => static function ( array $payload, array $args, AppContext $context ) { return $context->get_loader( 'tax_rate' )->load( $payload['tax_rate_id'] ); }, - ], - ]; + ), + ); } /** @@ -158,8 +158,8 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso $current = \WC_Tax::_get_tax_rate( $id, OBJECT ); } - $data = []; - $fields = [ + $data = array(); + $fields = array( 'country' => 'tax_rate_country', 'state' => 'tax_rate_state', 'rate' => 'tax_rate', @@ -169,7 +169,7 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso 'shipping' => 'tax_rate_shipping', 'order' => 'tax_rate_order', 'class' => 'tax_rate_class', - ]; + ); foreach ( $fields as $key => $field ) { if ( ! isset( $input[ $key ] ) ) { @@ -226,6 +226,6 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso */ do_action( "graphql_woocommerce_tax_rate_{$action}", $id, $input ); - return [ 'tax_rate_id' => $id ]; + return array( 'tax_rate_id' => $id ); } } diff --git a/includes/mutation/class-tax-rate-delete.php b/includes/mutation/class-tax-rate-delete.php index 5b6f66f25..babde8bf0 100644 --- a/includes/mutation/class-tax-rate-delete.php +++ b/includes/mutation/class-tax-rate-delete.php @@ -27,11 +27,11 @@ class Tax_Rate_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteTaxRate', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ] + ) ); } @@ -41,12 +41,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'Int' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the tax rate to update.', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -55,14 +55,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'taxRate' => [ + return array( + 'taxRate' => array( 'type' => 'TaxRate', 'resolve' => static function ( $payload ) { return $payload['taxRate']; }, - ], - ]; + ), + ); } /** @@ -107,9 +107,9 @@ public static function mutate_and_get_payload() { */ $tax = apply_filters( 'graphql_woocommerce_tax_rate_delete', $tax, $input ); - return [ + return array( 'taxRate' => $tax, - ]; + ); }; } } diff --git a/includes/mutation/class-tax-rate-update.php b/includes/mutation/class-tax-rate-update.php index 375750628..a3650b64f 100644 --- a/includes/mutation/class-tax-rate-update.php +++ b/includes/mutation/class-tax-rate-update.php @@ -24,11 +24,11 @@ class Tax_Rate_Update { public static function register_mutation() { register_graphql_mutation( 'updateTaxRate', - [ + array( 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => [ Tax_Rate_Create::class, 'mutate_and_get_payload' ], - ] + 'mutateAndGetPayload' => array( Tax_Rate_Create::class, 'mutate_and_get_payload' ), + ) ); } @@ -40,12 +40,12 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Tax_Rate_Create::get_input_fields(), - [ - 'id' => [ - 'type' => [ 'non_null' => 'Int' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'The ID of the tax rate to update.', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ); } @@ -55,13 +55,13 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return [ - 'taxRate' => [ + return array( + 'taxRate' => array( 'type' => 'TaxRate', 'resolve' => static function ( array $payload, array $args, AppContext $context ) { return $context->get_loader( 'tax_rate' )->load( $payload['tax_rate_id'] ); }, - ], - ]; + ), + ); } } diff --git a/includes/type/enum/class-attribute-operator-enum.php b/includes/type/enum/class-attribute-operator-enum.php index ed9942c50..220bb7c3a 100644 --- a/includes/type/enum/class-attribute-operator-enum.php +++ b/includes/type/enum/class-attribute-operator-enum.php @@ -20,14 +20,14 @@ class Attribute_Operator_Enum { public static function register() { register_graphql_enum_type( 'AttributeOperatorEnum', - [ + array( 'description' => __( 'Collection statistic attributes operators', 'wp-graphql-woocommerce' ), - 'values' => [ - 'IN' => [ 'value' => 'IN' ], - 'NOT_IN' => [ 'value' => 'NOT IN' ], - 'AND' => [ 'value' => 'AND' ], - ], - ] + 'values' => array( + 'IN' => array( 'value' => 'IN' ), + 'NOT_IN' => array( 'value' => 'NOT IN' ), + 'AND' => array( 'value' => 'AND' ), + ), + ) ); } } diff --git a/includes/type/enum/class-backorders.php b/includes/type/enum/class-backorders.php index ca54df3bb..7d3d58b5e 100644 --- a/includes/type/enum/class-backorders.php +++ b/includes/type/enum/class-backorders.php @@ -18,18 +18,18 @@ class Backorders { * @return void */ public static function register() { - $values = [ - 'NO' => [ 'value' => 'no' ], - 'NOTIFY' => [ 'value' => 'notify' ], - 'YES' => [ 'value' => 'yes' ], - ]; + $values = array( + 'NO' => array( 'value' => 'no' ), + 'NOTIFY' => array( 'value' => 'notify' ), + 'YES' => array( 'value' => 'yes' ), + ); register_graphql_enum_type( 'BackordersEnum', - [ + array( 'description' => __( 'Product backorder enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-cart-error-type.php b/includes/type/enum/class-cart-error-type.php index f280688aa..62d5d4736 100644 --- a/includes/type/enum/class-cart-error-type.php +++ b/includes/type/enum/class-cart-error-type.php @@ -18,19 +18,19 @@ class Cart_Error_Type { * @return void */ public static function register() { - $values = [ - 'INVALID_CART_ITEM' => [ 'value' => 'INVALID_CART_ITEM' ], - 'INVALID_COUPON' => [ 'value' => 'INVALID_COUPON' ], - 'INVALID_SHIPPING_METHOD' => [ 'value' => 'INVALID_SHIPPING_METHOD' ], - 'UNKNOWN' => [ 'value' => 'UNKNOWN' ], - ]; + $values = array( + 'INVALID_CART_ITEM' => array( 'value' => 'INVALID_CART_ITEM' ), + 'INVALID_COUPON' => array( 'value' => 'INVALID_COUPON' ), + 'INVALID_SHIPPING_METHOD' => array( 'value' => 'INVALID_SHIPPING_METHOD' ), + 'UNKNOWN' => array( 'value' => 'UNKNOWN' ), + ); register_graphql_enum_type( 'CartErrorType', - [ + array( 'description' => __( 'Cart error type enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-catalog-visibility.php b/includes/type/enum/class-catalog-visibility.php index 5c1e72585..eb31fd3ba 100644 --- a/includes/type/enum/class-catalog-visibility.php +++ b/includes/type/enum/class-catalog-visibility.php @@ -18,19 +18,19 @@ class Catalog_Visibility { * @return void */ public static function register() { - $values = [ - 'VISIBLE' => [ 'value' => 'visible' ], - 'CATALOG' => [ 'value' => 'catalog' ], - 'SEARCH' => [ 'value' => 'search' ], - 'HIDDEN' => [ 'value' => 'hidden' ], - ]; + $values = array( + 'VISIBLE' => array( 'value' => 'visible' ), + 'CATALOG' => array( 'value' => 'catalog' ), + 'SEARCH' => array( 'value' => 'search' ), + 'HIDDEN' => array( 'value' => 'hidden' ), + ); register_graphql_enum_type( 'CatalogVisibilityEnum', - [ + array( 'description' => __( 'Product catalog visibility enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-countries.php b/includes/type/enum/class-countries.php index c166e0253..246375571 100644 --- a/includes/type/enum/class-countries.php +++ b/includes/type/enum/class-countries.php @@ -23,16 +23,16 @@ public static function register() { array_walk( $countries, static function ( &$value, $code ) { - $value = [ 'value' => $code ]; + $value = array( 'value' => $code ); } ); register_graphql_enum_type( 'CountriesEnum', - [ + array( 'description' => __( 'Countries enumeration', 'wp-graphql-woocommerce' ), 'values' => $countries, - ] + ) ); } } diff --git a/includes/type/enum/class-currency-enum.php b/includes/type/enum/class-currency-enum.php index a37b2f4fa..76a151e59 100644 --- a/includes/type/enum/class-currency-enum.php +++ b/includes/type/enum/class-currency-enum.php @@ -22,20 +22,20 @@ public static function register() { array_walk( $currencies, static function ( &$name, $code ) { - $name = [ + $name = array( 'name' => $code, 'value' => $code, 'description' => $name, - ]; + ); } ); register_graphql_enum_type( 'CurrencyEnum', - [ + array( 'description' => __( 'Currencies enumeration', 'wp-graphql-woocommerce' ), 'values' => $currencies, - ] + ) ); } } diff --git a/includes/type/enum/class-customer-connection-orderby-enum.php b/includes/type/enum/class-customer-connection-orderby-enum.php index 6e1ef08c8..e91731cf5 100644 --- a/includes/type/enum/class-customer-connection-orderby-enum.php +++ b/includes/type/enum/class-customer-connection-orderby-enum.php @@ -20,35 +20,35 @@ class Customer_Connection_Orderby_Enum { public static function register() { register_graphql_enum_type( 'CustomerConnectionOrderbyEnum', - [ + array( 'description' => __( 'Field to order the connection by', 'wp-graphql-woocommerce' ), - 'values' => [ - 'ID' => [ + 'values' => array( + 'ID' => array( 'value' => 'ID', 'description' => __( 'Order by customer ID', 'wp-graphql-woocommerce' ), - ], - 'INCLUDE' => [ + ), + 'INCLUDE' => array( 'value' => 'include', 'description' => __( 'Order by include field', 'wp-graphql-woocommerce' ), - ], - 'NAME' => [ + ), + 'NAME' => array( 'value' => 'display_name', 'description' => __( 'Order by customer display name', 'wp-graphql-woocommerce' ), - ], - 'USERNAME' => [ + ), + 'USERNAME' => array( 'value' => 'username', 'description' => __( 'Order by customer username', 'wp-graphql-woocommerce' ), - ], - 'EMAIL' => [ + ), + 'EMAIL' => array( 'value' => 'email', 'description' => __( 'Order by customer email', 'wp-graphql-woocommerce' ), - ], - 'REGISTERED_DATE' => [ + ), + 'REGISTERED_DATE' => array( 'value' => 'registered', 'description' => __( 'Order by customer registration date', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/enum/class-discount-type.php b/includes/type/enum/class-discount-type.php index 0fdaa4136..a59d9b3b8 100644 --- a/includes/type/enum/class-discount-type.php +++ b/includes/type/enum/class-discount-type.php @@ -18,17 +18,17 @@ class Discount_Type { * @return void */ public static function register() { - $values = []; + $values = array(); foreach ( \wc_get_coupon_types() as $value => $description ) { $values[ strtoupper( $value ) ] = compact( 'value', 'description' ); } register_graphql_enum_type( 'DiscountTypeEnum', - [ + array( 'description' => __( 'Coupon discount type enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-id-type-enums.php b/includes/type/enum/class-id-type-enums.php index d1260b052..6a4fd972d 100644 --- a/includes/type/enum/class-id-type-enums.php +++ b/includes/type/enum/class-id-type-enums.php @@ -21,106 +21,106 @@ class Id_Type_Enums { public static function register() { register_graphql_enum_type( 'CouponIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Coupon. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - 'code' => [ + 'code' => array( 'name' => 'CODE', 'value' => 'code', 'description' => __( 'Coupon code.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); register_graphql_enum_type( 'OrderIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Order. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - 'order_key' => [ + 'order_key' => array( 'name' => 'ORDER_KEY', 'value' => 'order_key', 'description' => __( 'Order key.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); register_graphql_enum_type( 'ProductIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Product. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), 'slug' => self::get_value( 'slug' ), - 'sku' => [ + 'sku' => array( 'name' => 'SKU', 'value' => 'sku', 'description' => __( 'Unique store identifier for product.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); register_graphql_enum_type( 'ProductVariationIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single ProductVariation. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ], - ] + ), + ) ); register_graphql_enum_type( 'RefundIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Refund. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ], - ] + ), + ) ); register_graphql_enum_type( 'ShippingMethodIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Shipping Method. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ], - ] + ), + ) ); register_graphql_enum_type( 'ShippingZoneIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Shipping Zone. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ], - ] + ), + ) ); register_graphql_enum_type( 'TaxRateIdTypeEnum', - [ + array( 'description' => __( 'The Type of Identifier used to fetch a single Tax rate. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => [ + 'values' => array( 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ], - ] + ), + ) ); } @@ -133,33 +133,33 @@ public static function register() { private static function get_value( $value ) { switch ( $value ) { case 'slug': - return [ + return array( 'name' => 'SLUG', 'value' => 'slug', 'description' => __( 'Identify a resource by the slug. Available to non-hierarchcial Types where the slug is a unique identifier.', 'wp-graphql-woocommerce' ), - ]; + ); case 'database_id': - return [ + return array( 'name' => 'DATABASE_ID', 'value' => 'database_id', 'description' => __( 'Identify a resource by the Database ID.', 'wp-graphql-woocommerce' ), - ]; + ); case 'uri': - return [ + return array( 'name' => 'URI', 'value' => 'uri', 'description' => __( 'Identify a resource by the URI.', 'wp-graphql-woocommerce' ), - ]; + ); case 'id': default: - return [ + return array( 'name' => 'ID', 'value' => 'global_id', 'description' => __( 'Identify a resource by the (hashed) Global ID.', 'wp-graphql-woocommerce' ), - ]; + ); }//end switch } } diff --git a/includes/type/enum/class-manage-stock.php b/includes/type/enum/class-manage-stock.php index def96143e..4c36e447f 100644 --- a/includes/type/enum/class-manage-stock.php +++ b/includes/type/enum/class-manage-stock.php @@ -18,18 +18,18 @@ class Manage_Stock { * @return void */ public static function register() { - $values = [ - 'TRUE' => [ 'value' => true ], - 'FALSE' => [ 'value' => false ], - 'PARENT' => [ 'value' => 'parent' ], - ]; + $values = array( + 'TRUE' => array( 'value' => true ), + 'FALSE' => array( 'value' => false ), + 'PARENT' => array( 'value' => 'parent' ), + ); register_graphql_enum_type( 'ManageStockEnum', - [ + array( 'description' => __( 'Product manage stock enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-order-status.php b/includes/type/enum/class-order-status.php index 439b48be1..874b64716 100644 --- a/includes/type/enum/class-order-status.php +++ b/includes/type/enum/class-order-status.php @@ -20,7 +20,7 @@ class Order_Status { public static function register() { $statuses = \wc_get_order_statuses(); - $values = []; + $values = array(); foreach ( $statuses as $status => $description ) { $split_status_slug = explode( 'wc-', $status ); $value = array_pop( $split_status_slug ); @@ -30,10 +30,10 @@ public static function register() { register_graphql_enum_type( 'OrderStatusEnum', - [ + array( 'description' => __( 'Order status enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-orders-orderby-enum.php b/includes/type/enum/class-orders-orderby-enum.php index a61073636..90a481f13 100644 --- a/includes/type/enum/class-orders-orderby-enum.php +++ b/includes/type/enum/class-orders-orderby-enum.php @@ -29,32 +29,32 @@ protected static function values() { 'woographql_orderby_enum_values', array_merge( self::post_type_values(), - [ - 'ORDER_KEY' => [ + array( + 'ORDER_KEY' => array( 'value' => '_order_key', 'description' => __( 'Order by order key', 'wp-graphql-woocommerce' ), - ], - 'DISCOUNT' => [ + ), + 'DISCOUNT' => array( 'value' => '_cart_discount', 'description' => __( 'Order by order discount amount', 'wp-graphql-woocommerce' ), - ], - 'TOTAL' => [ + ), + 'TOTAL' => array( 'value' => '_order_total', 'description' => __( 'Order by order total', 'wp-graphql-woocommerce' ), - ], - 'TAX' => [ + ), + 'TAX' => array( 'value' => '_order_tax', 'description' => __( 'Order by order total', 'wp-graphql-woocommerce' ), - ], - 'DATE_PAID' => [ + ), + 'DATE_PAID' => array( 'value' => '_date_paid', 'description' => __( 'Order by date the order was paid', 'wp-graphql-woocommerce' ), - ], - 'DATE_COMPLETED' => [ + ), + 'DATE_COMPLETED' => array( 'value' => '_date_completed', 'description' => __( 'Order by date the order was completed', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ) ); } diff --git a/includes/type/enum/class-post-type-orderby-enum.php b/includes/type/enum/class-post-type-orderby-enum.php index 1cfbfec1e..98268d662 100644 --- a/includes/type/enum/class-post-type-orderby-enum.php +++ b/includes/type/enum/class-post-type-orderby-enum.php @@ -26,40 +26,40 @@ class Post_Type_Orderby_Enum { * @return array */ protected static function post_type_values() { - return [ - 'NAME' => [ + return array( + 'NAME' => array( 'value' => 'post_title', 'description' => __( 'Order by name', 'wp-graphql-woocommerce' ), - ], - 'SLUG' => [ + ), + 'SLUG' => array( 'value' => 'post_name', 'description' => __( 'Order by slug', 'wp-graphql-woocommerce' ), - ], - 'MODIFIED' => [ + ), + 'MODIFIED' => array( 'value' => 'post_modified', 'description' => __( 'Order by last modified date', 'wp-graphql-woocommerce' ), - ], - 'DATE' => [ + ), + 'DATE' => array( 'value' => 'post_date', 'description' => __( 'Order by publish date', 'wp-graphql-woocommerce' ), - ], - 'PARENT' => [ + ), + 'PARENT' => array( 'value' => 'post_parent', 'description' => __( 'Order by parent ID', 'wp-graphql-woocommerce' ), - ], - 'IN' => [ + ), + 'IN' => array( 'value' => 'post__in', 'description' => __( 'Preserve the ID order given in the IN array', 'wp-graphql-woocommerce' ), - ], - 'NAME_IN' => [ + ), + 'NAME_IN' => array( 'value' => 'post_name__in', 'description' => __( 'Preserve slug order given in the NAME_IN array', 'wp-graphql-woocommerce' ), - ], - 'MENU_ORDER' => [ + ), + 'MENU_ORDER' => array( 'value' => 'menu_order', 'description' => __( 'Order by the menu order value', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -80,7 +80,7 @@ public static function register() { $name = static::$name; register_graphql_enum_type( $name . 'OrderByEnum', - [ + array( 'description' => sprintf( /* translators: ordering enumeration description */ __( 'Fields to order the %s connection by', 'wp-graphql-woocommerce' ), @@ -88,7 +88,7 @@ public static function register() { ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound 'values' => apply_filters( "{$name}_orderby_enum_values", static::values() ), - ] + ) ); } } diff --git a/includes/type/enum/class-pricing-field-format.php b/includes/type/enum/class-pricing-field-format.php index 21078b106..d8b04b551 100644 --- a/includes/type/enum/class-pricing-field-format.php +++ b/includes/type/enum/class-pricing-field-format.php @@ -18,17 +18,17 @@ class Pricing_Field_Format { * @return void */ public static function register() { - $values = [ - 'FORMATTED' => [ 'value' => 'formatted' ], - 'RAW' => [ 'value' => 'raw' ], - ]; + $values = array( + 'FORMATTED' => array( 'value' => 'formatted' ), + 'RAW' => array( 'value' => 'raw' ), + ); register_graphql_enum_type( 'PricingFieldFormatEnum', - [ + array( 'description' => __( 'Pricing field format enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-product-attribute-enum.php b/includes/type/enum/class-product-attribute-enum.php index db30fdef0..93b3c4e7d 100644 --- a/includes/type/enum/class-product-attribute-enum.php +++ b/includes/type/enum/class-product-attribute-enum.php @@ -21,27 +21,27 @@ class Product_Attribute_Enum { */ public static function register() { // Get values from product attributes. - $taxonomy_values = []; + $taxonomy_values = array(); $taxonomies = wc_get_attribute_taxonomy_names(); foreach ( $taxonomies as $taxonomy ) { $tax_object = get_taxonomy( $taxonomy ); if ( false !== $tax_object && in_array( 'product', $tax_object->object_type, true ) ) { - $taxonomy_values[ WPEnumType::get_safe_name( $taxonomy ) ] = [ 'value' => $taxonomy ]; + $taxonomy_values[ WPEnumType::get_safe_name( $taxonomy ) ] = array( 'value' => $taxonomy ); } } if ( empty( $taxonomy_values ) ) { - $taxonomy_values['NONE'] = [ 'value' => 'none' ]; + $taxonomy_values['NONE'] = array( 'value' => 'none' ); } register_graphql_enum_type( 'ProductAttributeEnum', - [ + array( 'description' => __( 'Product attribute taxonomies', 'wp-graphql-woocommerce' ), 'values' => $taxonomy_values, - ] + ) ); } } diff --git a/includes/type/enum/class-product-attribute-types.php b/includes/type/enum/class-product-attribute-types.php index 65e359e0a..dc43a9f95 100644 --- a/includes/type/enum/class-product-attribute-types.php +++ b/includes/type/enum/class-product-attribute-types.php @@ -20,19 +20,19 @@ class Product_Attribute_Types { public static function register() { register_graphql_enum_type( 'ProductAttributeTypesEnum', - [ + array( 'description' => __( 'Product attribute type enumeration', 'wp-graphql-woocommerce' ), - 'values' => [ - 'LOCAL' => [ + 'values' => array( + 'LOCAL' => array( 'value' => 'local', 'description' => __( 'A local product attribute', 'wp-graphql-woocommerce' ), - ], - 'GLOBAL' => [ + ), + 'GLOBAL' => array( 'value' => 'global', 'description' => __( 'A global product attribute', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php index cc0667404..b3b555606 100644 --- a/includes/type/enum/class-product-attributes-connection-orderby-enum.php +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -20,43 +20,43 @@ class Product_Attributes_Connection_Orderby_Enum { public static function register() { register_graphql_enum_type( 'ProductAttributesConnectionOrderbyEnum', - [ + array( 'description' => __( 'Product attributes connection orderby enum', 'wp-graphql-woocommerce' ), - 'values' => [ - 'NAME' => [ + 'values' => array( + 'NAME' => array( 'value' => 'name', 'description' => __( 'Order the connection by name.', 'wp-graphql-woocommerce' ), - ], - 'SLUG' => [ + ), + 'SLUG' => array( 'value' => 'slug', 'description' => __( 'Order the connection by slug.', 'wp-graphql-woocommerce' ), - ], - 'TERM_GROUP' => [ + ), + 'TERM_GROUP' => array( 'value' => 'term_group', 'description' => __( 'Order the connection by term group.', 'wp-graphql-woocommerce' ), - ], - 'TERM_ID' => [ + ), + 'TERM_ID' => array( 'value' => 'term_id', 'description' => __( 'Order the connection by term id.', 'wp-graphql-woocommerce' ), - ], - 'TERM_ORDER' => [ + ), + 'TERM_ORDER' => array( 'value' => 'term_order', 'description' => __( 'Order the connection by term order.', 'wp-graphql-woocommerce' ), - ], - 'MENU_ORDER' => [ + ), + 'MENU_ORDER' => array( 'value' => 'menu_order', 'description' => __( 'Order the connection by woocommerce menu order.', 'wp-graphql-woocommerce' ), - ], - 'DESCRIPTION' => [ + ), + 'DESCRIPTION' => array( 'value' => 'description', 'description' => __( 'Order the connection by description.', 'wp-graphql-woocommerce' ), - ], - 'COUNT' => [ + ), + 'COUNT' => array( 'value' => 'count', 'description' => __( 'Order the connection by item count.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/enum/class-product-category-display.php b/includes/type/enum/class-product-category-display.php index dfaf43bb2..7a91ea1a1 100644 --- a/includes/type/enum/class-product-category-display.php +++ b/includes/type/enum/class-product-category-display.php @@ -20,27 +20,27 @@ class Product_Category_Display { public static function register() { register_graphql_enum_type( 'ProductCategoryDisplay', - [ + array( 'description' => __( 'Product category display type enumeration', 'wp-graphql-woocommerce' ), - 'values' => [ - 'DEFAULT' => [ + 'values' => array( + 'DEFAULT' => array( 'value' => 'default', 'description' => __( 'Display default content connected to this category.', 'wp-graphql-woocommerce' ), - ], - 'PRODUCTS' => [ + ), + 'PRODUCTS' => array( 'value' => 'products', 'description' => __( 'Display products associated with this category.', 'wp-graphql-woocommerce' ), - ], - 'SUBCATEGORIES' => [ + ), + 'SUBCATEGORIES' => array( 'value' => 'subcategories', 'description' => __( 'Display subcategories of this category.', 'wp-graphql-woocommerce' ), - ], - 'BOTH' => [ + ), + 'BOTH' => array( 'value' => 'both', 'description' => __( 'Display both products and subcategories of this category.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/enum/class-product-taxonomy.php b/includes/type/enum/class-product-taxonomy.php index a9e46408e..27890acc4 100644 --- a/includes/type/enum/class-product-taxonomy.php +++ b/includes/type/enum/class-product-taxonomy.php @@ -21,23 +21,23 @@ class Product_Taxonomy { */ public static function register() { // Get values from taxonomies connected to products. - $taxonomy_values = []; + $taxonomy_values = array(); $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies(); foreach ( $allowed_taxonomies as $taxonomy ) { $tax_object = get_taxonomy( $taxonomy ); if ( false !== $tax_object && in_array( 'product', $tax_object->object_type, true ) ) { - $taxonomy_values[ WPEnumType::get_safe_name( $taxonomy ) ] = [ 'value' => $taxonomy ]; + $taxonomy_values[ WPEnumType::get_safe_name( $taxonomy ) ] = array( 'value' => $taxonomy ); } } register_graphql_enum_type( 'ProductTaxonomyEnum', - [ + array( 'description' => __( 'Product taxonomies', 'wp-graphql-woocommerce' ), 'values' => $taxonomy_values, - ] + ) ); } } diff --git a/includes/type/enum/class-product-types.php b/includes/type/enum/class-product-types.php index 3fa0150ee..2f63fb9ed 100644 --- a/includes/type/enum/class-product-types.php +++ b/includes/type/enum/class-product-types.php @@ -20,44 +20,44 @@ class Product_Types { public static function register() { $values = apply_filters( 'graphql_product_types_enum_values', - [ - 'SIMPLE' => [ + array( + 'SIMPLE' => array( 'value' => 'simple', 'description' => __( 'A simple product', 'wp-graphql-woocommerce' ), - ], - 'GROUPED' => [ + ), + 'GROUPED' => array( 'value' => 'grouped', 'description' => __( 'A product group', 'wp-graphql-woocommerce' ), - ], - 'EXTERNAL' => [ + ), + 'EXTERNAL' => array( 'value' => 'external', 'description' => __( 'An external product', 'wp-graphql-woocommerce' ), - ], - 'VARIABLE' => [ + ), + 'VARIABLE' => array( 'value' => 'variable', 'description' => __( 'A variable product', 'wp-graphql-woocommerce' ), - ], - 'VARIATION' => [ + ), + 'VARIATION' => array( 'value' => 'variation', 'description' => __( 'A product variation', 'wp-graphql-woocommerce' ), - ], + ), - ] + ) ); if ( 'on' === woographql_setting( 'enable_unsupported_product_type', 'off' ) ) { - $values['UNSUPPORTED'] = [ + $values['UNSUPPORTED'] = array( 'value' => 'unsupported', 'description' => __( 'An unsupported product', 'wp-graphql-woocommerce' ), - ]; + ); } register_graphql_enum_type( 'ProductTypesEnum', - [ + array( 'description' => __( 'Product type enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-products-orderby-enum.php b/includes/type/enum/class-products-orderby-enum.php index f6e1a046b..841ad36d7 100644 --- a/includes/type/enum/class-products-orderby-enum.php +++ b/includes/type/enum/class-products-orderby-enum.php @@ -29,49 +29,49 @@ protected static function values() { 'woographql_product_orderby_enum_values', array_merge( self::post_type_values(), - [ - 'PRICE' => [ + array( + 'PRICE' => array( 'value' => 'price', 'description' => __( 'Order by product\'s current price', 'wp-graphql-woocommerce' ), - ], - 'REGULAR_PRICE' => [ + ), + 'REGULAR_PRICE' => array( 'value' => 'price', 'description' => __( 'Order by product\'s regular price', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'This field is deprecated and will be removed in a future version. Use "PRICE" instead.', 'wp-graphql-woocommerce' ), - ], - 'SALE_PRICE' => [ + ), + 'SALE_PRICE' => array( 'value' => 'price', 'description' => __( 'Order by product\'s sale price', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'This field is deprecated and will be removed in a future version. Use "PRICE" instead.', 'wp-graphql-woocommerce' ), - ], - 'POPULARITY' => [ + ), + 'POPULARITY' => array( 'value' => 'popularity', 'description' => __( 'Order by product popularity', 'wp-graphql-woocommerce' ), - ], - 'REVIEW_COUNT' => [ + ), + 'REVIEW_COUNT' => array( 'value' => 'comment_count', 'description' => __( 'Order by number of reviews on product', 'wp-graphql-woocommerce' ), - ], - 'RATING' => [ + ), + 'RATING' => array( 'value' => 'rating', 'description' => __( 'Order by product average rating', 'wp-graphql-woocommerce' ), - ], - 'ON_SALE_FROM' => [ + ), + 'ON_SALE_FROM' => array( 'value' => 'date', 'description' => __( 'Order by date product sale starts', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'This field is deprecated and will be removed in a future version.', 'wp-graphql-woocommerce' ), - ], - 'ON_SALE_TO' => [ + ), + 'ON_SALE_TO' => array( 'value' => 'date', 'description' => __( 'Order by date product sale ends', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'This field is deprecated and will be removed in a future version.', 'wp-graphql-woocommerce' ), - ], - 'TOTAL_SALES' => [ + ), + 'TOTAL_SALES' => array( 'value' => 'popularity', 'description' => __( 'Order by total sales of products sold', 'wp-graphql-woocommerce' ), 'deprecationReason' => __( 'This field is deprecated and will be removed in a future version. Use "POPULARITY" instead', 'wp-graphql-woocommerce' ), - ], - ] + ), + ) ) ); } diff --git a/includes/type/enum/class-shipping-location-type-enum.php b/includes/type/enum/class-shipping-location-type-enum.php index e4bd695af..8c4d28f3f 100644 --- a/includes/type/enum/class-shipping-location-type-enum.php +++ b/includes/type/enum/class-shipping-location-type-enum.php @@ -20,15 +20,15 @@ class Shipping_Location_Type_Enum { public static function register() { register_graphql_enum_type( 'ShippingLocationTypeEnum', - [ + array( 'description' => __( 'A Shipping zone location type.', 'wp-graphql-woocommerce' ), - 'values' => [ - 'COUNTRY' => [ 'value' => 'country' ], - 'CONTINENT' => [ 'value' => 'continent' ], - 'STATE' => [ 'value' => 'state' ], - 'POSTCODE' => [ 'value' => 'postcode' ], - ], - ] + 'values' => array( + 'COUNTRY' => array( 'value' => 'country' ), + 'CONTINENT' => array( 'value' => 'continent' ), + 'STATE' => array( 'value' => 'state' ), + 'POSTCODE' => array( 'value' => 'postcode' ), + ), + ) ); } } diff --git a/includes/type/enum/class-stock-status.php b/includes/type/enum/class-stock-status.php index da24340f7..15f57d1ba 100644 --- a/includes/type/enum/class-stock-status.php +++ b/includes/type/enum/class-stock-status.php @@ -20,10 +20,10 @@ class Stock_Status { public static function register() { register_graphql_enum_type( 'StockStatusEnum', - [ + array( 'description' => __( 'Product stock status enumeration', 'wp-graphql-woocommerce' ), 'values' => self::get_stock_statuses(), - ] + ) ); } @@ -35,11 +35,11 @@ public static function register() { private static function get_stock_statuses() { return apply_filters( 'graphql_woocommerce_product_stock_statuses', - [ - 'IN_STOCK' => [ 'value' => 'instock' ], - 'OUT_OF_STOCK' => [ 'value' => 'outofstock' ], - 'ON_BACKORDER' => [ 'value' => 'onbackorder' ], - ] + array( + 'IN_STOCK' => array( 'value' => 'instock' ), + 'OUT_OF_STOCK' => array( 'value' => 'outofstock' ), + 'ON_BACKORDER' => array( 'value' => 'onbackorder' ), + ) ); } } diff --git a/includes/type/enum/class-tax-class.php b/includes/type/enum/class-tax-class.php index 8620d923f..0af3966b2 100644 --- a/includes/type/enum/class-tax-class.php +++ b/includes/type/enum/class-tax-class.php @@ -20,28 +20,28 @@ class Tax_Class { * @return void */ public static function register() { - $values = [ - 'INHERIT_CART' => [ + $values = array( + 'INHERIT_CART' => array( 'value' => 'inherit', 'description' => __( 'Inherits Tax class from cart', 'wp-graphql-woocommerce' ), - ], - 'STANDARD' => [ + ), + 'STANDARD' => array( 'value' => '', 'description' => __( 'Standard Tax rate', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); $classes = \WC_Tax::get_tax_classes(); foreach ( $classes as $class ) { - $values[ WPEnumType::get_safe_name( $class ) ] = [ 'value' => sanitize_title( $class ) ]; + $values[ WPEnumType::get_safe_name( $class ) ] = array( 'value' => sanitize_title( $class ) ); } register_graphql_enum_type( 'TaxClassEnum', - [ + array( 'description' => __( 'Tax class enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ] + ) ); } } diff --git a/includes/type/enum/class-tax-rate-connection-orderby-enum.php b/includes/type/enum/class-tax-rate-connection-orderby-enum.php index 2d34a52e7..7bf97b917 100644 --- a/includes/type/enum/class-tax-rate-connection-orderby-enum.php +++ b/includes/type/enum/class-tax-rate-connection-orderby-enum.php @@ -20,13 +20,13 @@ class Tax_Rate_Connection_Orderby_Enum { public static function register() { register_graphql_enum_type( 'TaxRateConnectionOrderbyEnum', - [ + array( 'description' => __( 'Field to order the connection by', 'wp-graphql-woocommerce' ), - 'values' => [ - 'ID' => [ 'value' => 'id' ], - 'ORDER' => [ 'value' => 'order' ], - ], - ] + 'values' => array( + 'ID' => array( 'value' => 'id' ), + 'ORDER' => array( 'value' => 'order' ), + ), + ) ); } } diff --git a/includes/type/enum/class-tax-status.php b/includes/type/enum/class-tax-status.php index b60fa2434..78ea3cb7a 100644 --- a/includes/type/enum/class-tax-status.php +++ b/includes/type/enum/class-tax-status.php @@ -20,14 +20,14 @@ class Tax_Status { public static function register() { register_graphql_enum_type( 'TaxStatusEnum', - [ + array( 'description' => __( 'Product tax status enumeration', 'wp-graphql-woocommerce' ), - 'values' => [ - 'TAXABLE' => [ 'value' => 'taxable' ], - 'SHIPPING' => [ 'value' => 'shipping' ], - 'NONE' => [ 'value' => 'none' ], - ], - ] + 'values' => array( + 'TAXABLE' => array( 'value' => 'taxable' ), + 'SHIPPING' => array( 'value' => 'shipping' ), + 'NONE' => array( 'value' => 'none' ), + ), + ) ); } } diff --git a/includes/type/enum/class-taxonomy-operator.php b/includes/type/enum/class-taxonomy-operator.php index c23126b13..589982e42 100644 --- a/includes/type/enum/class-taxonomy-operator.php +++ b/includes/type/enum/class-taxonomy-operator.php @@ -20,16 +20,16 @@ class Taxonomy_Operator { public static function register() { register_graphql_enum_type( 'TaxonomyOperatorEnum', - [ + array( 'description' => __( 'Taxonomy query operators', 'wp-graphql-woocommerce' ), - 'values' => [ - 'IN' => [ 'value' => 'IN' ], - 'NOT_IN' => [ 'value' => 'NOT IN' ], - 'AND' => [ 'value' => 'AND' ], - 'EXISTS' => [ 'value' => 'EXISTS' ], - 'NOT_EXISTS' => [ 'value' => 'NOT EXISTS' ], - ], - ] + 'values' => array( + 'IN' => array( 'value' => 'IN' ), + 'NOT_IN' => array( 'value' => 'NOT IN' ), + 'AND' => array( 'value' => 'AND' ), + 'EXISTS' => array( 'value' => 'EXISTS' ), + 'NOT_EXISTS' => array( 'value' => 'NOT EXISTS' ), + ), + ) ); } } diff --git a/includes/type/enum/class-wc-setting-type-enum.php b/includes/type/enum/class-wc-setting-type-enum.php index cb9a6c853..df34f532c 100644 --- a/includes/type/enum/class-wc-setting-type-enum.php +++ b/includes/type/enum/class-wc-setting-type-enum.php @@ -20,22 +20,22 @@ class WC_Setting_Type_Enum { public static function register() { register_graphql_enum_type( 'WCSettingTypeEnum', - [ + array( 'description' => __( 'Type of WC setting.', 'wp-graphql-woocommerce' ), - 'values' => [ - 'TEXT' => [ 'value' => 'text' ], - 'EMAIL' => [ 'value' => 'email' ], - 'NUMBER' => [ 'value' => 'number' ], - 'COLOR' => [ 'value' => 'color' ], - 'PASSWORD' => [ 'value' => 'password' ], - 'TEXTAREA' => [ 'value' => 'textarea' ], - 'SELECT' => [ 'value' => 'select' ], - 'MULTI_SELECT' => [ 'value' => 'multi_select' ], - 'RADIO' => [ 'value' => 'radio' ], - 'IMAGE_WIDTH' => [ 'value' => 'image_width' ], - 'CHECKBOX' => [ 'value' => 'checkbox' ], - ], - ] + 'values' => array( + 'TEXT' => array( 'value' => 'text' ), + 'EMAIL' => array( 'value' => 'email' ), + 'NUMBER' => array( 'value' => 'number' ), + 'COLOR' => array( 'value' => 'color' ), + 'PASSWORD' => array( 'value' => 'password' ), + 'TEXTAREA' => array( 'value' => 'textarea' ), + 'SELECT' => array( 'value' => 'select' ), + 'MULTI_SELECT' => array( 'value' => 'multi_select' ), + 'RADIO' => array( 'value' => 'radio' ), + 'IMAGE_WIDTH' => array( 'value' => 'image_width' ), + 'CHECKBOX' => array( 'value' => 'checkbox' ), + ), + ) ); } } diff --git a/includes/type/input/class-cart-item-input.php b/includes/type/input/class-cart-item-input.php index 61a851108..195198ffe 100644 --- a/includes/type/input/class-cart-item-input.php +++ b/includes/type/input/class-cart-item-input.php @@ -20,31 +20,31 @@ class Cart_Item_Input { public static function register() { register_graphql_input_type( 'CartItemInput', - [ + array( 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'productId' => [ - 'type' => [ 'non_null' => 'Int' ], + 'fields' => array( + 'productId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), - ], - 'quantity' => [ + ), + 'quantity' => array( 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - ], - 'variationId' => [ + ), + 'variationId' => array( 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), - ], - 'variation' => [ - 'type' => [ 'list_of' => 'ProductAttributeInput' ], + ), + 'variation' => array( + 'type' => array( 'list_of' => 'ProductAttributeInput' ), 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), - ], - 'extraData' => [ + ), + 'extraData' => array( 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-cart-item-quantity-input.php b/includes/type/input/class-cart-item-quantity-input.php index c1691b7e3..ce0082630 100644 --- a/includes/type/input/class-cart-item-quantity-input.php +++ b/includes/type/input/class-cart-item-quantity-input.php @@ -20,19 +20,19 @@ class Cart_Item_Quantity_Input { public static function register() { register_graphql_input_type( 'CartItemQuantityInput', - [ + array( 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'key' => [ - 'type' => [ 'non_null' => 'ID' ], + 'fields' => array( + 'key' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Cart item being updated', 'wp-graphql-woocommerce' ), - ], - 'quantity' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'quantity' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Cart item\'s new quantity', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-collection-stats-query-input.php b/includes/type/input/class-collection-stats-query-input.php index b2eeae5ee..604ac8e7c 100644 --- a/includes/type/input/class-collection-stats-query-input.php +++ b/includes/type/input/class-collection-stats-query-input.php @@ -20,19 +20,19 @@ class Collection_Stats_Query_Input { public static function register() { register_graphql_input_type( 'CollectionStatsQueryInput', - [ + array( 'description' => __( 'Taxonomy query', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'taxonomy' => [ - 'type' => [ 'non_null' => 'ProductAttributeEnum' ], + 'fields' => array( + 'taxonomy' => array( + 'type' => array( 'non_null' => 'ProductAttributeEnum' ), 'description' => __( 'Product Taxonomy', 'wp-graphql-woocommerce' ), - ], - 'relation' => [ + ), + 'relation' => array( 'type' => 'RelationEnum', 'description' => __( 'Taxonomy relation to query', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-collection-stats-where-args.php b/includes/type/input/class-collection-stats-where-args.php index 3a2b9f5b7..2d535bb09 100644 --- a/includes/type/input/class-collection-stats-where-args.php +++ b/includes/type/input/class-collection-stats-where-args.php @@ -20,91 +20,91 @@ class Collection_Stats_Where_Args { public static function register() { register_graphql_input_type( 'CollectionStatsWhereArgs', - [ + array( 'description' => __( 'Arguments used to filter the collection results', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'search' => [ + 'fields' => array( + 'search' => array( 'type' => 'String', 'description' => __( 'Limit result set to products based on a keyword search.', 'wp-graphql-woocommerce' ), - ], - 'slugIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'slugIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products with specific slugs.', 'wp-graphql-woocommerce' ), - ], - 'typeIn' => [ - 'type' => [ 'list_of' => 'ProductTypesEnum' ], + ), + 'typeIn' => array( + 'type' => array( 'list_of' => 'ProductTypesEnum' ), 'description' => __( 'Limit result set to products assigned to a group of specific types.', 'wp-graphql-woocommerce' ), - ], - 'exclude' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'exclude' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Ensure result set excludes specific IDs.', 'wp-graphql-woocommerce' ), - ], - 'include' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'include' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to specific ids.', 'wp-graphql-woocommerce' ), - ], - 'sku' => [ + ), + 'sku' => array( 'type' => 'String', 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'wp-graphql-woocommerce' ), - ], - 'featured' => [ + ), + 'featured' => array( 'type' => 'Boolean', 'description' => __( 'Limit result set to featured products.', 'wp-graphql-woocommerce' ), - ], - 'parentIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'parentIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Specify objects whose parent is in an array.', 'wp-graphql-woocommerce' ), - ], - 'parentNotIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'parentNotIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Specify objects whose parent is not in an array.', 'wp-graphql-woocommerce' ), - ], - 'categoryIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'categoryIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products assigned to a group of specific categories by name.', 'wp-graphql-woocommerce' ), - ], - 'categoryIdIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'categoryIdIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to products assigned to a specific group of category IDs.', 'wp-graphql-woocommerce' ), - ], - 'tagIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'tagIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Limit result set to products assigned to a specific group of tags by name.', 'wp-graphql-woocommerce' ), - ], - 'tagIdIn' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'tagIdIn' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'Limit result set to products assigned to a specific group of tag IDs.', 'wp-graphql-woocommerce' ), - ], - 'attributes' => [ + ), + 'attributes' => array( 'type' => 'ProductAttributeQueryInput', 'description' => __( 'Limit result set to products with selected global attribute queries.', 'wp-graphql-woocommerce' ), - ], - 'stockStatus' => [ - 'type' => [ 'list_of' => 'StockStatusEnum' ], + ), + 'stockStatus' => array( + 'type' => array( 'list_of' => 'StockStatusEnum' ), 'description' => __( 'Limit result set to products in stock or out of stock.', 'wp-graphql-woocommerce' ), - ], - 'onSale' => [ + ), + 'onSale' => array( 'type' => 'Boolean', 'description' => __( 'Limit result set to products on sale.', 'wp-graphql-woocommerce' ), - ], - 'minPrice' => [ + ), + 'minPrice' => array( 'type' => 'Float', 'description' => __( 'Limit result set to products based on a minimum price.', 'wp-graphql-woocommerce' ), - ], - 'maxPrice' => [ + ), + 'maxPrice' => array( 'type' => 'Float', 'description' => __( 'Limit result set to products based on a maximum price.', 'wp-graphql-woocommerce' ), - ], - 'visibility' => [ + ), + 'visibility' => array( 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Limit result set to products with a specific visibility level.', 'wp-graphql-woocommerce' ), - ], - 'rating' => [ - 'type' => [ 'list_of' => 'Integer' ], + ), + 'rating' => array( + 'type' => array( 'list_of' => 'Integer' ), 'description' => __( 'Limit result set to products with a specific average rating. Must be between 1 and 5', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-create-account-input.php b/includes/type/input/class-create-account-input.php index cc743c428..6b12df8ad 100644 --- a/includes/type/input/class-create-account-input.php +++ b/includes/type/input/class-create-account-input.php @@ -20,19 +20,19 @@ class Create_Account_Input { public static function register() { register_graphql_input_type( 'CreateAccountInput', - [ + array( 'description' => __( 'Customer account credentials', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'username' => [ - 'type' => [ 'non_null' => 'String' ], + 'fields' => array( + 'username' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Customer username', 'wp-graphql-woocommerce' ), - ], - 'password' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'password' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Customer password', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-customer-address-input.php b/includes/type/input/class-customer-address-input.php index 37d6ae6e3..d10e44003 100644 --- a/includes/type/input/class-customer-address-input.php +++ b/includes/type/input/class-customer-address-input.php @@ -20,59 +20,59 @@ class Customer_Address_Input { public static function register() { register_graphql_input_type( 'CustomerAddressInput', - [ + array( 'description' => __( 'Customer address information', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'firstName' => [ + 'fields' => array( + 'firstName' => array( 'type' => 'String', 'description' => __( 'First name', 'wp-graphql-woocommerce' ), - ], - 'lastName' => [ + ), + 'lastName' => array( 'type' => 'String', 'description' => __( 'Last name', 'wp-graphql-woocommerce' ), - ], - 'company' => [ + ), + 'company' => array( 'type' => 'String', 'description' => __( 'Company', 'wp-graphql-woocommerce' ), - ], - 'address1' => [ + ), + 'address1' => array( 'type' => 'String', 'description' => __( 'Address 1', 'wp-graphql-woocommerce' ), - ], - 'address2' => [ + ), + 'address2' => array( 'type' => 'String', 'description' => __( 'Address 2', 'wp-graphql-woocommerce' ), - ], - 'city' => [ + ), + 'city' => array( 'type' => 'String', 'description' => __( 'City', 'wp-graphql-woocommerce' ), - ], - 'state' => [ + ), + 'state' => array( 'type' => 'String', 'description' => __( 'State', 'wp-graphql-woocommerce' ), - ], - 'postcode' => [ + ), + 'postcode' => array( 'type' => 'String', 'description' => __( 'Zip Postal Code', 'wp-graphql-woocommerce' ), - ], - 'country' => [ + ), + 'country' => array( 'type' => 'CountriesEnum', 'description' => __( 'Country', 'wp-graphql-woocommerce' ), - ], - 'email' => [ + ), + 'email' => array( 'type' => 'String', 'description' => __( 'E-mail', 'wp-graphql-woocommerce' ), - ], - 'phone' => [ + ), + 'phone' => array( 'type' => 'String', 'description' => __( 'Phone', 'wp-graphql-woocommerce' ), - ], - 'overwrite' => [ + ), + 'overwrite' => array( 'type' => 'Boolean', 'description' => __( 'Clear old address data', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-fee-line-input.php b/includes/type/input/class-fee-line-input.php index 848460585..5d0c6eae4 100644 --- a/includes/type/input/class-fee-line-input.php +++ b/includes/type/input/class-fee-line-input.php @@ -20,35 +20,35 @@ class Fee_Line_Input { public static function register() { register_graphql_input_type( 'FeeLineInput', - [ + array( 'description' => __( 'Fee line data.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ + 'fields' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Fee Line ID', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Fee name.', 'wp-graphql-woocommerce' ), - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'String', 'description' => __( 'Fee amount.', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Tax class of fee.', 'wp-graphql-woocommerce' ), - ], - 'taxStatus' => [ + ), + 'taxStatus' => array( 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status of fee.', 'wp-graphql-woocommerce' ), - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Line total (after discounts).', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-line-item-input.php b/includes/type/input/class-line-item-input.php index 501a608ef..7399d7424 100644 --- a/includes/type/input/class-line-item-input.php +++ b/includes/type/input/class-line-item-input.php @@ -20,51 +20,51 @@ class Line_Item_Input { public static function register() { register_graphql_input_type( 'LineItemInput', - [ + array( 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ + 'fields' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Line Item ID', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Line name', 'wp-graphql-woocommerce' ), - ], - 'productId' => [ + ), + 'productId' => array( 'type' => 'Int', 'description' => __( 'Product ID.', 'wp-graphql-woocommerce' ), - ], - 'variationId' => [ + ), + 'variationId' => array( 'type' => 'Int', 'description' => __( 'Variation ID, if applicable.', 'wp-graphql-woocommerce' ), - ], - 'quantity' => [ + ), + 'quantity' => array( 'type' => 'Int', 'description' => __( 'Quantity ordered.', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Tax class of product.', 'wp-graphql-woocommerce' ), - ], - 'subtotal' => [ + ), + 'subtotal' => array( 'type' => 'String', 'description' => __( 'Line subtotal (before discounts).', 'wp-graphql-woocommerce' ), - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Line total (after discounts).', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ - 'type' => [ 'list_of' => 'MetaDataInput' ], + ), + 'metaData' => array( + 'type' => array( 'list_of' => 'MetaDataInput' ), 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - ], - 'sku' => [ + ), + 'sku' => array( 'type' => 'string', 'description' => __( 'Product SKU.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-meta-data-input.php b/includes/type/input/class-meta-data-input.php index 74be1c4ee..9deacf6ff 100644 --- a/includes/type/input/class-meta-data-input.php +++ b/includes/type/input/class-meta-data-input.php @@ -20,23 +20,23 @@ class Meta_Data_Input { public static function register() { register_graphql_input_type( 'MetaDataInput', - [ + array( 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ + 'fields' => array( + 'id' => array( 'type' => 'String', 'description' => __( 'Meta ID.', 'wp-graphql-woocommerce' ), - ], - 'key' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'key' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Meta key.', 'wp-graphql-woocommerce' ), - ], - 'value' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'value' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Meta value.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-orderby-inputs.php b/includes/type/input/class-orderby-inputs.php index dbe9e909a..972998961 100644 --- a/includes/type/input/class-orderby-inputs.php +++ b/includes/type/input/class-orderby-inputs.php @@ -25,17 +25,17 @@ class Orderby_Inputs { public static function register_orderby_input( $base_name ) { register_graphql_input_type( $base_name . 'OrderbyInput', - [ + array( 'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'field' => [ - 'type' => [ 'non_null' => $base_name . 'OrderbyEnum' ], - ], - 'order' => [ + 'fields' => array( + 'field' => array( + 'type' => array( 'non_null' => $base_name . 'OrderbyEnum' ), + ), + 'order' => array( 'type' => 'OrderEnum', - ], - ], - ] + ), + ), + ) ); } @@ -45,11 +45,11 @@ public static function register_orderby_input( $base_name ) { * @return void */ public static function register() { - $input_types = [ + $input_types = array( 'PostType', 'Products', 'Orders', - ]; + ); foreach ( $input_types as $name ) { self::register_orderby_input( $name ); diff --git a/includes/type/input/class-product-attribute-filter-input.php b/includes/type/input/class-product-attribute-filter-input.php index 643be3b14..47f2d41d8 100644 --- a/includes/type/input/class-product-attribute-filter-input.php +++ b/includes/type/input/class-product-attribute-filter-input.php @@ -20,27 +20,27 @@ class Product_Attribute_Filter_Input { public static function register() { register_graphql_input_type( 'ProductAttributeFilterInput', - [ + array( 'description' => __( 'Product filter', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'taxonomy' => [ - 'type' => [ 'non_null' => 'ProductAttributeEnum' ], + 'fields' => array( + 'taxonomy' => array( + 'type' => array( 'non_null' => 'ProductAttributeEnum' ), 'description' => __( 'Which field to select taxonomy term by.', 'wp-graphql-woocommerce' ), - ], - 'terms' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'terms' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'A list of term slugs', 'wp-graphql-woocommerce' ), - ], - 'ids' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'ids' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'A list of term ids', 'wp-graphql-woocommerce' ), - ], - 'operator' => [ + ), + 'operator' => array( 'type' => 'AttributeOperatorEnum', 'description' => __( 'Filter operation type', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-product-attribute-input.php b/includes/type/input/class-product-attribute-input.php index 2ef5e1a4d..b9e8f385f 100644 --- a/includes/type/input/class-product-attribute-input.php +++ b/includes/type/input/class-product-attribute-input.php @@ -20,17 +20,17 @@ class Product_Attribute_Input { public static function register() { register_graphql_input_type( 'ProductAttributeInput', - [ + array( 'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'attributeName' => [ - 'type' => [ 'non_null' => 'String' ], - ], - 'attributeValue' => [ + 'fields' => array( + 'attributeName' => array( + 'type' => array( 'non_null' => 'String' ), + ), + 'attributeValue' => array( 'type' => 'String', - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-product-attribute-query-input.php b/includes/type/input/class-product-attribute-query-input.php index dc6a48687..1d27b5bc4 100644 --- a/includes/type/input/class-product-attribute-query-input.php +++ b/includes/type/input/class-product-attribute-query-input.php @@ -20,19 +20,19 @@ class Product_Attribute_Query_Input { public static function register() { register_graphql_input_type( 'ProductAttributeQueryInput', - [ + array( 'description' => __( 'Product filter', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'queries' => [ - 'type' => [ 'list_of' => 'ProductAttributeFilterInput' ], + 'fields' => array( + 'queries' => array( + 'type' => array( 'list_of' => 'ProductAttributeFilterInput' ), 'description' => __( 'Limit result set to products with selected global attributes.', 'wp-graphql-woocommerce' ), - ], - 'relation' => [ + ), + 'relation' => array( 'type' => 'AttributeOperatorEnum', 'description' => __( 'The logical relationship between attributes when filtering across multiple at once.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-product-taxonomy-filter-input.php b/includes/type/input/class-product-taxonomy-filter-input.php index 5b748d105..426ff4c79 100644 --- a/includes/type/input/class-product-taxonomy-filter-input.php +++ b/includes/type/input/class-product-taxonomy-filter-input.php @@ -20,27 +20,27 @@ class Product_Taxonomy_Filter_Input { public static function register() { register_graphql_input_type( 'ProductTaxonomyFilterInput', - [ + array( 'description' => __( 'Product filter', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'taxonomy' => [ - 'type' => [ 'non_null' => 'ProductTaxonomyEnum' ], + 'fields' => array( + 'taxonomy' => array( + 'type' => array( 'non_null' => 'ProductTaxonomyEnum' ), 'description' => __( 'Which field to select taxonomy term by.', 'wp-graphql-woocommerce' ), - ], - 'terms' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'terms' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'A list of term slugs', 'wp-graphql-woocommerce' ), - ], - 'ids' => [ - 'type' => [ 'list_of' => 'Int' ], + ), + 'ids' => array( + 'type' => array( 'list_of' => 'Int' ), 'description' => __( 'A list of term ids', 'wp-graphql-woocommerce' ), - ], - 'operator' => [ + ), + 'operator' => array( 'type' => 'TaxonomyOperatorEnum', 'description' => __( 'Filter operation type', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-product-taxonomy-input.php b/includes/type/input/class-product-taxonomy-input.php index 372700c20..f3e231ec0 100644 --- a/includes/type/input/class-product-taxonomy-input.php +++ b/includes/type/input/class-product-taxonomy-input.php @@ -20,19 +20,19 @@ class Product_Taxonomy_Input { public static function register() { register_graphql_input_type( 'ProductTaxonomyInput', - [ + array( 'description' => __( 'Product taxonomy filter type', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'relation' => [ + 'fields' => array( + 'relation' => array( 'type' => 'RelationEnum', 'description' => __( 'Logic relation between each filter.', 'wp-graphql-woocommerce' ), - ], - 'filters' => [ - 'type' => [ 'list_of' => 'ProductTaxonomyFilterInput' ], + ), + 'filters' => array( + 'type' => array( 'list_of' => 'ProductTaxonomyFilterInput' ), 'description' => __( 'Product taxonomy rules to be filter results by', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-shipping-line-input.php b/includes/type/input/class-shipping-line-input.php index c33ca5c19..87516724e 100644 --- a/includes/type/input/class-shipping-line-input.php +++ b/includes/type/input/class-shipping-line-input.php @@ -20,35 +20,35 @@ class Shipping_Line_Input { public static function register() { register_graphql_input_type( 'ShippingLineInput', - [ + array( 'description' => __( 'Shipping lines data.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ + 'fields' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Shipping Line ID', 'wp-graphql-woocommerce' ), - ], - 'methodTitle' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'methodTitle' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Shipping method name.', 'wp-graphql-woocommerce' ), - ], - 'methodId' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'methodId' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Shipping method ID.', 'wp-graphql-woocommerce' ), - ], - 'instanceId' => [ + ), + 'instanceId' => array( 'type' => 'String', 'description' => __( 'Shipping instance ID.', 'wp-graphql-woocommerce' ), - ], - 'total' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'total' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Line total (after discounts).', 'wp-graphql-woocommerce' ), - ], - 'metaData' => [ - 'type' => [ 'list_of' => 'MetaDataInput' ], + ), + 'metaData' => array( + 'type' => array( 'list_of' => 'MetaDataInput' ), 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-shipping-location-input.php b/includes/type/input/class-shipping-location-input.php index a8e436fbd..8e7a78c14 100644 --- a/includes/type/input/class-shipping-location-input.php +++ b/includes/type/input/class-shipping-location-input.php @@ -20,19 +20,19 @@ class Shipping_Location_Input { public static function register() { register_graphql_input_type( 'ShippingLocationInput', - [ + array( 'description' => __( 'Shipping lines data.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'code' => [ + 'fields' => array( + 'code' => array( 'type' => 'String', 'description' => __( 'Shipping location code.', 'wp-graphql-woocommerce' ), - ], - 'type' => [ + ), + 'type' => array( 'type' => 'ShippingLocationTypeEnum', 'description' => __( 'Shipping location type.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-tax-rate-connection-orderby-input.php b/includes/type/input/class-tax-rate-connection-orderby-input.php index 97a1bbd12..c8e05c8af 100644 --- a/includes/type/input/class-tax-rate-connection-orderby-input.php +++ b/includes/type/input/class-tax-rate-connection-orderby-input.php @@ -20,17 +20,17 @@ class Tax_Rate_Connection_Orderby_Input { public static function register() { register_graphql_input_type( 'TaxRateConnectionOrderbyInput', - [ + array( 'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'field' => [ - 'type' => [ 'non_null' => 'TaxRateConnectionOrderbyEnum' ], - ], - 'order' => [ + 'fields' => array( + 'field' => array( + 'type' => array( 'non_null' => 'TaxRateConnectionOrderbyEnum' ), + ), + 'order' => array( 'type' => 'OrderEnum', - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/input/class-wc-setting-input.php b/includes/type/input/class-wc-setting-input.php index 2f8f46a12..af6a6512d 100644 --- a/includes/type/input/class-wc-setting-input.php +++ b/includes/type/input/class-wc-setting-input.php @@ -20,19 +20,19 @@ class WC_Setting_Input { public static function register() { register_graphql_input_type( 'WCSettingInput', - [ + array( 'description' => __( 'WooCommerce setting input.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ + 'fields' => array( + 'id' => array( 'type' => 'String', 'description' => __( 'A unique identifier for the setting.', 'wp-graphql-woocommerce' ), - ], - 'value' => [ + ), + 'value' => array( 'type' => 'String', 'description' => __( 'Setting value.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/interface/class-attribute.php b/includes/type/interface/class-attribute.php index 59983a1b4..739a46fb6 100644 --- a/includes/type/interface/class-attribute.php +++ b/includes/type/interface/class-attribute.php @@ -20,25 +20,25 @@ class Attribute { public static function register_interface() { register_graphql_interface_type( 'Attribute', - [ + array( 'description' => __( 'Attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'name' => [ + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'name' => array( 'type' => 'String', 'description' => __( 'Name of attribute', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['name'] ) ? $source['name'] : null; }, - ], - 'value' => [ + ), + 'value' => array( 'type' => 'String', 'description' => __( 'Selected value of attribute', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['value'] ) ? $source['value'] : null; }, - ], - ], + ), + ), 'resolveType' => static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); if ( $value->is_taxonomy() ) { @@ -47,7 +47,7 @@ public static function register_interface() { return $type_registry->get_type( 'VariationAttribute' ); } }, - ] + ) ); } } diff --git a/includes/type/interface/class-cart-error.php b/includes/type/interface/class-cart-error.php index 59f59dfed..a925f54f0 100644 --- a/includes/type/interface/class-cart-error.php +++ b/includes/type/interface/class-cart-error.php @@ -20,7 +20,7 @@ class Cart_Error { public static function register_interface() { register_graphql_interface_type( 'CartError', - [ + array( 'description' => __( 'An error that occurred when updating the cart', 'wp-graphql-woocommerce' ), 'fields' => self::get_fields(), 'resolveType' => static function ( array $value ) { @@ -36,7 +36,7 @@ public static function register_interface() { return $type_registry->get_type( 'UnknownCartError' ); } }, - ] + ) ); } @@ -46,21 +46,21 @@ public static function register_interface() { * @return array */ public static function get_fields() { - return [ - 'type' => [ - 'type' => [ 'non_null' => 'CartErrorType' ], + return array( + 'type' => array( + 'type' => array( 'non_null' => 'CartErrorType' ), 'description' => __( 'Type of error', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['type'] ) ? $error['type'] : null; }, - ], - 'reasons' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'reasons' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Reason for error', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $error ) { - return ! empty( $error['reasons'] ) ? $error['reasons'] : [ 'Reasons for error unknown, sorry.' ]; + return ! empty( $error['reasons'] ) ? $error['reasons'] : array( 'Reasons for error unknown, sorry.' ); }, - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-cart-item.php b/includes/type/interface/class-cart-item.php index 160aa4446..8f6bece3a 100644 --- a/includes/type/interface/class-cart-item.php +++ b/includes/type/interface/class-cart-item.php @@ -27,9 +27,9 @@ public static function register_interface() { // Register cart item interface. register_graphql_interface_type( 'CartItem', - [ + array( 'description' => __( 'Cart item interface.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), 'connections' => self::get_connections(), 'resolveType' => static function ( $cart_item ) { @@ -47,17 +47,17 @@ public static function register_interface() { return $type_registry->get_type( $type_name ); }, - ] + ) ); register_graphql_object_type( 'SimpleCartItem', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'A item in the cart', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node', 'CartItem' ], - 'fields' => [], - ] + 'interfaces' => array( 'Node', 'CartItem' ), + 'fields' => array(), + ) ); } @@ -67,30 +67,30 @@ public static function register_interface() { * @return array */ public static function get_fields() { - return [ - 'key' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'key' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'CartItem ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['key'] ) ? $source['key'] : null; }, - ], - 'quantity' => [ + ), + 'quantity' => array( 'type' => 'Int', 'description' => __( 'Quantity of the product', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['quantity'] ) ? absint( $source['quantity'] ) : null; }, - ], - 'subtotal' => [ + ), + 'subtotal' => array( 'type' => 'String', 'description' => __( 'Item\'s subtotal', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = isset( $source['line_subtotal'] ) ? floatval( $source['line_subtotal'] ) : 0; @@ -100,16 +100,16 @@ public static function get_fields() { return \wc_graphql_price( $price ); }, - ], - 'subtotalTax' => [ + ), + 'subtotalTax' => array( 'type' => 'String', 'description' => __( 'Item\'s subtotal tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = isset( $source['line_subtotal_tax'] ) ? floatval( $source['line_subtotal_tax'] ) : 0; @@ -119,16 +119,16 @@ public static function get_fields() { return \wc_graphql_price( $price ); }, - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Item\'s total', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price_without_tax = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : 0; $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : 0; @@ -140,16 +140,16 @@ public static function get_fields() { return \wc_graphql_price( $price ); }, - ], - 'tax' => [ + ), + 'tax' => array( 'type' => 'String', 'description' => __( 'Item\'s tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : 0; @@ -159,27 +159,27 @@ public static function get_fields() { return \wc_graphql_price( $price ); }, - ], - 'extraData' => [ - 'type' => [ 'list_of' => 'MetaData' ], + ), + 'extraData' => array( + 'type' => array( 'list_of' => 'MetaData' ), 'description' => __( 'Object meta data', 'wp-graphql-woocommerce' ), - 'args' => [ - 'key' => [ + 'args' => array( + 'key' => array( 'type' => 'String', 'description' => __( 'Retrieve meta by key', 'wp-graphql-woocommerce' ), - ], - 'keysIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'keysIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { // Check if "key" argument set and assigns to target "keys" array. if ( ! empty( $args['key'] ) && ! empty( $source[ $args['key'] ] ) ) { - $keys = [ $args['key'] ]; + $keys = array( $args['key'] ); } elseif ( ! empty( $args['keysIn'] ) ) { // Check if "keysIn" argument set and assigns to target "keys" array. - $keys = []; + $keys = array(); foreach ( $args['keysIn'] as $key ) { if ( ! empty( $source[ $key ] ) ) { $keys[] = $key; @@ -189,7 +189,7 @@ public static function get_fields() { // If no arguments set, all extra data keys are assigns to target "keys" array. $keys = array_diff( array_keys( $source ), - [ + array( 'key', 'product_id', 'variation_id', @@ -202,26 +202,26 @@ public static function get_fields() { 'line_subtotal_tax', 'line_total', 'line_tax', - ] + ) ); }//end if // Create meta ID prefix. $id_prefix = apply_filters( 'graphql_woocommerce_cart_meta_id_prefix', 'cart_' ); // Format meta data for resolution. - $data = []; + $data = array(); foreach ( $keys as $key ) { - $data[] = (object) [ + $data[] = (object) array( 'id' => "{$id_prefix}_{$key}", 'key' => $key, 'value' => is_array( $source[ $key ] ) ? wp_json_encode( $source[ $key ] ) : $source[ $key ], - ]; + ); } return $data; }, - ], - ]; + ), + ); } /** @@ -230,16 +230,16 @@ public static function get_fields() { * @return array */ public static function get_connections() { - return [ - 'product' => [ + return array( + 'product' => array( 'toType' => 'Product', 'oneToOne' => true, - 'edgeFields' => [ - 'simpleVariations' => [ - 'type' => [ 'list_of' => 'SimpleAttribute' ], + 'edgeFields' => array( + 'simpleVariations' => array( + 'type' => array( 'list_of' => 'SimpleAttribute' ), 'description' => __( 'Simple variation attribute data', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { - $attributes = []; + $attributes = array(); $variation = $source['node']; $cart_item_data = $source['source']; @@ -250,8 +250,8 @@ public static function get_connections() { return $attributes; }, - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $id = $source['product_id']; $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -261,16 +261,16 @@ public static function get_connections() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ], - 'variation' => [ + ), + 'variation' => array( 'toType' => 'ProductVariation', 'oneToOne' => true, - 'edgeFields' => [ - 'attributes' => [ - 'type' => [ 'list_of' => 'VariationAttribute' ], + 'edgeFields' => array( + 'attributes' => array( + 'type' => array( 'list_of' => 'VariationAttribute' ), 'description' => __( 'Attributes of the variation.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { - $attributes = []; + $attributes = array(); $variation = $source['node']; $cart_item_data = $source['source']; @@ -285,8 +285,8 @@ public static function get_connections() { return Variation_Attribute_Connection_Resolver::variation_attributes_to_data_array( $attributes, $variation->ID ); }, - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $id = ! empty( $source['variation_id'] ) ? $source['variation_id'] : null; $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product_variation' ); @@ -300,7 +300,7 @@ public static function get_connections() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-downloadable-product.php b/includes/type/interface/class-downloadable-product.php index b2c72ee9d..03ee55a2e 100644 --- a/includes/type/interface/class-downloadable-product.php +++ b/includes/type/interface/class-downloadable-product.php @@ -23,12 +23,12 @@ class Downloadable_Product { public static function register_interface(): void { register_graphql_interface_type( 'DownloadableProduct', - [ + array( 'description' => __( 'A downloadable product.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -38,31 +38,31 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - 'downloadExpiry' => [ + ), + 'downloadExpiry' => array( 'type' => 'Int', 'description' => __( 'Download expiry', 'wp-graphql-woocommerce' ), - ], - 'downloadable' => [ + ), + 'downloadable' => array( 'type' => 'Boolean', 'description' => __( 'Is downloadable?', 'wp-graphql-woocommerce' ), - ], - 'downloadLimit' => [ + ), + 'downloadLimit' => array( 'type' => 'Int', 'description' => __( 'Download limit', 'wp-graphql-woocommerce' ), - ], - 'downloads' => [ - 'type' => [ 'list_of' => 'ProductDownload' ], + ), + 'downloads' => array( + 'type' => array( 'list_of' => 'ProductDownload' ), 'description' => __( 'Product downloads', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-inventoried-product.php b/includes/type/interface/class-inventoried-product.php index 44fcfa8c5..d9f48f88e 100644 --- a/includes/type/interface/class-inventoried-product.php +++ b/includes/type/interface/class-inventoried-product.php @@ -23,12 +23,12 @@ class Inventoried_Product { public static function register_interface(): void { register_graphql_interface_type( 'InventoriedProduct', - [ + array( 'description' => __( 'A product with stock information.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -38,43 +38,43 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - 'manageStock' => [ + ), + 'manageStock' => array( 'type' => 'ManageStockEnum', 'description' => __( 'If product manage stock', 'wp-graphql-woocommerce' ), - ], - 'lowStockAmount' => [ + ), + 'lowStockAmount' => array( 'type' => 'Int', 'description' => __( 'Low stock amount', 'wp-graphql-woocommerce' ), - ], - 'stockQuantity' => [ + ), + 'stockQuantity' => array( 'type' => 'Int', 'description' => __( 'Number of items available for sale', 'wp-graphql-woocommerce' ), - ], - 'backorders' => [ + ), + 'backorders' => array( 'type' => 'BackordersEnum', 'description' => __( 'Product backorders status', 'wp-graphql-woocommerce' ), - ], - 'soldIndividually' => [ + ), + 'soldIndividually' => array( 'type' => 'Boolean', 'description' => __( 'If should be sold individually', 'wp-graphql-woocommerce' ), - ], - 'backordersAllowed' => [ + ), + 'backordersAllowed' => array( 'type' => 'Boolean', 'description' => __( 'Can product be backordered?', 'wp-graphql-woocommerce' ), - ], - 'stockStatus' => [ + ), + 'stockStatus' => array( 'type' => 'StockStatusEnum', 'description' => __( 'Product stock status', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-payment-token.php b/includes/type/interface/class-payment-token.php index ca35e1be3..e3a80fa67 100644 --- a/includes/type/interface/class-payment-token.php +++ b/includes/type/interface/class-payment-token.php @@ -23,9 +23,9 @@ class Payment_Token { public static function register_interface() { register_graphql_interface_type( 'PaymentToken', - [ + array( 'description' => __( 'Payment token object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), 'resolveType' => static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); @@ -45,7 +45,7 @@ public static function register_interface() { ); } }, - ] + ) ); } @@ -55,46 +55,46 @@ public static function register_interface() { * @param array $other_fields Optional fields to be added. * @return array */ - public static function get_fields( $other_fields = [] ) { + public static function get_fields( $other_fields = array() ) { return array_merge( - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Token ID unique identifier', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_id() ) ? Relay::toGlobalId( 'token', $source->get_id() ) : null; }, - ], - 'tokenId' => [ - 'type' => [ 'non_null' => 'Integer' ], + ), + 'tokenId' => array( + 'type' => array( 'non_null' => 'Integer' ), 'description' => __( 'Token database ID.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_id() ) ? $source->get_id() : null; }, - ], - 'type' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'type' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Token type', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_type() ) ? $source->get_type() : null; }, - ], - 'gateway' => [ + ), + 'gateway' => array( 'type' => 'PaymentGateway', 'description' => __( 'Token payment gateway', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $gateway_id = $source->get_gateway_id(); return null; }, - ], - 'isDefault' => [ + ), + 'isDefault' => array( 'type' => 'Boolean', 'description' => __( 'Is token connected to user\'s preferred payment method', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! is_null( $source->is_default() ) ? $source->is_default() : false; }, - ], - ], + ), + ), $other_fields ); } diff --git a/includes/type/interface/class-product-attribute.php b/includes/type/interface/class-product-attribute.php index ead157920..a089b2b3d 100644 --- a/includes/type/interface/class-product-attribute.php +++ b/includes/type/interface/class-product-attribute.php @@ -20,9 +20,9 @@ class Product_Attribute { public static function register_interface() { register_graphql_interface_type( 'ProductAttribute', - [ + array( 'description' => __( 'Product attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), 'resolveType' => static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); @@ -32,7 +32,7 @@ public static function register_interface() { return $type_registry->get_type( 'LocalProductAttribute' ); } }, - ] + ) ); } @@ -42,68 +42,68 @@ public static function register_interface() { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Attribute Global ID', 'wp-graphql-woocommerce' ), - ], - 'attributeId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'attributeId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Attribute ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_id() ) ? $attribute->get_id() : null; }, - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Attribute name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, - ], - 'label' => [ + ), + 'label' => array( 'type' => 'String', 'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, - ], - 'options' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'options' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Attribute options', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { $slugs = $attribute->get_slugs(); return ! empty( $slugs ) ? $slugs : null; }, - ], - 'position' => [ + ), + 'position' => array( 'type' => 'Int', 'description' => __( 'Attribute position', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_position() ) ? $attribute->get_position() : null; }, - ], - 'visible' => [ + ), + 'visible' => array( 'type' => 'Boolean', 'description' => __( 'Is attribute visible', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_visible() ) ? $attribute->get_visible() : null; }, - ], - 'variation' => [ + ), + 'variation' => array( 'type' => 'Boolean', 'description' => __( 'Is attribute on product variation', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_variation() ) ? $attribute->get_variation() : null; }, - ], - 'scope' => [ - 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], + ), + 'scope' => array( + 'type' => array( 'non_null' => 'ProductAttributeTypesEnum' ), 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return $attribute->is_taxonomy() ? 'global' : 'local'; }, - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-product-union.php b/includes/type/interface/class-product-union.php index 6477af97d..3e08805fa 100644 --- a/includes/type/interface/class-product-union.php +++ b/includes/type/interface/class-product-union.php @@ -24,12 +24,12 @@ class Product_Union { public static function register_interface(): void { register_graphql_interface_type( 'ProductUnion', - [ + array( 'description' => __( 'Union between the product and product variation types', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -40,48 +40,48 @@ public static function register_interface(): void { */ public static function get_fields() { return array_merge( - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - 'slug' => [ + ), + 'slug' => array( 'type' => 'String', 'description' => __( 'Product slug', 'wp-graphql-woocommerce' ), - ], - 'type' => [ + ), + 'type' => array( 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Product name', 'wp-graphql-woocommerce' ), - ], - 'featured' => [ + ), + 'featured' => array( 'type' => 'Boolean', 'description' => __( 'If the product is featured', 'wp-graphql-woocommerce' ), - ], - 'catalogVisibility' => [ + ), + 'catalogVisibility' => array( 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Catalog visibility', 'wp-graphql-woocommerce' ), - ], - 'sku' => [ + ), + 'sku' => array( 'type' => 'String', 'description' => __( 'Product SKU', 'wp-graphql-woocommerce' ), - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Product description', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PostObjectFieldFormatEnum', 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -89,8 +89,8 @@ public static function get_fields() { } return $source->description; }, - ], - 'image' => [ + ), + 'image' => array( 'type' => 'MediaItem', 'description' => __( 'Main image', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { @@ -100,16 +100,16 @@ public static function get_fields() { } return $context->get_loader( 'post' )->load_deferred( $source->image_id ); }, - ], - 'onSale' => [ + ), + 'onSale' => array( 'type' => 'Boolean', 'description' => __( 'Is product on sale?', 'wp-graphql-woocommerce' ), - ], - 'purchasable' => [ + ), + 'purchasable' => array( 'type' => 'Boolean', 'description' => __( 'Can product be purchased?', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), Product::get_fields() ); } diff --git a/includes/type/interface/class-product-variation.php b/includes/type/interface/class-product-variation.php index 3ae0228d6..ce1426ae0 100644 --- a/includes/type/interface/class-product-variation.php +++ b/includes/type/interface/class-product-variation.php @@ -27,7 +27,7 @@ class Product_Variation { public static function register_interface(): void { register_graphql_fields( 'ProductVariation', self::get_fields() ); register_graphql_connection( - [ + array( 'fromType' => 'ProductVariation', 'toType' => 'VariationAttribute', 'fromFieldName' => 'attributes', @@ -36,10 +36,10 @@ public static function register_interface(): void { return $resolver->resolve( $source, $args, $context, $info ); }, - ] + ) ); register_graphql_connection( - [ + array( 'fromType' => 'ProductVariation', 'toType' => 'Product', 'fromFieldName' => 'parent', @@ -56,18 +56,18 @@ public static function register_interface(): void { return $resolver->one_to_one()->get_connection(); }, - ] + ) ); register_graphql_object_type( 'SimpleProductVariation', - [ + array( 'eagerlyLoadType' => true, 'model' => \WPGraphQL\WooCommerce\Model\Product_Variation::class, 'description' => __( 'A product variation', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node', 'ProductVariation' ], - 'fields' => [], - ] + 'interfaces' => array( 'Node', 'ProductVariation' ), + 'fields' => array(), + ) ); } @@ -77,44 +77,44 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Product name', 'wp-graphql-woocommerce' ), - ], - 'date' => [ + ), + 'date' => array( 'type' => 'String', 'description' => __( 'Date variation created', 'wp-graphql-woocommerce' ), - ], - 'modified' => [ + ), + 'modified' => array( 'type' => 'String', 'description' => __( 'Date variation last updated', 'wp-graphql-woocommerce' ), - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Product description', 'wp-graphql-woocommerce' ), - ], - 'sku' => [ + ), + 'sku' => array( 'type' => 'String', 'description' => __( 'Product variation SKU (Stock-keeping unit)', 'wp-graphql-woocommerce' ), - ], - 'price' => [ + ), + 'price' => array( 'type' => 'String', 'description' => __( 'Product variation\'s active price', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -123,16 +123,16 @@ public static function get_fields() { return $source->price; } }, - ], - 'regularPrice' => [ + ), + 'regularPrice' => array( 'type' => 'String', 'description' => __( 'Product variation\'s regular price', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -142,16 +142,16 @@ public static function get_fields() { return $source->regularPrice; } }, - ], - 'salePrice' => [ + ), + 'salePrice' => array( 'type' => 'String', 'description' => __( 'Product variation\'s sale price', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -161,116 +161,116 @@ public static function get_fields() { return $source->salePrice; } }, - ], - 'dateOnSaleFrom' => [ + ), + 'dateOnSaleFrom' => array( 'type' => 'String', 'description' => __( 'Date on sale from', 'wp-graphql-woocommerce' ), - ], - 'dateOnSaleTo' => [ + ), + 'dateOnSaleTo' => array( 'type' => 'String', 'description' => __( 'Date on sale to', 'wp-graphql-woocommerce' ), - ], - 'onSale' => [ + ), + 'onSale' => array( 'type' => 'Boolean', 'description' => __( 'Is variation on sale?', 'wp-graphql-woocommerce' ), - ], - 'status' => [ + ), + 'status' => array( 'type' => 'String', 'description' => __( 'Variation status', 'wp-graphql-woocommerce' ), - ], - 'purchasable' => [ + ), + 'purchasable' => array( 'type' => 'Boolean', 'description' => __( 'If product variation can be bought', 'wp-graphql-woocommerce' ), - ], - 'virtual' => [ + ), + 'virtual' => array( 'type' => 'Boolean', 'description' => __( 'Is product virtual?', 'wp-graphql-woocommerce' ), - ], - 'downloadable' => [ + ), + 'downloadable' => array( 'type' => 'Boolean', 'description' => __( 'Is downloadable?', 'wp-graphql-woocommerce' ), - ], - 'downloads' => [ - 'type' => [ 'list_of' => 'ProductDownload' ], + ), + 'downloads' => array( + 'type' => array( 'list_of' => 'ProductDownload' ), 'description' => __( 'Product downloads', 'wp-graphql-woocommerce' ), - ], - 'downloadLimit' => [ + ), + 'downloadLimit' => array( 'type' => 'Int', 'description' => __( 'Download limit', 'wp-graphql-woocommerce' ), - ], - 'downloadExpiry' => [ + ), + 'downloadExpiry' => array( 'type' => 'Int', 'description' => __( 'Download expiry', 'wp-graphql-woocommerce' ), - ], - 'taxStatus' => [ + ), + 'taxStatus' => array( 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Product variation tax class', 'wp-graphql-woocommerce' ), - ], - 'manageStock' => [ + ), + 'manageStock' => array( 'type' => 'ManageStockEnum', 'description' => __( 'if/how product variation stock is managed', 'wp-graphql-woocommerce' ), - ], - 'stockQuantity' => [ + ), + 'stockQuantity' => array( 'type' => 'Int', 'description' => __( 'Product variation stock quantity', 'wp-graphql-woocommerce' ), - ], - 'stockStatus' => [ + ), + 'stockStatus' => array( 'type' => 'StockStatusEnum', 'description' => __( 'Product stock status', 'wp-graphql-woocommerce' ), - ], - 'backorders' => [ + ), + 'backorders' => array( 'type' => 'BackordersEnum', 'description' => __( 'Product variation backorders', 'wp-graphql-woocommerce' ), - ], - 'backordersAllowed' => [ + ), + 'backordersAllowed' => array( 'type' => 'Boolean', 'description' => __( 'Can product be backordered?', 'wp-graphql-woocommerce' ), - ], - 'weight' => [ + ), + 'weight' => array( 'type' => 'String', 'description' => __( 'Product variation weight', 'wp-graphql-woocommerce' ), - ], - 'length' => [ + ), + 'length' => array( 'type' => 'String', 'description' => __( 'Product variation length', 'wp-graphql-woocommerce' ), - ], - 'width' => [ + ), + 'width' => array( 'type' => 'String', 'description' => __( 'Product variation width', 'wp-graphql-woocommerce' ), - ], - 'height' => [ + ), + 'height' => array( 'type' => 'String', 'description' => __( 'Product variation height', 'wp-graphql-woocommerce' ), - ], - 'menuOrder' => [ + ), + 'menuOrder' => array( 'type' => 'Int', 'description' => __( 'Menu order', 'wp-graphql-woocommerce' ), - ], - 'purchaseNote' => [ + ), + 'purchaseNote' => array( 'type' => 'String', 'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ), - ], - 'shippingClass' => [ + ), + 'shippingClass' => array( 'type' => 'String', 'description' => __( 'Product variation shipping class', 'wp-graphql-woocommerce' ), - ], - 'catalogVisibility' => [ + ), + 'catalogVisibility' => array( 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Product variation catalog visibility', 'wp-graphql-woocommerce' ), - ], - 'hasAttributes' => [ + ), + 'hasAttributes' => array( 'type' => 'Boolean', 'description' => __( 'Does product variation have any visible attributes', 'wp-graphql-woocommerce' ), - ], - 'type' => [ + ), + 'type' => array( 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), - ], - 'image' => [ + ), + 'image' => array( 'type' => 'MediaItem', 'description' => __( 'Product variation main image', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { @@ -278,8 +278,8 @@ public static function get_fields() { ? $context->get_loader( 'post' )->load_deferred( $source->image_id ) : null; }, - ], + ), 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ]; + ); } } diff --git a/includes/type/interface/class-product-with-attributes.php b/includes/type/interface/class-product-with-attributes.php index 1bcaa6bf4..8d44fc45a 100644 --- a/includes/type/interface/class-product-with-attributes.php +++ b/includes/type/interface/class-product-with-attributes.php @@ -27,13 +27,13 @@ class Product_With_Attributes { public static function register_interface(): void { register_graphql_interface_type( 'ProductWithAttributes', - [ + array( 'description' => __( 'Products with default attributes.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), 'connections' => self::get_connections(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -43,16 +43,16 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -61,8 +61,8 @@ public static function get_fields() { * @return array */ public static function get_connections() { - return [ - 'defaultAttributes' => [ + return array( + 'defaultAttributes' => array( 'toType' => 'VariationAttribute', 'fromFieldName' => 'defaultAttributes', 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -70,22 +70,22 @@ public static function get_connections() { return $resolver->resolve( $source, $args, $context, $info ); }, - ], - 'attributes' => [ + ), + 'attributes' => array( 'toType' => 'ProductAttribute', 'fromFieldName' => 'attributes', - 'connectionArgs' => [ - 'type' => [ + 'connectionArgs' => array( + 'type' => array( 'type' => 'ProductAttributeTypesEnum', 'description' => __( 'Filter results by attribute scope.', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Attribute_Connection_Resolver(); return $resolver->resolve( $source, $args, $context, $info ); }, - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-product-with-dimensions.php b/includes/type/interface/class-product-with-dimensions.php index 3a125df6d..1020be8e7 100644 --- a/includes/type/interface/class-product-with-dimensions.php +++ b/includes/type/interface/class-product-with-dimensions.php @@ -23,12 +23,12 @@ class Product_With_Dimensions { public static function register_interface(): void { register_graphql_interface_type( 'ProductWithDimensions', - [ + array( 'description' => __( 'A physical product.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -38,43 +38,43 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - 'weight' => [ + ), + 'weight' => array( 'type' => 'String', 'description' => __( 'Product\'s weight', 'wp-graphql-woocommerce' ), - ], - 'length' => [ + ), + 'length' => array( 'type' => 'String', 'description' => __( 'Product\'s length', 'wp-graphql-woocommerce' ), - ], - 'width' => [ + ), + 'width' => array( 'type' => 'String', 'description' => __( 'Product\'s width', 'wp-graphql-woocommerce' ), - ], - 'height' => [ + ), + 'height' => array( 'type' => 'String', 'description' => __( 'Product\'s height', 'wp-graphql-woocommerce' ), - ], - 'shippingClassId' => [ + ), + 'shippingClassId' => array( 'type' => 'Int', 'description' => __( 'shipping class ID', 'wp-graphql-woocommerce' ), - ], - 'shippingRequired' => [ + ), + 'shippingRequired' => array( 'type' => 'Boolean', 'description' => __( 'Does product need to be shipped?', 'wp-graphql-woocommerce' ), - ], - 'shippingTaxable' => [ + ), + 'shippingTaxable' => array( 'type' => 'Boolean', 'description' => __( 'Is product shipping taxable?', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-product-with-pricing.php b/includes/type/interface/class-product-with-pricing.php index 0e1a47532..eb582bf90 100644 --- a/includes/type/interface/class-product-with-pricing.php +++ b/includes/type/interface/class-product-with-pricing.php @@ -23,12 +23,12 @@ class Product_With_Pricing { public static function register_interface(): void { register_graphql_interface_type( 'ProductWithPricing', - [ + array( 'description' => __( 'Products with pricing.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), 'fields' => self::get_fields(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -38,24 +38,24 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - 'price' => [ + ), + 'price' => array( 'type' => 'String', 'description' => __( 'Product\'s active price', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -66,16 +66,16 @@ public static function get_fields() { return $source->price; } }, - ], - 'regularPrice' => [ + ), + 'regularPrice' => array( 'type' => 'String', 'description' => __( 'Product\'s regular price', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -85,16 +85,16 @@ public static function get_fields() { return $source->regularPrice; } }, - ], - 'salePrice' => [ + ), + 'salePrice' => array( 'type' => 'String', 'description' => __( 'Product\'s sale price', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -104,15 +104,15 @@ public static function get_fields() { return $source->salePrice; } }, - ], - 'taxStatus' => [ + ), + 'taxStatus' => array( 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Tax class', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-product-with-variations.php b/includes/type/interface/class-product-with-variations.php index bda2197de..3f95f09da 100644 --- a/includes/type/interface/class-product-with-variations.php +++ b/includes/type/interface/class-product-with-variations.php @@ -27,13 +27,13 @@ class Product_With_Variations { public static function register_interface(): void { register_graphql_interface_type( 'ProductWithVariations', - [ + array( 'description' => __( 'A product with variations.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node', 'ProductWithAttributes' ], + 'interfaces' => array( 'Node', 'ProductWithAttributes' ), 'fields' => self::get_fields(), 'connections' => self::get_connections(), - 'resolveType' => [ Core::class, 'resolve_product_type' ], - ] + 'resolveType' => array( Core::class, 'resolve_product_type' ), + ) ); } @@ -43,16 +43,16 @@ public static function register_interface(): void { * @return array */ public static function get_fields() { - return [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + return array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'Int' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), - ], - ]; + ), + ); } /** @@ -61,8 +61,8 @@ public static function get_fields() { * @return array */ public static function get_connections() { - return [ - 'variations' => [ + return array( + 'variations' => array( 'toType' => 'ProductVariation', 'connectionArgs' => Products::get_connection_args(), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -74,7 +74,7 @@ public static function get_connections() { return $resolver->get_connection(); }, - ], - ]; + ), + ); } } diff --git a/includes/type/interface/class-product.php b/includes/type/interface/class-product.php index afcf7c13e..f008caa1c 100644 --- a/includes/type/interface/class-product.php +++ b/includes/type/interface/class-product.php @@ -33,19 +33,19 @@ public static function register_interface() { register_graphql_field( 'RootQuery', 'product', - [ + array( 'type' => 'Product', 'description' => __( 'A product object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'args' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The ID for identifying the product', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'ProductIdTypeEnum', 'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -84,7 +84,7 @@ public static function register_interface() { return Factory::resolve_crud_object( $product_id, $context ); }, - ] + ) ); } @@ -94,32 +94,32 @@ public static function register_interface() { * @return array */ public static function get_fields() { - return [ - 'type' => [ + return array( + 'type' => array( 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Product name', 'wp-graphql-woocommerce' ), - ], - 'featured' => [ + ), + 'featured' => array( 'type' => 'Boolean', 'description' => __( 'If the product is featured', 'wp-graphql-woocommerce' ), - ], - 'catalogVisibility' => [ + ), + 'catalogVisibility' => array( 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Catalog visibility', 'wp-graphql-woocommerce' ), - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Product description', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PostObjectFieldFormatEnum', 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -127,16 +127,16 @@ public static function get_fields() { } return $source->description; }, - ], - 'shortDescription' => [ + ), + 'shortDescription' => array( 'type' => 'String', 'description' => __( 'Product short description', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PostObjectFieldFormatEnum', 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -145,44 +145,44 @@ public static function get_fields() { // @codingStandardsIgnoreLine. return $source->shortDescription; }, - ], - 'sku' => [ + ), + 'sku' => array( 'type' => 'String', 'description' => __( 'Product SKU', 'wp-graphql-woocommerce' ), - ], - 'dateOnSaleFrom' => [ + ), + 'dateOnSaleFrom' => array( 'type' => 'String', 'description' => __( 'Date on sale from', 'wp-graphql-woocommerce' ), - ], - 'dateOnSaleTo' => [ + ), + 'dateOnSaleTo' => array( 'type' => 'String', 'description' => __( 'Date on sale to', 'wp-graphql-woocommerce' ), - ], - 'totalSales' => [ + ), + 'totalSales' => array( 'type' => 'Int', 'description' => __( 'Number total of sales', 'wp-graphql-woocommerce' ), - ], - 'reviewsAllowed' => [ + ), + 'reviewsAllowed' => array( 'type' => 'Boolean', 'description' => __( 'If reviews are allowed', 'wp-graphql-woocommerce' ), - ], - 'purchaseNote' => [ + ), + 'purchaseNote' => array( 'type' => 'String', 'description' => __( 'Purchase note', 'wp-graphql-woocommerce' ), - ], - 'menuOrder' => [ + ), + 'menuOrder' => array( 'type' => 'Int', 'description' => __( 'Menu order', 'wp-graphql-woocommerce' ), - ], - 'averageRating' => [ + ), + 'averageRating' => array( 'type' => 'Float', 'description' => __( 'Product average count', 'wp-graphql-woocommerce' ), - ], - 'reviewCount' => [ + ), + 'reviewCount' => array( 'type' => 'Int', 'description' => __( 'Product review count', 'wp-graphql-woocommerce' ), - ], - 'image' => [ + ), + 'image' => array( 'type' => 'MediaItem', 'description' => __( 'Main image', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { @@ -192,20 +192,20 @@ public static function get_fields() { } return $context->get_loader( 'post' )->load_deferred( $source->image_id ); }, - ], - 'onSale' => [ + ), + 'onSale' => array( 'type' => 'Boolean', 'description' => __( 'Is product on sale?', 'wp-graphql-woocommerce' ), - ], - 'purchasable' => [ + ), + 'purchasable' => array( 'type' => 'Boolean', 'description' => __( 'Can product be purchased?', 'wp-graphql-woocommerce' ), - ], - 'virtual' => [ + ), + 'virtual' => array( 'type' => 'Boolean', 'description' => __( 'Is product virtual?', 'wp-graphql-woocommerce' ), - ], + ), 'metaData' => \WPGraphQL\WooCommerce\Type\WPObject\Meta_Data_Type::get_metadata_field_definition(), - ]; + ); } } diff --git a/includes/type/object/class-cart-error-types.php b/includes/type/object/class-cart-error-types.php index e47b28cd5..d3d9a79c8 100644 --- a/includes/type/object/class-cart-error-types.php +++ b/includes/type/object/class-cart-error-types.php @@ -20,97 +20,97 @@ class Cart_Error_Types { public static function register() { register_graphql_object_type( 'CartItemError', - [ + array( 'description' => __( 'Error that occurred when adding an item to the cart.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'CartError' ], - 'fields' => [ - 'productId' => [ - 'type' => [ 'non_null' => 'Int' ], + 'interfaces' => array( 'CartError' ), + 'fields' => array( + 'productId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['productId'] ) ? $error['productId'] : null; }, - ], - 'quantity' => [ + ), + 'quantity' => array( 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['quantity'] ) ? $error['quantity'] : null; }, - ], - 'variationId' => [ + ), + 'variationId' => array( 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['variationId'] ) ? $error['variationId'] : null; }, - ], - 'variation' => [ - 'type' => [ 'list_of' => 'ProductAttributeOutput' ], + ), + 'variation' => array( + 'type' => array( 'list_of' => 'ProductAttributeOutput' ), 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['variation'] ) ? $error['variation'] : null; }, - ], - 'extraData' => [ + ), + 'extraData' => array( 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['extraData'] ) ? $error['extraData'] : null; }, - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'CouponError', - [ + array( 'description' => __( 'Error that occurred when applying a coupon to the cart.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'CartError' ], - 'fields' => [ - 'code' => [ - 'type' => [ 'non_null' => 'String' ], + 'interfaces' => array( 'CartError' ), + 'fields' => array( + 'code' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Coupon code of the coupon the failed to be applied', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['code'] ) ? $error['code'] : null; }, - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'ShippingMethodError', - [ + array( 'description' => __( 'Error that occurred when setting the chosen shipping method for the eventually order.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'CartError' ], - 'fields' => [ - 'package' => [ - 'type' => [ 'non_null' => 'Integer' ], + 'interfaces' => array( 'CartError' ), + 'fields' => array( + 'package' => array( + 'type' => array( 'non_null' => 'Integer' ), 'description' => __( 'Index of package for desired shipping method', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return isset( $error['package'] ) && is_int( $error['package'] ) ? $error['package'] : null; }, - ], - 'chosenMethod' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'chosenMethod' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'ID of chosen shipping rate', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $error ) { return ! empty( $error['chosen_method'] ) ? $error['chosen_method'] : null; }, - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'UnknownCartError', - [ + array( 'description' => __( 'Error that occurred with no recognizable reason.', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'CartError' ], - 'fields' => [], - ] + 'interfaces' => array( 'CartError' ), + 'fields' => array(), + ) ); } } diff --git a/includes/type/object/class-cart-type.php b/includes/type/object/class-cart-type.php index 7acbf2e60..3da50fcdc 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -38,18 +38,18 @@ public static function register() { * * @return array */ - public static function get_cart_fields( $other_fields = [] ) { + public static function get_cart_fields( $other_fields = array() ) { return array_merge( - [ - 'subtotal' => [ + array( + 'subtotal' => array( 'type' => 'String', 'description' => __( 'Cart subtotal', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_subtotal() ) ? $source->get_subtotal() : 0; @@ -59,16 +59,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'subtotalTax' => [ + ), + 'subtotalTax' => array( 'type' => 'String', 'description' => __( 'Cart subtotal tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_subtotal_tax() ) ? $source->get_subtotal_tax() : 0; @@ -78,16 +78,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'discountTotal' => [ + ), + 'discountTotal' => array( 'type' => 'String', 'description' => __( 'Cart discount total', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_discount_total() ) ? $source->get_discount_total() : 0; @@ -97,16 +97,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'discountTax' => [ + ), + 'discountTax' => array( 'type' => 'String', 'description' => __( 'Cart discount tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_discount_tax() ) ? $source->get_discount_tax() : 0; @@ -116,16 +116,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'availableShippingMethods' => [ - 'type' => [ 'list_of' => 'ShippingPackage' ], + ), + 'availableShippingMethods' => array( + 'type' => array( 'list_of' => 'ShippingPackage' ), 'description' => __( 'Available shipping methods for this order.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { - $packages = []; + $packages = array(); $available_packages = $source->needs_shipping() ? \WC()->shipping()->calculate_shipping( $source->get_shipping_packages() ) - : []; + : array(); foreach ( $available_packages as $index => $package ) { $package['index'] = $index; @@ -134,16 +134,16 @@ public static function get_cart_fields( $other_fields = [] ) { return $packages; }, - ], - 'chosenShippingMethods' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'chosenShippingMethods' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Shipping method chosen for this order.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { - $chosen_shipping_methods = []; + $chosen_shipping_methods = array(); $available_packages = $source->needs_shipping() ? \WC()->shipping()->calculate_shipping( $source->get_shipping_packages() ) - : []; + : array(); foreach ( $available_packages as $i => $package ) { if ( isset( \WC()->session->chosen_shipping_methods[ $i ] ) ) { @@ -153,16 +153,16 @@ public static function get_cart_fields( $other_fields = [] ) { return $chosen_shipping_methods; }, - ], - 'shippingTotal' => [ + ), + 'shippingTotal' => array( 'type' => 'String', 'description' => __( 'Cart shipping total', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_shipping_total() ) ? $source->get_shipping_total() : 0; @@ -172,16 +172,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'shippingTax' => [ + ), + 'shippingTax' => array( 'type' => 'String', 'description' => __( 'Cart shipping tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_shipping_tax() ) ? $source->get_shipping_tax() : 0; @@ -191,16 +191,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'contentsTotal' => [ + ), + 'contentsTotal' => array( 'type' => 'String', 'description' => __( 'Cart contents total', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { if ( $source->display_prices_including_tax() ) { $cart_subtotal = $source->get_subtotal() + $source->get_subtotal_tax(); @@ -218,16 +218,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'contentsTax' => [ + ), + 'contentsTax' => array( 'type' => 'String', 'description' => __( 'Cart contents tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_cart_contents_tax() ) ? $source->get_cart_contents_tax() @@ -239,16 +239,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'feeTotal' => [ + ), + 'feeTotal' => array( 'type' => 'String', 'description' => __( 'Cart fee total', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_fee_total() ) ? $source->get_fee_total() : 0; @@ -258,16 +258,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'feeTax' => [ + ), + 'feeTax' => array( 'type' => 'String', 'description' => __( 'Cart fee tax', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_fee_tax() ) ? $source->get_fee_tax() : 0; @@ -277,16 +277,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Cart total after calculation', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $source->calculate_totals(); $price = isset( $source->get_totals()['total'] ) @@ -299,16 +299,16 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'totalTax' => [ + ), + 'totalTax' => array( 'type' => 'String', 'description' => __( 'Cart total tax amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_total_tax() ) ? $source->get_total_tax() : 0; @@ -318,23 +318,23 @@ public static function get_cart_fields( $other_fields = [] ) { return wc_graphql_price( $price ); }, - ], - 'totalTaxes' => [ - 'type' => [ 'list_of' => 'CartTax' ], + ), + 'totalTaxes' => array( + 'type' => array( 'list_of' => 'CartTax' ), 'description' => __( 'Cart total taxes itemized', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $taxes = $source->get_tax_totals(); return ! empty( $taxes ) ? array_values( $taxes ) : null; }, - ], - 'isEmpty' => [ + ), + 'isEmpty' => array( 'type' => 'Boolean', 'description' => __( 'Is cart empty', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! is_null( $source->is_empty() ) ? $source->is_empty() : null; }, - ], - 'displayPricesIncludeTax' => [ + ), + 'displayPricesIncludeTax' => array( 'type' => 'Boolean', 'description' => __( 'Do display prices include taxes', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -342,8 +342,8 @@ public static function get_cart_fields( $other_fields = [] ) { ? $source->display_prices_including_tax() : null; }, - ], - 'needsShippingAddress' => [ + ), + 'needsShippingAddress' => array( 'type' => 'Boolean', 'description' => __( 'Is customer shipping address needed', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -351,25 +351,25 @@ public static function get_cart_fields( $other_fields = [] ) { ? $source->needs_shipping_address() : null; }, - ], - 'fees' => [ - 'type' => [ 'list_of' => 'CartFee' ], + ), + 'fees' => array( + 'type' => array( 'list_of' => 'CartFee' ), 'description' => __( 'Additional fees on the cart.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $fees = $source->get_fees(); return ! empty( $fees ) ? array_values( $fees ) : null; }, - ], - 'appliedCoupons' => [ - 'type' => [ 'list_of' => 'AppliedCoupon' ], + ), + 'appliedCoupons' => array( + 'type' => array( 'list_of' => 'AppliedCoupon' ), 'description' => __( 'Coupons applied to the cart', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $applied_coupons = $source->get_applied_coupons(); return ! empty( $applied_coupons ) ? $applied_coupons : null; }, - ], - ], + ), + ), $other_fields ); } @@ -380,19 +380,19 @@ public static function get_cart_fields( $other_fields = [] ) { * @param array $other_connections Extra connections configs to be added or override the default connection definitions. * @return array */ - public static function get_cart_connections( $other_connections = [] ) { + public static function get_cart_connections( $other_connections = array() ) { return array_merge( - [ - 'contents' => [ + array( + 'contents' => array( 'toType' => 'CartItem', - 'connectionArgs' => [ - 'needsShipping' => [ + 'connectionArgs' => array( + 'needsShipping' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to cart items that require shipping', 'wp-graphql-woocommerce' ), - ], - ], - 'connectionFields' => [ - 'itemCount' => [ + ), + ), + 'connectionFields' => array( + 'itemCount' => array( 'type' => 'Int', 'description' => __( 'Total number of items in the cart.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -407,8 +407,8 @@ public static function get_cart_connections( $other_connections = [] ) { return array_sum( array_column( $items, 'quantity' ) ); }, - ], - 'productCount' => [ + ), + 'productCount' => array( 'type' => 'Int', 'description' => __( 'Total number of different products in the cart', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -418,15 +418,15 @@ public static function get_cart_connections( $other_connections = [] ) { return count( array_values( $source['edges'][0]['source']->get_cart() ) ); }, - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Cart_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], - ], + ), + ), $other_connections ); } @@ -439,7 +439,7 @@ public static function get_cart_connections( $other_connections = [] ) { public static function register_cart() { register_graphql_object_type( 'Cart', - [ + array( 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), /** * Allows for a decisive filtering of the cart fields. @@ -457,7 +457,7 @@ public static function register_cart() { * @return array */ 'connections' => apply_filters( 'woographql_cart_connection_definitions', self::get_cart_connections() ), - ] + ) ); } @@ -469,53 +469,53 @@ public static function register_cart() { public static function register_cart_fee() { register_graphql_object_type( 'CartFee', - [ + array( 'description' => __( 'An additional fee', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Fee ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, - ], - 'name' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'name' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Fee name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->name ) ? $source->name : null; }, - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Fee tax class', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->tax_class ) ? $source->tax_class : null; }, - ], - 'taxable' => [ + ), + 'taxable' => array( 'type' => 'Boolean', 'description' => __( 'Is fee taxable?', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! is_null( $source->taxable ) ? $source->taxable : null; }, - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'Float', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! is_null( $source->amount ) ? $source->amount : 0; }, - ], - 'total' => [ + ), + 'total' => array( 'type' => 'Float', 'description' => __( 'Fee total', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! is_null( $source->total ) ? $source->total : 0; }, - ], - ], - ] + ), + ), + ) ); } @@ -527,39 +527,39 @@ public static function register_cart_fee() { public static function register_cart_tax() { register_graphql_object_type( 'CartTax', - [ + array( 'description' => __( 'An itemized cart tax item', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Tax Rate ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->tax_rate_id ) ? $source->tax_rate_id : null; }, - ], - 'label' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'label' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Tax label', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->label ) ? $source->label : null; }, - ], - 'isCompound' => [ + ), + 'isCompound' => array( 'type' => 'Boolean', 'description' => __( 'Is tax compound?', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->is_compound ) ? $source->is_compound : null; }, - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'String', 'description' => __( 'Tax amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $amount = ! empty( $source->amount ) ? $source->amount : null; @@ -573,9 +573,9 @@ public static function register_cart_tax() { return wc_graphql_price( $amount ); }, - ], - ], - ] + ), + ), + ) ); } @@ -587,28 +587,28 @@ public static function register_cart_tax() { public static function register_applied_coupon() { register_graphql_object_type( 'AppliedCoupon', - [ + array( 'description' => __( 'Coupon applied to the shopping cart.', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'code' => [ - 'type' => [ 'non_null' => 'String' ], + 'fields' => array( + 'code' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Coupon code', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return $source; }, - ], - 'discountAmount' => [ - 'type' => [ 'non_null' => 'String' ], - 'args' => [ - 'excludeTax' => [ + ), + 'discountAmount' => array( + 'type' => array( 'non_null' => 'String' ), + 'args' => array( + 'excludeTax' => array( 'type' => 'Boolean', 'description' => __( 'Exclude Taxes (Default "true")', 'wp-graphql-woocommerce' ), - ], - 'format' => [ + ), + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Discount applied with this coupon', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args ) { $ex_tax = ! empty( $args['excludeTax'] ) ? $args['excludeTax'] : true; @@ -620,16 +620,16 @@ public static function register_applied_coupon() { return wc_graphql_price( $amount ); }, - ], - 'discountTax' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'discountTax' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Taxes on discount applied with this coupon', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { $tax = Factory::resolve_cart()->get_coupon_discount_tax_amount( $source ); @@ -639,17 +639,17 @@ public static function register_applied_coupon() { return wc_graphql_price( $tax ); }, - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Description of applied coupon', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $coupon = new \WC_Coupon( $source ); return $coupon->get_description(); }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-collection-stats-type.php b/includes/type/object/class-collection-stats-type.php index 5dec08f03..cf41ee5ec 100644 --- a/includes/type/object/class-collection-stats-type.php +++ b/includes/type/object/class-collection-stats-type.php @@ -20,18 +20,18 @@ class Collection_Stats_Type { public static function register() { register_graphql_object_type( 'PriceRange', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'Price range', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'minPrice' => [ + 'fields' => array( + 'minPrice' => array( 'type' => 'String', - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Minimum price', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args ) { if ( empty( $source['min_price'] ) ) { @@ -44,15 +44,15 @@ public static function register() { return wc_graphql_price( $source['min_price'] ); }, - ], - 'maxPrice' => [ + ), + 'maxPrice' => array( 'type' => 'String', - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Maximum price', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args ) { if ( empty( $source['max_price'] ) ) { @@ -65,26 +65,26 @@ public static function register() { return wc_graphql_price( $source['max_price'] ); }, - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'AttributeCount', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'Product attribute terms count', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'slug' => [ - 'type' => [ 'non_null' => 'ProductAttributeEnum' ], + 'fields' => array( + 'slug' => array( + 'type' => array( 'non_null' => 'ProductAttributeEnum' ), 'description' => __( 'Attribute name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return $source->name; }, - ], - 'label' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'label' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Attribute taxonomy', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $taxonomy = get_taxonomy( $source->name ); @@ -94,9 +94,9 @@ public static function register() { } return $taxonomy->label; }, - ], - 'name' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'name' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Attribute name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $taxonomy = get_taxonomy( $source->name ); @@ -106,30 +106,30 @@ public static function register() { } return $taxonomy->labels->singular_name; }, - ], - 'terms' => [ - 'type' => [ 'list_of' => 'SingleAttributeCount' ], + ), + 'terms' => array( + 'type' => array( 'list_of' => 'SingleAttributeCount' ), 'description' => __( 'Attribute terms', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'SingleAttributeCount', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'Single attribute term count', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'termId' => [ - 'type' => [ 'non_null' => 'ID' ], + 'fields' => array( + 'termId' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Term ID', 'wp-graphql-woocommerce' ), - ], - 'count' => [ + ), + 'count' => array( 'type' => 'Int', 'description' => __( 'Number of products.', 'wp-graphql-woocommerce' ), - ], - 'node' => [ + ), + 'node' => array( 'type' => 'TermNode', 'description' => __( 'Term object.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -148,53 +148,53 @@ public static function register() { } return new \WPGraphQL\Model\Term( $term ); }, - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'RatingCount', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'Single rating count', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'rating' => [ - 'type' => [ 'non_null' => 'Int' ], + 'fields' => array( + 'rating' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Average rating', 'wp-graphql-woocommerce' ), - ], - 'count' => [ + ), + 'count' => array( 'type' => 'Int', 'description' => __( 'Number of products', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'StockStatusCount', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'Single stock status count', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'status' => [ - 'type' => [ 'non_null' => 'StockStatusEnum' ], + 'fields' => array( + 'status' => array( + 'type' => array( 'non_null' => 'StockStatusEnum' ), 'description' => __( 'Status', 'wp-graphql-woocommerce' ), - ], - 'count' => [ + ), + 'count' => array( 'type' => 'Int', 'description' => __( 'Number of products.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); register_graphql_object_type( 'CollectionStats', - [ + array( 'description' => __( 'Data about a collection of products', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'priceRange' => [ + 'fields' => array( + 'priceRange' => array( 'type' => 'PriceRange', 'description' => __( 'Min and max prices found in collection of products, provided using the smallest unit of the currency', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -202,24 +202,24 @@ public static function register() { $max_price = ! empty( $source['max_price'] ) ? $source['max_price'] : null; return compact( 'min_price', 'max_price' ); }, - ], - 'attributeCounts' => [ - 'type' => [ 'list_of' => 'AttributeCount' ], - 'args' => [ - 'page' => [ + ), + 'attributeCounts' => array( + 'type' => array( 'list_of' => 'AttributeCount' ), + 'args' => array( + 'page' => array( 'type' => 'Int', 'description' => __( 'Page of results to return', 'wp-graphql-woocommerce' ), - ], - 'perPage' => [ + ), + 'perPage' => array( 'type' => 'Int', 'description' => __( 'Number of results to return per page', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Returns number of products within attribute terms', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, $args ) { $page = ! empty( $args['page'] ) ? $args['page'] : 1; $per_page = ! empty( $args['perPage'] ) ? $args['perPage'] : 0; - $attribute_counts = ! empty( $source['attribute_counts'] ) ? $source['attribute_counts'] : []; + $attribute_counts = ! empty( $source['attribute_counts'] ) ? $source['attribute_counts'] : array(); $attribute_counts = array_slice( $attribute_counts, ( $page - 1 ) * $per_page, @@ -234,24 +234,24 @@ static function ( $name, $terms ) { array_values( $attribute_counts ) ); }, - ], - 'ratingCounts' => [ - 'type' => [ 'list_of' => 'RatingCount' ], - 'args' => [ - 'page' => [ + ), + 'ratingCounts' => array( + 'type' => array( 'list_of' => 'RatingCount' ), + 'args' => array( + 'page' => array( 'type' => 'Int', 'description' => __( 'Page of results to return', 'wp-graphql-woocommerce' ), - ], - 'perPage' => [ + ), + 'perPage' => array( 'type' => 'Int', 'description' => __( 'Number of results to return per page', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Returns number of products with each average rating', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, $args ) { $page = ! empty( $args['page'] ) ? $args['page'] : 1; $per_page = ! empty( $args['perPage'] ) ? $args['perPage'] : 0; - $rating_counts = ! empty( $source['rating_counts'] ) ? $source['rating_counts'] : []; + $rating_counts = ! empty( $source['rating_counts'] ) ? $source['rating_counts'] : array(); $rating_counts = array_slice( $rating_counts, ( $page - 1 ) * $per_page, @@ -260,24 +260,24 @@ static function ( $name, $terms ) { return $rating_counts; }, - ], - 'stockStatusCounts' => [ - 'type' => [ 'list_of' => 'StockStatusCount' ], - 'args' => [ - 'page' => [ + ), + 'stockStatusCounts' => array( + 'type' => array( 'list_of' => 'StockStatusCount' ), + 'args' => array( + 'page' => array( 'type' => 'Int', 'description' => __( 'Page of results to return', 'wp-graphql-woocommerce' ), - ], - 'perPage' => [ + ), + 'perPage' => array( 'type' => 'Int', 'description' => __( 'Number of results to return per page', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Returns number of products with each stock status', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, $args ) { $page = ! empty( $args['page'] ) ? $args['page'] : 1; $per_page = ! empty( $args['perPage'] ) ? $args['perPage'] : 0; - $stock_status_counts = ! empty( $source['stock_status_counts'] ) ? $source['stock_status_counts'] : []; + $stock_status_counts = ! empty( $source['stock_status_counts'] ) ? $source['stock_status_counts'] : array(); $stock_status_counts = array_slice( $stock_status_counts, ( $page - 1 ) * $per_page, @@ -286,9 +286,9 @@ static function ( $name, $terms ) { return $stock_status_counts; }, - ], - ], - ] + ), + ), + ) ); } @@ -300,7 +300,7 @@ static function ( $name, $terms ) { * * @return \WP_REST_Request */ - public static function prepare_rest_request( array $where_args = [] ) { + public static function prepare_rest_request( array $where_args = array() ) { $request = new \WP_REST_Request(); if ( empty( $where_args ) ) { return $request; @@ -309,7 +309,7 @@ public static function prepare_rest_request( array $where_args = [] ) { $request->set_param( 'paged', 0 ); $request->set_param( 'ignore_sticky_posts', true ); - $key_mapping = [ + $key_mapping = array( 'slugIn' => 'slug', 'typeIn' => 'type', 'categoryIdIn' => 'category', @@ -319,9 +319,9 @@ public static function prepare_rest_request( array $where_args = [] ) { 'visibility' => 'catalog_visibility', 'minPrice' => 'min_price', 'maxPrice' => 'max_price', - ]; + ); - $needs_formatting = [ 'attributes', 'categoryIn', 'tagIn' ]; + $needs_formatting = array( 'attributes', 'categoryIn', 'tagIn' ); foreach ( $where_args as $key => $value ) { if ( in_array( $key, $needs_formatting, true ) ) { continue; @@ -372,12 +372,12 @@ static function ( $tag ) { if ( ! empty( $where_args['attributes'] ) && ! empty( $where_args['attributes']['queries'] ) ) { $attributes = $where_args['attributes']['queries']; - $att_queries = []; - $operator_mapping = [ + $att_queries = array(); + $operator_mapping = array( 'IN' => 'in', 'NOT IN' => 'not_in', 'AND' => 'and', - ]; + ); foreach ( $attributes as $filter ) { if ( empty( $filter['terms'] ) && empty( $filter['ids'] ) ) { @@ -387,21 +387,21 @@ static function ( $tag ) { $operator = ! empty( $filter['operator'] ) ? $operator_mapping[ $filter['operator'] ] : 'in'; if ( ! empty( $filter['terms'] ) ) { foreach ( $filter['terms'] as $term ) { - $att_queries[] = [ + $att_queries[] = array( 'attribute' => $filter['taxonomy'], 'operator' => $operator, 'slug' => $term, - ]; + ); } } if ( ! empty( $filter['ids'] ) ) { foreach ( $filter['ids'] as $term_id ) { - $att_queries[] = [ + $att_queries[] = array( 'attribute' => $filter['taxonomy'], 'operator' => $operator, 'term_id' => $term_id, - ]; + ); } } } diff --git a/includes/type/object/class-country-state-type.php b/includes/type/object/class-country-state-type.php index a2c536f2f..1fd10951e 100644 --- a/includes/type/object/class-country-state-type.php +++ b/includes/type/object/class-country-state-type.php @@ -22,25 +22,25 @@ class Country_State_Type { public static function register() { register_graphql_object_type( 'CountryState', - [ + array( 'description' => __( 'shipping country state object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'code' => [ - 'type' => [ 'non_null' => 'String' ], + 'fields' => array( + 'code' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Country state code', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['code'] ) ? $source['code'] : null; }, - ], - 'name' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'name' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Country state name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['name'] ) ? $source['name'] : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-coupon-type.php b/includes/type/object/class-coupon-type.php index d6e9b3040..4f2268ed7 100644 --- a/includes/type/object/class-coupon-type.php +++ b/includes/type/object/class-coupon-type.php @@ -22,89 +22,89 @@ class Coupon_Type { public static function register() { register_graphql_object_type( 'Coupon', - [ + array( 'description' => __( 'A coupon object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the coupon', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the coupon in the database', 'wp-graphql-woocommerce' ), - ], - 'code' => [ + ), + 'code' => array( 'type' => 'String', 'description' => __( 'Coupon code', 'wp-graphql-woocommerce' ), - ], - 'date' => [ + ), + 'date' => array( 'type' => 'String', 'description' => __( 'Date coupon created', 'wp-graphql-woocommerce' ), - ], - 'modified' => [ + ), + 'modified' => array( 'type' => 'String', 'description' => __( 'Date coupon modified', 'wp-graphql-woocommerce' ), - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Explanation of what the coupon does', 'wp-graphql-woocommerce' ), - ], - 'discountType' => [ + ), + 'discountType' => array( 'type' => 'DiscountTypeEnum', 'description' => __( 'Type of discount', 'wp-graphql-woocommerce' ), - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'Float', 'description' => __( 'Amount off provided by the coupon', 'wp-graphql-woocommerce' ), - ], - 'dateExpiry' => [ + ), + 'dateExpiry' => array( 'type' => 'String', 'description' => __( 'Date coupon expires', 'wp-graphql-woocommerce' ), - ], - 'usageCount' => [ + ), + 'usageCount' => array( 'type' => 'Int', 'description' => __( 'How many times the coupon has been used', 'wp-graphql-woocommerce' ), - ], - 'individualUse' => [ + ), + 'individualUse' => array( 'type' => 'Boolean', 'description' => __( 'Individual use means this coupon cannot be used in conjunction with other coupons', 'wp-graphql-woocommerce' ), - ], - 'usageLimit' => [ + ), + 'usageLimit' => array( 'type' => 'Int', 'description' => __( 'Amount of times this coupon can be used globally', 'wp-graphql-woocommerce' ), - ], - 'usageLimitPerUser' => [ + ), + 'usageLimitPerUser' => array( 'type' => 'Int', 'description' => __( 'Amount of times this coupon can be used by a customer', 'wp-graphql-woocommerce' ), - ], - 'limitUsageToXItems' => [ + ), + 'limitUsageToXItems' => array( 'type' => 'Int', 'description' => __( 'The number of products in your cart this coupon can apply to (for product discounts)', 'wp-graphql-woocommerce' ), - ], - 'freeShipping' => [ + ), + 'freeShipping' => array( 'type' => 'Boolean', 'description' => __( 'Does this coupon grant free shipping?', 'wp-graphql-woocommerce' ), - ], - 'excludeSaleItems' => [ + ), + 'excludeSaleItems' => array( 'type' => 'Boolean', 'description' => __( 'Excluding sale items mean this coupon cannot be used on items that are on sale (or carts that contain on sale items)', 'wp-graphql-woocommerce' ), - ], - 'minimumAmount' => [ + ), + 'minimumAmount' => array( 'type' => 'Float', 'description' => __( 'Minimum spend amount that must be met before this coupon can be used', 'wp-graphql-woocommerce' ), - ], - 'maximumAmount' => [ + ), + 'maximumAmount' => array( 'type' => 'Float', 'description' => __( 'Maximum spend amount that must be met before this coupon can be used ', 'wp-graphql-woocommerce' ), - ], - 'emailRestrictions' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'emailRestrictions' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Only customers with a matching email address can use the coupon', 'wp-graphql-woocommerce' ), - ], + ), 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ], - ] + ), + ) ); } } diff --git a/includes/type/object/class-customer-address-type.php b/includes/type/object/class-customer-address-type.php index c8b2e1be6..d81cddf39 100644 --- a/includes/type/object/class-customer-address-type.php +++ b/includes/type/object/class-customer-address-type.php @@ -22,88 +22,88 @@ class Customer_Address_Type { public static function register() { register_graphql_object_type( 'CustomerAddress', - [ + array( 'description' => __( 'A customer address object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'firstName' => [ + 'fields' => array( + 'firstName' => array( 'type' => 'String', 'description' => __( 'First name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['first_name'] ) ? $address['first_name'] : null; }, - ], - 'lastName' => [ + ), + 'lastName' => array( 'type' => 'String', 'description' => __( 'Last name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['last_name'] ) ? $address['last_name'] : null; }, - ], - 'company' => [ + ), + 'company' => array( 'type' => 'String', 'description' => __( 'Company', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['company'] ) ? $address['company'] : null; }, - ], - 'address1' => [ + ), + 'address1' => array( 'type' => 'String', 'description' => __( 'Address 1', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['address_1'] ) ? $address['address_1'] : null; }, - ], - 'address2' => [ + ), + 'address2' => array( 'type' => 'String', 'description' => __( 'Address 2', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['address_2'] ) ? $address['address_2'] : null; }, - ], - 'city' => [ + ), + 'city' => array( 'type' => 'String', 'description' => __( 'City', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['city'] ) ? $address['city'] : null; }, - ], - 'state' => [ + ), + 'state' => array( 'type' => 'String', 'description' => __( 'State', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['state'] ) ? $address['state'] : null; }, - ], - 'postcode' => [ + ), + 'postcode' => array( 'type' => 'String', 'description' => __( 'Zip Postal Code', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['postcode'] ) ? $address['postcode'] : null; }, - ], - 'country' => [ + ), + 'country' => array( 'type' => 'CountriesEnum', 'description' => __( 'Country', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['country'] ) ? $address['country'] : null; }, - ], - 'email' => [ + ), + 'email' => array( 'type' => 'String', 'description' => __( 'E-mail', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['email'] ) ? $address['email'] : null; }, - ], - 'phone' => [ + ), + 'phone' => array( 'type' => 'String', 'description' => __( 'Phone', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $address ) { return ! empty( $address['phone'] ) ? $address['phone'] : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-customer-type.php b/includes/type/object/class-customer-type.php index ca7436dae..0fdc11895 100644 --- a/includes/type/object/class-customer-type.php +++ b/includes/type/object/class-customer-type.php @@ -27,95 +27,95 @@ class Customer_Type { * * @return array */ - public static function get_fields( $other_fields = [] ) { + public static function get_fields( $other_fields = array() ) { return array_merge( - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the customer', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $database_id = absint( $source->ID ); return ! empty( $database_id ) ? $database_id : null; }, - ], - 'isVatExempt' => [ + ), + 'isVatExempt' => array( 'type' => 'Boolean', 'description' => __( 'Is customer VAT exempt?', 'wp-graphql-woocommerce' ), - ], - 'hasCalculatedShipping' => [ + ), + 'hasCalculatedShipping' => array( 'type' => 'Boolean', 'description' => __( 'Has calculated shipping?', 'wp-graphql-woocommerce' ), - ], - 'calculatedShipping' => [ + ), + 'calculatedShipping' => array( 'type' => 'Boolean', 'description' => __( 'Has customer calculated shipping?', 'wp-graphql-woocommerce' ), - ], - 'lastOrder' => [ + ), + 'lastOrder' => array( 'type' => 'Order', 'description' => __( 'Gets the customers last order.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->last_order_id, $context ); }, - ], - 'orderCount' => [ + ), + 'orderCount' => array( 'type' => 'Int', 'description' => __( 'Return the number of orders this customer has.', 'wp-graphql-woocommerce' ), - ], - 'totalSpent' => [ + ), + 'totalSpent' => array( 'type' => 'Float', 'description' => __( 'Return how much money this customer has spent.', 'wp-graphql-woocommerce' ), - ], - 'username' => [ + ), + 'username' => array( 'type' => 'String', 'description' => __( 'Return the customer\'s username.', 'wp-graphql-woocommerce' ), - ], - 'email' => [ + ), + 'email' => array( 'type' => 'String', 'description' => __( 'Return the customer\'s email.', 'wp-graphql-woocommerce' ), - ], - 'firstName' => [ + ), + 'firstName' => array( 'type' => 'String', 'description' => __( 'Return the customer\'s first name.', 'wp-graphql-woocommerce' ), - ], - 'lastName' => [ + ), + 'lastName' => array( 'type' => 'String', 'description' => __( 'Return the customer\'s last name.', 'wp-graphql-woocommerce' ), - ], - 'displayName' => [ + ), + 'displayName' => array( 'type' => 'String', 'description' => __( 'Return the customer\'s display name.', 'wp-graphql-woocommerce' ), - ], - 'role' => [ + ), + 'role' => array( 'type' => 'String', 'description' => __( 'Return the customer\'s user role.', 'wp-graphql-woocommerce' ), - ], - 'date' => [ + ), + 'date' => array( 'type' => 'String', 'description' => __( 'Return the date customer was created', 'wp-graphql-woocommerce' ), - ], - 'modified' => [ + ), + 'modified' => array( 'type' => 'String', 'description' => __( 'Return the date customer was last updated', 'wp-graphql-woocommerce' ), - ], - 'billing' => [ + ), + 'billing' => array( 'type' => 'CustomerAddress', 'description' => __( 'Return the date customer billing address properties', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'CustomerAddress', 'description' => __( 'Return the date customer shipping address properties', 'wp-graphql-woocommerce' ), - ], - 'isPayingCustomer' => [ + ), + 'isPayingCustomer' => array( 'type' => 'Boolean', 'description' => __( 'Return the date customer was last updated', 'wp-graphql-woocommerce' ), - ], + ), 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - 'session' => [ - 'type' => [ 'list_of' => 'MetaData' ], + 'session' => array( + 'type' => array( 'list_of' => 'MetaData' ), 'description' => __( 'Session data for the viewing customer', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { /** @@ -127,7 +127,7 @@ public static function get_fields( $other_fields = [] ) { if ( (string) $session->get_customer_id() === (string) $source->ID ) { $session_data = $session->get_session_data(); - $session = []; + $session = array(); foreach ( $session_data as $key => $value ) { $meta = new \stdClass(); $meta->id = null; @@ -141,8 +141,8 @@ public static function get_fields( $other_fields = [] ) { throw new UserError( __( 'It\'s not possible to access another user\'s session data', 'wp-graphql-woocommerce' ) ); }, - ], - ], + ), + ), $other_fields ); } @@ -154,32 +154,32 @@ public static function get_fields( $other_fields = [] ) { * * @return array */ - public static function get_connections( $other_connections = [] ) { + public static function get_connections( $other_connections = array() ) { return array_merge( - [ - 'downloadableItems' => [ + array( + 'downloadableItems' => array( 'toType' => 'DownloadableItem', - 'connectionArgs' => [ - 'active' => [ + 'connectionArgs' => array( + 'active' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that can be downloaded now.', 'wp-graphql-woocommerce' ), - ], - 'expired' => [ + ), + 'expired' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that are expired.', 'wp-graphql-woocommerce' ), - ], - 'hasDownloadsRemaining' => [ + ), + 'hasDownloadsRemaining' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Downloadable_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], - ], + ), + ), $other_connections ); } @@ -192,9 +192,9 @@ public static function get_connections( $other_connections = [] ) { public static function register() { register_graphql_object_type( 'Customer', - [ + array( 'description' => __( 'A customer object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], + 'interfaces' => array( 'Node' ), /** * Allows for a decisive filtering of the order fields. * Note: Only use if deregisteration or renaming the field(s) has failed. @@ -211,7 +211,7 @@ public static function register() { * @return array */ 'connections' => apply_filters( 'woographql_customer_connection_definitions', self::get_connections() ), - ] + ) ); /** @@ -219,9 +219,9 @@ public static function register() { */ register_graphql_fields( 'Customer', - [ - 'availablePaymentMethods' => [ - 'type' => [ 'list_of' => 'PaymentToken' ], + array( + 'availablePaymentMethods' => array( + 'type' => array( 'list_of' => 'PaymentToken' ), 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { if ( get_current_user_id() === $source->ID ) { @@ -229,14 +229,14 @@ public static function register() { } if ( get_current_user_id() === 0 ) { - return []; + return array(); } throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) ); }, - ], - 'availablePaymentMethodsCC' => [ - 'type' => [ 'list_of' => 'PaymentTokenCC' ], + ), + 'availablePaymentMethodsCC' => array( + 'type' => array( 'list_of' => 'PaymentTokenCC' ), 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { if ( get_current_user_id() === $source->ID ) { @@ -249,14 +249,14 @@ static function ( $token ) { } if ( get_current_user_id() === 0 ) { - return []; + return array(); } throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) ); }, - ], - 'availablePaymentMethodsEC' => [ - 'type' => [ 'list_of' => 'PaymentTokenECheck' ], + ), + 'availablePaymentMethodsEC' => array( + 'type' => array( 'list_of' => 'PaymentTokenECheck' ), 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { if ( get_current_user_id() === $source->ID ) { @@ -269,13 +269,13 @@ static function ( $token ) { } if ( get_current_user_id() === 0 ) { - return []; + return array(); } throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) ); }, - ], - ] + ), + ) ); } @@ -291,7 +291,7 @@ public static function register_session_handler_fields() { register_graphql_field( 'Customer', 'sessionToken', - [ + array( 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -308,7 +308,7 @@ public static function register_session_handler_fields() { return null; }, - ] + ) ); /** * Register the "wooSessionToken" field to the "User" type. @@ -316,7 +316,7 @@ public static function register_session_handler_fields() { register_graphql_field( 'User', 'wooSessionToken', - [ + array( 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -333,7 +333,7 @@ public static function register_session_handler_fields() { return null; }, - ] + ) ); } @@ -347,8 +347,8 @@ public static function register_authorizing_url_fields( $fields_to_register ) { if ( in_array( 'cart_url', $fields_to_register, true ) ) { register_graphql_fields( 'Customer', - [ - 'cartUrl' => [ + array( + 'cartUrl' => array( 'type' => 'String', 'description' => __( 'A nonced link to the cart page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -363,10 +363,10 @@ public static function register_authorizing_url_fields( $fields_to_register ) { // Build nonced url as an unauthenticated user. $nonce_name = woographql_setting( 'cart_url_nonce_param', '_wc_cart' ); - $query_params = [ + $query_params = array( 'session_id' => $customer_id, $nonce_name => woographql_create_nonce( "load-cart_{$customer_id}" ), - ]; + ); $query_params = apply_filters( 'graphql_cart_url_query_params', $query_params, $customer_id, $source ); $url = add_query_arg( $query_params, @@ -375,8 +375,8 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return esc_url_raw( $url ); }, - ], - 'cartNonce' => [ + ), + 'cartNonce' => array( 'type' => 'String', 'description' => __( 'A nonce for the cart page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -391,16 +391,16 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return woographql_create_nonce( "load-cart_{$customer_id}" ); }, - ], - ] + ), + ) ); }//end if if ( in_array( 'checkout_url', $fields_to_register, true ) ) { register_graphql_fields( 'Customer', - [ - 'checkoutUrl' => [ + array( + 'checkoutUrl' => array( 'type' => 'String', 'description' => __( 'A nonce link to the checkout page for session user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -415,10 +415,10 @@ public static function register_authorizing_url_fields( $fields_to_register ) { // Build nonced url as an unauthenticated user. $nonce_name = woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ); - $query_params = [ + $query_params = array( 'session_id' => $customer_id, $nonce_name => woographql_create_nonce( "load-checkout_{$customer_id}" ), - ]; + ); $query_params = apply_filters( 'graphql_checkout_url_query_params', $query_params, $customer_id, $source ); $url = add_query_arg( $query_params, @@ -427,8 +427,8 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return esc_url_raw( $url ); }, - ], - 'checkoutNonce' => [ + ), + 'checkoutNonce' => array( 'type' => 'String', 'description' => __( 'A nonce for the checkout page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -443,16 +443,16 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return woographql_create_nonce( "load-checkout_{$customer_id}" ); }, - ], - ] + ), + ) ); }//end if if ( in_array( 'account_url', $fields_to_register, true ) ) { register_graphql_fields( 'Customer', - [ - 'accountUrl' => [ + array( + 'accountUrl' => array( 'type' => 'String', 'description' => __( 'A nonce link to the account page for session user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -471,10 +471,10 @@ public static function register_authorizing_url_fields( $fields_to_register ) { // Build nonced url as an unauthenticated user. $nonce_name = woographql_setting( 'account_url_nonce_param', '_wc_account' ); - $query_params = [ + $query_params = array( 'session_id' => $customer_id, $nonce_name => woographql_create_nonce( "load-account_{$customer_id}" ), - ]; + ); $query_params = apply_filters( 'graphql_account_url_query_params', $query_params, $customer_id, $source ); $url = add_query_arg( $query_params, @@ -483,8 +483,8 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return esc_url_raw( $url ); }, - ], - 'accountNonce' => [ + ), + 'accountNonce' => array( 'type' => 'String', 'description' => __( 'A nonce for the account page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -503,16 +503,16 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return woographql_create_nonce( "load-account_{$customer_id}" ); }, - ], - ] + ), + ) ); }//end if if ( in_array( 'add_payment_method_url', $fields_to_register, true ) ) { register_graphql_fields( 'Customer', - [ - 'addPaymentMethodUrl' => [ + array( + 'addPaymentMethodUrl' => array( 'type' => 'String', 'description' => __( 'A nonce link to the add payment method page for the authenticated user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -532,17 +532,17 @@ public static function register_authorizing_url_fields( $fields_to_register ) { // Build nonced url as an unauthenticated user. $nonce_name = woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ); $url = add_query_arg( - [ + array( 'session_id' => $customer_id, $nonce_name => woographql_create_nonce( "add-payment-method_{$customer_id}" ), - ], + ), site_url( woographql_setting( 'authorizing_url_endpoint', 'transfer-session' ) ) ); return esc_url_raw( $url ); }, - ], - 'addPaymentMethodNonce' => [ + ), + 'addPaymentMethodNonce' => array( 'type' => 'String', 'description' => __( 'A nonce for the add payment method page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -561,8 +561,8 @@ public static function register_authorizing_url_fields( $fields_to_register ) { return woographql_create_nonce( "add-payment-method_{$customer_id}" ); }, - ], - ] + ), + ) ); }//end if } diff --git a/includes/type/object/class-downloadable-item-type.php b/includes/type/object/class-downloadable-item-type.php index 3b9583b73..ae0675e6f 100644 --- a/includes/type/object/class-downloadable-item-type.php +++ b/includes/type/object/class-downloadable-item-type.php @@ -27,39 +27,39 @@ class Downloadable_Item_Type { public static function register() { register_graphql_object_type( 'DownloadableItem', - [ + array( 'description' => __( 'A downloadable item', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Downloadable item unique identifier', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['download_id'] ) ? Relay::toGlobalId( 'download', $source['download_id'] ) : null; }, - ], - 'downloadId' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'downloadId' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Downloadable item ID.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['download_id'] ) ? $source['download_id'] : null; }, - ], - 'url' => [ + ), + 'url' => array( 'type' => 'String', 'description' => __( 'Download URL of the downloadable item.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['download_url'] ) ? $source['download_url'] : null; }, - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Name of the downloadable item.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['download_name'] ) ? $source['download_name'] : null; }, - ], - 'downloadsRemaining' => [ + ), + 'downloadsRemaining' => array( 'type' => 'Int', 'description' => __( 'Number of times the item can be downloaded.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -67,22 +67,22 @@ public static function register() { ? $source['downloads_remaining'] : null; }, - ], - 'accessExpires' => [ + ), + 'accessExpires' => array( 'type' => 'String', 'description' => __( 'The date the downloadable item expires', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['access_expires'] ) ? $source['access_expires'] : null; }, - ], - 'product' => [ + ), + 'product' => array( 'type' => 'ProductUnion', 'description' => __( 'Product of downloadable item.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source['product_id'], $context ); }, - ], - 'download' => [ + ), + 'download' => array( 'type' => 'ProductDownload', 'description' => __( 'ProductDownload of the downloadable item', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -117,9 +117,9 @@ public static function register() { return $download; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-meta-data-type.php b/includes/type/object/class-meta-data-type.php index ad6a85206..08dee3430 100644 --- a/includes/type/object/class-meta-data-type.php +++ b/includes/type/object/class-meta-data-type.php @@ -22,24 +22,24 @@ class Meta_Data_Type { public static function register() { register_graphql_object_type( 'MetaData', - [ + array( 'description' => __( 'Extra data defined on the WC object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ + 'fields' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Meta ID.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, - ], - 'key' => [ - 'type' => [ 'non_null' => 'String' ], + ), + 'key' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Meta key.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->key ) ? (string) $source->key : null; }, - ], - 'value' => [ + ), + 'value' => array( 'type' => 'String', 'description' => __( 'Meta value.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -53,9 +53,9 @@ public static function register() { return (string) $source->value; }, - ], - ], - ] + ), + ), + ) ); } @@ -65,23 +65,23 @@ public static function register() { * @return array */ public static function get_metadata_field_definition() { - return [ - 'type' => [ 'list_of' => 'MetaData' ], + return array( + 'type' => array( 'list_of' => 'MetaData' ), 'description' => __( 'Object meta data', 'wp-graphql-woocommerce' ), - 'args' => [ - 'key' => [ + 'args' => array( + 'key' => array( 'type' => 'String', 'description' => __( 'Retrieve meta by key', 'wp-graphql-woocommerce' ), - ], - 'keysIn' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'keysIn' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ), - ], - 'multiple' => [ + ), + 'multiple' => array( 'type' => 'Boolean', 'description' => __( 'Retrieve meta with matching keys', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { // Set unique flag. $single = empty( $args['multiple'] ); @@ -91,7 +91,7 @@ public static function get_metadata_field_definition() { $key = $args['key']; $data = $source->get_meta( $key, false ); if ( empty( $data ) ) { - $data = []; + $data = array(); } elseif ( $single ) { $data = array_slice( $data, 0, 1 ); } @@ -106,7 +106,7 @@ static function ( $value ) { // Check "keysIn" argument and format meta_data objects. $keys_in = $args['keysIn']; - $found = []; + $found = array(); $data = array_filter( $source->get_meta_data(), static function ( $meta ) use ( $keys_in, $single, &$found ) { @@ -121,7 +121,7 @@ static function ( $meta ) use ( $keys_in, $single, &$found ) { ); } else { // If no arguments set return all meta (in accordance with unique flag). - $found = []; + $found = array(); $data = array_filter( $source->get_meta_data(), static function ( $meta ) use ( $single, &$found ) { @@ -137,6 +137,6 @@ static function ( $meta ) use ( $single, &$found ) { return ! empty( $data ) ? $data : null; }, - ]; + ); } } diff --git a/includes/type/object/class-order-item-type.php b/includes/type/object/class-order-item-type.php index db55989b6..0de58a8b6 100644 --- a/includes/type/object/class-order-item-type.php +++ b/includes/type/object/class-order-item-type.php @@ -24,189 +24,189 @@ class Order_Item_Type { * @return void */ public static function register() { - $types = [ - 'CouponLine' => [ + $types = array( + 'CouponLine' => array( // Description. __( 'a coupon line object', 'wp-graphql-woocommerce' ), // Fields. - [ - 'code' => [ + array( + 'code' => array( 'type' => 'String', 'description' => __( 'Line\'s Coupon code', 'wp-graphql-woocommerce' ), - ], - 'discount' => [ + ), + 'discount' => array( 'type' => 'String', 'description' => __( 'Line\'s Discount total', 'wp-graphql-woocommerce' ), - ], - 'discountTax' => [ + ), + 'discountTax' => array( 'type' => 'String', 'description' => __( 'Line\'s Discount total tax', 'wp-graphql-woocommerce' ), - ], - 'coupon' => [ + ), + 'coupon' => array( 'type' => 'Coupon', 'description' => __( 'Line\'s Coupon', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->coupon_id, $context ); }, - ], - ], - ], - 'FeeLine' => [ + ), + ), + ), + 'FeeLine' => array( // Description. __( 'a fee line object', 'wp-graphql-woocommerce' ), // Fields. - [ - 'amount' => [ + array( + 'amount' => array( 'type' => 'String', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Fee name', 'wp-graphql-woocommerce' ), - ], - 'taxStatus' => [ + ), + 'taxStatus' => array( 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status of fee', 'wp-graphql-woocommerce' ), - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Line total (after discounts)', 'wp-graphql-woocommerce' ), - ], - 'totalTax' => [ + ), + 'totalTax' => array( 'type' => 'String', 'description' => __( 'Line total tax (after discounts)', 'wp-graphql-woocommerce' ), - ], - 'taxes' => [ - 'type' => [ 'list_of' => 'OrderItemTax' ], + ), + 'taxes' => array( + 'type' => array( 'list_of' => 'OrderItemTax' ), 'description' => __( 'Line taxes', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Line tax class', 'wp-graphql-woocommerce' ), - ], - ], - ], - 'ShippingLine' => [ + ), + ), + ), + 'ShippingLine' => array( // Description. __( 'a shipping line object', 'wp-graphql-woocommerce' ), // Fields. - [ - 'methodTitle' => [ + array( + 'methodTitle' => array( 'type' => 'String', 'description' => __( 'Shipping Line\'s shipping method name', 'wp-graphql-woocommerce' ), - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Line total (after discounts)', 'wp-graphql-woocommerce' ), - ], - 'totalTax' => [ + ), + 'totalTax' => array( 'type' => 'String', 'description' => __( 'Line total tax (after discounts)', 'wp-graphql-woocommerce' ), - ], - 'taxes' => [ - 'type' => [ 'list_of' => 'OrderItemTax' ], + ), + 'taxes' => array( + 'type' => array( 'list_of' => 'OrderItemTax' ), 'description' => __( 'Line taxes', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Line tax class', 'wp-graphql-woocommerce' ), - ], - 'shippingMethod' => [ + ), + 'shippingMethod' => array( 'type' => 'ShippingMethod', 'description' => __( 'Shipping Line\'s shipping method', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return Factory::resolve_shipping_method( $source->method_id ); }, - ], - ], - ], - 'TaxLine' => [ + ), + ), + ), + 'TaxLine' => array( // Description. __( 'a tax line object', 'wp-graphql-woocommerce' ), // Fields. - [ - 'rateCode' => [ + array( + 'rateCode' => array( 'type' => 'String', 'description' => __( 'Tax rate code/name', 'wp-graphql-woocommerce' ), - ], - 'label' => [ + ), + 'label' => array( 'type' => 'String', 'description' => __( 'Tax rate label', 'wp-graphql-woocommerce' ), - ], - 'taxTotal' => [ + ), + 'taxTotal' => array( 'type' => 'String', 'description' => __( 'Tax total (not including shipping taxes)', 'wp-graphql-woocommerce' ), - ], - 'shippingTaxTotal' => [ + ), + 'shippingTaxTotal' => array( 'type' => 'String', 'description' => __( 'Tax line\'s shipping tax total', 'wp-graphql-woocommerce' ), - ], - 'isCompound' => [ + ), + 'isCompound' => array( 'type' => 'Boolean', 'description' => __( 'Is this a compound tax rate?', 'wp-graphql-woocommerce' ), - ], - 'taxRate' => [ + ), + 'taxRate' => array( 'type' => 'TaxRate', 'description' => __( 'Tax line\'s tax rate', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_tax_rate( $source->rate_id, $context ); }, - ], - ], - ], - 'LineItem' => [ + ), + ), + ), + 'LineItem' => array( // Description. __( 'a line item object', 'wp-graphql-woocommerce' ), // Fields. - [ - 'productId' => [ + array( + 'productId' => array( 'type' => 'Int', 'description' => __( 'Line item\'s product ID', 'wp-graphql-woocommerce' ), - ], - 'variationId' => [ + ), + 'variationId' => array( 'type' => 'Int', 'description' => __( 'Line item\'s product variation ID', 'wp-graphql-woocommerce' ), - ], - 'quantity' => [ + ), + 'quantity' => array( 'type' => 'Int', 'description' => __( 'Line item\'s product quantity', 'wp-graphql-woocommerce' ), - ], - 'taxClass' => [ + ), + 'taxClass' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Line item\'s tax class', 'wp-graphql-woocommerce' ), - ], - 'subtotal' => [ + ), + 'subtotal' => array( 'type' => 'String', 'description' => __( 'Line item\'s subtotal', 'wp-graphql-woocommerce' ), - ], - 'subtotalTax' => [ + ), + 'subtotalTax' => array( 'type' => 'String', 'description' => __( 'Line item\'s subtotal tax', 'wp-graphql-woocommerce' ), - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Line item\'s total', 'wp-graphql-woocommerce' ), - ], - 'totalTax' => [ + ), + 'totalTax' => array( 'type' => 'String', 'description' => __( 'Line item\'s total tax', 'wp-graphql-woocommerce' ), - ], - 'taxes' => [ - 'type' => [ 'list_of' => 'OrderItemTax' ], + ), + 'taxes' => array( + 'type' => array( 'list_of' => 'OrderItemTax' ), 'description' => __( 'Line item\'s taxes', 'wp-graphql-woocommerce' ), - ], - 'itemDownloads' => [ - 'type' => [ 'list_of' => 'ProductDownload' ], + ), + 'itemDownloads' => array( + 'type' => array( 'list_of' => 'ProductDownload' ), 'description' => __( 'Line item\'s taxes', 'wp-graphql-woocommerce' ), - ], - 'taxStatus' => [ + ), + 'taxStatus' => array( 'type' => 'TaxStatusEnum', 'description' => __( 'Line item\'s taxes', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), // Connections. - [ - 'product' => [ + array( + 'product' => array( 'toType' => 'Product', 'oneToOne' => true, 'resolve' => static function ( $source, array $args, AppContext $context, $info ) { @@ -218,8 +218,8 @@ public static function register() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ], - 'variation' => [ + ), + 'variation' => array( 'toType' => 'ProductVariation', 'oneToOne' => true, 'resolve' => static function ( $source, array $args, AppContext $context, $info ) { @@ -235,59 +235,59 @@ public static function register() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ], - ], - ], - ]; + ), + ), + ), + ); // Registers order item objects. foreach ( $types as $type_name => $config ) { register_graphql_object_type( $type_name, - [ + array( 'description' => $config[0], 'fields' => self::get_fields( $config[1] ), 'connections' => ! empty( $config[2] ) ? $config[2] : null, - 'interfaces' => [ 'Node' ], - ] + 'interfaces' => array( 'Node' ), + ) ); } // Registers tax statement object. register_graphql_object_type( 'OrderItemTax', - [ + array( 'description' => __( 'Order item tax statement', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'taxLineId' => [ - 'type' => [ 'non_null' => 'Int' ], + 'fields' => array( + 'taxLineId' => array( + 'type' => array( 'non_null' => 'Int' ), 'description' => __( 'Order item ID for tax line connected to this statement', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['ID'] ) ? $source['ID'] : null; }, - ], - 'subtotal' => [ + ), + 'subtotal' => array( 'type' => 'Float', 'description' => __( 'Subtotal', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['subtotal'] ) ? $source['subtotal'] : null; }, - ], - 'total' => [ + ), + 'total' => array( 'type' => 'Float', 'description' => __( 'Total', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['total'] ) ? $source['total'] : null; }, - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'Float', 'description' => __( 'Amount taxed', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['amount'] ) ? $source['amount'] : null; }, - ], - 'taxLine' => [ + ), + 'taxLine' => array( 'type' => 'TaxLine', 'description' => __( 'Tax line connected to this statement', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -299,9 +299,9 @@ public static function register() { return Factory::resolve_order_item( $item ); }, - ], - ], - ] + ), + ), + ) ); } @@ -311,24 +311,24 @@ public static function register() { * @param array $fields - type specific fields. * @return array */ - private static function get_fields( $fields = [] ) { + private static function get_fields( $fields = array() ) { return array_merge( - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The ID of the order item in the database', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the order item in the database', 'wp-graphql-woocommerce' ), - ], - 'orderId' => [ + ), + 'orderId' => array( 'type' => 'Int', 'description' => __( 'The Id of the order the order item belongs to.', 'wp-graphql-woocommerce' ), - ], + ), 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ], + ), $fields ); } diff --git a/includes/type/object/class-order-type.php b/includes/type/object/class-order-type.php index 354d34e09..690ac4471 100644 --- a/includes/type/object/class-order-type.php +++ b/includes/type/object/class-order-type.php @@ -28,12 +28,12 @@ class Order_Type { public static function register() { register_graphql_object_type( 'Order', - [ + array( 'description' => __( 'A order object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ + 'interfaces' => array( 'Node', 'NodeWithComments', - ], + ), /** * Allows for a decisive filtering of the order fields. * Note: Only use if deregisteration or renaming the field(s) has failed. @@ -50,7 +50,7 @@ public static function register() { * @return array */ 'connections' => apply_filters( 'woographql_order_connection_definitions', self::get_connections() ), - ] + ) ); } @@ -60,74 +60,74 @@ public static function register() { * @param array $other_fields Extra fields configs to be added or override the default field definitions. * @return array */ - public static function get_fields( $other_fields = [] ) { + public static function get_fields( $other_fields = array() ) { return array_merge( - [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the order', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the order in the database', 'wp-graphql-woocommerce' ), - ], - 'orderKey' => [ + ), + 'orderKey' => array( 'type' => 'String', 'description' => __( 'Order key', 'wp-graphql-woocommerce' ), - ], - 'date' => [ + ), + 'date' => array( 'type' => 'String', 'description' => __( 'Date order was created', 'wp-graphql-woocommerce' ), - ], - 'modified' => [ + ), + 'modified' => array( 'type' => 'String', 'description' => __( 'Date order was last updated', 'wp-graphql-woocommerce' ), - ], - 'currency' => [ + ), + 'currency' => array( 'type' => 'String', 'description' => __( 'Order currency', 'wp-graphql-woocommerce' ), - ], - 'paymentMethod' => [ + ), + 'paymentMethod' => array( 'type' => 'String', 'description' => __( 'Payment method', 'wp-graphql-woocommerce' ), - ], - 'paymentMethodTitle' => [ + ), + 'paymentMethodTitle' => array( 'type' => 'String', 'description' => __( 'Payment method title', 'wp-graphql-woocommerce' ), - ], - 'transactionId' => [ + ), + 'transactionId' => array( 'type' => 'String', 'description' => __( 'Transaction ID', 'wp-graphql-woocommerce' ), - ], - 'customerIpAddress' => [ + ), + 'customerIpAddress' => array( 'type' => 'String', 'description' => __( 'Customer IP Address', 'wp-graphql-woocommerce' ), - ], - 'customerUserAgent' => [ + ), + 'customerUserAgent' => array( 'type' => 'String', 'description' => __( 'Customer User Agent', 'wp-graphql-woocommerce' ), - ], - 'createdVia' => [ + ), + 'createdVia' => array( 'type' => 'String', 'description' => __( 'How order was created', 'wp-graphql-woocommerce' ), - ], - 'dateCompleted' => [ + ), + 'dateCompleted' => array( 'type' => 'String', 'description' => __( 'Date order was completed', 'wp-graphql-woocommerce' ), - ], - 'datePaid' => [ + ), + 'datePaid' => array( 'type' => 'String', 'description' => __( 'Date order was paid', 'wp-graphql-woocommerce' ), - ], - 'discountTotal' => [ + ), + 'discountTotal' => array( 'type' => 'String', 'description' => __( 'Discount total amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -137,16 +137,16 @@ public static function get_fields( $other_fields = [] ) { return $source->discountTotal; } }, - ], - 'discountTax' => [ + ), + 'discountTax' => array( 'type' => 'String', 'description' => __( 'Discount tax amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -156,16 +156,16 @@ public static function get_fields( $other_fields = [] ) { return $source->discountTax; } }, - ], - 'shippingTotal' => [ + ), + 'shippingTotal' => array( 'type' => 'String', 'description' => __( 'Shipping total amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -175,16 +175,16 @@ public static function get_fields( $other_fields = [] ) { // @codingStandardsIgnoreLine. return $source->shippingTotal; }, - ], - 'shippingTax' => [ + ), + 'shippingTax' => array( 'type' => 'String', 'description' => __( 'Shipping tax amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -194,16 +194,16 @@ public static function get_fields( $other_fields = [] ) { // @codingStandardsIgnoreLine. return $source->shippingTax; }, - ], - 'cartTax' => [ + ), + 'cartTax' => array( 'type' => 'String', 'description' => __( 'Cart tax amount', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -213,16 +213,16 @@ public static function get_fields( $other_fields = [] ) { return $source->cartTax; } }, - ], - 'total' => [ + ), + 'total' => array( 'type' => 'String', 'description' => __( 'Order grand total', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -231,16 +231,16 @@ public static function get_fields( $other_fields = [] ) { return $source->total; } }, - ], - 'totalTax' => [ + ), + 'totalTax' => array( 'type' => 'String', 'description' => __( 'Order taxes', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -250,16 +250,16 @@ public static function get_fields( $other_fields = [] ) { return $source->totalTax; } }, - ], - 'subtotal' => [ + ), + 'subtotal' => array( 'type' => 'String', 'description' => __( 'Order subtotal', 'wp-graphql-woocommerce' ), - 'args' => [ - 'format' => [ + 'args' => array( + 'format' => array( 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -268,51 +268,51 @@ public static function get_fields( $other_fields = [] ) { return $source->subtotal; } }, - ], - 'orderNumber' => [ + ), + 'orderNumber' => array( 'type' => 'String', 'description' => __( 'Order number', 'wp-graphql-woocommerce' ), - ], - 'orderVersion' => [ + ), + 'orderVersion' => array( 'type' => 'String', 'description' => __( 'Order version', 'wp-graphql-woocommerce' ), - ], - 'pricesIncludeTax' => [ + ), + 'pricesIncludeTax' => array( 'type' => 'Boolean', 'description' => __( 'Prices include taxes?', 'wp-graphql-woocommerce' ), - ], - 'cartHash' => [ + ), + 'cartHash' => array( 'type' => 'String', 'description' => __( 'Cart hash', 'wp-graphql-woocommerce' ), - ], - 'customerNote' => [ + ), + 'customerNote' => array( 'type' => 'String', 'description' => __( 'Customer note', 'wp-graphql-woocommerce' ), - ], - 'isDownloadPermitted' => [ + ), + 'isDownloadPermitted' => array( 'type' => 'Boolean', 'description' => __( 'Is product download is permitted', 'wp-graphql-woocommerce' ), - ], - 'billing' => [ + ), + 'billing' => array( 'type' => 'CustomerAddress', 'description' => __( 'Order billing properties', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'CustomerAddress', 'description' => __( 'Order shipping properties', 'wp-graphql-woocommerce' ), - ], - 'status' => [ + ), + 'status' => array( 'type' => 'OrderStatusEnum', 'description' => __( 'Order status', 'wp-graphql-woocommerce' ), - ], - 'parent' => [ + ), + 'parent' => array( 'type' => 'Order', 'description' => __( 'Parent order', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $order, array $args, AppContext $context ) { return Factory::resolve_crud_object( $order->parent_id, $context ); }, - ], - 'customer' => [ + ), + 'customer' => array( 'type' => 'Customer', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $order, array $args, AppContext $context ) { @@ -323,37 +323,37 @@ public static function get_fields( $other_fields = [] ) { return Factory::resolve_customer( $order->customer_id, $context ); }, - ], - 'shippingAddressMapUrl' => [ + ), + 'shippingAddressMapUrl' => array( 'type' => 'String', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), - ], - 'hasBillingAddress' => [ + ), + 'hasBillingAddress' => array( 'type' => 'Boolean', 'description' => __( 'Order has a billing address?', 'wp-graphql-woocommerce' ), - ], - 'hasShippingAddress' => [ + ), + 'hasShippingAddress' => array( 'type' => 'Boolean', 'description' => __( 'Order has a shipping address?', 'wp-graphql-woocommerce' ), - ], - 'needsShippingAddress' => [ + ), + 'needsShippingAddress' => array( 'type' => 'Boolean', 'description' => __( 'If order needs shipping address', 'wp-graphql-woocommerce' ), - ], - 'hasDownloadableItem' => [ + ), + 'hasDownloadableItem' => array( 'type' => 'Boolean', 'description' => __( 'If order contains a downloadable product', 'wp-graphql-woocommerce' ), - ], - 'needsPayment' => [ + ), + 'needsPayment' => array( 'type' => 'Boolean', 'description' => __( 'If order needs payment', 'wp-graphql-woocommerce' ), - ], - 'needsProcessing' => [ + ), + 'needsProcessing' => array( 'type' => 'Boolean', 'description' => __( 'If order needs processing before it can be completed', 'wp-graphql-woocommerce' ), - ], + ), 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ], + ), $other_fields ); } @@ -364,57 +364,57 @@ public static function get_fields( $other_fields = [] ) { * @param array $other_connections Extra connections configs to be added or override the default connection definitions. * @return array */ - public static function get_connections( $other_connections = [] ) { + public static function get_connections( $other_connections = array() ) { return array_merge( - [ - 'taxLines' => [ + array( + 'taxLines' => array( 'toType' => 'TaxLine', - 'connectionArgs' => [], - 'resolve' => [ self::class, 'resolve_item_connection' ], - ], - 'feeLines' => [ + 'connectionArgs' => array(), + 'resolve' => array( self::class, 'resolve_item_connection' ), + ), + 'feeLines' => array( 'toType' => 'FeeLine', - 'connectionArgs' => [], - 'resolve' => [ self::class, 'resolve_item_connection' ], - ], - 'shippingLines' => [ + 'connectionArgs' => array(), + 'resolve' => array( self::class, 'resolve_item_connection' ), + ), + 'shippingLines' => array( 'toType' => 'ShippingLine', - 'connectionArgs' => [], - 'resolve' => [ self::class, 'resolve_item_connection' ], - ], - 'couponLines' => [ + 'connectionArgs' => array(), + 'resolve' => array( self::class, 'resolve_item_connection' ), + ), + 'couponLines' => array( 'toType' => 'CouponLine', - 'connectionArgs' => [], - 'resolve' => [ self::class, 'resolve_item_connection' ], - ], - 'lineItems' => [ + 'connectionArgs' => array(), + 'resolve' => array( self::class, 'resolve_item_connection' ), + ), + 'lineItems' => array( 'toType' => 'LineItem', - 'connectionArgs' => [], - 'resolve' => [ self::class, 'resolve_item_connection' ], - ], - 'downloadableItems' => [ + 'connectionArgs' => array(), + 'resolve' => array( self::class, 'resolve_item_connection' ), + ), + 'downloadableItems' => array( 'toType' => 'DownloadableItem', - 'connectionArgs' => [ - 'active' => [ + 'connectionArgs' => array( + 'active' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that can be downloaded now.', 'wp-graphql-woocommerce' ), - ], - 'expired' => [ + ), + 'expired' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that are expired.', 'wp-graphql-woocommerce' ), - ], - 'hasDownloadsRemaining' => [ + ), + 'hasDownloadsRemaining' => array( 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Downloadable_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], - ], + ), + ), $other_connections ); } diff --git a/includes/type/object/class-payment-gateway-type.php b/includes/type/object/class-payment-gateway-type.php index 2b64ffd6e..cc435acd4 100644 --- a/includes/type/object/class-payment-gateway-type.php +++ b/includes/type/object/class-payment-gateway-type.php @@ -22,40 +22,40 @@ class Payment_Gateway_Type { public static function register() { register_graphql_object_type( 'PaymentGateway', - [ + array( 'description' => __( 'A payment gateway object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, - ], - 'title' => [ + ), + 'title' => array( 'type' => 'String', 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->title ) ? $source->title : null; }, - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'gateway\'s description', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->description ) ? $source->description : null; }, - ], - 'icon' => [ + ), + 'icon' => array( 'type' => 'String', 'description' => __( 'gateway\'s icon', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->icon ) ? $source->icon : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-payment-token-types.php b/includes/type/object/class-payment-token-types.php index cd961a401..a4f91f379 100644 --- a/includes/type/object/class-payment-token-types.php +++ b/includes/type/object/class-payment-token-types.php @@ -24,20 +24,20 @@ class Payment_Token_Types { public static function register() { register_graphql_object_type( 'PaymentTokenCC', - [ + array( 'description' => __( 'A credit cart payment token', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'PaymentToken' ], + 'interfaces' => array( 'PaymentToken' ), 'fields' => Payment_Token::get_fields( self::get_credit_card_fields() ), - ] + ) ); register_graphql_object_type( 'PaymentTokenECheck', - [ + array( 'description' => __( 'A electronic check payment token', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'PaymentToken' ], + 'interfaces' => array( 'PaymentToken' ), 'fields' => Payment_Token::get_fields( self::get_e_check_fields() ), - ] + ) ); } @@ -47,15 +47,15 @@ public static function register() { * @return array */ public static function get_e_check_fields() { - return [ - 'last4' => [ + return array( + 'last4' => array( 'type' => 'Integer', 'description' => __( 'Last 4 digits of the stored account number', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_last4() ) ? $source->get_last4() : null; }, - ], - ]; + ), + ); } /** @@ -64,35 +64,35 @@ public static function get_e_check_fields() { * @return array */ public static function get_credit_card_fields() { - return [ - 'cardType' => [ + return array( + 'cardType' => array( 'type' => 'String', 'description' => __( 'Card type (visa, mastercard, etc)', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_card_type() ) ? $source->get_card_type() : null; }, - ], - 'expiryYear' => [ + ), + 'expiryYear' => array( 'type' => 'String', 'description' => __( 'Card\'s expiration year.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_expiry_year() ) ? $source->get_expiry_year() : null; }, - ], - 'expiryMonth' => [ + ), + 'expiryMonth' => array( 'type' => 'String', 'description' => __( 'Card\'s expiration month', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_expiry_month() ) ? $source->get_expiry_month() : null; }, - ], - 'last4' => [ + ), + 'last4' => array( 'type' => 'Integer', 'description' => __( 'Last 4 digits of the stored credit card number', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_last4() ) ? $source->get_last4() : null; }, - ], - ]; + ), + ); } } diff --git a/includes/type/object/class-product-attribute-types.php b/includes/type/object/class-product-attribute-types.php index 0bc146cf4..dc51f5b1d 100644 --- a/includes/type/object/class-product-attribute-types.php +++ b/includes/type/object/class-product-attribute-types.php @@ -23,97 +23,97 @@ public static function register() { // Local. register_graphql_object_type( 'LocalProductAttribute', - [ + array( 'description' => __( 'A product attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'ProductAttribute' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'ProductAttribute' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Attribute Global ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! empty( $attribute->_relay_id ) ? $attribute->_relay_id : Relay::toGlobalId( 'LocalProductAttribute', $attribute->get_id() ); }, - ], - 'scope' => [ - 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], + ), + 'scope' => array( + 'type' => array( 'non_null' => 'ProductAttributeTypesEnum' ), 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), 'resolve' => static function () { return 'local'; }, - ], - ], - ] + ), + ), + ) ); // Global. register_graphql_object_type( 'GlobalProductAttribute', - [ + array( 'description' => __( 'A product attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'ProductAttribute' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'ProductAttribute' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Attribute Global ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! empty( $attribute->_relay_id ) ? $attribute->_relay_id : Relay::toGlobalId( 'GlobalProductAttribute', $attribute->get_id() ); }, - ], - 'scope' => [ - 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], + ), + 'scope' => array( + 'type' => array( 'non_null' => 'ProductAttributeTypesEnum' ), 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), 'resolve' => static function () { return 'global'; }, - ], - 'label' => [ + ), + 'label' => array( 'type' => 'String', 'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { $taxonomy = get_taxonomy( $attribute->get_name() ); return $taxonomy ? $taxonomy->labels->singular_name : null; }, - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Product attribute name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return $attribute->get_name(); }, - ], - 'slug' => [ + ), + 'slug' => array( 'type' => 'String', 'description' => __( 'Product attribute slug', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, - ], - ], - ] + ), + ), + ) ); // ProductAttributeOutput for CartItemError and CartItem edges. register_graphql_object_type( 'ProductAttributeOutput', - [ + array( 'description' => __( 'A simple product attribute object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'attributeName' => [ + 'fields' => array( + 'attributeName' => array( 'type' => 'String', 'description' => __( 'Attribute name.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $attribute ) { return ! empty( $attribute['attributeName'] ) ? $attribute['attributeName'] : null; }, - ], - 'attributeValue' => [ + ), + 'attributeValue' => array( 'type' => 'String', 'description' => __( 'Attribute value.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( array $attribute ) { return ! empty( $attribute['attributeValue'] ) ? $attribute['attributeValue'] : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-product-category-type.php b/includes/type/object/class-product-category-type.php index 980f02136..ee49ee944 100644 --- a/includes/type/object/class-product-category-type.php +++ b/includes/type/object/class-product-category-type.php @@ -24,8 +24,8 @@ class Product_Category_Type { public static function register_fields() { register_graphql_fields( 'ProductCategory', - [ - 'image' => [ + array( + 'image' => array( 'type' => 'MediaItem', 'description' => __( 'Product category image', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { @@ -34,24 +34,24 @@ public static function register_fields() { ? $context->get_loader( 'post' )->load_deferred( $thumbnail_id ) : null; }, - ], - 'display' => [ + ), + 'display' => array( 'type' => 'ProductCategoryDisplay', 'description' => __( 'Product category display type', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $display = get_term_meta( $source->term_id, 'display_type', true ); return ! empty( $display ) ? $display : 'default'; }, - ], - 'menuOrder' => [ + ), + 'menuOrder' => array( 'type' => 'Integer', 'description' => __( 'Product category menu order', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { $order = get_term_meta( $source->term_id, 'order', true ); return ! empty( $order ) ? $order : 0; }, - ], - ] + ), + ) ); } } diff --git a/includes/type/object/class-product-download-type.php b/includes/type/object/class-product-download-type.php index bdd593a72..c6dbda0fe 100644 --- a/includes/type/object/class-product-download-type.php +++ b/includes/type/object/class-product-download-type.php @@ -22,67 +22,67 @@ class Product_Download_Type { public static function register() { register_graphql_object_type( 'ProductDownload', - [ + array( 'description' => __( 'A product object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'downloadId' => [ - 'type' => [ 'non_null' => 'String' ], + 'fields' => array( + 'downloadId' => array( + 'type' => array( 'non_null' => 'String' ), 'description' => __( 'Product download ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_id() : null; }, - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Product download name', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_name() : null; }, - ], - 'filePathType' => [ + ), + 'filePathType' => array( 'type' => 'String', 'description' => __( 'Type of file path set', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_type_of_file_path() : null; }, - ], - 'fileType' => [ + ), + 'fileType' => array( 'type' => 'String', 'description' => __( 'File type', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_file_type() : null; }, - ], - 'fileExt' => [ + ), + 'fileExt' => array( 'type' => 'String', 'description' => __( 'File extension', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_file_extension() : null; }, - ], - 'allowedFileType' => [ + ), + 'allowedFileType' => array( 'type' => 'Boolean', 'description' => __( 'Is file allowed', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->is_allowed_filetype() : null; }, - ], - 'fileExists' => [ + ), + 'fileExists' => array( 'type' => 'Boolean', 'description' => __( 'Validate file exists', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->file_exists() : null; }, - ], - 'file' => [ + ), + 'file' => array( 'type' => 'String', 'description' => __( 'Download file', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_file() : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-product-types.php b/includes/type/object/class-product-types.php index 8630b6ad9..387d0a196 100644 --- a/includes/type/object/class-product-types.php +++ b/includes/type/object/class-product-types.php @@ -41,9 +41,9 @@ public static function register() { * * @return array */ - public static function get_product_interfaces( $other_interfaces = [] ) { + public static function get_product_interfaces( $other_interfaces = array() ) { return array_merge( - [ + array( 'Node', 'Product', 'ProductUnion', @@ -53,7 +53,7 @@ public static function get_product_interfaces( $other_interfaces = [] ) { 'NodeWithFeaturedImage', 'ContentNode', 'UniformResourceIdentifiable', - ], + ), $other_interfaces ); } @@ -66,20 +66,30 @@ public static function get_product_interfaces( $other_interfaces = [] ) { private static function register_simple_product_type() { register_graphql_object_type( 'SimpleProduct', - [ + array( 'eagerlyLoadType' => true, 'model' => \WPGraphQL\WooCommerce\Model\Product::class, 'description' => __( 'A simple product object', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces( - [ + array( 'DownloadableProduct', 'InventoriedProduct', 'ProductWithDimensions', 'ProductWithPricing', - ] + ) ), - 'fields' => [], - ] + 'fields' => array( + 'dateModified' => array( + 'type' => 'String', + 'description' => __( 'The date the product was last modified in GMT (ISO8601 format).', 'wp-graphql-woocommerce' ), + 'resolve' => static function ( Model $source ) { + $modified = $source->get_date_modified(); + return $modified ? $modified->date( 'c' ) : null; + }, + ), + ), + + ) ); } @@ -91,20 +101,30 @@ private static function register_simple_product_type() { private static function register_variable_product_type() { register_graphql_object_type( 'VariableProduct', - [ + array( 'eagerlyLoadType' => true, 'model' => \WPGraphQL\WooCommerce\Model\Product::class, 'description' => __( 'A variable product object', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces( - [ + array( 'InventoriedProduct', 'ProductWithDimensions', 'ProductWithPricing', 'ProductWithVariations', - ] + ) + ), + 'fields' => array( + 'dateModified' => array( + 'type' => 'String', + 'description' => __( 'The date the product was last modified in GMT (ISO8601 format).', 'wp-graphql-woocommerce' ), + 'resolve' => static function ( Model $source ) { + $modified = $source->get_date_modified(); + return $modified ? $modified->date( 'c' ) : null; + }, + ), ), - 'fields' => [], - ] + + ) ); } @@ -116,24 +136,30 @@ private static function register_variable_product_type() { private static function register_external_product_type() { register_graphql_object_type( 'ExternalProduct', - [ + array( 'eagerlyLoadType' => true, 'model' => \WPGraphQL\WooCommerce\Model\Product::class, 'description' => __( 'A external product object', 'wp-graphql-woocommerce' ), - 'interfaces' => self::get_product_interfaces( [ 'ProductWithPricing' ] ), - 'fields' => array_merge( - [ - 'externalUrl' => [ - 'type' => 'String', - 'description' => __( 'External product url', 'wp-graphql-woocommerce' ), - ], - 'buttonText' => [ - 'type' => 'String', - 'description' => __( 'External product Buy button text', 'wp-graphql-woocommerce' ), - ], - ] + 'interfaces' => self::get_product_interfaces( array( 'ProductWithPricing' ) ), + 'fields' => array( + 'externalUrl' => array( + 'type' => 'String', + 'description' => __( 'External product url', 'wp-graphql-woocommerce' ), + ), + 'buttonText' => array( + 'type' => 'String', + 'description' => __( 'External product Buy button text', 'wp-graphql-woocommerce' ), + ), + 'dateModified' => array( + 'type' => 'String', + 'description' => __( 'The date the product was last modified in GMT (ISO8601 format).', 'wp-graphql-woocommerce' ), + 'resolve' => static function ( Model $source ) { + $modified = $source->get_date_modified(); + return $modified ? $modified->date( 'c' ) : null; + }, + ), ), - ] + ) ); } @@ -145,26 +171,26 @@ private static function register_external_product_type() { private static function register_group_product_type() { register_graphql_object_type( 'GroupProduct', - [ + array( 'eagerlyLoadType' => true, 'model' => \WPGraphQL\WooCommerce\Model\Product::class, 'description' => __( 'A group product object', 'wp-graphql-woocommerce' ), - 'interfaces' => self::get_product_interfaces( [ 'ProductWithPricing' ] ), - 'fields' => [ - 'addToCartText' => [ + 'interfaces' => self::get_product_interfaces( array( 'ProductWithPricing' ) ), + 'fields' => array( + 'addToCartText' => array( 'type' => 'String', 'description' => __( 'Product\'s add to cart button text description', 'wp-graphql-woocommerce' ), - ], - 'addToCartDescription' => [ + ), + 'addToCartDescription' => array( 'type' => 'String', 'description' => __( 'Product\'s add to cart button text description', 'wp-graphql-woocommerce' ), - ], - 'price' => [ + ), + 'price' => array( 'type' => 'String', 'description' => __( 'Products\' price range', 'wp-graphql-woocommerce' ), 'resolve' => static function ( Model $source ) { $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); - $child_prices = []; + $child_prices = array(); $children = array_filter( array_map( 'wc_get_product', $source->grouped_ids ) ); $children = array_filter( $children, 'wc_products_array_filter_visible_grouped' ); @@ -196,9 +222,17 @@ private static function register_group_product_type() { return wc_graphql_price( $min_price ); }, - ], - ], - ] + ), + 'dateModified' => array( + 'type' => 'String', + 'description' => __( 'The date the product was last modified in GMT (ISO8601 format).', 'wp-graphql-woocommerce' ), + 'resolve' => static function ( Model $source ) { + $modified = $source->get_date_modified(); + return $modified ? $modified->date( 'c' ) : null; + }, + ), + ), + ) ); } @@ -210,28 +244,36 @@ private static function register_group_product_type() { private static function register_unsupported_product_type() { register_graphql_object_type( WooGraphQL::get_supported_product_type(), - [ + array( 'eagerlyLoadType' => true, 'model' => \WPGraphQL\WooCommerce\Model\Product::class, 'description' => __( 'A product object for a product type that is unsupported by the current API.', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces( - [ + array( 'DownloadableProduct', 'InventoriedProduct', 'ProductWithDimensions', 'ProductWithPricing', - ] + ) ), - 'fields' => [ - 'type' => [ + 'fields' => array( + 'type' => array( 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), 'resolve' => static function () { return 'unsupported'; }, - ], - ], - ] + ), + 'dateModified' => array( + 'type' => 'String', + 'description' => __( 'The date the product was last modified in GMT (ISO8601 format).', 'wp-graphql-woocommerce' ), + 'resolve' => static function ( Model $source ) { + $modified = $source->get_date_modified(); + return $modified ? $modified->date( 'c' ) : null; + }, + ), + ), + ) ); } } diff --git a/includes/type/object/class-refund-type.php b/includes/type/object/class-refund-type.php index 2388bbdb3..0bb02be22 100644 --- a/includes/type/object/class-refund-type.php +++ b/includes/type/object/class-refund-type.php @@ -24,31 +24,31 @@ class Refund_Type { public static function register() { register_graphql_object_type( 'Refund', - [ + array( 'description' => __( 'A refund object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the refund', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the refund in the database', 'wp-graphql-woocommerce' ), - ], - 'title' => [ + ), + 'title' => array( 'type' => 'String', 'description' => __( 'A title for the new post type', 'wp-graphql-woocommerce' ), - ], - 'amount' => [ + ), + 'amount' => array( 'type' => 'Float', 'description' => __( 'Refunded amount', 'wp-graphql-woocommerce' ), - ], - 'reason' => [ + ), + 'reason' => array( 'type' => 'String', 'description' => __( 'Reason for refund', 'wp-graphql-woocommerce' ), - ], - 'refundedBy' => [ + ), + 'refundedBy' => array( 'type' => 'User', 'description' => __( 'User who completed the refund', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, AppContext $context ) { @@ -58,15 +58,15 @@ public static function register() { } return null; }, - ], - 'date' => [ + ), + 'date' => array( 'type' => 'String', 'description' => __( 'The date of the refund', 'wp-graphql-woocommerce' ), - ], + ), 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ], - ] + ), + ) ); } } diff --git a/includes/type/object/class-root-query.php b/includes/type/object/class-root-query.php index 31dd1bea7..3e888729e 100644 --- a/includes/type/object/class-root-query.php +++ b/includes/type/object/class-root-query.php @@ -28,15 +28,15 @@ class Root_Query { public static function register_fields() { register_graphql_fields( 'RootQuery', - [ - 'cart' => [ + array( + 'cart' => array( 'type' => 'Cart', - 'args' => [ - 'recalculateTotals' => [ + 'args' => array( + 'recalculateTotals' => array( 'type' => 'Boolean', 'description' => __( 'Should cart totals be recalculated.', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $_, $args ) { $token_invalid = apply_filters( 'graphql_woocommerce_session_token_errors', null ); @@ -51,14 +51,14 @@ public static function register_fields() { return $cart; }, - ], - 'cartItem' => [ + ), + 'cartItem' => array( 'type' => 'CartItem', - 'args' => [ - 'key' => [ - 'type' => [ 'non_null' => 'ID' ], - ], - ], + 'args' => array( + 'key' => array( + 'type' => array( 'non_null' => 'ID' ), + ), + ), 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args ) { $item = Factory::resolve_cart()->get_cart_item( $args['key'] ); @@ -68,14 +68,14 @@ public static function register_fields() { return $item; }, - ], - 'cartFee' => [ + ), + 'cartFee' => array( 'type' => 'CartFee', - 'args' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], - ], - ], + 'args' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), + ), + ), 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args ) { $fees = Factory::resolve_cart()->get_fees(); @@ -87,17 +87,17 @@ public static function register_fields() { return $fees[ $fee_id ]; }, - ], - 'coupon' => [ + ), + 'coupon' => array( 'type' => 'Coupon', 'description' => __( 'A coupon object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ 'type' => [ 'non_null' => 'ID' ] ], - 'idType' => [ + 'args' => array( + 'id' => array( 'type' => array( 'non_null' => 'ID' ) ), + 'idType' => array( 'type' => 'CouponIdTypeEnum', 'description' => __( 'Type of ID being used identify coupon', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -145,20 +145,20 @@ public static function register_fields() { return Factory::resolve_crud_object( $coupon_id, $context ); }, - ], - 'customer' => [ + ), + 'customer' => array( 'type' => 'Customer', 'description' => __( 'A customer object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Get the customer by their global ID', 'wp-graphql-woocommerce' ), - ], - 'customerId' => [ + ), + 'customerId' => array( 'type' => 'Int', 'description' => __( 'Get the customer by their database ID', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { $current_user_id = get_current_user_id(); @@ -193,20 +193,20 @@ public static function register_fields() { // Resolve to the session customer. return Factory::resolve_session_customer(); }, - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Order', 'description' => __( 'A order object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'The ID for identifying the order', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'OrderIdTypeEnum', 'description' => __( 'Type of ID being used identify order', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -250,13 +250,13 @@ public static function register_fields() { if ( ! $is_authorized && get_current_user_id() ) { /** @var \WC_Order[] $orders */ $orders = wc_get_orders( - [ + array( 'type' => 'shop_order', - 'post__in' => [ $order_id ], + 'post__in' => array( $order_id ), 'customer_id' => get_current_user_id(), 'no_rows_found' => true, 'return' => 'ids', - ] + ) ); if ( in_array( $order_id, $orders, true ) ) { @@ -271,20 +271,20 @@ public static function register_fields() { return Factory::resolve_crud_object( $order_id, $context ); }, - ], - 'productVariation' => [ + ), + 'productVariation' => array( 'type' => 'ProductVariation', 'description' => __( 'A product variation object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'The ID for identifying the product variation', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'ProductVariationIdTypeEnum', 'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -317,20 +317,20 @@ public static function register_fields() { return Factory::resolve_crud_object( $variation_id, $context ); }, - ], - 'refund' => [ + ), + 'refund' => array( 'type' => 'Refund', 'description' => __( 'A refund object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'args' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The ID for identifying the refund', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'RefundIdTypeEnum', 'description' => __( 'Type of ID being used identify refund', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -377,13 +377,13 @@ public static function register_fields() { /** @var \WC_Order[] $orders */ $orders = wc_get_orders( - [ + array( 'type' => 'shop_order', - 'post__in' => [ $order_id ], + 'post__in' => array( $order_id ), 'customer_id' => get_current_user_id(), 'no_rows_found' => true, 'return' => 'ids', - ] + ) ); if ( in_array( $order_id, $orders, true ) ) { @@ -398,20 +398,20 @@ public static function register_fields() { return Factory::resolve_crud_object( $refund_id, $context ); }, - ], - 'shippingMethod' => [ + ), + 'shippingMethod' => array( 'type' => 'ShippingMethod', 'description' => __( 'A shipping method object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'The ID for identifying the shipping method', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'ShippingMethodIdTypeEnum', 'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args ) { if ( ! \wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { throw new UserError( __( 'Sorry, you cannot view shipping methods.', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() ); @@ -437,20 +437,20 @@ public static function register_fields() { return Factory::resolve_shipping_method( $method_id ); }, - ], - 'shippingZone' => [ + ), + 'shippingZone' => array( 'type' => 'ShippingZone', 'description' => __( 'A shipping zone object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'The ID for identifying the shipping zone', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'ShippingZoneIdTypeEnum', 'description' => __( 'Type of ID being used identify shipping zone', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { if ( ! \wc_shipping_enabled() ) { throw new UserError( __( 'Shipping is disabled.', 'wp-graphql-woocommerce' ), 404 ); @@ -480,20 +480,20 @@ public static function register_fields() { return $context->get_loader( 'shipping_zone' )->load( $zone_id ); }, - ], - 'taxRate' => [ + ), + 'taxRate' => array( 'type' => 'TaxRate', 'description' => __( 'A tax rate object', 'wp-graphql-woocommerce' ), - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'The ID for identifying the tax rate', 'wp-graphql-woocommerce' ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'TaxRateIdTypeEnum', 'description' => __( 'Type of ID being used identify tax rate', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { throw new UserError( __( 'Sorry, you cannot view tax rates.', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() ); @@ -518,9 +518,9 @@ public static function register_fields() { return Factory::resolve_tax_rate( $rate_id, $context ); }, - ], - 'countries' => [ - 'type' => [ 'list_of' => 'CountriesEnum' ], + ), + 'countries' => array( + 'type' => array( 'list_of' => 'CountriesEnum' ), 'description' => __( 'Countries', 'wp-graphql-woocommerce' ), 'resolve' => static function () { $wc_countries = new \WC_Countries(); @@ -528,9 +528,9 @@ public static function register_fields() { return array_keys( $countries ); }, - ], - 'allowedCountries' => [ - 'type' => [ 'list_of' => 'CountriesEnum' ], + ), + 'allowedCountries' => array( + 'type' => array( 'list_of' => 'CountriesEnum' ), 'description' => __( 'Countries that the store sells to', 'wp-graphql-woocommerce' ), 'resolve' => static function () { $wc_countries = new \WC_Countries(); @@ -538,15 +538,15 @@ public static function register_fields() { return array_keys( $countries ); }, - ], - 'countryStates' => [ - 'type' => [ 'list_of' => 'CountryState' ], - 'args' => [ - 'country' => [ - 'type' => [ 'non_null' => 'CountriesEnum' ], + ), + 'countryStates' => array( + 'type' => array( 'list_of' => 'CountryState' ), + 'args' => array( + 'country' => array( + 'type' => array( 'non_null' => 'CountriesEnum' ), 'description' => __( 'Target country', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'description' => __( 'Countries that the store sells to', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $_, $args ) { $country = $args['country']; @@ -554,7 +554,7 @@ public static function register_fields() { $states = $wc_countries->get_shipping_country_states(); if ( ! empty( $states ) && ! empty( $states[ $country ] ) ) { - $formatted_states = []; + $formatted_states = array(); foreach ( $states[ $country ] as $code => $name ) { $formatted_states[] = compact( 'name', 'code' ); } @@ -562,51 +562,51 @@ public static function register_fields() { return $formatted_states; } - return []; + return array(); }, - ], - 'collectionStats' => [ + ), + 'collectionStats' => array( 'type' => 'CollectionStats', - 'args' => [ - 'calculatePriceRange' => [ + 'args' => array( + 'calculatePriceRange' => array( 'type' => 'Boolean', 'description' => __( 'If true, calculates the minimum and maximum product prices for the collection.', 'wp-graphql-woocommerce' ), - ], - 'calculateRatingCounts' => [ + ), + 'calculateRatingCounts' => array( 'type' => 'Boolean', 'description' => __( 'If true, calculates rating counts for products in the collection.', 'wp-graphql-woocommerce' ), - ], - 'calculateStockStatusCounts' => [ + ), + 'calculateStockStatusCounts' => array( 'type' => 'Boolean', 'description' => __( 'If true, calculates stock counts for products in the collection.', 'wp-graphql-woocommerce' ), - ], - 'taxonomies' => [ - 'type' => [ 'list_of' => 'CollectionStatsQueryInput' ], - ], - 'where' => [ + ), + 'taxonomies' => array( + 'type' => array( 'list_of' => 'CollectionStatsQueryInput' ), + ), + 'where' => array( 'type' => 'CollectionStatsWhereArgs', - ], - ], + ), + ), 'description' => __( 'Statistics for a product taxonomy query', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $_, $args ) { /** @var array $data */ - $data = [ + $data = array( 'min_price' => null, 'max_price' => null, 'attribute_counts' => null, 'stock_status_counts' => null, 'rating_counts' => null, - ]; + ); $filters = new ProductQueryFilters(); // Process client-side filters. - $request = Collection_Stats_Type::prepare_rest_request( $args['where'] ?? [] ); + $request = Collection_Stats_Type::prepare_rest_request( $args['where'] ?? array() ); // Format taxonomies. if ( ! empty( $args['taxonomies'] ) ) { - $calculate_attribute_counts = []; + $calculate_attribute_counts = array(); foreach ( $args['taxonomies'] as $attribute_to_count ) { - $attribute = [ 'taxonomy' => $attribute_to_count['taxonomy'] ]; + $attribute = array( 'taxonomy' => $attribute_to_count['taxonomy'] ); // Set the query type. if ( ! empty( $attribute_to_count['relation'] ) ) { $attribute['query_type'] = strtolower( $attribute_to_count['relation'] ); @@ -649,19 +649,19 @@ public static function register_fields() { $filter_request = clone $request; $counts = $filters->get_stock_status_counts( $filter_request ); - $data['stock_status_counts'] = []; + $data['stock_status_counts'] = array(); foreach ( $counts as $key => $value ) { - $data['stock_status_counts'][] = (object) [ + $data['stock_status_counts'][] = (object) array( 'status' => $key, 'count' => $value, - ]; + ); } } if ( ! empty( $request['calculate_attribute_counts'] ) ) { - $taxonomy__or_queries = []; - $taxonomy__and_queries = []; + $taxonomy__or_queries = array(); + $taxonomy__and_queries = array(); foreach ( $request['calculate_attribute_counts'] as $attributes_to_count ) { if ( ! isset( $attributes_to_count['taxonomy'] ) ) { continue; @@ -674,7 +674,7 @@ public static function register_fields() { } } - $data['attribute_counts'] = []; + $data['attribute_counts'] = array(); if ( ! empty( $taxonomy__or_queries ) ) { foreach ( $taxonomy__or_queries as $taxonomy ) { /** @@ -695,15 +695,15 @@ static function ( $query ) use ( $taxonomy ) { } $filter_request->set_param( 'attributes', $filter_attributes ); - $counts = $filters->get_attribute_counts( $filter_request, [ $taxonomy ] ); + $counts = $filters->get_attribute_counts( $filter_request, array( $taxonomy ) ); - $data['attribute_counts'][ $taxonomy ] = []; + $data['attribute_counts'][ $taxonomy ] = array(); foreach ( $counts as $key => $value ) { - $data['attribute_counts'][ $taxonomy ][] = (object) [ + $data['attribute_counts'][ $taxonomy ][] = (object) array( 'taxonomy' => $taxonomy, 'termId' => $key, 'count' => $value, - ]; + ); } } } @@ -712,13 +712,13 @@ static function ( $query ) use ( $taxonomy ) { $counts = $filters->get_attribute_counts( $request, $taxonomy__and_queries ); foreach ( $taxonomy__and_queries as $taxonomy ) { - $data['attribute_counts'][ $taxonomy ] = []; + $data['attribute_counts'][ $taxonomy ] = array(); foreach ( $counts as $key => $value ) { - $data['attribute_counts'][ $taxonomy ][] = (object) [ + $data['attribute_counts'][ $taxonomy ][] = (object) array( 'taxonomy' => $taxonomy, 'termId' => $key, 'count' => $value, - ]; + ); } } } @@ -732,20 +732,20 @@ static function ( $query ) use ( $taxonomy ) { */ $filter_request = clone $request; $counts = $filters->get_rating_counts( $filter_request ); - $data['rating_counts'] = []; + $data['rating_counts'] = array(); foreach ( $counts as $key => $value ) { - $data['rating_counts'][] = (object) [ + $data['rating_counts'][] = (object) array( 'rating' => $key, 'count' => $value, - ]; + ); } } return $data; }, - ], - ] + ), + ) ); // Product queries. @@ -774,25 +774,25 @@ static function ( $query ) use ( $taxonomy ) { register_graphql_field( 'RootQuery', $field_name, - [ + array( 'type' => $type_name, /* translators: Product type slug */ 'description' => sprintf( __( 'A %s product object', 'wp-graphql-woocommerce' ), $type_key ), 'deprecationReason' => 'Use "product" instead.', - 'args' => [ - 'id' => [ + 'args' => array( + 'id' => array( 'type' => 'ID', 'description' => sprintf( /* translators: %s: product type */ __( 'The ID for identifying the %s product', 'wp-graphql-woocommerce' ), $type_name ), - ], - 'idType' => [ + ), + 'idType' => array( 'type' => 'ProductIdTypeEnum', 'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ), - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context ) use ( $type_key, $unsupported_type_enabled ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -837,7 +837,7 @@ static function ( $query ) use ( $taxonomy ) { return Factory::resolve_crud_object( $product_id, $context ); }, - ] + ) ); }//end foreach } diff --git a/includes/type/object/class-shipping-location-type.php b/includes/type/object/class-shipping-location-type.php index 5eb6997b6..c7bd82ef6 100644 --- a/includes/type/object/class-shipping-location-type.php +++ b/includes/type/object/class-shipping-location-type.php @@ -22,20 +22,20 @@ class Shipping_Location_Type { public static function register() { register_graphql_object_type( 'ShippingLocation', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'A Shipping zone object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'code' => [ + 'fields' => array( + 'code' => array( 'type' => 'String', 'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'type' => [ + ), + 'type' => array( 'type' => 'ShippingLocationTypeEnum', 'description' => __( 'Shipping zone location name.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-shipping-method-type.php b/includes/type/object/class-shipping-method-type.php index f86df1841..237ccc37c 100644 --- a/includes/type/object/class-shipping-method-type.php +++ b/includes/type/object/class-shipping-method-type.php @@ -22,28 +22,28 @@ class Shipping_Method_Type { public static function register() { register_graphql_object_type( 'ShippingMethod', - [ + array( 'description' => __( 'A shipping method object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ - 'type' => [ 'non_null' => 'ID' ], + ), + 'databaseId' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The ID of the shipping method in the database', 'wp-graphql-woocommerce' ), - ], - 'title' => [ + ), + 'title' => array( 'type' => 'String', 'description' => __( 'Shipping method title.', 'wp-graphql-woocommerce' ), - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'Shipping method description.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-shipping-package-type.php b/includes/type/object/class-shipping-package-type.php index 76ff18c95..34c4c5c7c 100644 --- a/includes/type/object/class-shipping-package-type.php +++ b/includes/type/object/class-shipping-package-type.php @@ -22,14 +22,14 @@ class Shipping_Package_Type { public static function register() { register_graphql_object_type( 'ShippingPackage', - [ + array( 'description' => __( 'Shipping package object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'packageDetails' => [ + 'fields' => array( + 'packageDetails' => array( 'type' => 'String', 'description' => __( 'Shipping package details', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { - $product_names = []; + $product_names = array(); foreach ( $source['contents'] as $item_id => $values ) { $product_names[ $item_id ] = html_entity_decode( $values['data']->get_name() . ' ×' . $values['quantity'] ); } @@ -39,24 +39,24 @@ public static function register() { return implode( ', ', $product_names ); }, - ], - 'rates' => [ - 'type' => [ 'list_of' => 'ShippingRate' ], + ), + 'rates' => array( + 'type' => array( 'list_of' => 'ShippingRate' ), 'description' => __( 'Shipping package rates', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source['rates'] ) ? $source['rates'] : null; }, - ], - 'supportsShippingCalculator' => [ + ), + 'supportsShippingCalculator' => array( 'type' => 'Boolean', 'description' => __( 'This shipping package supports the shipping calculator.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound return apply_filters( 'woocommerce_shipping_show_shipping_calculator', true, $source['index'], $source ); }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-shipping-rate-type.php b/includes/type/object/class-shipping-rate-type.php index e9e00edb1..5cf99f250 100644 --- a/includes/type/object/class-shipping-rate-type.php +++ b/includes/type/object/class-shipping-rate-type.php @@ -22,46 +22,46 @@ class Shipping_Rate_Type { public static function register() { register_graphql_object_type( 'ShippingRate', - [ + array( 'description' => __( 'Shipping rate object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Shipping rate ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_id() ) ? $source->get_id() : null; }, - ], - 'methodId' => [ - 'type' => [ 'non_null' => 'ID' ], + ), + 'methodId' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'Shipping method ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_method_id() ) ? $source->get_method_id() : null; }, - ], - 'instanceId' => [ + ), + 'instanceId' => array( 'type' => 'Int', 'description' => __( 'Shipping instance ID', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_instance_id() ) ? $source->get_instance_id() : null; }, - ], - 'label' => [ + ), + 'label' => array( 'type' => 'String', 'description' => __( 'Shipping rate label', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_label() ) ? $source->get_label() : null; }, - ], - 'cost' => [ + ), + 'cost' => array( 'type' => 'String', 'description' => __( 'Shipping rate cost', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return ! empty( $source->get_cost() ) ? $source->get_cost() : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-shipping-zone-type.php b/includes/type/object/class-shipping-zone-type.php index c4aac3261..54a4fd6b3 100644 --- a/includes/type/object/class-shipping-zone-type.php +++ b/includes/type/object/class-shipping-zone-type.php @@ -26,37 +26,37 @@ class Shipping_Zone_Type { public static function register() { register_graphql_object_type( 'ShippingZone', - [ + array( 'description' => __( 'A Shipping zone object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Shipping zone name.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'Shipping zone order.', 'wp-graphql-woocommerce' ), - ], - 'locations' => [ - 'type' => [ 'list_of' => 'ShippingLocation' ], + ), + 'locations' => array( + 'type' => array( 'list_of' => 'ShippingLocation' ), 'description' => __( 'Shipping zone locations.', 'wp-graphql-woocommerce' ), - ], - ], - 'connections' => [ - 'methods' => [ + ), + ), + 'connections' => array( + 'methods' => array( 'toType' => 'ShippingMethod', - 'edgeFields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'edgeFields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the shipping method.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $edge ) { if ( isset( $edge['node'] ) ) { @@ -67,8 +67,8 @@ public static function register() { } return null; }, - ], - 'instanceId' => [ + ), + 'instanceId' => array( 'type' => 'Int', 'description' => __( 'Shipping method instance ID.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $edge ) { @@ -78,8 +78,8 @@ public static function register() { } return null; }, - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'The order of the shipping method.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $edge ) { @@ -89,8 +89,8 @@ public static function register() { } return null; }, - ], - 'enabled' => [ + ), + 'enabled' => array( 'type' => 'Boolean', 'description' => __( 'Whether the shipping method is enabled.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $edge ) { @@ -101,12 +101,12 @@ public static function register() { } return false; }, - ], - 'settings' => [ - 'type' => [ 'list_of' => 'WCSetting' ], + ), + 'settings' => array( + 'type' => array( 'list_of' => 'WCSetting' ), 'description' => __( 'Shipping method settings.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $edge ) { - $settings = []; + $settings = array(); if ( isset( $edge['node'] ) ) { $shipping_method = $edge['node']->as_WC_Data(); $instance_settings = $shipping_method->instance_settings; @@ -116,25 +116,25 @@ public static function register() { $value = ! empty( $instance_settings[ $key ] ) ? $instance_settings[ $key ] : $default_value; $settings[] = array_merge( $field, - [ + array( 'id' => $key, 'value' => $value, - ] + ) ); } } return $settings; }, - ], - ], + ), + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-simple-attribute-type.php b/includes/type/object/class-simple-attribute-type.php index ceb4d71c4..a778300b1 100644 --- a/includes/type/object/class-simple-attribute-type.php +++ b/includes/type/object/class-simple-attribute-type.php @@ -22,11 +22,11 @@ class Simple_Attribute_Type { public static function register() { register_graphql_object_type( 'SimpleAttribute', - [ + array( 'description' => __( 'A simple attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Attribute' ], - 'fields' => [], - ] + 'interfaces' => array( 'Attribute' ), + 'fields' => array(), + ) ); } } diff --git a/includes/type/object/class-tax-class-type.php b/includes/type/object/class-tax-class-type.php index cb0319aad..6bd68411b 100644 --- a/includes/type/object/class-tax-class-type.php +++ b/includes/type/object/class-tax-class-type.php @@ -22,34 +22,34 @@ class Tax_Class_Type { public static function register() { register_graphql_object_type( 'TaxClass', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'A Tax class object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the tax class.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['slug'] ) ? \GraphQLRelay\Relay::toGlobalId( 'tax_class', $source['slug'] ) : null; }, - ], - 'slug' => [ + ), + 'slug' => array( 'type' => 'String', 'description' => __( 'The globally unique identifier for the tax class.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['slug'] ) ? $source['slug'] : null; }, - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Tax class name.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['name'] ) ? $source['name'] : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-tax-rate-type.php b/includes/type/object/class-tax-rate-type.php index c4e969a16..83fcfe793 100644 --- a/includes/type/object/class-tax-rate-type.php +++ b/includes/type/object/class-tax-rate-type.php @@ -22,74 +22,74 @@ class Tax_Rate_Type { public static function register() { register_graphql_object_type( 'TaxRate', - [ + array( 'description' => __( 'A Tax rate object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Node' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Node' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ), - ], - 'databaseId' => [ + ), + 'databaseId' => array( 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), - ], - 'country' => [ + ), + 'country' => array( 'type' => 'String', 'description' => __( 'Country ISO 3166 code.', 'wp-graphql-woocommerce' ), - ], - 'state' => [ + ), + 'state' => array( 'type' => 'String', 'description' => __( 'State code.', 'wp-graphql-woocommerce' ), - ], - 'postcode' => [ + ), + 'postcode' => array( 'type' => 'String', 'description' => __( 'Postcode/ZIP.', 'wp-graphql-woocommerce' ), 'deprecationReason' => 'Use "postcodes" instead.', - ], - 'city' => [ + ), + 'city' => array( 'type' => 'String', 'description' => __( 'City name.', 'wp-graphql-woocommerce' ), 'deprecationReason' => 'Use "cities" instead.', - ], - 'postcodes' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'postcodes' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'Postcodes/ZIPs.', 'wp-graphql-woocommerce' ), - ], - 'cities' => [ - 'type' => [ 'list_of' => 'String' ], + ), + 'cities' => array( + 'type' => array( 'list_of' => 'String' ), 'description' => __( 'City names.', 'wp-graphql-woocommerce' ), - ], - 'rate' => [ + ), + 'rate' => array( 'type' => 'String', 'description' => __( 'Tax rate.', 'wp-graphql-woocommerce' ), - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Tax rate name.', 'wp-graphql-woocommerce' ), - ], - 'priority' => [ + ), + 'priority' => array( 'type' => 'Int', 'description' => __( 'Tax priority.', 'wp-graphql-woocommerce' ), - ], - 'compound' => [ + ), + 'compound' => array( 'type' => 'Boolean', 'description' => __( 'Whether or not this is a compound rate.', 'wp-graphql-woocommerce' ), - ], - 'shipping' => [ + ), + 'shipping' => array( 'type' => 'Boolean', 'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'wp-graphql-woocommerce' ), - ], - 'order' => [ + ), + 'order' => array( 'type' => 'Int', 'description' => __( 'Indicates the order that will appear in queries.', 'wp-graphql-woocommerce' ), - ], - 'class' => [ + ), + 'class' => array( 'type' => 'TaxClassEnum', 'description' => __( 'Tax class. Default is standard.', 'wp-graphql-woocommerce' ), - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-variation-attribute-type.php b/includes/type/object/class-variation-attribute-type.php index 7b1fcbcb6..a7a9efc6c 100644 --- a/includes/type/object/class-variation-attribute-type.php +++ b/includes/type/object/class-variation-attribute-type.php @@ -22,25 +22,25 @@ class Variation_Attribute_Type { public static function register() { register_graphql_object_type( 'VariationAttribute', - [ + array( 'description' => __( 'A product variation attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => [ 'Attribute' ], - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'interfaces' => array( 'Attribute' ), + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The Global ID of the attribute.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['id'] ) ? $source['id'] : null; }, - ], - 'attributeId' => [ + ), + 'attributeId' => array( 'type' => 'Int', 'description' => __( 'The Database ID of the attribute.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['attributeId'] ) ? $source['attributeId'] : null; }, - ], - 'label' => [ + ), + 'label' => array( 'type' => 'String', 'description' => __( 'Label of attribute', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { @@ -50,23 +50,23 @@ public static function register() { return \wc_attribute_taxonomy_slug( $source['name'] ); }, - ], - 'name' => [ + ), + 'name' => array( 'type' => 'String', 'description' => __( 'Name of attribute', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['name'] ) ? $source['name'] : null; }, - ], - 'value' => [ + ), + 'value' => array( 'type' => 'String', 'description' => __( 'Selected value of attribute', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source ) { return isset( $source['value'] ) ? $source['value'] : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/type/object/class-wc-setting-type.php b/includes/type/object/class-wc-setting-type.php index 55d22ac5d..a767d77cc 100644 --- a/includes/type/object/class-wc-setting-type.php +++ b/includes/type/object/class-wc-setting-type.php @@ -22,68 +22,68 @@ class WC_Setting_Type { public static function register() { register_graphql_object_type( 'WCSetting', - [ + array( 'eagerlyLoadType' => true, 'description' => __( 'A WC setting object', 'wp-graphql-woocommerce' ), - 'fields' => [ - 'id' => [ - 'type' => [ 'non_null' => 'ID' ], + 'fields' => array( + 'id' => array( + 'type' => array( 'non_null' => 'ID' ), 'description' => __( 'The globally unique identifier for the WC setting.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['id'] ) ? $source['id'] : null; }, - ], - 'label' => [ + ), + 'label' => array( 'type' => 'String', 'description' => __( 'A human readable label for the setting used in user interfaces.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['title'] ) ? $source['title'] : null; }, - ], - 'description' => [ + ), + 'description' => array( 'type' => 'String', 'description' => __( 'A human readable description for the setting used in user interfaces.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['description'] ) ? $source['description'] : null; }, - ], - 'type' => [ + ), + 'type' => array( 'type' => 'WCSettingTypeEnum', 'description' => __( 'Type of setting.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['type'] ) ? $source['type'] : null; }, - ], - 'value' => [ + ), + 'value' => array( 'type' => 'String', 'description' => __( 'Setting value.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['value'] ) ? $source['value'] : null; }, - ], - 'default' => [ + ), + 'default' => array( 'type' => 'String', 'description' => __( 'Default value for the setting.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['default'] ) ? $source['default'] : null; }, - ], - 'tip' => [ + ), + 'tip' => array( 'type' => 'String', 'description' => __( 'Additional help text shown to the user about the setting', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['desc_tip'] ) ? $source['desc_tip'] : null; }, - ], - 'placeholder' => [ + ), + 'placeholder' => array( 'type' => 'String', 'description' => __( 'Placeholder text to be displayed in text inputs.', 'wp-graphql-woocommerce' ), 'resolve' => static function ( $source, array $args, $context, $info ) { return ! empty( $source['placeholder'] ) ? $source['placeholder'] : null; }, - ], - ], - ] + ), + ), + ) ); } } diff --git a/includes/utils/class-protected-router.php b/includes/utils/class-protected-router.php index 9935a5d3c..e3f47a536 100644 --- a/includes/utils/class-protected-router.php +++ b/includes/utils/class-protected-router.php @@ -60,17 +60,17 @@ private function init() { /** * Create the rewrite rule for the route */ - add_action( 'init', [ $this, 'add_rewrite_rule' ], 10 ); + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10 ); /** * Add the query var for the route */ - add_filter( 'query_vars', [ $this, 'add_query_var' ], 1, 1 ); + add_filter( 'query_vars', array( $this, 'add_query_var' ), 1, 1 ); /** * Redirects the route to the graphql processor */ - add_action( 'pre_get_posts', [ $this, 'resolve_request' ], 1 ); + add_action( 'pre_get_posts', array( $this, 'resolve_request' ), 1 ); } /** @@ -195,7 +195,7 @@ public function resolve_request() { * Remove the resolve_request function from the pre_get_posts action * to prevent an infinite loop */ - remove_action( 'pre_get_posts', [ $this, 'resolve_request' ], 1 ); + remove_action( 'pre_get_posts', array( $this, 'resolve_request' ), 1 ); /** * Access the $wp_query object @@ -228,9 +228,9 @@ public function resolve_request() { public static function get_nonce_names() { $enabled_authorizing_url_fields = WooCommerce_Filters::enabled_authorizing_url_fields(); if ( empty( $enabled_authorizing_url_fields ) ) { - return []; + return array(); } - $nonce_names = []; + $nonce_names = array(); foreach ( array_keys( $enabled_authorizing_url_fields ) as $field ) { $nonce_names[ $field ] = WooCommerce_Filters::get_authorizing_url_nonce_param_name( $field ); } diff --git a/includes/utils/class-ql-session-handler.php b/includes/utils/class-ql-session-handler.php index 210f2d90d..93dd65467 100644 --- a/includes/utils/class-ql-session-handler.php +++ b/includes/utils/class-ql-session-handler.php @@ -115,15 +115,15 @@ public function init() { * @var self $this */ if ( Router::is_graphql_http_request() ) { - add_action( 'woocommerce_set_cart_cookies', [ $this, 'set_customer_session_token' ], 10 ); - add_action( 'woographql_update_session', [ $this, 'set_customer_session_token' ], 10 ); - add_action( 'shutdown', [ $this, 'save_data' ] ); + add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_token' ), 10 ); + add_action( 'woographql_update_session', array( $this, 'set_customer_session_token' ), 10 ); + add_action( 'shutdown', array( $this, 'save_data' ) ); } else { - add_action( 'woocommerce_set_cart_cookies', [ $this, 'set_customer_session_cookie' ], 10 ); - add_action( 'shutdown', [ $this, 'save_data' ], 20 ); - add_action( 'wp_logout', [ $this, 'destroy_session' ] ); + add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 ); + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); if ( ! is_user_logged_in() ) { - add_filter( 'nonce_user_logged_out', [ $this, 'maybe_update_nonce_user_logged_out' ], 10, 2 ); + add_filter( 'nonce_user_logged_out', array( $this, 'maybe_update_nonce_user_logged_out' ), 10, 2 ); } } } @@ -338,15 +338,15 @@ public function build_token() { ); // Configure the token array, which will be encoded. - $token = [ + $token = array( 'iss' => get_bloginfo( 'url' ), 'iat' => $this->_session_issued, 'nbf' => $not_before, 'exp' => $this->_session_expiration, - 'data' => [ + 'data' => array( 'customer_id' => $this->_customer_id, - ], - ]; + ), + ); /** * Filter the token, allowing for individual systems to configure the token as needed @@ -453,7 +453,7 @@ public function set_session_expiration() { $this->_session_expiration = apply_filters( 'wc_session_expiration', $this->_session_issued + ( 60 * 60 * 48 ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $this->_session_expiration = apply_filters_deprecated( 'graphql_woocommerce_cart_session_expire', - [ $this->_session_expiration ], + array( $this->_session_expiration ), '0.21.0', 'wc_session_expiration' ); diff --git a/includes/utils/class-session-transaction-manager.php b/includes/utils/class-session-transaction-manager.php index be6b9d56b..58aa3b5eb 100644 --- a/includes/utils/class-session-transaction-manager.php +++ b/includes/utils/class-session-transaction-manager.php @@ -59,16 +59,16 @@ public static function get( &$session_handler ) { public function __construct( &$session_handler ) { $this->session_handler = $session_handler; - add_action( 'graphql_before_resolve_field', [ $this, 'update_transaction_queue' ], 10, 4 ); - add_action( 'graphql_mutation_response', [ $this, 'pop_transaction_id' ], 20, 6 ); + add_action( 'graphql_before_resolve_field', array( $this, 'update_transaction_queue' ), 10, 4 ); + add_action( 'graphql_mutation_response', array( $this, 'pop_transaction_id' ), 20, 6 ); - add_action( 'woographql_session_transaction_complete', [ $this->session_handler, 'save_if_dirty' ], 10 ); + add_action( 'woographql_session_transaction_complete', array( $this->session_handler, 'save_if_dirty' ), 10 ); - add_action( 'woocommerce_add_to_cart', [ $this->session_handler, 'mark_dirty' ] ); - add_action( 'woocommerce_cart_item_removed', [ $this->session_handler, 'mark_dirty' ] ); - add_action( 'woocommerce_cart_item_restored', [ $this->session_handler, 'mark_dirty' ] ); - add_action( 'woocommerce_cart_item_set_quantity', [ $this->session_handler, 'mark_dirty' ] ); - add_action( 'woocommerce_cart_emptied', [ $this->session_handler, 'mark_dirty' ] ); + add_action( 'woocommerce_add_to_cart', array( $this->session_handler, 'mark_dirty' ) ); + add_action( 'woocommerce_cart_item_removed', array( $this->session_handler, 'mark_dirty' ) ); + add_action( 'woocommerce_cart_item_restored', array( $this->session_handler, 'mark_dirty' ) ); + add_action( 'woocommerce_cart_item_set_quantity', array( $this->session_handler, 'mark_dirty' ) ); + add_action( 'woocommerce_cart_emptied', array( $this->session_handler, 'mark_dirty' ) ); } /** @@ -94,7 +94,7 @@ public static function get_session_mutations() { */ return \apply_filters( 'woographql_session_mutations', - [ + array( 'addToCart', 'updateItemQuantities', 'addFee', @@ -108,7 +108,7 @@ public static function get_session_mutations() { 'updateCustomer', 'updateSession', 'forgetSession', - ] + ) ); } @@ -191,7 +191,7 @@ public function get_transaction_queue() { // Get transaction queue. $transaction_queue = get_transient( "woo_session_transactions_queue_{$this->session_handler->get_customer_id()}" ); if ( ! $transaction_queue ) { - $transaction_queue = []; + $transaction_queue = array(); } // If transaction ID not in queue, add it, and start transaction. @@ -238,7 +238,7 @@ public function pop_transaction_id( $payload, $input, $unfiltered_input, $contex // Throw if transaction ID not on top. if ( $this->transaction_id !== $transaction_queue[0]['transaction_id'] ) { - $this->save_transaction_queue( [] ); + $this->save_transaction_queue( array() ); $this->transaction_id = null; throw new UserError( __( 'Woo session transaction executed out of order', 'wp-graphql-woocommerce' ) ); } else { @@ -267,7 +267,7 @@ public function pop_transaction_id( $payload, $input, $unfiltered_input, $contex * * @return void */ - public function save_transaction_queue( $queue = [] ) { + public function save_transaction_queue( $queue = array() ) { // If queue empty delete transient and bail. if ( empty( $queue ) ) { delete_transient( "woo_session_transactions_queue_{$this->session_handler->get_customer_id()}" ); diff --git a/tests/_config/wpunit.suite.yml b/tests/_config/wpunit.suite.yml new file mode 100644 index 000000000..2cd3807fb --- /dev/null +++ b/tests/_config/wpunit.suite.yml @@ -0,0 +1,13 @@ +actor: WPBrowserTester +modules: + enabled: + - WPBrowser + - \Helper\WP + config: + WPBrowser: + wpRootFolder: 'C:\xampp\htdocs\wordpress' # <-- full path to your WordPress + dbName: 'wordpress_test' + dbHost: '127.0.0.1' + dbUser: 'root' + dbPassword: '' + dbPrefix: 'wp_' diff --git a/tests/_support/Factory/CartFactory.php b/tests/_support/Factory/CartFactory.php index 15dc7bc3d..1601f6be2 100644 --- a/tests/_support/Factory/CartFactory.php +++ b/tests/_support/Factory/CartFactory.php @@ -20,7 +20,7 @@ class CartFactory { * @return array */ public function add( ...$products ) { - $keys = []; + $keys = array(); foreach ( $products as $product ) { if ( gettype( $product ) === 'array' ) { @@ -34,8 +34,8 @@ public function add( ...$products ) { $product['product_id'], ! empty( $product['quantity'] ) ? $product['quantity'] : 1, ! empty( $product['variation_id'] ) ? $product['variation_id'] : 0, - ! empty( $product['variation'] ) ? $product['variation'] : [], - ! empty( $product['cart_item_data'] ) ? $product['cart_item_data'] : [] + ! empty( $product['variation'] ) ? $product['variation'] : array(), + ! empty( $product['cart_item_data'] ) ? $product['cart_item_data'] : array() ); } else { WC()->cart->add_to_cart( $product, 1 ); diff --git a/tests/_support/Factory/CouponFactory.php b/tests/_support/Factory/CouponFactory.php index b90c2e550..7f8ebfbf6 100644 --- a/tests/_support/Factory/CouponFactory.php +++ b/tests/_support/Factory/CouponFactory.php @@ -17,9 +17,9 @@ class CouponFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'coupon_class' => '\WC_Coupon', - ]; + ); } public function create_object( $args ) { @@ -34,13 +34,13 @@ public function create_object( $args ) { $amount = Dummy::instance()->number( 25, 75 ); $coupon->set_props( array_merge( - [ + array( 'code' => $amount . 'off', 'amount' => floatval( $amount ), 'date_expires' => null, 'discount_type' => 'percent', 'description' => 'Test coupon', - ], + ), $args ) ); @@ -59,7 +59,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); diff --git a/tests/_support/Factory/CustomerFactory.php b/tests/_support/Factory/CustomerFactory.php index 9ba5f0cb4..0ad732392 100644 --- a/tests/_support/Factory/CustomerFactory.php +++ b/tests/_support/Factory/CustomerFactory.php @@ -17,7 +17,7 @@ class CustomerFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = []; + $this->default_generation_definitions = array(); $this->dummy = Factory::create(); } @@ -41,10 +41,10 @@ public function create_object( $args ) { $phone = $this->dummy->phoneNumber(); $args = array_merge( - [ - 'billing' => [], - 'shipping' => [], - ], + array( + 'billing' => array(), + 'shipping' => array(), + ), $args ); @@ -71,7 +71,7 @@ public function create_object( $args ) { // Set data. $customer->set_props( array_merge( - [ + array( 'email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, @@ -79,7 +79,7 @@ public function create_object( $args ) { 'role' => 'customer', 'username' => $username, 'is_paying_customer' => false, - ], + ), $args ) ); @@ -98,7 +98,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); diff --git a/tests/_support/Factory/OrderFactory.php b/tests/_support/Factory/OrderFactory.php index f9901cad9..5c68b2f16 100644 --- a/tests/_support/Factory/OrderFactory.php +++ b/tests/_support/Factory/OrderFactory.php @@ -15,7 +15,7 @@ class OrderFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'status' => '', 'customer_id' => 0, 'customer_note' => '', @@ -23,7 +23,7 @@ public function __construct( $factory = null ) { 'created_via' => '', 'cart_hash' => '', 'order_id' => 0, - ]; + ); } public function create_object( $args ) { @@ -36,7 +36,7 @@ public function create_object( $args ) { // Set props. foreach ( $args as $key => $value ) { - if ( is_callable( [ $order, "set_{$key}" ] ) ) { + if ( is_callable( array( $order, "set_{$key}" ) ) ) { $order->{"set_{$key}"}( $value ); } } @@ -50,7 +50,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); @@ -66,7 +66,7 @@ public function get_object_by_id( $id ) { return \wc_get_order( $id ); } - public function createNew( $args = [], $items = [] ) { + public function createNew( $args = array(), $items = array() ) { if ( ! isset( $args['customer_id'] ) ) { $customer = new \WC_Customer( $this->factory->customer->create() ); $args['customer_id'] = $customer->get_id(); @@ -88,10 +88,10 @@ public function createNew( $args = [], $items = [] ) { for ( $i = 0; $i < $random_amount; $i++ ) { $order = $this->add_line_item( $order, - [ + array( 'product' => $this->factory->product->createSimple(), 'qty' => rand( 1, 6 ), - ], + ), false ); } @@ -107,12 +107,12 @@ public function createNew( $args = [], $items = [] ) { $rate = new \WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' ); $item = new \WC_Order_Item_Shipping(); $item->set_props( - [ + array( 'method_title' => $rate->label, 'method_id' => $rate->id, 'total' => \wc_format_decimal( $rate->cost ), 'taxes' => $rate->taxes, - ] + ) ); foreach ( $rate->get_meta_data() as $key => $value ) { $item->add_meta_data( $key, $value, true ); @@ -140,7 +140,7 @@ public function createNew( $args = [], $items = [] ) { } } - public function add_line_item( $order, $args = [], $save = true ) { + public function add_line_item( $order, $args = array(), $save = true ) { $order = $save ? \wc_get_order( $order ) : $order; if ( ! empty( $args['variation_id'] ) ) { @@ -161,12 +161,12 @@ public function add_line_item( $order, $args = [], $save = true ) { $item = new \WC_Order_Item_Product(); $item->set_props( - [ + array( 'product' => $product, 'quantity' => $qty, - 'subtotal' => \wc_get_price_excluding_tax( $product, [ 'qty' => $qty ] ), - 'total' => \wc_get_price_excluding_tax( $product, [ 'qty' => $qty ] ), - ] + 'subtotal' => \wc_get_price_excluding_tax( $product, array( 'qty' => $qty ) ), + 'total' => \wc_get_price_excluding_tax( $product, array( 'qty' => $qty ) ), + ) ); // Set meta data. @@ -183,22 +183,22 @@ public function add_line_item( $order, $args = [], $save = true ) { $order->save(); } - public function add_shipping_line( $order, $args = [], $save = true ) { + public function add_shipping_line( $order, $args = array(), $save = true ) { $order = $save ? \wc_get_order( $order ) : $order; $this->factory->shipping_zone->createLegacyFlatRate(); $item = new WC_Order_Item_Shipping(); $item->set_props( array_merge( - [ + array( 'method_title' => 'Flat Rate', 'method_id' => 'flat_rate', 'total' => '', 'total_tax' => '', - 'taxes' => [ - 'total' => [], - ], - ], + 'taxes' => array( + 'total' => array(), + ), + ), $args ) ); @@ -227,7 +227,7 @@ public function add_coupon_line( $order, $coupon_id = 0, $save = true ) { // Create new coupon if $coupon_id not passed. if ( empty( $coupon_id ) ) { // Get order product IDs - $product_ids = []; + $product_ids = array(); foreach ( $order->get_items() as $item ) { if ( ! in_array( $item->get_product_id(), $product_ids, true ) ) { $product_ids[] = $item->get_product_id(); @@ -235,7 +235,7 @@ public function add_coupon_line( $order, $coupon_id = 0, $save = true ) { } $coupon = new \WC_Coupon( - $this->factory->coupon->create( [ 'product_ids' => $product_ids ] ) + $this->factory->coupon->create( array( 'product_ids' => $product_ids ) ) ); } else { $coupon = new \WC_Coupon( $coupon_id ); @@ -253,19 +253,19 @@ public function add_coupon_line( $order, $coupon_id = 0, $save = true ) { $order->save(); } - public function add_fee( $order, $args = [], $save = true ) { + public function add_fee( $order, $args = array(), $save = true ) { $order = \wc_get_order( $order ); // Get thre customer country code. $country_code = $order->get_shipping_country(); // Set the array for tax calculations. - $calculate_tax_for = [ + $calculate_tax_for = array( 'country' => $country_code, 'state' => '', 'postcode' => '', 'city' => '', - ]; + ); $imported_total_fee = 8.4342; @@ -301,7 +301,7 @@ public function add_fee( $order, $args = [], $save = true ) { $order->save(); } - public function add_tax( $order, $args = [], $save = true ) { + public function add_tax( $order, $args = array(), $save = true ) { $order = \wc_get_order( $order ); if ( empty( $args['rate_id'] ) ) { @@ -313,14 +313,14 @@ public function add_tax( $order, $args = [], $save = true ) { $item = new \WC_Order_Item_Tax(); $item->set_props( array_merge( - [ + array( 'rate_id' => $rate_id, 'tax_total' => 100.66, 'shipping_tax_total' => 150.45, 'rate_code' => \WC_Tax::get_rate_code( $rate_id ), 'label' => \WC_Tax::get_rate_label( $rate_id ), 'compound' => \WC_Tax::is_compound( $rate_id ), - ], + ), $args ) ); diff --git a/tests/_support/Factory/PaymentTokenFactory.php b/tests/_support/Factory/PaymentTokenFactory.php index 7ed9f5829..498b9cea7 100644 --- a/tests/_support/Factory/PaymentTokenFactory.php +++ b/tests/_support/Factory/PaymentTokenFactory.php @@ -18,7 +18,7 @@ class PaymentTokenFactory { * @since 2.6 * @return \WC_Payment_Token_CC object */ - public static function createCCToken( $user_id = '', $args = [] ) { + public static function createCCToken( $user_id = '', $args = array() ) { $token = new \WC_Payment_Token_CC(); $token->set_last4( 1234 ); $token->set_expiry_month( '08' ); @@ -31,7 +31,7 @@ public static function createCCToken( $user_id = '', $args = [] ) { // Set props. foreach ( $args as $key => $value ) { - if ( is_callable( [ $token, "set_{$key}" ] ) ) { + if ( is_callable( array( $token, "set_{$key}" ) ) ) { $token->{"set_{$key}"}( $value ); } } @@ -46,7 +46,7 @@ public static function createCCToken( $user_id = '', $args = [] ) { * @since 2.6 * @return \WC_Payment_Token_ECheck object */ - public static function createECheckToken( $user_id = '', $args = [] ) { + public static function createECheckToken( $user_id = '', $args = array() ) { $token = new \WC_Payment_Token_ECheck(); $token->set_last4( 1234 ); $token->set_token( time() ); @@ -57,7 +57,7 @@ public static function createECheckToken( $user_id = '', $args = [] ) { // Set props. foreach ( $args as $key => $value ) { - if ( is_callable( [ $token, "set_{$key}" ] ) ) { + if ( is_callable( array( $token, "set_{$key}" ) ) ) { $token->{"set_{$key}"}( $value ); } } @@ -73,14 +73,14 @@ public static function createECheckToken( $user_id = '', $args = [] ) { * @param string $extra A string to insert and get to test the metadata functionality of a token * @return \WC_Payment_Token_Stub object */ - public static function createStubToken( $extra, $args = [] ) { + public static function createStubToken( $extra, $args = array() ) { $token = new \WC_Payment_Token_Stub(); $token->set_extra( $extra ); $token->set_token( time() ); // Set props. foreach ( $args as $key => $value ) { - if ( is_callable( [ $token, "set_{$key}" ] ) ) { + if ( is_callable( array( $token, "set_{$key}" ) ) ) { $token->{"set_{$key}"}( $value ); } } diff --git a/tests/_support/Factory/ProductFactory.php b/tests/_support/Factory/ProductFactory.php index ee497a911..899b6b2e5 100644 --- a/tests/_support/Factory/ProductFactory.php +++ b/tests/_support/Factory/ProductFactory.php @@ -17,9 +17,9 @@ class ProductFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'product_class' => '\WC_Product_Simple', - ]; + ); } public function create_object( $args ) { @@ -32,7 +32,7 @@ public function create_object( $args ) { $product = new $product_class(); foreach ( $args as $key => $value ) { - if ( is_callable( [ $product, "set_{$key}" ] ) ) { + if ( is_callable( array( $product, "set_{$key}" ) ) ) { $product->{"set_{$key}"}( $value ); } } @@ -50,7 +50,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s product field.', $field, $object->get_type() ) ); @@ -66,12 +66,12 @@ public function get_object_by_id( $product_id ) { return \wc_get_product( absint( $product_id ) ); } - public function createSimple( $args = [] ) { + public function createSimple( $args = array() ) { $name = Dummy::instance()->product(); $price = Dummy::instance()->price( 15, 200 ); $regular_price = $price; - $generation_definitions = [ + $generation_definitions = array( 'name' => $name, 'slug' => $this->slugify( $name ), 'regular_price' => $regular_price, @@ -86,13 +86,13 @@ public function createSimple( $args = [] ) { 'description' => '[shortcode_test]', 'short_description' => Dummy::instance()->sentence(), 'product_class' => '\WC_Product_Simple', - ]; + ); return $this->create( $args, $generation_definitions ); } - public function createManySimple( $count = 5, $args = []) { - $products = []; + public function createManySimple( $count = 5, $args = array() ) { + $products = array(); for ( $i = 0; $i < $count; $i++ ) { $products[] = $this->createSimple( $args ); } @@ -100,11 +100,11 @@ public function createManySimple( $count = 5, $args = []) { return $products; } - public function createExternal( $args = [] ) { + public function createExternal( $args = array() ) { $name = Dummy::instance()->product(); $price = Dummy::instance()->price( 15, 200 ); - $generation_definitions = [ + $generation_definitions = array( 'name' => $name, 'slug' => $this->slugify( $name ), 'regular_price' => $price, @@ -112,58 +112,58 @@ public function createExternal( $args = [] ) { 'product_url' => 'http://woocommerce.com', 'button_text' => 'Buy external product', 'product_class' => '\WC_Product_External', - ]; + ); return $this->create( $args, $generation_definitions ); } - public function createGrouped( $args = [] ) { + public function createGrouped( $args = array() ) { $name = Dummy::instance()->product() . 'Group'; - $generation_definitions = [ + $generation_definitions = array( 'name' => $name, 'slug' => $this->slugify( $name ), 'sku' => uniqid(), 'product_class' => '\WC_Product_Grouped', - ]; + ); $args = array_merge( - [ 'children' => [ $this->createSimple() ] ], + array( 'children' => array( $this->createSimple() ) ), $args ); return $this->create( $args, $generation_definitions ); } - public function createVariable( $args = [] ) { + public function createVariable( $args = array() ) { $name = Dummy::instance()->product(); - $generation_definitions = [ + $generation_definitions = array( 'name' => $name, 'slug' => $this->slugify( $name ), 'sku' => uniqid(), 'product_class' => '\WC_Product_Variable', - ]; + ); $args = array_merge( - [ - 'attribute_data' => [ - $this->createAttribute( 'size', [ 'small', 'medium', 'large' ] ), // Create Size attribute. - $this->createAttribute( 'color', [ 'red', 'blue', 'green' ] ), // Create Color attribute. - [ + array( + 'attribute_data' => array( + $this->createAttribute( 'size', array( 'small', 'medium', 'large' ) ), // Create Size attribute. + $this->createAttribute( 'color', array( 'red', 'blue', 'green' ) ), // Create Color attribute. + array( 'attribute_id' => 0, 'attribute_taxonomy' => 'logo', - 'term_ids' => [ 'Yes', 'No' ], - ], // Create Logo attribute. - ], - ], + 'term_ids' => array( 'Yes', 'No' ), + ), // Create Logo attribute. + ), + ), $args ); return $this->create( $args, $generation_definitions ); } - public function createAttribute( $raw_name = 'size', $terms = [ 'small' ], $label = '' ) { + public function createAttribute( $raw_name = 'size', $terms = array( 'small' ), $label = '' ) { global $wpdb, $wc_product_attributes; // Make sure caches are clean. @@ -190,13 +190,13 @@ public function createAttribute( $raw_name = 'size', $terms = [ 'small' ], $labe unregister_taxonomy( $taxonomy_name ); $attribute_id = wc_create_attribute( - [ + array( 'name' => ! empty( $label ) ? $label : $raw_name, 'slug' => $raw_name, 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => 0, - ] + ) ); if ( is_wp_error( $attribute_id ) ) { @@ -207,23 +207,23 @@ public function createAttribute( $raw_name = 'size', $terms = [ 'small' ], $labe // Register as taxonomy. register_taxonomy( $taxonomy_name, - apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, [ 'product' ] ), + apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, array( 'product' ) ), apply_filters( 'woocommerce_taxonomy_args_' . $taxonomy_name, - [ - 'labels' => [ + array( + 'labels' => array( 'name' => ! empty( $label ) ? $label : $raw_name, - ], + ), 'hierarchical' => false, 'show_ui' => false, 'query_var' => true, 'rewrite' => false, - ], + ), ) ); // Set product attributes global. - $wc_product_attributes = []; + $wc_product_attributes = array(); foreach ( wc_get_attribute_taxonomies() as $taxonomy ) { $wc_product_attributes[ wc_attribute_taxonomy_name( $taxonomy->attribute_name ) ] = $taxonomy; @@ -231,12 +231,12 @@ public function createAttribute( $raw_name = 'size', $terms = [ 'small' ], $labe } $attribute = wc_get_attribute( $attribute_id ); - $return = [ + $return = array( 'attribute_name' => $attribute->name, 'attribute_taxonomy' => $attribute->slug, 'attribute_id' => $attribute_id, - 'term_ids' => [], - ]; + 'term_ids' => array(), + ); foreach ( $terms as $term ) { $result = term_exists( $term, $attribute->slug ); @@ -265,8 +265,8 @@ public function createAttributeObject( string $id, string $taxonomy, array $opti return $attribute; } - private function setVariationAttributes( \WC_Product_Variable $product, array $attribute_data = [] ) { - $attributes = []; + private function setVariationAttributes( \WC_Product_Variable $product, array $attribute_data = array() ) { + $attributes = array(); foreach ( $attribute_data as $index => $data ) { $attribute = new \WC_Product_Attribute(); $attribute->set_id( $data['attribute_id'] ); @@ -281,30 +281,30 @@ private function setVariationAttributes( \WC_Product_Variable $product, array $a $product->set_attributes( $attributes ); } - public function createRelated( $args = [] ) { - $cross_sell_ids = [ + public function createRelated( $args = array() ) { + $cross_sell_ids = array( $this->createSimple(), $this->createSimple(), - ]; - $upsell_ids = [ + ); + $upsell_ids = array( $this->createSimple(), $this->createSimple(), - ]; - $tag_ids = [ $this->createProductTag( 'related' ) ]; - $related_product_id = $this->createSimple( [ 'tag_ids' => $tag_ids ] ); + ); + $tag_ids = array( $this->createProductTag( 'related' ) ); + $related_product_id = $this->createSimple( array( 'tag_ids' => $tag_ids ) ); - return [ + return array( 'product' => $this->createSimple( - [ + array( 'tag_ids' => $tag_ids, 'cross_sell_ids' => $cross_sell_ids, 'upsell_ids' => $upsell_ids, - ] + ) ), - 'related' => [ $related_product_id ], + 'related' => array( $related_product_id ), 'cross_sell' => $cross_sell_ids, 'upsell' => $upsell_ids, - ]; + ); } public function createProductTag( $term ) { @@ -318,11 +318,11 @@ public function createProductTag( $term ) { } public function getStockStatusEnum( $status ) { - $statuses = [ + $statuses = array( 'instock' => 'IN_STOCK', 'outofstock' => 'OUT_OF_STOCK', 'onbackorder' => 'ON_BACKORDER', - ]; + ); if ( in_array( $status, array_keys( $statuses ), true ) ) { return $statuses[ $status ]; @@ -335,7 +335,7 @@ public function createProductCategory( $term, $parent_id = 0 ) { if ( term_exists( $term, 'product_cat' ) ) { $term = get_term( $term, 'product_cat', ARRAY_A ); } else { - $args = []; + $args = array(); if ( $parent_id ) { $args['parent'] = $parent_id; } @@ -353,17 +353,17 @@ public function createDownload( $id = 0 ) { if ( $id ) { $product = \wc_get_product( $id ); - $product->set_downloads( [ $download ] ); + $product->set_downloads( array( $download ) ); $product->save(); } return $download; } - public function createReview( $product_id, $args = [] ) { + public function createReview( $product_id, $args = array() ) { $firstName = Dummy::instance()->firstname(); $data = array_merge( - [ + array( 'comment_post_ID' => $product_id, 'comment_author' => $firstName, 'comment_author_email' => "{$firstName}@example.com", @@ -371,7 +371,7 @@ public function createReview( $product_id, $args = [] ) { 'comment_content' => Dummy::instance()->text(), 'comment_approved' => 1, 'comment_type' => 'review', - ], + ), $args ); diff --git a/tests/_support/Factory/ProductVariationFactory.php b/tests/_support/Factory/ProductVariationFactory.php index dff3d2277..98d48e62f 100644 --- a/tests/_support/Factory/ProductVariationFactory.php +++ b/tests/_support/Factory/ProductVariationFactory.php @@ -15,9 +15,9 @@ class ProductVariationFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'variation_class' => '\WC_Product_Variation', - ]; + ); } public function create_object( $args ) { @@ -31,7 +31,7 @@ public function create_object( $args ) { // Create variation. $variation = new $variation_class(); foreach ( $args as $field => $field_value ) { - if ( ! is_callable( [ $variation, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $variation, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s product variation field.', $field, $variation->get_type() ) ); @@ -59,7 +59,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s product variation field.', $field, $object->get_type() ) ); @@ -75,70 +75,70 @@ public function get_object_by_id( $product_id ) { return wc_get_product( absint( $product_id ) ); } - public function createSome( $product_id = null, $args = [] ) { + public function createSome( $product_id = null, $args = array() ) { if ( ! $product_id ) { $product_id = $this->factory->product->createVariable(); } $product = wc_get_product( $product_id ); // Create variation stub data. - $variation_data = [ - [ + $variation_data = array( + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pa_size' => 'small', 'logo' => 'Yes', - ], + ), 'image_id' => null, - 'downloads' => [ $this->factory->product->createDownload() ], + 'downloads' => array( $this->factory->product->createDownload() ), 'regular_price' => 10, - ], - [ + ), + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pa_size' => 'medium', 'logo' => 'No', - ], + ), 'image_id' => $this->factory->post->create( - [ + array( 'post_status' => 'publish', 'post_type' => 'attachment', 'post_content' => 'product image', - ] + ) ), - 'downloads' => [], + 'downloads' => array(), 'regular_price' => 15, - ], - [ + ), + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pa_size' => 'large', 'logo' => 'Yes', - ], + ), 'image_id' => null, - 'downloads' => [], + 'downloads' => array(), 'regular_price' => 20, - ], - ]; + ), + ); - $variations = []; + $variations = array(); foreach ( $variation_data as $data ) { $variation_args = array_merge( $data, $args ); - $variation = $this->create_and_get( $variation_args, [ 'variation_class' => '\WC_Product_Variation' ] ); + $variation = $this->create_and_get( $variation_args, array( 'variation_class' => '\WC_Product_Variation' ) ); $variations[] = $variation->get_id(); } $product->set_default_attributes( - [ + array( 'pa_size' => 'medium', - ] + ) ); $product->save(); - return [ + return array( 'product' => $product_id, 'variations' => $variations, - ]; + ); } } diff --git a/tests/_support/Factory/RefundFactory.php b/tests/_support/Factory/RefundFactory.php index 71fb9496d..6895b7df9 100644 --- a/tests/_support/Factory/RefundFactory.php +++ b/tests/_support/Factory/RefundFactory.php @@ -15,13 +15,13 @@ class RefundFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'amount' => 0, 'order_id' => 0, 'reason' => 'defective', 'refund_payment' => false, 'restock_items' => false, - ]; + ); } public function create_object( $args ) { @@ -41,7 +41,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { + if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); @@ -57,7 +57,7 @@ public function get_object_by_id( $id ) { return \wc_get_order( $id ); } - public function createNew( $order, $args = [] ) { + public function createNew( $order, $args = array() ) { $order = \wc_get_order( $order ); if ( empty( $order ) ) { @@ -66,13 +66,13 @@ public function createNew( $order, $args = [] ) { return $this->create( array_merge( - [ + array( 'amount' => floatval( $order->get_total() ), 'order_id' => $order->get_id(), 'reason' => 'defective', 'refund_payment' => false, 'restock_items' => false, - ], + ), $args ) ); diff --git a/tests/_support/Factory/ShippingZoneFactory.php b/tests/_support/Factory/ShippingZoneFactory.php index 32a0ea8c2..68b2cf41b 100644 --- a/tests/_support/Factory/ShippingZoneFactory.php +++ b/tests/_support/Factory/ShippingZoneFactory.php @@ -18,11 +18,10 @@ public function __construct( $factory = null ) { parent::__construct( $factory ); $this->dummy = Dummy::instance(); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'zone_name' => 'Test Shipping Zone ' . $this->dummy->number(), 'zone_order' => 0, - ]; - + ); } public function create_object( $args ) { @@ -53,7 +52,7 @@ public function create_object( $args ) { } foreach ( $args as $key => $value ) { - if ( is_callable( [ $object, "set_{$key}" ] ) ) { + if ( is_callable( array( $object, "set_{$key}" ) ) ) { $object->{"set_{$key}"}( $value ); } } @@ -87,7 +86,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $key => $value ) { - if ( is_callable( [ $object, "set_{$key}" ] ) ) { + if ( is_callable( array( $object, "set_{$key}" ) ) ) { $object->{"set_{$key}"}( $value ); } } @@ -116,37 +115,37 @@ public function reloadShippingMethods() { WC()->shipping()->load_shipping_methods(); } - public function createLegacyFlatRate( $args = [] ) { + public function createLegacyFlatRate( $args = array() ) { $flat_rate_settings = array_merge( - [ + array( 'enabled' => 'yes', 'title' => 'Flat rate', 'availability' => 'all', 'countries' => '', 'tax_status' => 'taxable', 'cost' => '10', - ], + ), $args ); update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings ); - update_option( 'woocommerce_flat_rate', [] ); + update_option( 'woocommerce_flat_rate', array() ); $this->reloadShippingMethods(); return 'legacy_flat_rate'; } - public function createLegacyFreeShipping( $args = [] ) { + public function createLegacyFreeShipping( $args = array() ) { $free_shipping_settings = array_merge( - [ + array( 'enabled' => 'yes', 'title' => 'Free shipping', 'availability' => 'all', 'countries' => '', - ], + ), $args ); update_option( 'woocommerce_free_shipping_settings', $free_shipping_settings ); - update_option( 'woocommerce_free_shipping', [] ); + update_option( 'woocommerce_free_shipping', array() ); $this->reloadShippingMethods(); return 'legacy_free_shipping'; diff --git a/tests/_support/Factory/TaxClassFactory.php b/tests/_support/Factory/TaxClassFactory.php index f6d589e27..5da09461a 100644 --- a/tests/_support/Factory/TaxClassFactory.php +++ b/tests/_support/Factory/TaxClassFactory.php @@ -17,25 +17,25 @@ class TaxClassFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'name' => '', - 'slug' => '', - ]; + 'slug' => '', + ); $this->dummy = Dummy::instance(); } - public function create_object( $args = [] ) { - $name = ! empty( $args['name'] ) ? $args['name'] : 'TaxClassNo' . Dummy::instance()->number(); - $slug = ! empty( $args['slug'] ) ? $args['slug'] : ''; + public function create_object( $args = array() ) { + $name = ! empty( $args['name'] ) ? $args['name'] : 'TaxClassNo' . Dummy::instance()->number(); + $slug = ! empty( $args['slug'] ) ? $args['slug'] : ''; $tax_class = \WC_Tax::create_tax_class( $name, $slug ); - if ( is_wp_error( $tax_class ) ) { - \codecept_debug( $tax_class->get_error_message() ); + if ( is_wp_error( $tax_class ) ) { + \codecept_debug( $tax_class->get_error_message() ); throw new \Exception( $tax_class->get_error_message() ); } - return $tax_class; + return $tax_class; } public function update_object( $object, $fields ) { @@ -44,15 +44,15 @@ public function update_object( $object, $fields ) { public function get_object_by_id( $slug ) { $tax_class = \WC_Tax::get_tax_class_by( 'slug', $slug ); - if ( ! $tax_class ) { - return null; - } + if ( ! $tax_class ) { + return null; + } - if ( is_wp_error( $tax_class ) ) { - \codecept_debug( $tax_class->get_error_message() ); - return null; - } + if ( is_wp_error( $tax_class ) ) { + \codecept_debug( $tax_class->get_error_message() ); + return null; + } - return $tax_class; + return $tax_class; } } diff --git a/tests/_support/Factory/TaxRateFactory.php b/tests/_support/Factory/TaxRateFactory.php index f9fa00333..dad454096 100644 --- a/tests/_support/Factory/TaxRateFactory.php +++ b/tests/_support/Factory/TaxRateFactory.php @@ -17,9 +17,9 @@ class TaxRateFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = [ + $this->default_generation_definitions = array( 'zone_name' => '', - ]; + ); $this->dummy = Dummy::instance(); } @@ -28,8 +28,8 @@ public function create_object( $args ) { codecept_debug( $args ); } - $rate_args = []; - $fields = [ + $rate_args = array(); + $fields = array( 'country' => 'tax_rate_country', 'state' => 'tax_rate_state', 'rate' => 'tax_rate', @@ -39,7 +39,7 @@ public function create_object( $args ) { 'shipping' => 'tax_rate_shipping', 'order' => 'tax_rate_order', 'class' => 'tax_rate_class', - ]; + ); foreach ( $args as $key => $value ) { if ( in_array( $key, array_keys( $fields ), true ) ) { @@ -48,7 +48,7 @@ public function create_object( $args ) { } $rate_args = array_merge( - [ + array( 'tax_rate_country' => 'US', 'tax_rate_state' => '*', 'tax_rate' => 20.0000, @@ -57,7 +57,7 @@ public function create_object( $args ) { 'tax_rate_compound' => 1, 'tax_rate_shipping' => 1, 'tax_rate_order' => 0, - ], + ), $rate_args ); @@ -92,7 +92,7 @@ public function get_object_by_id( $id ) { foreach ( $locales as $locale ) { if ( empty( $rate->{'tax_rate_' . $locale->location_type} ) ) { - $rate->{'tax_rate_' . $locale->location_type} = []; + $rate->{'tax_rate_' . $locale->location_type} = array(); } $rate->{'tax_rate_' . $locale->location_type}[] = $locale->location_code; } diff --git a/tests/_support/Helper/GraphQLE2E.php b/tests/_support/Helper/GraphQLE2E.php index 1f2c69503..4aafa01b8 100644 --- a/tests/_support/Helper/GraphQLE2E.php +++ b/tests/_support/Helper/GraphQLE2E.php @@ -19,7 +19,7 @@ public function wantHTTPResponseHeaders( $headers ) { return $rest->grabHttpHeader( $headers ); } - $response_headers = []; + $response_headers = array(); foreach ( $headers as $header ) { $rest->seeHttpHeaderOnce( $header ); $response_headers[] = $rest->grabHttpHeader( $header ); @@ -33,7 +33,7 @@ public function wantHTTPResponseHeaders( $headers ) { * @param string $session_header * @return array */ - public function login( $input, $request_headers = [] ) { + public function login( $input, $request_headers = array() ) { $mutation = ' mutation ( $input: LoginInput! ) { login( input: $input ) { @@ -61,7 +61,7 @@ public function login( $input, $request_headers = [] ) { * * @return array */ - public function addToCart( $input, $request_headers = [] ) { + public function addToCart( $input, $request_headers = array() ) { // Add to cart mutation $mutation = ' mutation ( $input: AddToCartInput! ) { @@ -101,7 +101,7 @@ public function addToCart( $input, $request_headers = [] ) { * * @return array */ - public function updateItemQuantities( $input, $request_headers = [] ) { + public function updateItemQuantities( $input, $request_headers = array() ) { // Update cart items mutation $mutation = ' mutation updateItemQuantities( $input: UpdateItemQuantitiesInput! ) { @@ -134,7 +134,7 @@ public function updateItemQuantities( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function removeItemsFromCart( $input, $request_headers = [] ) { + public function removeItemsFromCart( $input, $request_headers = array() ) { // Remove item from cart mutation $mutation = ' mutation ( $input: RemoveItemsFromCartInput! ) { @@ -173,7 +173,7 @@ public function removeItemsFromCart( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function restoreCartItems( $input, $request_headers = [] ) { + public function restoreCartItems( $input, $request_headers = array() ) { $mutation = ' mutation restoreCartItems( $input: RestoreCartItemsInput! ) { restoreCartItems( input: $input ) { @@ -211,7 +211,7 @@ public function restoreCartItems( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function emptyCart( $input, $request_headers = [] ) { + public function emptyCart( $input, $request_headers = array() ) { $mutation = ' mutation emptyCart( $input: EmptyCartInput! ) { emptyCart( input: $input ) { @@ -253,7 +253,7 @@ public function emptyCart( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function addFee( $input, $request_headers = [] ) { + public function addFee( $input, $request_headers = array() ) { $mutation = ' mutation addFee( $input: AddFeeInput! ) { addFee( input: $input ) { @@ -281,7 +281,7 @@ public function addFee( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function applyCoupon( $input, $request_headers = [] ) { + public function applyCoupon( $input, $request_headers = array() ) { $mutation = ' mutation applyCoupon( $input: ApplyCouponInput! ) { applyCoupon( input: $input ) { @@ -321,7 +321,7 @@ public function applyCoupon( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function removeCoupons( $input, $request_headers = [] ) { + public function removeCoupons( $input, $request_headers = array() ) { $mutation = ' mutation removeCoupons( $input: RemoveCouponsInput! ) { removeCoupons( input: $input ) { @@ -359,7 +359,7 @@ public function removeCoupons( $input, $request_headers = [] ) { * @param string $session_header * @return array */ - public function updateShippingMethod( $input, $request_headers = [] ) { + public function updateShippingMethod( $input, $request_headers = array() ) { // updateShippingMethod mutation. $mutation = ' mutation ($input: UpdateShippingMethodInput!){ @@ -397,7 +397,7 @@ public function updateShippingMethod( $input, $request_headers = [] ) { * * @return array */ - public function checkout( $input, $request_headers = [] ) { + public function checkout( $input, $request_headers = array() ) { // Checkout mutation. $mutation = ' mutation checkout( $input: CheckoutInput! ) { @@ -578,7 +578,7 @@ public function checkout( $input, $request_headers = [] ) { * * @return array */ - public function sendGraphQLRequest( $query, $input, $request_headers = [] ) { + public function sendGraphQLRequest( $query, $input, $request_headers = array() ) { $rest = $this->getModule( 'REST' ); // Add item to cart. @@ -593,10 +593,10 @@ public function sendGraphQLRequest( $query, $input, $request_headers = [] ) { $rest->sendPost( '/graphql', json_encode( - [ + array( 'query' => $query, - 'variables' => [ 'input' => $input ], - ] + 'variables' => array( 'input' => $input ), + ) ) ); @@ -629,50 +629,50 @@ public function sendGraphQLRequest( $query, $input, $request_headers = [] ) { public function getCatalog() { $this->_setupStore(); - $product_catalog = []; - $products = [ - [ + $product_catalog = array(); + $products = array( + array( 'post_title' => 't-shirt', - 'meta_input' => [ + 'meta_input' => array( '_price' => 45, '_regular_price' => 45, - ], - ], - [ + ), + ), + array( 'post_title' => 'jeans', - 'meta_input' => [ + 'meta_input' => array( '_price' => 60, '_regular_price' => 60, - ], - ], - [ + ), + ), + array( 'post_title' => 'belt', - 'meta_input' => [ + 'meta_input' => array( '_price' => 45, '_regular_price' => 45, - ], - ], - [ + ), + ), + array( 'post_title' => 'shoes', - 'meta_input' => [ + 'meta_input' => array( '_price' => 115, '_regular_price' => 115, - ], - ], - [ + ), + ), + array( 'post_title' => 'socks', - 'meta_input' => [ + 'meta_input' => array( '_price' => 20, '_regular_price' => 20, - ], - ], - ]; + ), + ), + ); foreach ( $products as $product ) { $this->haveAProductInTheDatabase( $product, $product_id ); $product_catalog[ $product['post_title'] ] = $product_id; } - $cart_page_content = ' + $cart_page_content = '
@@ -836,28 +836,28 @@ public function getCatalog() { '; // Create cart page. - $wpdb = $this->getModule( 'WPDb' ); - + $wpdb = $this->getModule( 'WPDb' ); + $cart_page_id = $wpdb->havePostInDatabase( - [ + array( 'post_type' => 'page', 'post_title' => 'Cart', 'post_name' => 'cart', 'post_author' => 1, 'post_content' => $cart_page_content, 'post_status' => 'publish', - ] + ) ); $wpdb->haveOptionInDatabase( 'woocommerce_cart_page_id', $cart_page_id ); $checkout_page_id = $wpdb->havePostInDatabase( - [ + array( 'post_type' => 'page', 'post_title' => 'Checkout', 'post_name' => 'checkout', 'post_author' => 1, 'post_content' => $checkout_page_content, 'post_status' => 'publish', - ] + ) ); $wpdb->haveOptionInDatabase( 'woocommerce_checkout_page_id', $checkout_page_id ); @@ -883,19 +883,19 @@ public function _setupStore() { // Enable payment gateway. $wpdb->haveOptionInDatabase( 'woocommerce_bacs_settings', - [ + array( '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. + // Additional cart fees. add_action( 'woocommerce_cart_calculate_fees', static function () { @@ -939,15 +939,15 @@ static function () { $zone->add_shipping_method( 'flat_rate' ); $zone->add_shipping_method( 'free_shipping' ); - global $wp_rewrite; + global $wp_rewrite; - //Write the rule - $wp_rewrite->set_permalink_structure('/%postname%/'); + // Write the rule + $wp_rewrite->set_permalink_structure( '/%postname%/' ); - //Set the option - update_option( "rewrite_rules", FALSE ); + // Set the option + update_option( 'rewrite_rules', false ); - //Flush the rules and tell it to write htaccess + // Flush the rules and tell it to write htaccess $wp_rewrite->flush_rules( true ); } @@ -967,10 +967,10 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple' // Create Product $product_id = $wpdb->havePostInDatabase( array_replace_recursive( - [ + array( 'post_type' => 'product', 'post_title' => 't-shirt', - 'meta_input' => [ + 'meta_input' => array( '_visibility' => 'visible', '_sku' => '', '_price' => '100', @@ -991,38 +991,38 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple' '_length' => '', '_width' => '', '_height' => '', - '_upsell_ids' => [], - '_cross_sell_ids' => [], + '_upsell_ids' => array(), + '_cross_sell_ids' => array(), '_purchase_note' => '', - '_default_attributes' => [], - '_product_attributes' => [], + '_default_attributes' => array(), + '_product_attributes' => array(), '_virtual' => false, '_downloadable' => false, '_download_limit' => -1, '_download_expiry' => -1, '_featured' => false, - '_wc_rating_counts' => [], + '_wc_rating_counts' => array(), '_wc_average_rating' => 0, '_wc_review_count' => 0, - ], - ], + ), + ), $args ) ); if ( ! $term_id ) { $term_id = $wpdb->grabTermIdFromDatabase( - [ + array( 'name' => $term, 'slug' => $term, - ] + ) ); } $term_taxonomy_id = $wpdb->grabTermTaxonomyIdFromDatabase( - [ + array( 'term_id' => $term_id, 'taxonomy' => 'product_type', - ] + ) ); $wpdb->haveTermRelationshipInDatabase( $product_id, $term_id ); } @@ -1034,10 +1034,10 @@ public function setupStoreAndUsers() { $userId = $wpdb->haveUserInDatabase( 'jimbo1234', 'customer', - [ + array( 'user_pass' => 'password', 'user_email' => 'jimbo1234@example.com', - ] + ) ); } diff --git a/tests/_support/Helper/Wpunit.php b/tests/_support/Helper/Wpunit.php index b0307f53e..b84493d48 100644 --- a/tests/_support/Helper/Wpunit.php +++ b/tests/_support/Helper/Wpunit.php @@ -30,10 +30,10 @@ public function _initialize() { */ public function _beforeSuite( $settings = null ) { $helper = $this->product(); - $helper->create_attribute( 'size', [ 'small', 'medium', 'large' ], 'Product size' ); - $helper->create_attribute( 'color', [ 'red', 'blue', 'green' ], 'Product color' ); + $helper->create_attribute( 'size', array( 'small', 'medium', 'large' ), 'Product size' ); + $helper->create_attribute( 'color', array( 'red', 'blue', 'green' ), 'Product color' ); codecept_debug( 'ATTRIBUTES_LOADED' ); - add_action( 'init_graphql_request', [ self::class, 'shortcode_test_init' ] ); + add_action( 'init_graphql_request', array( self::class, 'shortcode_test_init' ) ); codecept_debug( 'SHORTCODE_INITIALIZED' ); \Stripe\Stripe::setApiKey( defined( 'STRIPE_API_SECRET_KEY' ) ? STRIPE_API_SECRET_KEY : getenv( 'STRIPE_API_SECRET_KEY' ) @@ -81,12 +81,12 @@ public function tax_rate() { } public function get_nodes( $ids, $crud ) { - $nodes = []; + $nodes = array(); foreach ( $ids as $id ) { $nodes[] = $crud->get_query_data( $id ); } - return [ 'nodes' => $nodes ]; + return array( 'nodes' => $nodes ); } public function clear_loader_cache( $loader_name ) { @@ -95,7 +95,7 @@ public function clear_loader_cache( $loader_name ) { } public static function shortcode_test_init() { - add_shortcode( 'shortcode_test', [ self::class, 'shortcode_test_handler' ] ); + add_shortcode( 'shortcode_test', array( self::class, 'shortcode_test_handler' ) ); } public static function shortcode_test_handler( $atts ) { diff --git a/tests/_support/Helper/crud-helpers/cart.php b/tests/_support/Helper/crud-helpers/cart.php index 004f2779f..4bd0b3f05 100644 --- a/tests/_support/Helper/crud-helpers/cart.php +++ b/tests/_support/Helper/crud-helpers/cart.php @@ -10,7 +10,7 @@ public function to_relay_id( $id ) { public function add( ...$products ) { $keys = array(); - foreach( $products as $product ) { + foreach ( $products as $product ) { if ( gettype( $product ) === 'array' ) { if ( empty( $product['product_id'] ) ) { codecept_debug( $product ); @@ -51,9 +51,9 @@ public function print_query( $id = 0 ) { 'isEmpty' => $cart->is_empty(), 'displayPricesIncludeTax' => $cart->display_prices_including_tax(), 'needsShippingAddress' => $cart->needs_shipping_address(), - 'totalTaxes' => ! empty( $cart->get_tax_totals() ) + 'totalTaxes' => ! empty( $cart->get_tax_totals() ) ? array_map( - function( $tax_data ) { + function ( $tax_data ) { return array( 'id' => $tax_data->tax_rate_id, 'label' => $tax_data->label, @@ -79,8 +79,8 @@ public function print_item_query( $key ) { if ( ! empty( $variation ) ) { $variation = \wc_get_product( $variation ); foreach ( $variation->get_attributes() as $name => $default_value ) { - if ( isset( $variation_data["attribute_{$name}"] ) ) { - $value = $variation_data["attribute_{$name}"]; + if ( isset( $variation_data[ "attribute_{$name}" ] ) ) { + $value = $variation_data[ "attribute_{$name}" ]; } else { $value = $default_value; } @@ -145,7 +145,7 @@ public function print_fee_query( $id ) { $fees = $cart->get_fees(); $fee = ! empty( $fees[ $id ] ) ? $fees[ $id ] : null; - return !empty( $fee ) + return ! empty( $fee ) ? array( 'id' => $fee->id, 'name' => $fee->name, @@ -158,15 +158,15 @@ public function print_fee_query( $id ) { } public function print_nodes( $processors = array(), $_ = null ) { - $cart = WC()->cart; - $ids = array_keys( $cart->get_cart() ); + $cart = WC()->cart; + $ids = array_keys( $cart->get_cart() ); $default_processors = array( - 'mapper' => function( $key ) { + 'mapper' => function ( $key ) { return array( 'key' => $key ); }, - 'filter' => function( $key ) { + 'filter' => function ( $key ) { return true; - } + }, ); $processors = array_merge( $default_processors, $processors ); @@ -177,24 +177,24 @@ public function print_nodes( $processors = array(), $_ = null ) { } public function print_fee_nodes( $processors = array(), $_ = null ) { - $cart = WC()->cart; - $ids = array_keys( $cart->get_fees() ); + $cart = WC()->cart; + $ids = array_keys( $cart->get_fees() ); $default_processors = array( - 'mapper' => function( $id ) { + 'mapper' => function ( $id ) { return array( 'id' => $id ); }, - 'sorter' => function( $id_a, $id_b ) { + 'sorter' => function ( $id_a, $id_b ) { return 0; }, - 'filter' => function( $id ) { + 'filter' => function ( $id ) { return true; - } + }, ); $processors = array_merge( $default_processors, $processors ); $results = array_filter( $ids, $processors['filter'] ); - if( ! empty( $results ) ) { + if ( ! empty( $results ) ) { usort( $results, $processors['sorter'] ); } diff --git a/tests/_support/Helper/crud-helpers/coupon.php b/tests/_support/Helper/crud-helpers/coupon.php index b9e57cd48..015386ff0 100644 --- a/tests/_support/Helper/crud-helpers/coupon.php +++ b/tests/_support/Helper/crud-helpers/coupon.php @@ -22,11 +22,11 @@ public function create( $args = array(), $save = true ) { $coupon->set_props( array_merge( array( - 'code' => $amount . 'off', - 'amount' => floatval( $amount ), - 'date_expires' => null, - 'discount_type' => 'percent', - 'description' => 'Test coupon', + 'code' => $amount . 'off', + 'amount' => floatval( $amount ), + 'date_expires' => null, + 'discount_type' => 'percent', + 'description' => 'Test coupon', ), $args ) @@ -38,7 +38,7 @@ public function create( $args = array(), $save = true ) { } // Return instance in not saving. - if( ! $save ) { + if ( ! $save ) { return $coupon; } @@ -79,46 +79,46 @@ public function print_query( $id ) { 'emailRestrictions' => ! empty( $data->get_email_restrictions() ) ? $data->get_email_restrictions() : null, - 'products' => [ + 'products' => array( 'nodes' => array_map( - function( $id ) { + function ( $id ) { return array( 'databaseId' => $id ); }, $data->get_product_ids() ), - ], - 'excludedProducts' => [ + ), + 'excludedProducts' => array( 'nodes' => array_map( - function( $id ) { + function ( $id ) { return array( 'databaseId' => $id ); }, $data->get_excluded_product_ids() ), - ], - 'productCategories' => [ + ), + 'productCategories' => array( 'nodes' => array_map( - function( $id ) { + function ( $id ) { return array( 'productCategoryId' => $id ); }, $data->get_product_categories() ), - ], - 'excludedProductCategories' => [ + ), + 'excludedProductCategories' => array( 'nodes' => array_map( - function( $id ) { + function ( $id ) { return array( 'productCategoryId' => $id ); }, $data->get_excluded_product_categories() ), - ], - 'usedBy' => [ + ), + 'usedBy' => array( 'nodes' => array_map( - function( $id ) { + function ( $id ) { return array( 'databaseId' => $id ); }, $data->get_used_by() ), - ], + ), ); } diff --git a/tests/_support/Helper/crud-helpers/customer.php b/tests/_support/Helper/crud-helpers/customer.php index ae8f05b74..fc6b6e138 100644 --- a/tests/_support/Helper/crud-helpers/customer.php +++ b/tests/_support/Helper/crud-helpers/customer.php @@ -39,28 +39,28 @@ public function create( $args = array() ) { 'role' => 'customer', 'username' => $username, 'billing' => array( - 'first_name' => $first_name, - 'last_name' => $last_name, - 'company' => '', - 'address_1' => $street, - 'address_2' => '', - 'city' => $city, - 'state' => $state, - 'postcode' => $postcode, - 'country' => $country, - 'email' => $email, - 'phone' => $phone, + 'first_name' => $first_name, + 'last_name' => $last_name, + 'company' => '', + 'address_1' => $street, + 'address_2' => '', + 'city' => $city, + 'state' => $state, + 'postcode' => $postcode, + 'country' => $country, + 'email' => $email, + 'phone' => $phone, ), 'shipping' => array( - 'first_name' => $first_name, - 'last_name' => $last_name, - 'company' => '', - 'address_1' => $street, - 'address_2' => '', - 'city' => $city, - 'state' => $state, - 'postcode' => $postcode, - 'country' => $country, + 'first_name' => $first_name, + 'last_name' => $last_name, + 'company' => '', + 'address_1' => $street, + 'address_2' => '', + 'city' => $city, + 'state' => $state, + 'postcode' => $postcode, + 'country' => $country, ), 'is_paying_customer' => false, ), @@ -77,7 +77,7 @@ public function create( $args = array() ) { } public function print_query( $id, $session = false ) { - $data = new WC_Customer( $id, $session ); + $data = new WC_Customer( $id, $session ); $wp_user = get_user_by( 'ID', $data->get_id() ); return array( diff --git a/tests/_support/Helper/crud-helpers/includes/class-dummy.php b/tests/_support/Helper/crud-helpers/includes/class-dummy.php index b950ae368..5231fd9dd 100644 --- a/tests/_support/Helper/crud-helpers/includes/class-dummy.php +++ b/tests/_support/Helper/crud-helpers/includes/class-dummy.php @@ -1,8 +1,7 @@ username(); - $fn = $this->firstname(); - $ln = $this->lastname(); - - $dump = array( - "primaryText" => $this->words(6), - "secondaryText" => $this->sentence(), - "userid" => $this->number(), - "rid" => $this->number(), - - "link" => "http://www.google.com", - "date" => $this->mdy(), - "time" => $this->hm(), - "text" => $this->text(40,140), - "body" => $this->text(140,600), - "number" => $this->number(), - "background" => $this->image(640,480), - "image" => $this->image(), - "thumbnail" => $this->placeholder(150,150), - "price" => $this->price(), - "product" => $this->product(), - "firstname" => $fn, - "lastname" => $ln, - "name" => $fn." ".$ln, - "username" => $un, - "email" => $this->email($un), - "street" => $this->street(), - "city" => $this->city(), - "state" => $this->state(), - "zipcode" => $this->zipcode(), - "telephone" => $this->telephone() - ); - - return($dump); - } - - public function dump( $qty = 5 ) { - $a = array(); - - for($b=0;$b<$qty;$b++) { - $a[] = $this->all(); - } - - return($a); - } - - public function yesno( $w = 5 ) { - if (rand(0,10) > $w) { - return(true); - } else { - return(false); - } - } - - public function mdy() { - return(rand(1,12)."/".rand(1,30)."/".rand(1943,2010)); - } - - public function hm( $s = false ) { - $t = rand(1,12).":".rand(10,59); - - if ($s) { $t = $t.":".rand(10,59); } - - if ($this->yesno()) { $t .= " AM"; } else { $t .= " PM"; } - - return($t); - } - - public function text( $min = 30, $max = 120, $nospaces = false ) { - $s = "Aliquam lectus nulla, eleifend ut tellus in, euismod porttitor arcu. Aliquam erat volutpat. Morbi massa sapien, condimentum ultrices pretium porta, semper ac lacus. Nulla pharetra, urna a lacinia facilisis, neque libero placerat turpis, vel tincidunt massa nunc ac nunc. In nec volutpat ligula. Sed hendrerit ligula vel felis venenatis egestas. Duis sit amet pharetra erat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi rutrum vel magna et tincidunt. Curabitur mattis, sem eget suscipit porta, nibh enim auctor mi, eu lacinia magna velit eu quam. Donec commodo ultrices lorem vel ultrices. Aliquam erat volutpat. Praesent in libero bibendum, euismod dui quis, volutpat purus. Fusce non est egestas, volutpat ipsum ut, cursus augue. In hac habitasse platea dictumst. Mum volutpat."; - $s = explode(" ",$s); - shuffle($s); - $s = implode(" ", $s); - $s = ucfirst(substr($s, 0, rand($min,$max))); - - if ($nospaces) { - $s = str_replace(" ","",$s); - } - - return($s); - } - - public function words( $max = 5, $cmin = 2, $cmax = 6) { - $t = array(); - - for ($a=0; $a <= ($max-1); $a++) { - $t[] = str_replace(array(",","."), array("",""), $this->text($cmin, ($cmax+2), true)); - } - - return(implode(" ",$t)); - } - - public function sentence( $min = 3, $max = 10 ) { - $l = rand($min,$max); - - $w = ucfirst(strtolower($this->words($l)))."."; - return($w); - } - - function number($min=10, $max=1000) { - return(round(rand($min,$max))); - } - - public function image( $w = 300, $h = 300 ) { - $c = array("city","people","animals","food","business","cats","technics","sports"); - shuffle($c); - $u = "http://lorempixel.com/".$w."/".$h."/".current($c); - - return($u); - } - - public function placeholder( $w = 300, $h = 300 ) { - return("http://placehold.it/".$w."x".$h); - } - - public function price( $min = 2, $max = 500 ) { - $c = array("00","99","49","00","50","29"); shuffle($c); - $p = rand($min,$max).".".current($c); - return($p); - } - - public function product() { - $items = "book,exam,hub cap,paperclip,model train,phaser,socks,light saber,lamp,piano,salad,lunch,violin,pony,deoderant,powder,radio,purse,mp3 player,eyeliner,laptop,wheel,glove,boot,pen,slippers,bed,dog,wall,paper,cellular phone,clock,tree,guitar,mullet,dog,cushion,table,ginger,roundabout,cake,teapot,dreadlocks,lampshade,piggy bank,church,eagle,butterfly,keyboard,laptop"; - $adj1 = "original,brand new,mint,new-in-box,trendy,vintage,retro,old,new,gently used,big,small,tarnished,broken,refurbished"; - $adj2 = "hipster,red,blue,green,orange,muddy,waterproof,purple,stainless steel,24k gold,handmade,custom"; - - $a = explode(",",$adj1); - $a2 = explode(",",$adj2); - $i = explode(",",$items); - shuffle($a); - shuffle($a2); - shuffle($i); - - //$t = ucfirst($a[0]." ".$a2[3]." ".$i[1]); - $t = ucfirst($a2[3]." ".$i[1]); - return($t); - } - - public function firstname( $gender = "any" ) { - $m = explode(",","James,John,Robert,Michael,William,David,Richard,Charles,Joseph,Thomas,Christopher,Daniel,Paul,Mark,Donald,George,Kenneth,Steven,Edward,Brian,Ronald,Anthony,Kevin,Jason,Matthew,Gary,Timothy,Jose,Larry,Jeffrey,Frank,Scott,Eric,Stephen,Andrew,Raymond,Gregory,Joshua,Jerry,Dennis,Walter,Patrick,Peter,Harold,Douglas,Henry,Carl,Arthur,Ryan,Roger"); - $fm = explode(",","Mary,Patricia,Linda,Barbara,Elizabeth,Jennifer,Maria,Susan,Margaret,Dorothy,Lisa,Nancy,Karen,Betty,Helen,Sandra,Donna,Carol,Ruth,Sharon,Michelle,Laura,Sarah,Kimberly,Deborah,Jessica,Shirley,Cynthia,Angela,Melissa,Brenda,Amy,Anna,Rebecca,Virginia,Kathleen,Pamela,Martha,Debra,Amanda,Stephanie,Carolyn,Christine,Marie,Janet,Catherine,Frances,Ann,Joyce,Diane"); - $all = array_merge($m, $fm); - - shuffle($m); - shuffle($fm); - shuffle($all); - - switch ($gender) { - default: - return(current($all)); - break; - case "m": - return(current($m)); - break; - case "fm": - return(current($fm)); - break; - } - } - - public function lastname() { - $list = explode(",","Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins,Dexter,Dennis,Menace,Jesus,Bart,Homer,Dan,Bub,Sparkster,Yanni"); - shuffle($list); - return(current($list)); - } - - public function name() { - $f = $this->firstname(); - $l = $this->lastname(); - return($f." ".$l); - } - - public function username() { - $n = rand(1,300); - $f = substr($this->firstname(),0,1); - $l = $this->lastname() .$n; - - return(strtolower($f.$l)); - - } - - public function email( $u = false ) { - if (!$u) { $u = $this->username(); } - $m = array("@gmail.com","@hotmail.com","@yahoo.com","@aol.com","@redlinederby.com"); - shuffle($m); - $m = current($m); - - - return(strtolower($u.$m)); - } - - public function street() { - $list = explode(",","Second,Third,First,Fourth,Park,Fifth,Main,Sixth,Oak,Seventh,Pine,Maple,Cedar,Eighth,Elm,Washington,Ninth,Lake,Hill"); - $n = rand(700,5500); - shuffle($list); - return($n." ".current($list)." St."); - } - - public function city() { - $list = explode(",","Gotham City,Metropolis,Oz,Smallville,Mos Eisley,Mayberry,Bedrock,Springfield,Vice City,Atlantis,Hill Valley,New New York,Cloud City,Bikini Bottom"); - shuffle($list); - return(current($list)); - } - - public function state( $full = false ) { - $list = array('AL'=>"Alabama",'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts", 'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri", 'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon", 'PA'=>"Pennsylvania", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota", 'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia", 'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming"); - $abbv = array_rand($list, 1); - - if ($full) { - return($list[$abbv]); - } else { - return($abbv); - } - } - - public function zipcode() { - return(rand(12345,98765)); - } - - public function address() { - $a = $this->street()."
".$this->city().", ".$this->state()." ".$this->zipcode(); - return($a); - } - - public function telephone() { - return(rand(123,876)."-".rand(123,987)."-".rand(1234,9876)); - } -} \ No newline at end of file + public function __construct() { + } + + public function all() { + $un = $this->username(); + $fn = $this->firstname(); + $ln = $this->lastname(); + + $dump = array( + 'primaryText' => $this->words( 6 ), + 'secondaryText' => $this->sentence(), + 'userid' => $this->number(), + 'rid' => $this->number(), + 'link' => 'http://www.google.com', + 'date' => $this->mdy(), + 'time' => $this->hm(), + 'text' => $this->text( 40, 140 ), + 'body' => $this->text( 140, 600 ), + 'number' => $this->number(), + 'background' => $this->image( 640, 480 ), + 'image' => $this->image(), + 'thumbnail' => $this->placeholder( 150, 150 ), + 'price' => $this->price(), + 'product' => $this->product(), + 'firstname' => $fn, + 'lastname' => $ln, + 'name' => $fn . ' ' . $ln, + 'username' => $un, + 'email' => $this->email( $un ), + 'street' => $this->street(), + 'city' => $this->city(), + 'state' => $this->state(), + 'zipcode' => $this->zipcode(), + 'telephone' => $this->telephone(), + ); + + return( $dump ); + } + + public function dump( $qty = 5 ) { + $a = array(); + + for ( $b = 0;$b < $qty;$b++ ) { + $a[] = $this->all(); + } + + return( $a ); + } + + public function yesno( $w = 5 ) { + if ( rand( 0, 10 ) > $w ) { + return( true ); + } else { + return( false ); + } + } + + public function mdy() { + return( rand( 1, 12 ) . '/' . rand( 1, 30 ) . '/' . rand( 1943, 2010 ) ); + } + + public function hm( $s = false ) { + $t = rand( 1, 12 ) . ':' . rand( 10, 59 ); + + if ( $s ) { + $t = $t . ':' . rand( 10, 59 ); } + + if ( $this->yesno() ) { + $t .= ' AM'; + } else { + $t .= ' PM'; } + + return( $t ); + } + + public function text( $min = 30, $max = 120, $nospaces = false ) { + $s = 'Aliquam lectus nulla, eleifend ut tellus in, euismod porttitor arcu. Aliquam erat volutpat. Morbi massa sapien, condimentum ultrices pretium porta, semper ac lacus. Nulla pharetra, urna a lacinia facilisis, neque libero placerat turpis, vel tincidunt massa nunc ac nunc. In nec volutpat ligula. Sed hendrerit ligula vel felis venenatis egestas. Duis sit amet pharetra erat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi rutrum vel magna et tincidunt. Curabitur mattis, sem eget suscipit porta, nibh enim auctor mi, eu lacinia magna velit eu quam. Donec commodo ultrices lorem vel ultrices. Aliquam erat volutpat. Praesent in libero bibendum, euismod dui quis, volutpat purus. Fusce non est egestas, volutpat ipsum ut, cursus augue. In hac habitasse platea dictumst. Mum volutpat.'; + $s = explode( ' ', $s ); + shuffle( $s ); + $s = implode( ' ', $s ); + $s = ucfirst( substr( $s, 0, rand( $min, $max ) ) ); + + if ( $nospaces ) { + $s = str_replace( ' ', '', $s ); + } + + return( $s ); + } + + public function words( $max = 5, $cmin = 2, $cmax = 6 ) { + $t = array(); + + for ( $a = 0; $a <= ( $max - 1 ); $a++ ) { + $t[] = str_replace( array( ',', '.' ), array( '', '' ), $this->text( $cmin, ( $cmax + 2 ), true ) ); + } + + return( implode( ' ', $t ) ); + } + + public function sentence( $min = 3, $max = 10 ) { + $l = rand( $min, $max ); + + $w = ucfirst( strtolower( $this->words( $l ) ) ) . '.'; + return( $w ); + } + + function number( $min = 10, $max = 1000 ) { + return( round( rand( $min, $max ) ) ); + } + + public function image( $w = 300, $h = 300 ) { + $c = array( 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' ); + shuffle( $c ); + $u = 'http://lorempixel.com/' . $w . '/' . $h . '/' . current( $c ); + + return( $u ); + } + + public function placeholder( $w = 300, $h = 300 ) { + return( 'http://placehold.it/' . $w . 'x' . $h ); + } + + public function price( $min = 2, $max = 500 ) { + $c = array( '00', '99', '49', '00', '50', '29' ); + shuffle( $c ); + $p = rand( $min, $max ) . '.' . current( $c ); + return( $p ); + } + + public function product() { + $items = 'book,exam,hub cap,paperclip,model train,phaser,socks,light saber,lamp,piano,salad,lunch,violin,pony,deoderant,powder,radio,purse,mp3 player,eyeliner,laptop,wheel,glove,boot,pen,slippers,bed,dog,wall,paper,cellular phone,clock,tree,guitar,mullet,dog,cushion,table,ginger,roundabout,cake,teapot,dreadlocks,lampshade,piggy bank,church,eagle,butterfly,keyboard,laptop'; + $adj1 = 'original,brand new,mint,new-in-box,trendy,vintage,retro,old,new,gently used,big,small,tarnished,broken,refurbished'; + $adj2 = 'hipster,red,blue,green,orange,muddy,waterproof,purple,stainless steel,24k gold,handmade,custom'; + + $a = explode( ',', $adj1 ); + $a2 = explode( ',', $adj2 ); + $i = explode( ',', $items ); + shuffle( $a ); + shuffle( $a2 ); + shuffle( $i ); + + // $t = ucfirst($a[0]." ".$a2[3]." ".$i[1]); + $t = ucfirst( $a2[3] . ' ' . $i[1] ); + return( $t ); + } + + public function firstname( $gender = 'any' ) { + $m = explode( ',', 'James,John,Robert,Michael,William,David,Richard,Charles,Joseph,Thomas,Christopher,Daniel,Paul,Mark,Donald,George,Kenneth,Steven,Edward,Brian,Ronald,Anthony,Kevin,Jason,Matthew,Gary,Timothy,Jose,Larry,Jeffrey,Frank,Scott,Eric,Stephen,Andrew,Raymond,Gregory,Joshua,Jerry,Dennis,Walter,Patrick,Peter,Harold,Douglas,Henry,Carl,Arthur,Ryan,Roger' ); + $fm = explode( ',', 'Mary,Patricia,Linda,Barbara,Elizabeth,Jennifer,Maria,Susan,Margaret,Dorothy,Lisa,Nancy,Karen,Betty,Helen,Sandra,Donna,Carol,Ruth,Sharon,Michelle,Laura,Sarah,Kimberly,Deborah,Jessica,Shirley,Cynthia,Angela,Melissa,Brenda,Amy,Anna,Rebecca,Virginia,Kathleen,Pamela,Martha,Debra,Amanda,Stephanie,Carolyn,Christine,Marie,Janet,Catherine,Frances,Ann,Joyce,Diane' ); + $all = array_merge( $m, $fm ); + + shuffle( $m ); + shuffle( $fm ); + shuffle( $all ); + + switch ( $gender ) { + default: + return( current( $all ) ); + break; + case 'm': + return( current( $m ) ); + break; + case 'fm': + return( current( $fm ) ); + break; + } + } + + public function lastname() { + $list = explode( ',', 'Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins,Dexter,Dennis,Menace,Jesus,Bart,Homer,Dan,Bub,Sparkster,Yanni' ); + shuffle( $list ); + return( current( $list ) ); + } + + public function name() { + $f = $this->firstname(); + $l = $this->lastname(); + return( $f . ' ' . $l ); + } + + public function username() { + $n = rand( 1, 300 ); + $f = substr( $this->firstname(), 0, 1 ); + $l = $this->lastname() . $n; + + return( strtolower( $f . $l ) ); + } + + public function email( $u = false ) { + if ( ! $u ) { + $u = $this->username(); } + $m = array( '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' ); + shuffle( $m ); + $m = current( $m ); + + return( strtolower( $u . $m ) ); + } + + public function street() { + $list = explode( ',', 'Second,Third,First,Fourth,Park,Fifth,Main,Sixth,Oak,Seventh,Pine,Maple,Cedar,Eighth,Elm,Washington,Ninth,Lake,Hill' ); + $n = rand( 700, 5500 ); + shuffle( $list ); + return( $n . ' ' . current( $list ) . ' St.' ); + } + + public function city() { + $list = explode( ',', 'Gotham City,Metropolis,Oz,Smallville,Mos Eisley,Mayberry,Bedrock,Springfield,Vice City,Atlantis,Hill Valley,New New York,Cloud City,Bikini Bottom' ); + shuffle( $list ); + return( current( $list ) ); + } + + public function state( $full = false ) { + $list = array( + 'AL' => 'Alabama', + 'AK' => 'Alaska', + 'AZ' => 'Arizona', + 'AR' => 'Arkansas', + 'CA' => 'California', + 'CO' => 'Colorado', + 'CT' => 'Connecticut', + 'DE' => 'Delaware', + 'DC' => 'District Of Columbia', + 'FL' => 'Florida', + 'GA' => 'Georgia', + 'HI' => 'Hawaii', + 'ID' => 'Idaho', + 'IL' => 'Illinois', + 'IN' => 'Indiana', + 'IA' => 'Iowa', + 'KS' => 'Kansas', + 'KY' => 'Kentucky', + 'LA' => 'Louisiana', + 'ME' => 'Maine', + 'MD' => 'Maryland', + 'MA' => 'Massachusetts', + 'MI' => 'Michigan', + 'MN' => 'Minnesota', + 'MS' => 'Mississippi', + 'MO' => 'Missouri', + 'MT' => 'Montana', + 'NE' => 'Nebraska', + 'NV' => 'Nevada', + 'NH' => 'New Hampshire', + 'NJ' => 'New Jersey', + 'NM' => 'New Mexico', + 'NY' => 'New York', + 'NC' => 'North Carolina', + 'ND' => 'North Dakota', + 'OH' => 'Ohio', + 'OK' => 'Oklahoma', + 'OR' => 'Oregon', + 'PA' => 'Pennsylvania', + 'RI' => 'Rhode Island', + 'SC' => 'South Carolina', + 'SD' => 'South Dakota', + 'TN' => 'Tennessee', + 'TX' => 'Texas', + 'UT' => 'Utah', + 'VT' => 'Vermont', + 'VA' => 'Virginia', + 'WA' => 'Washington', + 'WV' => 'West Virginia', + 'WI' => 'Wisconsin', + 'WY' => 'Wyoming', + ); + $abbv = array_rand( $list, 1 ); + + if ( $full ) { + return( $list[ $abbv ] ); + } else { + return( $abbv ); + } + } + + public function zipcode() { + return( rand( 12345, 98765 ) ); + } + + public function address() { + $a = $this->street() . '
' . $this->city() . ', ' . $this->state() . ' ' . $this->zipcode(); + return( $a ); + } + + public function telephone() { + return( rand( 123, 876 ) . '-' . rand( 123, 987 ) . '-' . rand( 1234, 9876 ) ); + } +} diff --git a/tests/_support/Helper/crud-helpers/order-item.php b/tests/_support/Helper/crud-helpers/order-item.php index 41a5a5805..26a3343a7 100644 --- a/tests/_support/Helper/crud-helpers/order-item.php +++ b/tests/_support/Helper/crud-helpers/order-item.php @@ -21,7 +21,7 @@ public function add_coupon( $order, $coupon_id = 0, $save = true ) { if ( empty( $coupon_id ) ) { // Get order product IDs $product_ids = array(); - foreach( $order->get_items() as $item ) { + foreach ( $order->get_items() as $item ) { if ( ! in_array( $item->get_product_id(), $product_ids ) ) { $product_ids[] = $item->get_product_id(); } @@ -31,7 +31,7 @@ public function add_coupon( $order, $coupon_id = 0, $save = true ) { CouponHelper::instance()->create( array( 'product_ids' => $product_ids ) ) ); } else { - $coupon = new WC_Coupon( $coupon_id ); + $coupon = new WC_Coupon( $coupon_id ); } // Apply coupon to order. @@ -55,17 +55,17 @@ public function add_fee( $order, $args = array(), $save = true ) { // Set the array for tax calculations. $calculate_tax_for = array( - 'country' => $country_code, - 'state' => '', - 'postcode' => '', - 'city' => '' + 'country' => $country_code, + 'state' => '', + 'postcode' => '', + 'city' => '', ); $imported_total_fee = 8.4342; // Create and add fee to order. $item = new WC_Order_Item_Fee(); - $item->set_name( "Fee" ); // Generic fee name + $item->set_name( 'Fee' ); // Generic fee name $item->set_amount( $imported_total_fee ); // Fee amount $item->set_tax_class( '' ); // default for '' $item->set_tax_status( 'taxable' ); // or 'none' @@ -225,4 +225,4 @@ public function print_query( $id ) { public function print_nodes( $ids = 0, $processors = array() ) { return array(); } -} \ No newline at end of file +} diff --git a/tests/_support/Helper/crud-helpers/order.php b/tests/_support/Helper/crud-helpers/order.php index 01b0fd9ce..7eb8a8eb9 100644 --- a/tests/_support/Helper/crud-helpers/order.php +++ b/tests/_support/Helper/crud-helpers/order.php @@ -14,15 +14,15 @@ public function to_relay_id( $id ) { return Relay::toGlobalId( 'order', $id ); } - public function set_to_customer_billing_address( $order, $customer, $save = true ) { - if ( ! is_a( $order, WC_Order::class ) ) { - $order = new WC_Order( absint( $order ) ); - } - if ( ! is_a( $customer, WC_Customer::class ) ) { - $customer = new WC_Customer( $customer ); - } - - // Set billing address + public function set_to_customer_billing_address( $order, $customer, $save = true ) { + if ( ! is_a( $order, WC_Order::class ) ) { + $order = new WC_Order( absint( $order ) ); + } + if ( ! is_a( $customer, WC_Customer::class ) ) { + $customer = new WC_Customer( $customer ); + } + + // Set billing address $order->set_billing_first_name( $customer->get_first_name() ); $order->set_billing_last_name( $customer->get_last_name() ); $order->set_billing_company( $customer->get_billing_company() ); @@ -33,24 +33,24 @@ public function set_to_customer_billing_address( $order, $customer, $save = true $order->set_billing_postcode( $customer->get_billing_postcode() ); $order->set_billing_country( $customer->get_billing_country() ); $order->set_billing_email( $customer->get_billing_email() ); - $order->set_billing_phone( $customer->get_billing_phone() ); + $order->set_billing_phone( $customer->get_billing_phone() ); - if ( $save ) { - return $order->save(); + if ( $save ) { + return $order->save(); } return $order; - } + } - public function set_to_customer_shipping_address( $order, $customer, $save = true ) { - if ( ! is_a( $order, WC_Order::class ) ) { - $order = new WC_Order( absint( $order ) ); - } - if ( ! is_a( $customer, WC_Customer::class ) ) { - $customer = new WC_Customer( $customer ); - } + public function set_to_customer_shipping_address( $order, $customer, $save = true ) { + if ( ! is_a( $order, WC_Order::class ) ) { + $order = new WC_Order( absint( $order ) ); + } + if ( ! is_a( $customer, WC_Customer::class ) ) { + $customer = new WC_Customer( $customer ); + } - // Set shipping address + // Set shipping address $order->set_shipping_first_name( $customer->get_first_name() ); $order->set_shipping_last_name( $customer->get_last_name() ); $order->set_shipping_company( $customer->get_shipping_company() ); @@ -59,46 +59,46 @@ public function set_to_customer_shipping_address( $order, $customer, $save = tru $order->set_shipping_city( $customer->get_shipping_city() ); $order->set_shipping_state( $customer->get_shipping_state() ); $order->set_shipping_postcode( $customer->get_shipping_postcode() ); - $order->set_shipping_country( $customer->get_shipping_country() ); + $order->set_shipping_country( $customer->get_shipping_country() ); - if ( $save ) { - return $order->save(); + if ( $save ) { + return $order->save(); } return $order; - } + } public function create( $args = array(), $items = array() ) { if ( empty( $args['customer_id'] ) ) { - $customer = new WC_Customer( CustomerHelper::instance()->create() ); + $customer = new WC_Customer( CustomerHelper::instance()->create() ); $customer_id = $customer->get_id(); } else { $customer_id = $args['customer_id']; } $shipping_method_helper = ShippingMethodHelper::instance(); - $shipping_method_helper->create_legacy_flat_rate_instance(); - - // Create order - $order_data = array_merge( - array( - 'status' => 'pending', - 'customer_id' => $customer_id, - 'customer_note' => '', - 'total' => '', - ), - $args + $shipping_method_helper->create_legacy_flat_rate_instance(); + + // Create order + $order_data = array_merge( + array( + 'status' => 'pending', + 'customer_id' => $customer_id, + 'customer_note' => '', + 'total' => '', + ), + $args ); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception - $order = wc_create_order( $order_data ); + $order = wc_create_order( $order_data ); // Add line items if ( ! empty( $items['line_items'] ) ) { - foreach( $items['line_items'] as $item ) { + foreach ( $items['line_items'] as $item ) { $order = OrderItemHelper::instance()->add_line_item( $order, $item, false ); } } else { - for ( $i = 0; $i < rand( 1, 3 ); $i++ ) { + for ( $i = 0; $i < rand( 1, 3 ); $i++ ) { $order = OrderItemHelper::instance()->add_line_item( $order, array( @@ -107,33 +107,34 @@ public function create( $args = array(), $items = array() ) { ), false ); - } + } } $order->save(); - - // Add billing / shipping address - $order = $this->set_to_customer_billing_address( $order, $customer_id, false ); - $order = $this->set_to_customer_shipping_address( $order, $customer_id, false ); + // Add billing / shipping address + $order = $this->set_to_customer_billing_address( $order, $customer_id, false ); + $order = $this->set_to_customer_shipping_address( $order, $customer_id, false ); // Add shipping costs $shipping_taxes = WC_Tax::calc_shipping_tax( '10', WC_Tax::get_shipping_tax_rates() ); $rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' ); $item = new WC_Order_Item_Shipping(); - $item->set_props( array( - 'method_title' => $rate->label, - 'method_id' => $rate->id, - 'total' => wc_format_decimal( $rate->cost ), - 'taxes' => $rate->taxes, - ) ); + $item->set_props( + array( + 'method_title' => $rate->label, + 'method_id' => $rate->id, + 'total' => wc_format_decimal( $rate->cost ), + 'taxes' => $rate->taxes, + ) + ); foreach ( $rate->get_meta_data() as $key => $value ) { $item->add_meta_data( $key, $value, true ); } - $order->add_item( $item ); + $order->add_item( $item ); // Set payment gateway $payment_gateways = WC()->payment_gateways->payment_gateways(); - $order->set_payment_method( $payment_gateways['bacs'] ); + $order->set_payment_method( $payment_gateways['bacs'] ); // Set totals $order->set_shipping_total( 10 ); @@ -141,14 +142,14 @@ public function create( $args = array(), $items = array() ) { $order->set_discount_tax( 0 ); $order->set_cart_tax( 0 ); $order->set_shipping_tax( 0 ); - $order->set_total( 50 ); // 4 x $10 simple helper product + $order->set_total( 50 ); // 4 x $10 simple helper product // Set meta data. if ( ! empty( $args['meta_data'] ) ) { $order->set_meta_data( $args['meta_data'] ); } - // Save and return ID. + // Save and return ID. return $order->save(); } @@ -157,24 +158,24 @@ public function get_order_key( $id ) { } public function has_product( $id, $product_id ) { - $order = new WC_Order( $id ); + $order = new WC_Order( $id ); $line_items = $order->get_items(); - foreach ( $line_items as $item ) { - if ( $item['product_id'] == $product_id ) { - return true; - } + foreach ( $line_items as $item ) { + if ( $item['product_id'] == $product_id ) { + return true; + } } return false; } - public function print_query( $id ) { + public function print_query( $id ) { $data = new WC_Order( $id ); if ( ! $data->get_id() ) { return null; } // Get unformatted country before it's cached. - $billing_country = ! empty( $data->get_billing_country( 'edit' ) ) + $billing_country = ! empty( $data->get_billing_country( 'edit' ) ) ? 'US' : null; $shipping_country = ! empty( $data->get_address( 'shipping' )['country'] ) @@ -186,10 +187,10 @@ public function print_query( $id ) { 'databaseId' => $data->get_id(), 'currency' => ! empty( $data->get_currency() ) ? $data->get_currency() : null, 'orderVersion' => ! empty( $data->get_version() ) ? $data->get_version() : null, - 'date' => $data->get_date_created()->__toString(), - 'modified' => $data->get_date_modified()->__toString(), + 'date' => $data->get_date_created()->__toString(), + 'modified' => $data->get_date_modified()->__toString(), 'status' => WPEnumType::get_safe_name( $data->get_status() ), - 'discountTotal' => \wc_graphql_price( $data->get_discount_total(), array( 'currency' => $data->get_currency() ) ), + 'discountTotal' => \wc_graphql_price( $data->get_discount_total(), array( 'currency' => $data->get_currency() ) ), 'discountTax' => \wc_graphql_price( $data->get_discount_tax(), array( 'currency' => $data->get_currency() ) ), 'shippingTotal' => \wc_graphql_price( $data->get_shipping_total(), array( 'currency' => $data->get_currency() ) ), 'shippingTax' => \wc_graphql_price( $data->get_shipping_tax(), array( 'currency' => $data->get_currency() ) ), @@ -328,8 +329,8 @@ public function print_restricted_query( $id ) { 'databaseId' => $id, 'currency' => null, 'orderVersion' => null, - 'date' => $data->get_date_created()->__toString(), - 'modified' => $data->get_date_modified()->__toString(), + 'date' => $data->get_date_created()->__toString(), + 'modified' => $data->get_date_modified()->__toString(), 'status' => WPEnumType::get_safe_name( $data->get_status() ), 'discountTotal' => \wc_graphql_price( $data->get_discount_total(), array( 'currency' => $data->get_currency() ) ), 'discountTax' => \wc_graphql_price( $data->get_discount_tax(), array( 'currency' => $data->get_currency() ) ), @@ -424,7 +425,8 @@ public function print_restricted_query( $id ) { : null, 'datePaid' => ! empty( $data->get_date_paid() ) ? $data->get_date_paid()->__toString() - : null,'cartHash' => null, + : null, + 'cartHash' => null, 'shippingAddressMapUrl' => ! empty( $data->get_shipping_address_map_url() ) ? $data->get_shipping_address_map_url() : null, diff --git a/tests/_support/Helper/crud-helpers/product-variation.php b/tests/_support/Helper/crud-helpers/product-variation.php index 8dd805f4a..de9299b16 100644 --- a/tests/_support/Helper/crud-helpers/product-variation.php +++ b/tests/_support/Helper/crud-helpers/product-variation.php @@ -22,7 +22,7 @@ public function reset_indexes() { } private function next_slug() { - $slug = 'test-variation-' . absint( $this->index ); + $slug = 'test-variation-' . absint( $this->index ); $this->index += 1; return $slug; } @@ -45,7 +45,7 @@ public function create( $product_id, $args = array() ) { } // Create medium size variation with image - $image_id = \wp_insert_post( + $image_id = \wp_insert_post( array( 'post_author' => 1, 'post_content' => '', @@ -99,7 +99,7 @@ public function create( $product_id, $args = array() ) { public function print_query( $id ) { $data = new WC_Product_Variation( $id ); - if( empty( $data ) ) { + if ( empty( $data ) ) { return null; } @@ -154,7 +154,7 @@ public function print_query( $id ) { : null, 'hasAttributes' => ! empty( $data->has_attributes() ) ? $data->has_attributes() : null, 'type' => WPEnumType::get_safe_name( $data->get_type() ), - 'parent' => array ( + 'parent' => array( 'node' => array( 'id' => Relay::toGlobalId( 'product', $data->get_parent_id() ), ), @@ -173,8 +173,8 @@ public function print_attributes( $id, $from = 'VARIATION' ) { $results = array(); - foreach( $attributes as $name => $value ) { - $term = get_term_by( 'slug', $value, $name ); + foreach ( $attributes as $name => $value ) { + $term = get_term_by( 'slug', $value, $name ); $results[] = array( 'id' => base64_encode( $product->get_id() . '||' . $name . '||' . $value ), 'attributeId' => ! empty( $term ) ? $term->term_id : 0, @@ -183,11 +183,11 @@ public function print_attributes( $id, $from = 'VARIATION' ) { ); } - return ! empty ( $results ) ? array( 'nodes' => $results ) : null; + return ! empty( $results ) ? array( 'nodes' => $results ) : null; } public function field( $id, $field_name = 'id' ) { - $get = 'get_' . $field_name; + $get = 'get_' . $field_name; $variation = new WC_Product_Variation( $id ); if ( ! empty( $variation ) ) { return $variation->{$get}(); diff --git a/tests/_support/Helper/crud-helpers/product.php b/tests/_support/Helper/crud-helpers/product.php index 2ec343215..efd503a16 100644 --- a/tests/_support/Helper/crud-helpers/product.php +++ b/tests/_support/Helper/crud-helpers/product.php @@ -22,7 +22,7 @@ public function reset_indexes() { } private function next_slug() { - $slug = 'test-product-' . absint( $this->index ); + $slug = 'test-product-' . absint( $this->index ); $this->index += 1; return $slug; } @@ -35,7 +35,7 @@ public static function get_stock_status_enum( $status ) { ); if ( in_array( $status, array_keys( $statuses ) ) ) { - return $statuses[$status]; + return $statuses[ $status ]; } return null; @@ -55,7 +55,7 @@ public function create_product_category( $term, $parent_id = 0 ) { if ( term_exists( $term, 'product_cat' ) ) { $term = get_term( $term, 'product_cat', ARRAY_A ); } else { - $args = []; + $args = array(); if ( $parent_id ) { $args['parent'] = $parent_id; } @@ -100,9 +100,9 @@ public function create_simple( $args = array() ) { } public function create_external( $args = array() ) { - $product = new WC_Product_External(); - $name = $this->dummy->product(); - $price = $this->dummy->price( 15, 200 ); + $product = new WC_Product_External(); + $name = $this->dummy->product(); + $price = $this->dummy->price( 15, 200 ); $product->set_props( array_merge( array( @@ -124,7 +124,7 @@ public function create_grouped( $args = array(), $children = array() ) { $children = array( $this->create_simple() ); } - $product = new WC_Product_Grouped(); + $product = new WC_Product_Grouped(); $product->set_props( array_merge( array( @@ -136,12 +136,15 @@ public function create_grouped( $args = array(), $children = array() ) { ) ); $product->set_children( $children ); - return array( 'parent' => $product->save(), 'children' => $children ); + return array( + 'parent' => $product->save(), + 'children' => $children, + ); } public function create_variable( $args = array() ) { $product = new WC_Product_Variable(); - $props = array_merge( + $props = array_merge( array( 'name' => $this->dummy->product(), 'slug' => $this->next_slug(), @@ -204,7 +207,7 @@ public function create_related( $args = array() ) { 'upsell_ids' => $upsell_ids, ) ), - 'related' => array( $related_product_id ), + 'related' => array( $related_product_id ), 'cross_sell' => $cross_sell_ids, 'upsell' => $upsell_ids, ); @@ -278,7 +281,7 @@ public function create_attribute( $raw_name = 'size', $terms = array( 'small' ), $result = term_exists( $term, $attribute->slug ); if ( ! $result ) { - $result = wp_insert_term( $term, $attribute->slug ); + $result = wp_insert_term( $term, $attribute->slug ); $return['term_ids'][] = absint( $result['term_id'] ); } else { $return['term_ids'][] = absint( $result['term_id'] ); @@ -300,7 +303,7 @@ public static function createDownload( $id = 0 ) { if ( $id ) { $product = \wc_get_product( $id ); - $product->set_downloads( array($download) ); + $product->set_downloads( array( $download ) ); $product->save(); } @@ -308,9 +311,9 @@ public static function createDownload( $id = 0 ) { } public function print_query( $id, $raw = false ) { - $data = wc_get_product( $id ); + $data = wc_get_product( $id ); $is_shop_manager = false; - $user = wp_get_current_user(); + $user = wp_get_current_user(); if ( $user && in_array( 'shop_manager', (array) $user->roles ) ) { $is_shop_manager = true; } @@ -380,7 +383,7 @@ public function print_query( $id, $raw = false ) { 'shippingTaxable' => $data->is_shipping_taxable(), 'link' => get_post_permalink( $id ), 'totalSales' => $is_shop_manager ? $data->get_total_sales() : null, - 'catalogVisibility' => $is_shop_manager ? strtoupper( $data->get_catalog_visibility() ) :null, + 'catalogVisibility' => $is_shop_manager ? strtoupper( $data->get_catalog_visibility() ) : null, ); } @@ -390,7 +393,7 @@ public function print_attributes( $id ) { $results = array(); - foreach( $attributes as $attribute_name => $attribute ) { + foreach ( $attributes as $attribute_name => $attribute ) { $results[] = array( 'id' => base64_encode( $attribute_name . ':' . $id . ':' . $attribute->get_name() ), 'attributeId' => $attribute->get_id(), @@ -405,12 +408,12 @@ public function print_attributes( $id ) { ); } - return ! empty ( $results ) ? array( 'nodes' => $results ) : null; + return ! empty( $results ) ? array( 'nodes' => $results ) : null; } public function print_downloads( $id ) { - $product = wc_get_product( $id ); - $downloads = (array) $product->get_downloads(); + $product = wc_get_product( $id ); + $downloads = (array) $product->get_downloads(); if ( empty( $downloads ) ) { return null; } @@ -433,10 +436,10 @@ public function print_downloads( $id ) { } public function print_grouped( $id ) { - $data = wc_get_product( $id ); + $data = wc_get_product( $id ); $children = array( 'nodes' => array() ); foreach ( $data->get_children() as $child ) { - $parent_id = $this->field( $child, 'parent_id' ); + $parent_id = $this->field( $child, 'parent_id' ); $children['nodes'][] = array( 'id' => $this->to_relay_id( $child ), 'parent' => ! empty( $parent_id ) ? array( 'id' => $this->to_relay_id( $parent_id ) ) : null, @@ -461,7 +464,7 @@ public function print_external( $id ) { } public function field( $id, $field_name = 'id', $args = array() ) { - $get = 'get_' . $field_name; + $get = 'get_' . $field_name; $product = wc_get_product( $id ); if ( ! empty( $product ) ) { return $product->{$get}( ...$args ); @@ -472,7 +475,7 @@ public function field( $id, $field_name = 'id', $args = array() ) { public function create_review( $product_id, $args = array() ) { $firstName = $this->dummy->firstname(); - $data = array_merge( + $data = array_merge( array( 'comment_post_ID' => $product_id, 'comment_author' => $firstName, @@ -503,7 +506,7 @@ public function print_review_edges( $ids ) { $reviews[] = array( 'rating' => floatval( get_comment_meta( $review_id, 'rating', true ) ), 'node' => array( - 'id' => Relay::toGlobalId( 'comment', $review_id ) + 'id' => Relay::toGlobalId( 'comment', $review_id ), ), ); } diff --git a/tests/_support/Helper/crud-helpers/refund.php b/tests/_support/Helper/crud-helpers/refund.php index c5fee8a40..12125572d 100644 --- a/tests/_support/Helper/crud-helpers/refund.php +++ b/tests/_support/Helper/crud-helpers/refund.php @@ -53,7 +53,7 @@ public function print_query( $id ) { 'reason' => $data->get_reason(), 'amount' => $data->get_amount(), 'refundedBy' => array( - 'id' => Relay::toGlobalId( 'user', $data->get_refunded_by() ) + 'id' => Relay::toGlobalId( 'user', $data->get_refunded_by() ), ), 'date' => $data->get_date_modified(), ); diff --git a/tests/_support/Helper/crud-helpers/tax-rate.php b/tests/_support/Helper/crud-helpers/tax-rate.php index ae8b38c79..539796c6e 100644 --- a/tests/_support/Helper/crud-helpers/tax-rate.php +++ b/tests/_support/Helper/crud-helpers/tax-rate.php @@ -22,7 +22,7 @@ public function get_index() { public function create( $args = array() ) { $rate_args = array(); - $fields = array( + $fields = array( 'country' => 'tax_rate_country', 'state' => 'tax_rate_state', 'rate' => 'tax_rate', @@ -33,7 +33,7 @@ public function create( $args = array() ) { 'order' => 'tax_rate_order', 'class' => 'tax_rate_class', ); - foreach( $args as $key => $value ) { + foreach ( $args as $key => $value ) { if ( in_array( $key, array_keys( $fields ) ) ) { $rate_args[ $fields[ $key ] ] = $value; } @@ -44,7 +44,7 @@ public function create( $args = array() ) { 'tax_rate_country' => 'US', 'tax_rate_state' => '*', 'tax_rate' => 20.0000, - 'tax_rate_name' => "VAT", + 'tax_rate_name' => 'VAT', 'tax_rate_priority' => 1, 'tax_rate_compound' => 1, 'tax_rate_shipping' => 1, @@ -96,8 +96,8 @@ public function print_query( $id ) { 'databaseId' => absint( $rate->tax_rate_id ), 'country' => ! empty( $rate->tax_rate_country ) ? $rate->tax_rate_country : null, 'state' => ! empty( $rate->tax_rate_state ) ? $rate->tax_rate_state : null, - 'postcode' => ! empty( $rate->tax_rate_postcode ) ? $rate->tax_rate_postcode : array( "*" ), - 'city' => ! empty( $rate->tax_rate_city ) ? $rate->tax_rate_city : array( "*" ), + 'postcode' => ! empty( $rate->tax_rate_postcode ) ? $rate->tax_rate_postcode : array( '*' ), + 'city' => ! empty( $rate->tax_rate_city ) ? $rate->tax_rate_city : array( '*' ), 'rate' => ! empty( $rate->tax_rate ) ? $rate->tax_rate : null, 'name' => ! empty( $rate->tax_rate_name ) ? $rate->tax_rate_name : null, 'priority' => absint( $rate->tax_rate_priority ), diff --git a/tests/_support/Helper/crud-helpers/wcg-helper.php b/tests/_support/Helper/crud-helpers/wcg-helper.php index 4248802b3..107201737 100644 --- a/tests/_support/Helper/crud-helpers/wcg-helper.php +++ b/tests/_support/Helper/crud-helpers/wcg-helper.php @@ -15,38 +15,38 @@ protected function __construct() { $this->dummy = new Dummy(); } - public static function instance(){ + public static function instance() { return new static(); } - public abstract function to_relay_id( $id ); + abstract public function to_relay_id( $id ); - public abstract function print_query( $id ); + abstract public function print_query( $id ); public function print_nodes( $ids, $processors = array() ) { $default_processors = array( - 'mapper' => function( $id ) { - return array( 'id' => Relay::toGlobalId( $this->node_type, $id ) ); + 'mapper' => function ( $id ) { + return array( 'id' => Relay::toGlobalId( $this->node_type, $id ) ); }, - 'sorter' => function( $id_a, $id_b ) { + 'sorter' => function ( $id_a, $id_b ) { if ( $id_a == $id_b ) { return 0; } return ( $id_a > $id_b ) ? -1 : 1; }, - 'filter' => function( $id ) { + 'filter' => function ( $id ) { return true; - } + }, ); $processors = array_merge( $default_processors, $processors ); $results = array_filter( $ids, $processors['filter'] ); - if( ! empty( $results ) ) { + if ( ! empty( $results ) ) { usort( $results, $processors['sorter'] ); } return array_values( array_map( $processors['mapper'], $results ) ); } -} \ No newline at end of file +} diff --git a/tests/_support/TestCase/WooGraphQLTestCase.php b/tests/_support/TestCase/WooGraphQLTestCase.php index d03c2c71c..9365f553c 100644 --- a/tests/_support/TestCase/WooGraphQLTestCase.php +++ b/tests/_support/TestCase/WooGraphQLTestCase.php @@ -35,7 +35,7 @@ public function setUp(): void { parent::setUp(); // Load factories. - $factories = [ + $factories = array( 'Product', 'ProductVariation', 'Cart', @@ -47,7 +47,7 @@ public function setUp(): void { 'Order', 'Refund', 'PaymentToken', - ]; + ); foreach ( $factories as $factory ) { $factory_name = strtolower( preg_replace( '/\B([A-Z])/', '_$1', $factory ) ); @@ -58,7 +58,7 @@ public function setUp(): void { $this->factory->shipping_zone->createLegacyFlatRate(); // Create test users. - $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); $this->customer = $this->factory->customer->create(); // For these tests, we are not concerned with Approved Download Directory functionality. diff --git a/tests/_support/Utils/Dummy.php b/tests/_support/Utils/Dummy.php index 930e67547..a89bfd02e 100644 --- a/tests/_support/Utils/Dummy.php +++ b/tests/_support/Utils/Dummy.php @@ -39,7 +39,7 @@ public function all() { $fn = $this->firstname(); $ln = $this->lastname(); - $dump = [ + $dump = array( 'primaryText' => $this->words( 6 ), 'secondaryText' => $this->sentence(), 'userid' => $this->number(), @@ -66,13 +66,13 @@ public function all() { 'state' => $this->state(), 'zipcode' => $this->zipcode(), 'telephone' => $this->telephone(), - ]; + ); return( $dump ); } public function dump( $qty = 5 ) { - $a = []; + $a = array(); for ( $b = 0;$b < $qty;$b++ ) { $a[] = $this->all(); @@ -122,10 +122,10 @@ public function text( $min = 30, $max = 120, $nospaces = false ) { } public function words( $max = 5, $cmin = 2, $cmax = 6 ) { - $t = []; + $t = array(); for ( $a = 0; $a <= ( $max - 1 ); $a++ ) { - $t[] = str_replace( [ ',', '.' ], [ '', '' ], $this->text( $cmin, ( $cmax + 2 ), true ) ); + $t[] = str_replace( array( ',', '.' ), array( '', '' ), $this->text( $cmin, ( $cmax + 2 ), true ) ); } return( implode( ' ', $t ) ); @@ -143,7 +143,7 @@ public function number( $min = 10, $max = 1000 ) { } public function image( $w = 300, $h = 300 ) { - $c = [ 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' ]; + $c = array( 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' ); shuffle( $c ); $u = 'http://lorempixel.com/' . $w . '/' . $h . '/' . current( $c ); @@ -155,7 +155,7 @@ public function placeholder( $w = 300, $h = 300 ) { } public function price( $min = 2, $max = 500 ) { - $c = [ '00', '99', '49', '00', '50', '29' ]; + $c = array( '00', '99', '49', '00', '50', '29' ); shuffle( $c ); $p = rand( $min, $max ) . '.' . current( $c ); return( $p ); @@ -220,7 +220,7 @@ public function username() { public function email( $u = false ) { if ( ! $u ) { $u = $this->username(); } - $m = [ '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' ]; + $m = array( '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' ); shuffle( $m ); $m = current( $m ); @@ -241,7 +241,7 @@ public function city() { } public function state( $full = false ) { - $list = [ + $list = array( 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', @@ -293,7 +293,7 @@ public function state( $full = false ) { 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', - ]; + ); $abbv = array_rand( $list, 1 ); if ( $full ) { diff --git a/tests/acceptance/CustomerProceedsToCheckoutCept.php b/tests/acceptance/CustomerProceedsToCheckoutCept.php index f6cd96061..b0818b520 100644 --- a/tests/acceptance/CustomerProceedsToCheckoutCept.php +++ b/tests/acceptance/CustomerProceedsToCheckoutCept.php @@ -12,9 +12,9 @@ // Make quick helper for managing the session token. $request_headers = static function () use ( $I ) { - return [ + return array( 'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ), - ]; + ); }; // Begin test. @@ -23,11 +23,11 @@ /** * Add "T-Shirt" to cart and confirm response data. */ -$add_to_cart_input = [ +$add_to_cart_input = array( 'clientMutationId' => 'someId', 'productId' => $product_catalog['t-shirt'], 'quantity' => 3, -]; +); $success = $I->addToCart( $add_to_cart_input ); @@ -54,18 +54,18 @@ '; $success = $I->sendGraphQLRequest( $update_session_mutation, - [ - 'sessionData' => [ - [ + array( + 'sessionData' => array( + array( 'key' => 'client_session_id', 'value' => 'test-client-session-id', - ], - [ + ), + array( 'key' => 'client_session_id_expiration', 'value' => (string) ( time() + 3600 ), - ], - ], - ], + ), + ), + ), $request_headers() ); diff --git a/tests/acceptance/NewCustomerCheckingOutCept.php b/tests/acceptance/NewCustomerCheckingOutCept.php index 1ac45c8ac..4c4cd962b 100644 --- a/tests/acceptance/NewCustomerCheckingOutCept.php +++ b/tests/acceptance/NewCustomerCheckingOutCept.php @@ -5,9 +5,9 @@ // Make quick helper for managing the session token. $request_headers = function () use ( $I, &$last_request_headers ) { - $last_request_headers = [ + $last_request_headers = array( 'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ), - ]; + ); return $last_request_headers; }; @@ -18,11 +18,11 @@ /** * Add "T-Shirt" to cart and confirm response data. */ -$add_to_cart_input = [ +$add_to_cart_input = array( 'clientMutationId' => 'someId', 'productId' => $product_catalog['t-shirt'], 'quantity' => 3, -]; +); $success = $I->addToCart( $add_to_cart_input ); @@ -36,11 +36,11 @@ /** * Add "Belt" to cart and confirm response data. */ -$add_to_cart_input = [ +$add_to_cart_input = array( 'clientMutationId' => 'someId', 'productId' => $product_catalog['belt'], 'quantity' => 2, -]; +); $success = $I->addToCart( $add_to_cart_input, @@ -57,11 +57,11 @@ /** * Add "Jeans" to cart and confirm response data. */ -$add_to_cart_input = [ +$add_to_cart_input = array( 'clientMutationId' => 'someId', 'productId' => $product_catalog['jeans'], 'quantity' => 4, -]; +); $success = $I->addToCart( $add_to_cart_input, @@ -78,11 +78,11 @@ /** * Add "Socks" to cart and confirm response data. */ -$add_to_cart_input = [ +$add_to_cart_input = array( 'clientMutationId' => 'someId', 'productId' => $product_catalog['socks'], 'quantity' => 1, -]; +); $success = $I->addToCart( $add_to_cart_input, @@ -101,10 +101,10 @@ /** * Remove "Socks" from cart and confirm response data. */ -$remove_from_cart_input = [ +$remove_from_cart_input = array( 'clientMutationId' => 'someId', 'keys' => $socks_key, -]; +); $success = $I->removeItemsFromCart( $remove_from_cart_input, @@ -124,19 +124,19 @@ * - Change "Jeans" quantity to "1" * - Confirm response data. */ -$update_quantity_input = [ +$update_quantity_input = array( 'clientMutationId' => 'someId', - 'items' => [ - [ + 'items' => array( + array( 'key' => $belt_key, 'quantity' => 0, - ], - [ + ), + array( 'key' => $jeans_key, 'quantity' => 1, - ], - ], -]; + ), + ), +); $success = $I->updateItemQuantities( $update_quantity_input, @@ -162,11 +162,11 @@ /** * Place order for items in the cart using the "Checkout" mutation and confirm response data. */ -$checkout_input = [ +$checkout_input = array( 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', - 'shippingMethod' => [ 'flat rate' ], - 'billing' => [ + 'shippingMethod' => array( 'flat rate' ), + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -176,8 +176,8 @@ 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -185,8 +185,8 @@ 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ], -]; + ), +); $success = $I->checkout( $checkout_input, diff --git a/tests/acceptance/ReturningCustomerSessionCept.php b/tests/acceptance/ReturningCustomerSessionCept.php index db168c842..651346604 100644 --- a/tests/acceptance/ReturningCustomerSessionCept.php +++ b/tests/acceptance/ReturningCustomerSessionCept.php @@ -7,11 +7,11 @@ // Begin Tests. $I->wantTo( 'login' ); -$login_input = [ +$login_input = array( 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', -]; +); $success = $I->login( $login_input ); @@ -48,20 +48,20 @@ $response = $I->sendGraphQLRequest( $query, null, - [ + array( 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$initial_session_token}", - ] + ) ); -$expected_results = [ - 'data' => [ - 'customer' => [ +$expected_results = array( + 'data' => array( + 'customer' => array( 'databaseId' => $customer_id, 'username' => 'jimbo1234', - ], - ], -]; + ), + ), +); $I->assertEquals( $expected_results, $response ); @@ -70,18 +70,18 @@ /** * Add "T-Shirt" to cart and confirm response data. */ -$add_to_cart_input = [ +$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 ); @@ -113,29 +113,29 @@ $response = $I->sendGraphQLRequest( $cart_query, null, - [ + array( 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$initial_session_token}", - ] + ) ); -$expected_results = [ - 'data' => [ - 'cart' => [ - 'contents' => [ - 'nodes' => [ - [ +$expected_results = array( + 'data' => array( + 'cart' => array( + 'contents' => array( + 'nodes' => array( + array( 'key' => $shirt_key, - 'product' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'databaseId' => $product_catalog['t-shirt'], - ], - ], - ], - ], - ], - ], - ], -]; + ), + ), + ), + ), + ), + ), + ), +); $I->assertEquals( $expected_results, $response ); @@ -147,11 +147,11 @@ $I->wantTo( 'Login and continue previous session.' ); -$login_input = [ +$login_input = array( 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', -]; +); $success = $I->login( $login_input ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -184,25 +184,25 @@ } '; -$response = $I->sendGraphQLRequest( $cart_query, null, [ 'Authorization' => "Bearer {$authToken}" ] ); -$expected_results = [ - 'data' => [ - 'cart' => [ - 'contents' => [ - 'nodes' => [ - [ +$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' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'databaseId' => $product_catalog['t-shirt'], - ], - ], - ], - ], - ], - ], - ], -]; + ), + ), + ), + ), + ), + ), + ), +); $I->assertEquals( $expected_results, $response ); @@ -211,13 +211,13 @@ /** * Add "Belt" to cart and confirm response data. */ -$add_to_cart_input = [ +$add_to_cart_input = array( 'clientMutationId' => 'someId', 'productId' => $product_catalog['belt'], 'quantity' => 2, -]; +); -$success = $I->addToCart( $add_to_cart_input, [ 'Authorization' => "Bearer {$authToken}" ] ); +$success = $I->addToCart( $add_to_cart_input, array( 'Authorization' => "Bearer {$authToken}" ) ); $I->assertArrayNotHasKey( 'errors', $success ); $I->assertArrayHasKey( 'data', $success ); @@ -254,37 +254,37 @@ $response = $I->sendGraphQLRequest( $cart_query, null, - [ + array( 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$refreshed_session_token}", - ] + ) ); -$expected_results = [ - 'data' => [ - 'cart' => [ - 'contents' => [ - 'nodes' => [ - [ +$expected_results = array( + 'data' => array( + 'cart' => array( + 'contents' => array( + 'nodes' => array( + array( 'key' => $shirt_key, - 'product' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'databaseId' => $product_catalog['t-shirt'], - ], - ], - ], - [ + ), + ), + ), + array( 'key' => $belt_key, - 'product' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'databaseId' => $product_catalog['belt'], - ], - ], - ], - ], - ], - ], - ], -]; + ), + ), + ), + ), + ), + ), + ), +); $I->assertEquals( $expected_results, $response ); @@ -296,11 +296,11 @@ $I->wantTo( 'Login and start a new session.' ); -$login_input = [ +$login_input = array( 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', -]; +); $success = $I->login( $login_input ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -341,19 +341,19 @@ $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(), + ), + ), + ), ); -$expected_results = [ - 'data' => [ - 'cart' => [ - 'contents' => [ - 'nodes' => [], - ], - ], - ], -]; $I->assertEquals( $expected_results, $response ); diff --git a/tests/functional/CartTransactionQueueCest.php b/tests/functional/CartTransactionQueueCest.php index 9e3d26c68..f62b92123 100644 --- a/tests/functional/CartTransactionQueueCest.php +++ b/tests/functional/CartTransactionQueueCest.php @@ -11,7 +11,7 @@ public function _before( FunctionalTester $I, $scenario ) { $this->product_catalog = $I->getCatalog(); } - public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) { + public function _addTshirtToCart( FunctionalTester $I, $headers = array() ) { /** * Add t-shirt to the cart */ @@ -38,25 +38,24 @@ public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) { } } }'; - $success = $I->postRawRequest( + $success = $I->postRawRequest( $add_to_cart_query, - [ - 'input' => [ + array( + 'input' => array( 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 5, - ] - ], - [ 'headers' => $headers ] + ), + ), + array( 'headers' => $headers ) ); - $response_body = json_decode( $success->getBody(), true ); $I->assertQuerySuccessful( $response_body, - [ + array( $I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ), - ] + ) ); $key = $I->lodashGet( $response_body, 'data.addToCart.cartItem.key' ); @@ -64,7 +63,7 @@ public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) { /** * Assert existence and validity of "woocommerce-session" HTTP header. */ - $session_header = $success->getHeader('woocommerce-session'); + $session_header = $success->getHeader( 'woocommerce-session' ); $I->assertNotEmpty( $session_header ); $session_token = $session_header[0]; @@ -76,23 +75,23 @@ public function _startAuthenticatedSession( $I ) { // Begin Tests. $I->wantTo( 'login' ); - $login_input = [ + $login_input = array( 'clientMutationId' => 'someId', 'username' => 'jimbo1234@example.com', 'password' => 'password', - ]; + ); $success = $I->login( $login_input ); // Validate response. $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'login.customer.databaseId', Signal::NOT_NULL ), $I->expectField( 'login.authToken', Signal::NOT_NULL ), $I->expectField( 'login.refreshToken', Signal::NOT_NULL ), $I->expectField( 'login.sessionToken', Signal::NOT_NULL ), - ] + ) ); // Retrieve JWT Authorization Token for later use. @@ -103,22 +102,22 @@ public function _startAuthenticatedSession( $I ) { // You can also retrieve the token from the "woocommerce-session" HTTP response header. $initial_session_token = $I->lodashGet( $success, 'data.login.sessionToken' ); - $headers = [ + $headers = array( 'Authorization' => "Bearer {$auth_token}", 'woocommerce-session' => "Session {$initial_session_token}", - ]; + ); $tokens = $this->_addTshirtToCart( $I, $headers ); return array_merge( $tokens, - [ 'auth_token' => $auth_token ] + array( 'auth_token' => $auth_token ) ); } // tests public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester $I, $scenario ) { - //$scenario->skip( 'The test is unstable, and will be skipped until success is guaranteed on each run.' ); + // $scenario->skip( 'The test is unstable, and will be skipped until success is guaranteed on each run.' ); $tokens = $this->_startAuthenticatedSession( $I ); $key = $tokens['key']; @@ -188,147 +187,147 @@ public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester } '; - $operations = [ - [ + $operations = array( + array( 'query' => $update_item_quantities_mutation, - 'variables' => [ - 'input' => [ + 'variables' => array( + 'input' => array( 'clientMutationId' => 'some_id', - 'items' => [ - [ + 'items' => array( + array( 'key' => $key, 'quantity' => 3, - ], - ], - ], - ], - ], - [ + ), + ), + ), + ), + ), + array( 'query' => $update_item_quantities_mutation, - 'variables' => [ - 'input' => [ + 'variables' => array( + 'input' => array( 'clientMutationId' => 'some_id', - 'items' => [ - [ + 'items' => array( + array( 'key' => $key, 'quantity' => 4, - ], - ], - ], - ], - ], - [ + ), + ), + ), + ), + ), + array( 'query' => $remove_item_mutation, - 'variables' => [ - 'input' => [ + 'variables' => array( + 'input' => array( 'clientMutationId' => 'some_id', - 'keys' => [ $key ], - ], - ], - ], - [ + 'keys' => array( $key ), + ), + ), + ), + array( 'query' => $restore_item_mutation, - 'variables' => [ - 'input' => [ + 'variables' => array( + 'input' => array( 'clientMutationId' => 'some_id', - 'keys' => [ $key ], - ], - ], - ], - ]; + 'keys' => array( $key ), + ), + ), + ), + ); - $selected_options = [ - 'headers' => [ + $selected_options = array( + 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => "Bearer {$auth_token}", 'woocommerce-session' => "Session {$session_token}", - ], - ]; - $responses = $I->concurrentRequests( $operations, $selected_options, 800 ); + ), + ); + $responses = $I->concurrentRequests( $operations, $selected_options, 800 ); $I->assertQuerySuccessful( $responses[0], - [ + array( $I->expectObject( 'updateItemQuantities', - [ + array( $I->expectObject( 'updated.0', - [ + array( $I->expectField( 'key', $key ), - $I->expectField( 'quantity', 3 ) - ] + $I->expectField( 'quantity', 3 ), + ) ), $I->expectField( 'removed', Signal::IS_FALSY ), $I->expectObject( 'items.0', - [ + array( $I->expectField( 'key', $key ), - $I->expectField( 'quantity', 3 ) - ] - ) - ] - ) - ] + $I->expectField( 'quantity', 3 ), + ) + ), + ) + ), + ) ); $I->assertQuerySuccessful( $responses[1], - [ + array( $I->expectObject( 'updateItemQuantities', - [ + array( $I->expectObject( 'updated.0', - [ + array( $I->expectField( 'key', $key ), - $I->expectField( 'quantity', 4 ) - ] + $I->expectField( 'quantity', 4 ), + ) ), $I->expectField( 'removed', Signal::IS_FALSY ), $I->expectObject( 'items.0', - [ + array( $I->expectField( 'key', $key ), - $I->expectField( 'quantity', 4 ) - ] - ) - ] - ) - ] + $I->expectField( 'quantity', 4 ), + ) + ), + ) + ), + ) ); $I->assertQuerySuccessful( $responses[2], - [ + array( $I->expectObject( 'removeItemsFromCart', - [ + array( $I->expectField( 'cart.contents.nodes', Signal::IS_FALSY - ) - ] - ) - ] + ), + ) + ), + ) ); $I->assertQuerySuccessful( $responses[3], - [ + array( $I->expectObject( 'restoreCartItems', - [ + array( $I->expectObject( 'cart.contents.nodes.0', - [ + array( $I->expectField( 'key', $key ), - $I->expectField( 'quantity', 4 ) - ] - ) - ] - ) - ] + $I->expectField( 'quantity', 4 ), + ) + ), + ) + ), + ) ); } } diff --git a/tests/functional/ProtectedRouterCest.php b/tests/functional/ProtectedRouterCest.php index 42a848588..d1c696b0b 100644 --- a/tests/functional/ProtectedRouterCest.php +++ b/tests/functional/ProtectedRouterCest.php @@ -27,11 +27,11 @@ public function _startNewSession( FunctionalTester $I ) { * Add t-shirt to the cart */ $success = $I->addToCart( - [ + array( 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 5, - ], + ), ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -51,9 +51,9 @@ public function _startNewSession( FunctionalTester $I ) { } public function _getLastRequestHeaders( $I ) { - return [ + return array( 'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ), - ]; + ); } public function tryToProceedToCheckoutPage( FunctionalTester $I, $scenario ) { @@ -120,14 +120,14 @@ public function tryToProceedToCheckoutPageWithExpiredUrl( FunctionalTester $I, $ '; $success = $I->sendGraphQLRequest( $query, - [ - 'sessionData' => [ - [ + array( + 'sessionData' => array( + array( 'key' => 'client_session_id', 'value' => 'test-client-session-id', - ], - ], - ], + ), + ), + ), $this->_getLastRequestHeaders( $I ) ); @@ -148,14 +148,14 @@ public function tryToProceedToCheckoutPageWithExpiredUrl( FunctionalTester $I, $ $I->wantTo( 'Invalidate Checkout URL by updating the "client_session_id"' ); $success = $I->sendGraphQLRequest( $query, - [ - 'sessionData' => [ - [ + array( + 'sessionData' => array( + array( 'key' => 'client_session_id', 'value' => 'new-test-client-session-id', - ], - ], - ], + ), + ), + ), $this->_getLastRequestHeaders( $I ) ); diff --git a/tests/functional/QLSessionHandlerCest.php b/tests/functional/QLSessionHandlerCest.php index 82206ba14..f811d64ca 100644 --- a/tests/functional/QLSessionHandlerCest.php +++ b/tests/functional/QLSessionHandlerCest.php @@ -21,18 +21,18 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I * Add item to the cart */ $success = $I->addToCart( - [ + array( 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 5, - ] + ) ); $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ), - ] + ) ); $cart_item_key = $I->lodashGet( $success, 'data.addToCart.cartItem.key' ); @@ -76,30 +76,30 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I } '; - $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $actual, - [ + array( $I->expectField( 'cart.contents.nodes.#.key', $cart_item_key ), - ] + ) ); /** * Remove item from the cart */ $success = $I->removeItemsFromCart( - [ + array( 'clientMutationId' => 'someId', 'keys' => $cart_item_key, - ], - [ 'woocommerce-session' => "Session {$session_token}" ] + ), + array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'removeItemsFromCart.cartItems.#.key', $cart_item_key ), - ] + ) ); /** @@ -118,30 +118,30 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I } '; - $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $actual, - [ + array( $I->expectField( 'cart.contents.nodes', Signal::IS_FALSY ), - ] + ) ); /** * Restore item to the cart */ $success = $I->restoreCartItems( - [ + array( 'clientMutationId' => 'someId', - 'keys' => [ $cart_item_key ], - ], - [ 'woocommerce-session' => "Session {$session_token}" ] + 'keys' => array( $cart_item_key ), + ), + array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'restoreCartItems.cartItems.#.key', $cart_item_key ), - ] + ) ); /** @@ -160,12 +160,12 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I } '; - $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $actual, - [ + array( $I->expectField( 'cart.contents.nodes.#.key', $cart_item_key ), - ] + ) ); } @@ -174,18 +174,18 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * Add item to cart and retrieve session token to corrupt. */ $success = $I->addToCart( - [ + array( 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 1, - ] + ) ); $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ), - ] + ) ); $cart_item_key = $I->lodashGet( $success, 'data.addToCart.cartItem.key' ); @@ -209,12 +209,12 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ $invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ); $failed = $I->addToCart( - [ + array( 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 1, - ], - [ 'woocommerce-session' => "Session {$invalid_token}" ] + ), + array( 'woocommerce-session' => "Session {$invalid_token}" ) ); $I->assertQueryError( $failed ); @@ -228,11 +228,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ $invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ); $failed = $I->removeItemsFromCart( - [ + array( 'clientMutationId' => 'someId', 'keys' => $cart_item_key, - ], - [ 'woocommerce-session' => "Session {$invalid_token}" ] + ), + array( 'woocommerce-session' => "Session {$invalid_token}" ) ); $I->assertQueryError( $failed ); @@ -242,16 +242,16 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * GraphQL should throw an error and mutation will fail. */ $failed = $I->updateItemQuantities( - [ + array( 'clientMutationId' => 'someId', - 'items' => [ - [ + 'items' => array( + array( 'key' => $cart_item_key, 'quantity' => 0, - ], - ], - ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + ), + ), + ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -261,8 +261,8 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * GraphQL should throw an error and mutation will fail. */ $failed = $I->emptyCart( - [ 'clientMutationId' => 'someId' ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + array( 'clientMutationId' => 'someId' ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -272,12 +272,12 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * GraphQL should throw an error and mutation will fail. */ $failed = $I->addFee( - [ + array( 'clientMutationId' => 'someId', 'name' => 'extra_fee', 'amount' => 49.99, - ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -289,11 +289,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * @Note: No coupons exist in the database, but mutation should fail before that becomes a factor. */ $failed = $I->applyCoupon( - [ + array( 'clientMutationId' => 'someId', 'code' => 'some_coupon', - ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -305,11 +305,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * @Note: No coupons exist on the cart, but mutation should failed before that becomes a factor. */ $failed = $I->removeCoupons( - [ + array( 'clientMutationId' => 'someId', - 'codes' => [ 'some_coupon' ], - ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + 'codes' => array( 'some_coupon' ), + ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -322,11 +322,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * but mutation should failed before that becomes a factor. */ $failed = $I->restoreCartItems( - [ + array( 'clientMutationId' => 'someId', - 'keys' => [ $cart_item_key ], - ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + 'keys' => array( $cart_item_key ), + ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -339,11 +339,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * but mutation should failed before that becomes a factor. */ $failed = $I->updateShippingMethod( - [ + array( 'clientMutationId' => 'someId', - 'shippingMethods' => [ 'legacy_flat_rate' ], - ], - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + 'shippingMethods' => array( 'legacy_flat_rate' ), + ), + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); @@ -367,30 +367,30 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ $failed = $I->sendGraphQLRequest( $query, null, - [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] + array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) ); $I->assertQueryError( $failed ); } public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) { - //$scenario->skip( 'Test skipped until scenario can be created properly again.' ); + // $scenario->skip( 'Test skipped until scenario can be created properly again.' ); /** * Add item to the cart */ $success = $I->addToCart( - [ + array( 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['socks'], 'quantity' => 2, - ] + ) ); $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ), - ] + ) ); $cart_item_key = $I->lodashGet( $success, 'data.addToCart.cartItem.key' ); @@ -420,14 +420,14 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) { /** * Set shipping address, so shipping rates can be calculated */ - $input = [ + $input = array( 'clientMutationId' => 'someId', - 'shipping' => [ + 'shipping' => array( 'state' => 'New York', 'country' => 'US', 'postcode' => '12345', - ], - ]; + ), + ); $mutation = ' mutation ( $input: UpdateCustomerInput! ){ @@ -443,19 +443,19 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) { } '; - $actual = $I->sendGraphQLRequest( $mutation, $input, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $actual = $I->sendGraphQLRequest( $mutation, $input, array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $actual, - [ + array( $I->expectObject( 'updateCustomer.customer.shipping', - [ + array( $I->expectField( 'state', 'New York' ), $I->expectField( 'country', 'US' ), $I->expectField( 'postcode', '12345' ), - ] - ) - ] + ) + ), + ) ); /** @@ -483,34 +483,34 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) { } '; - $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $actual, - [ + array( $I->expectField( 'cart.contents.nodes.#.key', $cart_item_key ), $I->expectNode( 'cart.availableShippingMethods', - [ + array( $I->expectField( 'packageDetails', \html_entity_decode( 'socks ×2' ) ), $I->expectField( 'supportsShippingCalculator', true ), $I->expectNode( 'rates', - [ + array( $I->expectField( 'cost', '0.00' ), $I->expectField( 'label', 'Flat rate' ), - ] + ) ), $I->expectNode( 'rates', - [ + array( $I->expectField( 'cost', '0.00' ), $I->expectField( 'label', 'Free shipping' ), - ] + ) ), - ], + ), 0 ), - ] + ) ); $chosen_shipping_method = $I->lodashGet( $actual, 'data.cart.availableShippingMethods.0.rates.0.id' ); @@ -544,21 +544,21 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) { $success = $I->sendGraphQLRequest( $mutation, - [ + array( 'clientMutationId' => 'someId', - 'shippingMethods' => [ $chosen_shipping_method ], - ], - [ 'woocommerce-session' => "Session {$session_token}" ] + 'shippingMethods' => array( $chosen_shipping_method ), + ), + array( 'woocommerce-session' => "Session {$session_token}" ) ); $I->assertQuerySuccessful( $success, - [ + array( $I->expectField( 'updateShippingMethod.cart.chosenShippingMethods.#', $chosen_shipping_method ), - ] + ) ); } } diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php index 1a1b96e50..f48f9c2ff 100644 --- a/tests/functional/_bootstrap.php +++ b/tests/functional/_bootstrap.php @@ -1,5 +1,5 @@ - [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'productId' => $product_id, 'quantity' => 2, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -55,7 +55,7 @@ public function testAddToCartMutationWithProduct() { $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'addToCart.clientMutationId', 'someId' ), $this->expectedField( 'addToCart.cartItem.key', $cart_item_key ), $this->expectedField( 'addToCart.cartItem.product.node.id', $this->toRelayId( 'post', $product_id ) ), @@ -64,7 +64,7 @@ public function testAddToCartMutationWithProduct() { $this->expectedField( 'addToCart.cartItem.subtotalTax', wc_graphql_price( $cart_item['line_subtotal_tax'] ) ), $this->expectedField( 'addToCart.cartItem.total', wc_graphql_price( $cart_item['line_total'] ) ), $this->expectedField( 'addToCart.cartItem.tax', wc_graphql_price( $cart_item['line_tax'] ) ), - ] + ) ); } @@ -97,20 +97,20 @@ public function testAddToCartMutationWithProductVariation() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'productId' => $ids['product'], 'quantity' => 3, 'variationId' => $ids['variations'][0], - 'variation' => [ - [ + 'variation' => array( + array( 'attributeName' => 'color', 'attributeValue' => 'red', - ], - ], - ], - ]; + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -128,7 +128,7 @@ public function testAddToCartMutationWithProductVariation() { $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'addToCart.clientMutationId', 'someId' ), $this->expectedField( 'addToCart.cartItem.key', $cart_item_key ), $this->expectedField( 'addToCart.cartItem.product.node.id', $this->toRelayId( 'post', $ids['product'] ) ), @@ -138,26 +138,26 @@ public function testAddToCartMutationWithProductVariation() { $this->expectedField( 'addToCart.cartItem.subtotalTax', wc_graphql_price( $cart_item['line_subtotal_tax'] ) ), $this->expectedField( 'addToCart.cartItem.total', wc_graphql_price( $cart_item['line_total'] ) ), $this->expectedField( 'addToCart.cartItem.tax', wc_graphql_price( $cart_item['line_tax'] ) ), - ] + ) ); } public function testUpdateCartItemQuantitiesMutation() { // Create/add some products to the cart. - $cart_item_data = [ - [ + $cart_item_data = array( + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 5, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - ]; + ), + ); // Store cart item keys for use in mutation. $keys = $this->factory->cart->add( ...$cart_item_data ); @@ -184,95 +184,95 @@ public function testUpdateCartItemQuantitiesMutation() { '; // Define variables - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', - 'items' => [ - [ + 'items' => array( + array( 'key' => $keys[0], 'quantity' => 4, - ], - [ + ), + array( 'key' => $keys[1], 'quantity' => 2, - ], - [ + ), + array( 'key' => $keys[2], 'quantity' => 0, - ], - ], - ], - ]; + ), + ), + ), + ); // Execute mutation. $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'updateItemQuantities.clientMutationId', 'someId' ), $this->expectedNode( 'updateItemQuantities.updated', - [ + array( 'key' => $keys[0], 'quantity' => 4, - ] + ) ), $this->expectedNode( 'updateItemQuantities.updated', - [ + array( 'key' => $keys[1], 'quantity' => 2, - ] + ) ), $this->expectedNode( 'updateItemQuantities.removed', - [ + array( 'key' => $keys[2], 'quantity' => 1, - ] + ) ), $this->expectedNode( 'updateItemQuantities.items', - [ + array( 'key' => $keys[0], 'quantity' => 4, - ] + ) ), $this->expectedNode( 'updateItemQuantities.items', - [ + array( 'key' => $keys[1], 'quantity' => 2, - ] + ) ), $this->expectedNode( 'updateItemQuantities.items', - [ + array( 'key' => $keys[2], 'quantity' => 1, - ] + ) ), - ] + ) ); } public function testRemoveItemsFromCartMutation() { // Create/add some products to the cart. - $cart_item_data = [ - [ + $cart_item_data = array( + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 5, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - ]; + ), + ); // Store cart item keys for use in mutation. $keys = $this->factory->cart->add( ...$cart_item_data ); @@ -289,17 +289,17 @@ public function testRemoveItemsFromCartMutation() { '; // Define expected response data. - $expected = [ $this->expectedField( 'removeItemsFromCart.clientMutationId', 'someId' ) ]; + $expected = array( $this->expectedField( 'removeItemsFromCart.clientMutationId', 'someId' ) ); foreach ( $keys as $key ) { $expected[] = $this->expectedNode( 'removeItemsFromCart.cartItems', compact( 'key' ) ); } - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'keys' => $keys, - ], - ]; + ), + ); // Execute mutation w/ "keys" array. $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -317,12 +317,12 @@ public function testRemoveItemsFromCartMutation() { // Add more items and execute mutation with "all" flag. $keys = $this->factory->cart->add( ...$cart_item_data ); - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'all' => true, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -339,20 +339,20 @@ public function testRemoveItemsFromCartMutation() { public function testRestoreCartItemsMutation() { // Create/add some products to the cart. - $cart_item_data = [ - [ + $cart_item_data = array( + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 5, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - ]; + ), + ); $keys = $this->factory->cart->add( ...$cart_item_data ); $this->factory->cart->remove( ...$keys ); @@ -367,16 +367,16 @@ public function testRestoreCartItemsMutation() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'keys' => $keys, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'restoreCartItems.clientMutationId', 'someId' ) ]; + $expected = array( $this->expectedField( 'restoreCartItems.clientMutationId', 'someId' ) ); foreach ( $keys as $key ) { $expected[] = $this->expectedNode( 'restoreCartItems.cartItems', compact( 'key' ) ); } @@ -429,33 +429,33 @@ public function testEmptyCartMutation() { } '; - $variables = [ - 'input' => [ 'clientMutationId' => 'someId' ], - ]; + $variables = array( + 'input' => array( 'clientMutationId' => 'someId' ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'emptyCart.clientMutationId', 'someId' ), $this->expectedNode( 'emptyCart.deletedCart.contents.nodes', - [ + array( 'key' => $cart_item['key'], - 'product' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'id' => $this->toRelayId( 'post', $cart_item['product_id'] ), - ], - ], + ), + ), 'variation' => null, 'quantity' => $cart_item['quantity'], 'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ), 'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ), 'total' => wc_graphql_price( $cart_item['line_total'] ), 'tax' => wc_graphql_price( $cart_item['line_tax'] ), - ] + ) ), - ] + ) ); $this->assertTrue( \WC()->cart->is_empty() ); @@ -464,17 +464,17 @@ public function testEmptyCartMutation() { public function testApplyCouponMutation() { // Create products. $product_id = $this->factory->product->createSimple( - [ 'regular_price' => 100 ] + array( 'regular_price' => 100 ) ); // Create coupon. $coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ + array( 'amount' => 0.5, - 'product_ids' => [ $product_id ], + 'product_ids' => array( $product_id ), 'description' => 'lorem ipsum dolor', - ] + ) ) ); @@ -513,12 +513,12 @@ public function testApplyCouponMutation() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'code' => $coupon_code, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); // Get updated cart item. @@ -526,42 +526,42 @@ public function testApplyCouponMutation() { $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'applyCoupon.clientMutationId', 'someId' ), $this->expectedNode( 'applyCoupon.cart.appliedCoupons', - [ + array( 'code' => $coupon_code, 'description' => 'lorem ipsum dolor', - ] + ) ), $this->expectedNode( 'applyCoupon.cart.contents.nodes', - [ + array( 'key' => $cart_item['key'], - 'product' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'id' => $this->toRelayId( 'post', $cart_item['product_id'] ), - ], - ], + ), + ), 'quantity' => $cart_item['quantity'], 'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ), 'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ), 'total' => wc_graphql_price( $cart_item['line_total'] ), 'tax' => wc_graphql_price( $cart_item['line_tax'] ), - ] + ) ), - ] + ) ); $new_total = \WC()->cart->get_cart_contents_total(); // Use --debug to view. codecept_debug( - [ + array( 'old' => $old_total, 'new' => $new_total, - ] + ) ); $this->assertTrue( $old_total > $new_total ); @@ -575,19 +575,19 @@ public function testApplyCouponMutationWithInvalidCoupons() { // Create invalid coupon codes. $coupon_id = $this->factory->coupon->create( - [ 'product_ids' => [ $product_id ] ] + array( 'product_ids' => array( $product_id ) ) ); $expired_coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ - 'product_ids' => [ $product_id ], + array( + 'product_ids' => array( $product_id ), 'date_expires' => time() - 20, - ] + ) ) ); $applied_coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ 'product_ids' => [ $product_id ] ] + array( 'product_ids' => array( $product_id ) ) ) ); @@ -610,12 +610,12 @@ public function testApplyCouponMutationWithInvalidCoupons() { * * Can't pass coupon ID as coupon 'code'. Mutation should fail. */ - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'code' => '$coupon_id', - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertNotEmpty( $response['errors'] ); @@ -626,12 +626,12 @@ public function testApplyCouponMutationWithInvalidCoupons() { * * Can't pass expired coupon code. Mutation should fail. */ - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'code' => $expired_coupon_code, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertNotEmpty( $response['errors'] ); @@ -642,12 +642,12 @@ public function testApplyCouponMutationWithInvalidCoupons() { * * Can't pass coupon already applied to the cart. Mutation should fail. */ - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'code' => $applied_coupon_code, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertNotEmpty( $response['errors'] ); @@ -661,7 +661,7 @@ public function testRemoveCouponMutation() { $product_id = $this->factory->product->createSimple(); $coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ 'product_ids' => [ $product_id ] ] + array( 'product_ids' => array( $product_id ) ) ) ); @@ -698,12 +698,12 @@ public function testRemoveCouponMutation() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', - 'codes' => [ $coupon_code ], - ], - ]; + 'codes' => array( $coupon_code ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); // Get updated cart item. @@ -711,26 +711,26 @@ public function testRemoveCouponMutation() { $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'removeCoupons.clientMutationId', 'someId' ), $this->expectedField( 'removeCoupons.cart.appliedCoupons', static::IS_NULL ), $this->expectedNode( 'removeCoupons.cart.contents.nodes', - [ + array( 'key' => $cart_item['key'], - 'product' => [ - 'node' => [ + 'product' => array( + 'node' => array( 'id' => $this->toRelayId( 'post', $cart_item['product_id'] ), - ], - ], + ), + ), 'quantity' => $cart_item['quantity'], 'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ), 'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ), 'total' => wc_graphql_price( $cart_item['line_total'] ), 'tax' => wc_graphql_price( $cart_item['line_tax'] ), - ] + ) ), - ] + ) ); } @@ -739,7 +739,7 @@ public function testAddFeeMutation() { $product_id = $this->factory->product->createSimple(); $coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ 'product_ids' => [ $product_id ] ] + array( 'product_ids' => array( $product_id ) ) ) ); @@ -764,13 +764,13 @@ public function testAddFeeMutation() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'name' => 'extra_fee', 'amount' => 49.99, - ], - ]; + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertArrayHasKey( 'errors', $response ); @@ -782,30 +782,30 @@ public function testAddFeeMutation() { $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'addFee.clientMutationId', 'someId' ), $this->expectedField( 'addFee.cartFee', - [ + array( 'id' => $fee->id, 'name' => $fee->name, 'taxClass' => ! empty( $fee->tax_class ) ? $fee->tax_class : null, 'taxable' => $fee->taxable, 'amount' => (float) $fee->amount, 'total' => (float) $fee->total, - ] + ) ), - ] + ) ); } public function testAddToCartMutationErrors() { // Create products. $product_id = $this->factory->product->createSimple( - [ + array( 'manage_stock' => true, 'stock_quantity' => 1, - ] + ) ); $variation_ids = $this->factory->product_variation->createSome(); @@ -813,7 +813,7 @@ public function testAddToCartMutationErrors() { $attribute = new WC_Product_Attribute(); $attribute->set_id( 0 ); $attribute->set_name( 'test' ); - $attribute->set_options( [ 'yes', 'no' ] ); + $attribute->set_options( array( 'yes', 'no' ) ); $attribute->set_position( 3 ); $attribute->set_visible( true ); $attribute->set_variation( true ); @@ -849,25 +849,25 @@ public function testAddToCartMutationErrors() { '; \WC()->session->set( 'wc_notices', null ); - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'productId' => $variation_ids['product'], 'quantity' => 5, 'variationId' => $variation_ids['variations'][0], - ], - ]; + ), + ); $missing_attributes = $this->graphql( compact( 'query', 'variables' ) ); $this->assertArrayHasKey( 'errors', $missing_attributes ); \WC()->session->set( 'wc_notices', null ); - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'productId' => $product_id, 'quantity' => 5, - ], - ]; + ), + ); $not_enough_stock = $this->graphql( compact( 'query', 'variables' ) ); $this->assertArrayHasKey( 'errors', $not_enough_stock ); } @@ -879,7 +879,7 @@ public function testAddToCartMutationItemEdgeData() { $attribute = new WC_Product_Attribute(); $attribute->set_id( 0 ); $attribute->set_name( 'test' ); - $attribute->set_options( [ 'yes', 'no' ] ); + $attribute->set_options( array( 'yes', 'no' ) ); $attribute->set_position( 3 ); $attribute->set_visible( true ); $attribute->set_variation( true ); @@ -906,48 +906,48 @@ public function testAddToCartMutationItemEdgeData() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', 'productId' => $variation_ids['product'], 'quantity' => 3, 'variationId' => $variation_ids['variations'][1], - 'variation' => [ - [ + 'variation' => array( + array( 'attributeName' => 'test', 'attributeValue' => 'yes', - ], - [ + ), + array( 'attributeName' => 'color', 'attributeValue' => 'green', - ], - ], - ], - ]; + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'addToCart.cartItem.product', - [ + array( $this->expectedField( 'node.databaseId', $variation_ids['product'] ), $this->expectedObject( 'simpleVariations.#', - [ + array( $this->expectedField( 'name', 'attribute_test' ), $this->expectedField( 'value', 'yes' ), - ] + ) ), $this->expectedObject( 'simpleVariations.#', - [ + array( $this->expectedField( 'name', 'attribute_pa_color' ), $this->expectedField( 'value', 'green' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -959,7 +959,7 @@ public function testAddCartItemsMutationAndErrors() { $attribute = new WC_Product_Attribute(); $attribute->set_id( 0 ); $attribute->set_name( 'test' ); - $attribute->set_options( [ 'yes', 'no' ] ); + $attribute->set_options( array( 'yes', 'no' ) ); $attribute->set_position( 3 ); $attribute->set_visible( true ); $attribute->set_variation( true ); @@ -1000,73 +1000,73 @@ public function testAddCartItemsMutationAndErrors() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', - 'items' => [ - [ + 'items' => array( + array( 'productId' => $product_one, 'quantity' => 2, - ], - [ + ), + array( 'productId' => $variation_ids['product'], 'quantity' => 5, 'variationId' => $variation_ids['variations'][0], - ], - [ + ), + array( 'productId' => $invalid_product, 'quantity' => 4, - ], - [ + ), + array( 'productId' => $variation_ids['product'], 'quantity' => 3, 'variationId' => $variation_ids['variations'][1], - 'variation' => [ - [ + 'variation' => array( + array( 'attributeName' => 'test', 'attributeValue' => 'yes', - ], - [ + ), + array( 'attributeName' => 'color', 'attributeValue' => 'green', - ], - ], - ], - ], - ], - ]; + ), + ), + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'addCartItems.clientMutationId', 'someId' ), $this->expectedNode( 'addCartItems.added', - [ - 'product' => [ - 'node' => [ 'databaseId' => $product_one ], - ], + array( + 'product' => array( + 'node' => array( 'databaseId' => $product_one ), + ), 'variation' => null, 'quantity' => 2, - ] + ) ), $this->expectedNode( 'addCartItems.added', - [ - 'product' => [ - 'node' => [ 'databaseId' => $variation_ids['product'] ], - ], - 'variation' => [ - 'node' => [ 'databaseId' => $variation_ids['variations'][1] ], - ], + array( + 'product' => array( + 'node' => array( 'databaseId' => $variation_ids['product'] ), + ), + 'variation' => array( + 'node' => array( 'databaseId' => $variation_ids['variations'][1] ), + ), 'quantity' => 3, - ] + ) ), $this->expectedNode( 'addCartItems.cartErrors', - [ + array( $this->expectedField( 'type', 'INVALID_CART_ITEM' ), $this->expectedField( 'reasons.0', static::NOT_NULL ), $this->expectedField( 'productId', $variation_ids['product'] ), @@ -1074,11 +1074,11 @@ public function testAddCartItemsMutationAndErrors() { $this->expectedField( 'variationId', $variation_ids['variations'][0] ), $this->expectedField( 'variation', static::IS_NULL ), $this->expectedField( 'extraData', static::IS_NULL ), - ] + ) ), $this->expectedNode( 'addCartItems.cartErrors', - [ + array( $this->expectedField( 'type', 'INVALID_CART_ITEM' ), $this->expectedField( 'reasons.0', 'No product found matching the ID provided' ), $this->expectedField( 'productId', $invalid_product ), @@ -1086,32 +1086,32 @@ public function testAddCartItemsMutationAndErrors() { $this->expectedField( 'variationId', static::IS_NULL ), $this->expectedField( 'variation', static::IS_NULL ), $this->expectedField( 'extraData', static::IS_NULL ), - ] + ) ), - ] + ) ); } public function testFillCartMutationAndErrors() { // Create products. - $product_one = $this->factory->product->createSimple( [ 'regular_price' => 100 ] ); - $product_two = $this->factory->product->createSimple( [ 'regular_price' => 40 ] ); + $product_one = $this->factory->product->createSimple( array( 'regular_price' => 100 ) ); + $product_two = $this->factory->product->createSimple( array( 'regular_price' => 40 ) ); // Create coupons. $coupon_code_one = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ + array( 'amount' => 0.5, - 'product_ids' => [ $product_one ], - ] + 'product_ids' => array( $product_one ), + ) ) ); $coupon_code_two = wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ + array( 'amount' => 0.2, - 'product_ids' => [ $product_two ], - ] + 'product_ids' => array( $product_two ), + ) ) ); @@ -1164,62 +1164,62 @@ public function testFillCartMutationAndErrors() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'someId', - 'items' => [ - [ + 'items' => array( + array( 'productId' => $product_one, 'quantity' => 3, - ], - [ + ), + array( 'productId' => $product_two, 'quantity' => 2, - ], - [ + ), + array( 'productId' => $invalid_product, 'quantity' => 4, - ], - ], - 'coupons' => [ $coupon_code_one, $coupon_code_two, $invalid_coupon ], - 'shippingMethods' => [ 'legacy_flat_rate', $invalid_shipping_method ], - ], - ]; + ), + ), + 'coupons' => array( $coupon_code_one, $coupon_code_two, $invalid_coupon ), + 'shippingMethods' => array( 'legacy_flat_rate', $invalid_shipping_method ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'fillCart', - [ + array( $this->expectedField( 'clientMutationId', 'someId' ), $this->expectedObject( 'cart', - [ + array( $this->expectedField( 'chosenShippingMethods.0', 'legacy_flat_rate' ), $this->expectedObject( 'contents', - [ + array( $this->expectedNode( 'nodes', - [ + array( $this->expectedField( 'product.node.databaseId', $product_one ), $this->expectedField( 'quantity', 3 ), $this->expectedField( 'variation', static::IS_NULL ), - ] + ) ), $this->expectedNode( 'nodes', - [ + array( $this->expectedField( 'product.node.databaseId', $product_two ), $this->expectedField( 'quantity', 2 ), $this->expectedField( 'variation', static::IS_NULL ), - ] + ) ), - ] + ) ), $this->expectedNode( 'appliedCoupons', - [ + array( $this->expectedField( 'code', $coupon_code_one ), $this->expectedField( 'discountAmount', @@ -1229,11 +1229,11 @@ public function testFillCartMutationAndErrors() { 'discountTax', \wc_graphql_price( \WC()->cart->get_coupon_discount_tax_amount( $coupon_code_one ) ) ), - ] + ) ), $this->expectedNode( 'appliedCoupons', - [ + array( $this->expectedField( 'code', $coupon_code_two ), $this->expectedField( 'discountAmount', @@ -1243,38 +1243,38 @@ public function testFillCartMutationAndErrors() { 'discountTax', \wc_graphql_price( \WC()->cart->get_coupon_discount_tax_amount( $coupon_code_two ) ) ), - ] + ) ), - ] + ) ), $this->expectedNode( 'cartErrors', - [ + array( $this->expectedField( 'type', 'INVALID_CART_ITEM' ), - $this->expectedField( 'reasons', [ 'No product found matching the ID provided' ] ), + $this->expectedField( 'reasons', array( 'No product found matching the ID provided' ) ), $this->expectedField( 'productId', $invalid_product ), $this->expectedField( 'quantity', 4 ), - ] + ) ), $this->expectedNode( 'cartErrors', - [ + array( $this->expectedField( 'type', 'INVALID_COUPON' ), - $this->expectedField( 'reasons', [ "Coupon \"{$invalid_coupon}\" does not exist!" ] ), + $this->expectedField( 'reasons', array( "Coupon \"{$invalid_coupon}\" does not exist!" ) ), $this->expectedField( 'code', $invalid_coupon ), - ] + ) ), $this->expectedNode( 'cartErrors', - [ + array( $this->expectedField( 'type', 'INVALID_SHIPPING_METHOD' ), $this->expectedField( 'chosenMethod', $invalid_shipping_method ), $this->expectedField( 'package', 1 ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CartQueriesTest.php b/tests/wpunit/CartQueriesTest.php index 312d333c5..8f31bd8fa 100644 --- a/tests/wpunit/CartQueriesTest.php +++ b/tests/wpunit/CartQueriesTest.php @@ -8,7 +8,7 @@ private function key_to_cursor( $key ) { public function getExpectedCartData() { $cart = WC()->cart; - return [ + return array( $this->expectedField( 'cart.subtotal', \wc_graphql_price( $cart->get_subtotal() ) ), $this->expectedField( 'cart.subtotalTax', \wc_graphql_price( $cart->get_subtotal_tax() ) ), $this->expectedField( 'cart.discountTotal', \wc_graphql_price( $cart->get_discount_total() ) ), @@ -36,16 +36,16 @@ public function getExpectedCartData() { $this->expectedField( 'cart.rawFeeTax', static::NOT_NULL ), $this->expectedField( 'cart.rawtotal', static::NOT_NULL ), $this->expectedField( 'cart.rawTotalTax', static::NOT_NULL ), - ]; + ); } public function getExpectedCartItemData( $path, $cart_item_key ) { $cart = WC()->cart; $item = $cart->get_cart_item( $cart_item_key ); - return [ + return array( $this->expectedObject( $path, - [ + array( $this->expectedField( 'key', $item['key'] ), $this->expectedField( 'product.node.id', $this->toRelayId( 'post', $item['product_id'] ) ), $this->expectedField( 'product.node.databaseId', $item['product_id'] ), @@ -64,23 +64,23 @@ public function getExpectedCartItemData( $path, $cart_item_key ) { $this->expectedField( 'subtotalTax', \wc_graphql_price( $item['line_subtotal_tax'] ) ), $this->expectedField( 'total', \wc_graphql_price( $item['line_total'] ) ), $this->expectedField( 'tax', \wc_graphql_price( $item['line_tax'] ) ), - ] + ) ), - ]; + ); } // tests public function testCartQuery() { $cart = WC()->cart; $this->factory->cart->add( - [ + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ] + ) ); $query = ' @@ -139,7 +139,7 @@ public function testCartItemQuery() { $variations['product'], 3, $variations['variations'][0], - [ 'attribute_pa_color' => 'red' ] + array( 'attribute_pa_color' => 'red' ) ); $query = ' @@ -177,7 +177,7 @@ public function testCartItemQuery() { /** * Assertion One */ - $variables = [ 'key' => $key ]; + $variables = array( 'key' => $key ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $this->getExpectedCartItemData( 'cartItem', $key ) ); @@ -185,28 +185,28 @@ public function testCartItemQuery() { public function testCartItemConnection() { $keys = $this->factory->cart->add( - [ + array( 'product_id' => $this->factory->product->createSimple( - [ 'virtual' => true ] + array( 'virtual' => true ) ), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 10, - ] + ) ); $code = \wc_get_coupon_code_by_id( $this->factory->coupon->create( - [ + array( 'amount' => 45.50, 'discount_type' => 'fixed_cart', - ] + ) ) ); $cart = \WC()->cart; @@ -230,9 +230,9 @@ public function testCartItemConnection() { $response = $this->graphql( compact( 'query' ) ); - $expected = []; + $expected = array(); foreach ( $keys as $key ) { - $expected[] = $this->expectedNode( 'cart.contents.nodes', [ 'key' => $key ] ); + $expected[] = $this->expectedNode( 'cart.contents.nodes', array( 'key' => $key ) ); } $this->assertQuerySuccessful( $response, $expected ); @@ -242,15 +242,15 @@ public function testCartItemConnection() { * * Tests "needsShipping" parameter. */ - $variables = [ 'needsShipping' => true ]; + $variables = array( 'needsShipping' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ - $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[1] ] ), - $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[2] ] ), - ] + array( + $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[1] ) ), + $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[2] ) ), + ) ); /** @@ -258,14 +258,14 @@ public function testCartItemConnection() { * * Tests "needsShipping" parameter reversed. */ - $variables = [ 'needsShipping' => false ]; + $variables = array( 'needsShipping' => false ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ - $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[0] ] ), - ] + array( + $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[0] ) ), + ) ); } @@ -291,21 +291,21 @@ public function testCartFeeQuery() { /** * Assertion One */ - $variables = [ 'id' => $fee_ids[0] ]; + $variables = array( 'id' => $fee_ids[0] ); $response = $this->graphql( compact( 'query', 'variables' ) ); $fee = ( \WC()->cart->get_fees() )[ $fee_ids[0] ]; $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'cartFee.id', $fee->id ), $this->expectedField( 'cartFee.name', $fee->name ), $this->expectedField( 'cartFee.taxClass', $this->maybe( $fee->tax_class ) ), $this->expectedField( 'cartFee.taxable', $fee->taxable ), $this->expectedField( 'cartFee.amount', (float) $fee->amount ), $this->expectedField( 'cartFee.total', (float) $fee->total ), - ] + ) ); } @@ -329,9 +329,9 @@ public function testCartToCartFeeQuery() { */ $response = $this->graphql( compact( 'query' ) ); - $expected = []; + $expected = array(); foreach ( \WC()->cart->get_fees() as $fee_id => $value ) { - $expected[] = $this->expectedNode( 'cart.fees', [ 'id' => $fee_id ] ); + $expected[] = $this->expectedNode( 'cart.fees', array( 'id' => $fee_id ) ); } $this->assertQuerySuccessful( $response, $expected ); @@ -339,26 +339,26 @@ public function testCartToCartFeeQuery() { public function testCartItemPagination() { $cart_items = $this->factory->cart->add( - [ + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ] + ) ); $query = ' @@ -387,29 +387,29 @@ public function testCartItemPagination() { * * Tests "first" parameter. */ - $variables = [ + $variables = array( 'first' => 2, 'after' => '', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'cart.contents.itemCount', 6 ), $this->expectedField( 'cart.contents.productCount', 5 ), $this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', false ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[0] ) ], + array( $this->expectedField( 'key', $cart_items[0] ) ), 0 ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[1] ) ], + array( $this->expectedField( 'key', $cart_items[1] ) ), 1 ), $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ), $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[1] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -418,27 +418,27 @@ public function testCartItemPagination() { * * Tests "after" parameter. */ - $variables = [ + $variables = array( 'first' => 2, 'after' => $this->key_to_cursor( $cart_items[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', true ), $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[2] ) ), $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[3] ) ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[2] ) ], + array( $this->expectedField( 'key', $cart_items[2] ) ), 0 ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[3] ) ], + array( $this->expectedField( 'key', $cart_items[3] ) ), 1 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -447,24 +447,24 @@ public function testCartItemPagination() { * * Tests "last" parameter. */ - $variables = [ 'last' => 2 ]; + $variables = array( 'last' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'cart.contents.pageInfo.hasNextPage', false ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', true ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[3] ) ], + array( $this->expectedField( 'key', $cart_items[3] ) ), 0 ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[4] ) ], + array( $this->expectedField( 'key', $cart_items[4] ) ), 1 ), $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[3] ) ), $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[4] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -473,12 +473,12 @@ public function testCartItemPagination() { * * Tests "before" parameter. */ - $variables = [ + $variables = array( 'last' => 4, 'before' => $this->key_to_cursor( $cart_items[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', false ), $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ), @@ -486,20 +486,20 @@ public function testCartItemPagination() { $this->expectedField( 'cart.contents.edges.2.cursor', $this->key_to_cursor( $cart_items[2] ) ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[0] ) ], + array( $this->expectedField( 'key', $cart_items[0] ) ), 0 ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[1] ) ], + array( $this->expectedField( 'key', $cart_items[1] ) ), 1 ), $this->expectedEdge( 'cart.contents.edges', - [ $this->expectedField( 'key', $cart_items[2] ) ], + array( $this->expectedField( 'key', $cart_items[2] ) ), 2 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CheckoutMutationTest.php b/tests/wpunit/CheckoutMutationTest.php index 3ac4b0893..766de426b 100644 --- a/tests/wpunit/CheckoutMutationTest.php +++ b/tests/wpunit/CheckoutMutationTest.php @@ -20,18 +20,18 @@ public function setUp(): void { // Enable payment gateways. update_option( 'woocommerce_bacs_settings', - [ + array( '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' => '', - ] + ) ); update_option( 'woocommerce_stripe_settings', - [ + array( 'enabled' => 'yes', 'title' => 'Credit Card (Stripe)', 'description' => 'Pay with your credit card via Stripe', @@ -56,7 +56,7 @@ public function setUp(): void { 'payment_request_button_height' => '44', 'saved_cards' => 'yes', 'logging' => 'no', - ] + ) ); // Additional cart fees. @@ -71,7 +71,7 @@ static function () { // Create a tax rate. $this->factory->tax_rate->create( - [ + array( 'country' => '', 'state' => '', 'rate' => 20.000, @@ -80,7 +80,7 @@ static function () { 'compound' => '0', 'shipping' => '1', 'class' => '', - ] + ) ); } @@ -275,13 +275,13 @@ private function getCartQuery() { '; } - private function getCheckoutInput( $overwrite = [] ) { + private function getCheckoutInput( $overwrite = array() ) { return array_merge( - [ + array( 'paymentMethod' => 'bacs', - 'shippingMethod' => [ 'flat rate' ], + 'shippingMethod' => array( 'flat rate' ), 'customerNote' => 'Test customer note', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -292,8 +292,8 @@ private function getCheckoutInput( $overwrite = [] ) { 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', 'overwrite' => true, - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -301,14 +301,14 @@ private function getCheckoutInput( $overwrite = [] ) { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ], - 'metaData' => [ - [ + ), + 'metaData' => array( + array( 'key' => 'test_key', 'value' => 'test value', - ], - ], - ], + ), + ), + ), $overwrite ); } @@ -320,14 +320,14 @@ public function testCheckoutMutation() { WC()->customer->save(); $variable = $this->factory->product_variation->createSome(); - $product_ids = [ + $product_ids = array( $this->factory->product->createSimple(), $this->factory->product->createSimple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( $this->factory->coupon->create( - [ 'product_ids' => $product_ids ] + array( 'product_ids' => $product_ids ) ) ); @@ -337,11 +337,11 @@ public function testCheckoutMutation() { $product_ids[2], 2, $variable['variations'][0], - [ 'attribute_pa_color' => 'red' ] + array( 'attribute_pa_color' => 'red' ) ); WC()->cart->apply_coupon( $coupon->get_code() ); - $variables = [ 'input' => $this->getCheckoutInput() ]; + $variables = array( 'input' => $this->getCheckoutInput() ); $query = $this->getCheckoutMutation(); /** @@ -350,30 +350,30 @@ public function testCheckoutMutation() { * Test mutation and input. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'checkout.order.id', static::NOT_NULL ), $this->expectedField( 'checkout.order.status', 'ON_HOLD' ), $this->expectedNode( 'checkout.order.metaData', - [ + array( $this->expectedField( 'key', 'test_key' ), $this->expectedField( 'value', 'test value' ), - ] + ) ), $this->expectedNode( 'checkout.order.couponLines.nodes', - [ + array( $this->expectedField( 'code', $coupon->get_code() ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), $this->expectedField( 'discount', static::NOT_NULL ), $this->expectedField( 'discountTax', static::NOT_NULL ), $this->expectedField( 'coupon', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.feeLines.nodes', - [ + array( $this->expectedField( 'name', 'Surcharge' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), @@ -382,33 +382,33 @@ public function testCheckoutMutation() { $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.shippingLines.nodes', - [ + array( $this->expectedField( 'methodTitle', 'Flat rate' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.taxLines.nodes', - [ + array( $this->expectedField( 'label', 'VAT' ), $this->expectedField( 'rateCode', static::NOT_NULL ), $this->expectedField( 'taxTotal', static::NOT_NULL ), $this->expectedField( 'shippingTaxTotal', static::NOT_NULL ), $this->expectedField( 'isCompound', static::NOT_NULL ), $this->expectedField( 'taxRate', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[0] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -418,11 +418,11 @@ public function testCheckoutMutation() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[1] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -432,11 +432,11 @@ public function testCheckoutMutation() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[2] ), $this->expectedField( 'variationId', static::NOT_NULL ), $this->expectedField( 'quantity', static::NOT_NULL ), @@ -448,7 +448,7 @@ public function testCheckoutMutation() { $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), $this->expectedField( 'variation.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedField( 'checkout.customer.id', @@ -456,31 +456,31 @@ public function testCheckoutMutation() { ), $this->expectedField( 'checkout.result', 'success' ), $this->expectedField( 'checkout.redirect', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); // Confirm cart empty after successful checkout. $query = $this->getCartQuery(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedField( 'cart.contents.nodes', [] ), + $expected = array( + $this->expectedField( 'cart.contents.nodes', array() ), $this->expectedField( 'cart.total', '$0.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCheckoutMutationWithNewAccount() { $variable = $this->factory->product_variation->createSome(); - $product_ids = [ + $product_ids = array( $this->factory->product->createSimple(), $this->factory->product->createSimple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( $this->factory->coupon->create( - [ 'product_ids' => $product_ids ] + array( 'product_ids' => $product_ids ) ) ); @@ -490,17 +490,17 @@ public function testCheckoutMutationWithNewAccount() { $product_ids[2], 2, $variable['variations'][0], - [ 'attribute_pa_color' => 'red' ] + array( 'attribute_pa_color' => 'red' ) ); WC()->cart->apply_coupon( $coupon->get_code() ); - $input = [ - 'account' => [ + $input = array( + 'account' => array( 'username' => 'test_user_1', 'password' => 'test_pass', - ], - ]; - $variables = [ 'input' => $this->getCheckoutInput( $input ) ]; + ), + ); + $variables = array( 'input' => $this->getCheckoutInput( $input ) ); $query = $this->getCheckoutMutation(); /** @@ -509,19 +509,19 @@ public function testCheckoutMutationWithNewAccount() { * Test mutation and input. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'checkout.order.id', static::NOT_NULL ), $this->expectedField( 'checkout.order.status', 'ON_HOLD' ), $this->expectedNode( 'checkout.order.metaData', - [ + array( $this->expectedField( 'key', 'test_key' ), $this->expectedField( 'value', 'test value' ), - ] + ) ), $this->expectedNode( 'checkout.order.feeLines.nodes', - [ + array( $this->expectedField( 'name', 'Surcharge' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), @@ -530,33 +530,33 @@ public function testCheckoutMutationWithNewAccount() { $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.shippingLines.nodes', - [ + array( $this->expectedField( 'methodTitle', 'Flat rate' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.taxLines.nodes', - [ + array( $this->expectedField( 'label', 'VAT' ), $this->expectedField( 'rateCode', static::NOT_NULL ), $this->expectedField( 'taxTotal', static::NOT_NULL ), $this->expectedField( 'shippingTaxTotal', static::NOT_NULL ), $this->expectedField( 'isCompound', static::NOT_NULL ), $this->expectedField( 'taxRate', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[0] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -566,11 +566,11 @@ public function testCheckoutMutationWithNewAccount() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[1] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -580,11 +580,11 @@ public function testCheckoutMutationWithNewAccount() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[2] ), $this->expectedField( 'variationId', static::NOT_NULL ), $this->expectedField( 'quantity', static::NOT_NULL ), @@ -596,22 +596,22 @@ public function testCheckoutMutationWithNewAccount() { $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), $this->expectedField( 'variation.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedField( 'checkout.customer.id', static::NOT_NULL ), $this->expectedField( 'checkout.result', 'success' ), $this->expectedField( 'checkout.redirect', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); // Confirm cart empty after successful checkout. $query = $this->getCartQuery(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedField( 'cart.contents.nodes', [] ), + $expected = array( + $this->expectedField( 'cart.contents.nodes', array() ), $this->expectedField( 'cart.total', '$0.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -621,14 +621,14 @@ public function testCheckoutMutationWithNoAccount() { WC()->customer->save(); $variable = $this->factory->product_variation->createSome(); - $product_ids = [ + $product_ids = array( $this->factory->product->createSimple(), $this->factory->product->createSimple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( $this->factory->coupon->create( - [ 'product_ids' => $product_ids ] + array( 'product_ids' => $product_ids ) ) ); @@ -638,11 +638,11 @@ public function testCheckoutMutationWithNoAccount() { $product_ids[2], 2, $variable['variations'][0], - [ 'attribute_pa_color' => 'red' ] + array( 'attribute_pa_color' => 'red' ) ); WC()->cart->apply_coupon( $coupon->get_code() ); - $variables = [ 'input' => $this->getCheckoutInput() ]; + $variables = array( 'input' => $this->getCheckoutInput() ); $query = $this->getCheckoutMutation(); /** @@ -651,19 +651,19 @@ public function testCheckoutMutationWithNoAccount() { * Test mutation and input. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'checkout.order.id', static::NOT_NULL ), $this->expectedField( 'checkout.order.status', 'ON_HOLD' ), $this->expectedNode( 'checkout.order.metaData', - [ + array( $this->expectedField( 'key', 'test_key' ), $this->expectedField( 'value', 'test value' ), - ] + ) ), $this->expectedNode( 'checkout.order.feeLines.nodes', - [ + array( $this->expectedField( 'name', 'Surcharge' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), @@ -672,33 +672,33 @@ public function testCheckoutMutationWithNoAccount() { $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.shippingLines.nodes', - [ + array( $this->expectedField( 'methodTitle', 'Flat rate' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.taxLines.nodes', - [ + array( $this->expectedField( 'label', 'VAT' ), $this->expectedField( 'rateCode', static::NOT_NULL ), $this->expectedField( 'taxTotal', static::NOT_NULL ), $this->expectedField( 'shippingTaxTotal', static::NOT_NULL ), $this->expectedField( 'isCompound', static::NOT_NULL ), $this->expectedField( 'taxRate', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[0] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -708,11 +708,11 @@ public function testCheckoutMutationWithNoAccount() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[1] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -722,11 +722,11 @@ public function testCheckoutMutationWithNoAccount() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[2] ), $this->expectedField( 'variationId', static::NOT_NULL ), $this->expectedField( 'quantity', static::NOT_NULL ), @@ -738,22 +738,22 @@ public function testCheckoutMutationWithNoAccount() { $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), $this->expectedField( 'variation.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedField( 'checkout.customer.id', 'guest' ), $this->expectedField( 'checkout.result', 'success' ), $this->expectedField( 'checkout.redirect', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); // Confirm cart empty after successful checkout. $query = $this->getCartQuery(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedField( 'cart.contents.nodes', [] ), + $expected = array( + $this->expectedField( 'cart.contents.nodes', array() ), $this->expectedField( 'cart.total', '$0.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -762,35 +762,35 @@ public function testCheckoutMutationWithPrepaidOrder() { WC()->customer->set_billing_email( 'superfreak500@gmail.com' ); WC()->customer->save(); - $product_ids = [ + $product_ids = array( $this->factory->product->createSimple( - [ + array( 'virtual' => true, 'downloadable' => true, - ] + ) ), $this->factory->product->createSimple( - [ + array( 'virtual' => true, 'downloadable' => true, - ] + ) ), - ]; + ); $coupon = new WC_Coupon( - $this->factory->coupon->create( [ 'product_ids' => $product_ids ] ) + $this->factory->coupon->create( array( 'product_ids' => $product_ids ) ) ); WC()->cart->add_to_cart( $product_ids[0], 3 ); WC()->cart->add_to_cart( $product_ids[1], 6 ); WC()->cart->apply_coupon( $coupon->get_code() ); - $input = [ + $input = array( 'isPaid' => true, 'transactionId' => 'transaction_id', - ]; + ); - $variables = [ 'input' => $this->getCheckoutInput( $input ) ]; + $variables = array( 'input' => $this->getCheckoutInput( $input ) ); $query = $this->getCheckoutMutation(); /** @@ -799,19 +799,19 @@ public function testCheckoutMutationWithPrepaidOrder() { * Test mutation and input. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'checkout.order.id', static::NOT_NULL ), $this->expectedField( 'checkout.order.status', 'COMPLETED' ), $this->expectedNode( 'checkout.order.metaData', - [ + array( $this->expectedField( 'key', 'test_key' ), $this->expectedField( 'value', 'test value' ), - ] + ) ), $this->expectedNode( 'checkout.order.feeLines.nodes', - [ + array( $this->expectedField( 'name', 'Surcharge' ), $this->expectedField( 'databaseId', static::NOT_NULL ), $this->expectedField( 'orderId', static::NOT_NULL ), @@ -820,22 +820,22 @@ public function testCheckoutMutationWithPrepaidOrder() { $this->expectedField( 'total', static::NOT_NULL ), $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.taxLines.nodes', - [ + array( $this->expectedField( 'label', 'VAT' ), $this->expectedField( 'rateCode', static::NOT_NULL ), $this->expectedField( 'taxTotal', static::NOT_NULL ), $this->expectedField( 'shippingTaxTotal', static::NOT_NULL ), $this->expectedField( 'isCompound', static::NOT_NULL ), $this->expectedField( 'taxRate', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[0] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -845,11 +845,11 @@ public function testCheckoutMutationWithPrepaidOrder() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[1] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -859,22 +859,22 @@ public function testCheckoutMutationWithPrepaidOrder() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedField( 'checkout.customer.id', 'guest' ), $this->expectedField( 'checkout.result', 'success' ), $this->expectedField( 'checkout.redirect', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); // Confirm cart empty after successful checkout. $query = $this->getCartQuery(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedField( 'cart.contents.nodes', [] ), + $expected = array( + $this->expectedField( 'cart.contents.nodes', array() ), $this->expectedField( 'cart.total', '$0.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -887,7 +887,7 @@ public function testCheckoutMutationWithPrepaidOrder() { * @return array */ private function create_stripe_customer( $email ) { - $customer = \Stripe\Customer::create( [ 'email' => $email ] ); + $customer = \Stripe\Customer::create( array( 'email' => $email ) ); // use --debug flag to view. codecept_debug( $customer ); @@ -905,7 +905,7 @@ private function create_stripe_customer( $email ) { private function create_stripe_source( $customer ) { $source = \Stripe\Customer::createSource( $customer['id'], - [ 'source' => 'tok_visa' ] + array( 'source' => 'tok_visa' ) ); // use --debug flag to view. @@ -927,13 +927,13 @@ private function create_stripe_source( $customer ) { */ private function create_stripe_payment_intent( $amount, $customer ) { $payment_intent = \Stripe\PaymentIntent::create( - [ + array( 'amount' => $amount, 'currency' => 'gbp', - 'payment_method_types' => [ 'card' ], + 'payment_method_types' => array( 'card' ), 'customer' => $customer['id'], 'payment_method' => $customer['invoice_settings']['default_payment_method'], - ] + ) ); // use --debug flag to view. @@ -947,10 +947,10 @@ public function testCheckoutMutationWithStripe() { WC()->customer->save(); // Add items to the cart. - $product_ids = [ + $product_ids = array( $this->factory->product->createSimple(), $this->factory->product->createSimple(), - ]; + ); WC()->cart->add_to_cart( $product_ids[0], 1 ); WC()->cart->add_to_cart( $product_ids[1], 1 ); @@ -964,25 +964,25 @@ public function testCheckoutMutationWithStripe() { $this->markTestSkipped( $e->getMessage() ); } - $input = [ + $input = array( 'paymentMethod' => 'stripe', - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => '_stripe_source_id', 'value' => $stripe_source['id'], - ], - [ + ), + array( 'key' => '_stripe_customer_id', 'value' => $stripe_customer['id'], - ], - [ + ), + array( 'key' => '_stripe_intent_id', 'value' => $payment_intent['id'], - ], - ], - ]; + ), + ), + ); - $variables = [ 'input' => $this->getCheckoutInput( $input ) ]; + $variables = array( 'input' => $this->getCheckoutInput( $input ) ); // Remove "metaData" value field and "redirect" link from the mutation output. $query = ' mutation checkout( $input: CheckoutInput! ) { @@ -1032,24 +1032,24 @@ public function testCheckoutMutationWithStripe() { * Test mutation and input. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'checkout.order.id', static::NOT_NULL ), $this->expectedField( 'checkout.order.status', 'PROCESSING' ), $this->expectedNode( 'checkout.order.metaData', - [ $this->expectedField( 'key', '_stripe_source_id' ) ] + array( $this->expectedField( 'key', '_stripe_source_id' ) ) ), $this->expectedNode( 'checkout.order.metaData', - [ $this->expectedField( 'key', '_stripe_customer_id' ) ] + array( $this->expectedField( 'key', '_stripe_customer_id' ) ) ), $this->expectedNode( 'checkout.order.metaData', - [ $this->expectedField( 'key', '_stripe_intent_id' ) ] + array( $this->expectedField( 'key', '_stripe_intent_id' ) ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[0] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -1059,11 +1059,11 @@ public function testCheckoutMutationWithStripe() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedNode( 'checkout.order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $product_ids[1] ), $this->expectedField( 'quantity', static::NOT_NULL ), $this->expectedField( 'taxClass', static::NOT_NULL ), @@ -1073,20 +1073,20 @@ public function testCheckoutMutationWithStripe() { $this->expectedField( 'totalTax', static::NOT_NULL ), $this->expectedField( 'taxStatus', static::NOT_NULL ), $this->expectedField( 'product.node.id', static::NOT_NULL ), - ] + ) ), $this->expectedField( 'checkout.result', 'success' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); // Confirm cart empty after successful checkout. $query = $this->getCartQuery(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedField( 'cart.contents.nodes', [] ), + $expected = array( + $this->expectedField( 'cart.contents.nodes', array() ), $this->expectedField( 'cart.total', '$0.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -1095,22 +1095,22 @@ public function testCheckoutMutationCartItemValidation() { add_filter( 'woocommerce_hold_stock_for_checkout', '__return_false' ); $product_id = $this->factory->product->createSimple( - [ + array( 'manage_stock' => true, 'stock_quantity' => 3, - ] + ) ); $key = WC()->cart->add_to_cart( $product_id, 3 ); WC()->cart->set_quantity( $key, 5 ); - $input = [ - 'account' => [ + $input = array( + 'account' => array( 'username' => 'test_user_1', 'password' => 'test_pass', - ], - ]; - $variables = [ 'input' => $this->getCheckoutInput( $input ) ]; + ), + ); + $variables = array( 'input' => $this->getCheckoutInput( $input ) ); $query = $this->getCheckoutMutation(); /** @@ -1119,7 +1119,7 @@ public function testCheckoutMutationCartItemValidation() { * Ensure that checkout failed when stock is too low. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'checkout', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'checkout', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); } diff --git a/tests/wpunit/CollectionStatsQueryTest.php b/tests/wpunit/CollectionStatsQueryTest.php index 48cf49899..0b2a7e693 100644 --- a/tests/wpunit/CollectionStatsQueryTest.php +++ b/tests/wpunit/CollectionStatsQueryTest.php @@ -9,7 +9,7 @@ public function setUp(): void { update_option( 'woocommerce_attribute_lookup_enabled', 'yes' ); update_option( 'woocommerce_attribute_lookup_direct_updates', 'yes' ); } - + public function testCollectionStatsQuery() { $this->factory->product_variation->createSome( $this->factory->product->createVariable() @@ -47,106 +47,106 @@ public function testCollectionStatsQuery() { } '; - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_COLOR', 'terms' => 'red', 'operator' => 'IN', - ], - ], - ], - ], - 'taxonomies' => [ - [ + ), + ), + ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_COLOR', 'relation' => 'AND', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_COLOR' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'red' ), $this->expectedField( 'count', 2 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'blue' ), $this->expectedField( 'count', 2 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'green' ), $this->expectedField( 'count', 2 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), - ], + ), 0 ), $this->expectedNode( 'collectionStats.stockStatusCounts', - [ + array( $this->expectedField( 'status', 'IN_STOCK' ), $this->expectedField( 'count', 2 ), - ] + ) ), $this->expectedNode( 'collectionStats.stockStatusCounts', - [ + array( $this->expectedField( 'status', 'OUT_OF_STOCK' ), $this->expectedField( 'count', 0 ), - ] + ) ), $this->expectedNode( 'collectionStats.stockStatusCounts', - [ + array( $this->expectedField( 'status', 'ON_BACKORDER' ), $this->expectedField( 'count', 0 ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCollectionStatsQueryWithWhereArgs() { // Create product attributes. - $kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'special', 'normal' ], 'Product type' ); - $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; + $kind_attribute = $this->factory->product->createAttribute( 'kind', array( 'special', 'normal' ), 'Product type' ); + $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id; // Create attribute objects. $kind_attribute_normal_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $normal_term_id ] + array( $normal_term_id ) ); - + $kind_attribute_special_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $special_term_id ] + array( $special_term_id ) ); $kind_attribute_both = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $normal_term_id, $special_term_id ] + array( $normal_term_id, $special_term_id ) ); // Create taxonomies. @@ -156,38 +156,37 @@ public function testCollectionStatsQueryWithWhereArgs() { // Create products. $post_ids = $this->factory->product->createManySimple( 20, - [ - 'attributes' => [ $kind_attribute_normal_only ], - 'category_ids' => [ $clothing_category_id ], - 'default_attributes' => [ 'pa_kind' => 'normal' ], - ] + array( + 'attributes' => array( $kind_attribute_normal_only ), + 'category_ids' => array( $clothing_category_id ), + 'default_attributes' => array( 'pa_kind' => 'normal' ), + ) ); $this->factory->product->createManySimple( 5, - [ - 'category_ids' => [ $clothing_category_id ], - 'attributes' => [ $kind_attribute_special_only ], - 'default_attributes' => [ 'pa_kind' => 'special' ], - ] + array( + 'category_ids' => array( $clothing_category_id ), + 'attributes' => array( $kind_attribute_special_only ), + 'default_attributes' => array( 'pa_kind' => 'special' ), + ) ); $this->factory->product->createManySimple( 5, - [ - 'category_ids' => [ $clothing_category_id ], - 'tag_ids' => [ $shoes_tag_id ], - 'attributes' => [ $kind_attribute_special_only ], - 'default_attributes' => [ 'pa_kind' => 'special' ], - ] + array( + 'category_ids' => array( $clothing_category_id ), + 'tag_ids' => array( $shoes_tag_id ), + 'attributes' => array( $kind_attribute_special_only ), + 'default_attributes' => array( 'pa_kind' => 'special' ), + ) ); - $this->factory->product->createManySimple( 3, [ 'attributes' => [ $kind_attribute_both ] ] ); - + $this->factory->product->createManySimple( 3, array( 'attributes' => array( $kind_attribute_both ) ) ); - $query = " - query (\$where: CollectionStatsWhereArgs, \$taxonomies: [CollectionStatsQueryInput]) { + $query = ' + query ($where: CollectionStatsWhereArgs, $taxonomies: [CollectionStatsQueryInput]) { collectionStats( calculateRatingCounts: true - taxonomies: \$taxonomies - where: \$where + taxonomies: $taxonomies + where: $where ) { attributeCounts { @@ -200,249 +199,255 @@ public function testCollectionStatsQueryWithWhereArgs() { } } } - "; + '; /** * Query for products with the "clothing" category and confirm correct count. */ - $variables = [ + $variables = array( 'calculateRatingCounts' => true, - 'where' => [ - 'categoryIdIn' => [ $clothing_category_id ], - ], - 'taxonomies' => [ - [ + 'where' => array( + 'categoryIdIn' => array( $clothing_category_id ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_KIND', - 'relation' => "AND", - ], - ], - ]; + 'relation' => 'AND', + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_KIND' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'normal' ), $this->expectedField( 'count', 20 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'special' ), $this->expectedField( 'count', 10 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), - ], + ), 0 - ) - ]; + ), + ); $this->assertQuerySuccessful( $response, $expected ); // Test again with the "categoryIn" where arg. - $variables = [ + $variables = array( 'calculateRatingCounts' => true, - 'where' => [ - 'categoryIn' => [ 'clothing' ], - ], - 'taxonomies' => [ - [ + 'where' => array( + 'categoryIn' => array( 'clothing' ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_KIND', - 'relation' => "AND", - ], - ], - ]; + 'relation' => 'AND', + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); /** * Query for products with the "shoes" tag and confirm correct count. */ - $variables = [ + $variables = array( 'calculateRatingCounts' => true, - 'where' => [ - 'tagIdIn' => [ $shoes_tag_id ], - ], - 'taxonomies' => [ - [ + 'where' => array( + 'tagIdIn' => array( $shoes_tag_id ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_KIND', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_KIND' ), $this ->not() - ->expectedNode( 'terms', [ $this->expectedField( 'node.slug', 'normal' ) ] ), + ->expectedNode( 'terms', array( $this->expectedField( 'node.slug', 'normal' ) ) ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'special' ), $this->expectedField( 'count', 5 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), - ], + ), 0 - ) - ]; + ), + ); $this->assertQuerySuccessful( $response, $expected ); // Test again with the "tagIn" where arg. - $variables = [ + $variables = array( 'calculateRatingCounts' => true, - 'where' => [ - 'tagIn' => [ 'shoes' ], - ], - 'taxonomies' => [ - [ + 'where' => array( + 'tagIn' => array( 'shoes' ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_KIND', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); /** * Query for products with the "shoes" tag and confirm correct count. */ - $variables = [ + $variables = array( 'calculateRatingCounts' => true, - 'where' => [ - 'categoryIn' => [ 'clothing' ], - 'attributes' => [ - 'queries' => [ - [ + 'where' => array( + 'categoryIn' => array( 'clothing' ), + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', 'ids' => $normal_term_id, 'operator' => 'IN', - ], - ] - ], - ], - 'taxonomies' => [ - [ + ), + ), + ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_KIND', - 'relation' => "AND", - ], - ], - ]; + 'relation' => 'AND', + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_KIND' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'normal' ), $this->expectedField( 'count', 20 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ] + ) ), $this ->not() - ->expectedNode( 'terms', [ $this->expectedField( 'node.slug', 'special' ) ] ), - ], + ->expectedNode( 'terms', array( $this->expectedField( 'node.slug', 'special' ) ) ), + ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCollectionStatsQueryWithOrTaxQueries() { // Create product attributes. - $kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'normal', 'special' ], 'Product type' ); - $pattern_attribute = $this->factory->product->createAttribute( 'pattern', [ 'polka-dot', 'striped' ], 'Product pattern' ); + $kind_attribute = $this->factory->product->createAttribute( 'kind', array( 'normal', 'special' ), 'Product type' ); + $pattern_attribute = $this->factory->product->createAttribute( 'pattern', array( 'polka-dot', 'striped' ), 'Product pattern' ); - $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; - $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id; - $kind_attribute_normal_only = $this->factory->product->createAttributeObject( + $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; + $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id; + $kind_attribute_normal_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $normal_term_id ] + array( $normal_term_id ) ); $kind_attribute_special_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $special_term_id ] + array( $special_term_id ) ); - $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id; - $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id; + $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id; + $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id; $pattern_attribute_polka_dot_only = $this->factory->product->createAttributeObject( $pattern_attribute['attribute_id'], $pattern_attribute['attribute_taxonomy'], - [ $polka_dot_term_id ] + array( $polka_dot_term_id ) ); - $pattern_attribute_striped_only = $this->factory->product->createAttributeObject( + $pattern_attribute_striped_only = $this->factory->product->createAttributeObject( $pattern_attribute['attribute_id'], $pattern_attribute['attribute_taxonomy'], - [ $striped_term_id ] + array( $striped_term_id ) ); // Create products. $this->factory->product->createManySimple( 3, - [ - 'attributes' => [ $kind_attribute_normal_only ], - 'default_attributes' => [ 'pa_kind' => 'normal' ], - ] + array( + 'attributes' => array( $kind_attribute_normal_only ), + 'default_attributes' => array( 'pa_kind' => 'normal' ), + ) ); $this->factory->product->createManySimple( 7, - [ - 'attributes' => [ $kind_attribute_special_only ], - 'default_attributes' => [ 'pa_kind' => 'special' ], - ] + array( + 'attributes' => array( $kind_attribute_special_only ), + 'default_attributes' => array( 'pa_kind' => 'special' ), + ) ); $this->factory->product->createManySimple( 4, - [ - 'attributes' => [ $pattern_attribute_polka_dot_only ], - 'default_attributes' => [ 'pa_pattern' => 'polka-dot' ], - ] + array( + 'attributes' => array( $pattern_attribute_polka_dot_only ), + 'default_attributes' => array( 'pa_pattern' => 'polka-dot' ), + ) ); $this->factory->product->createManySimple( 6, - [ - 'attributes' => [ $pattern_attribute_striped_only ], - 'default_attributes' => [ 'pa_pattern' => 'striped' ], - ] + array( + 'attributes' => array( $pattern_attribute_striped_only ), + 'default_attributes' => array( 'pa_pattern' => 'striped' ), + ) ); $this->factory->product->createManySimple( 2, - [ - 'attributes' => [ + array( + 'attributes' => array( $kind_attribute_normal_only, $pattern_attribute_polka_dot_only, - ], - 'default_attributes' => [ 'pa_kind' => 'normal', 'pa_pattern' => 'polka-dot' ], - ] + ), + 'default_attributes' => array( + 'pa_kind' => 'normal', + 'pa_pattern' => 'polka-dot', + ), + ) ); $this->factory->product->createManySimple( 8, - [ - 'attributes' => [ + array( + 'attributes' => array( $kind_attribute_special_only, $pattern_attribute_striped_only, - ], - 'default_attributes' => [ 'pa_kind' => 'special', 'pa_pattern' => 'striped' ], - ] + ), + 'default_attributes' => array( + 'pa_kind' => 'special', + 'pa_pattern' => 'striped', + ), + ) ); $query = ' @@ -466,102 +471,102 @@ public function testCollectionStatsQueryWithOrTaxQueries() { } '; - $variables = [ - 'taxonomies' => [ - [ + $variables = array( + 'taxonomies' => array( + array( 'taxonomy' => 'PA_KIND', 'relation' => 'OR', - ], - [ + ), + array( 'taxonomy' => 'PA_PATTERN', 'relation' => 'OR', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_KIND' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'normal' ), $this->expectedField( 'count', 5 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 0 ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'special' ), $this->expectedField( 'count', 15 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 1 ), - ], + ), ), $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_PATTERN' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'polka-dot' ), $this->expectedField( 'count', 6 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 0 ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'striped' ), $this->expectedField( 'count', 14 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 1 ), - ], + ), ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCollectionStatsQueryWithAndTaxQueries() { // Create product attributes. - $kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'normal', 'special' ], 'Product type' ); - $pattern_attribute = $this->factory->product->createAttribute( 'pattern', [ 'polka-dot', 'striped' ], 'Product pattern' ); + $kind_attribute = $this->factory->product->createAttribute( 'kind', array( 'normal', 'special' ), 'Product type' ); + $pattern_attribute = $this->factory->product->createAttribute( 'pattern', array( 'polka-dot', 'striped' ), 'Product pattern' ); - $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; - $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id; - $kind_attribute_normal_only = $this->factory->product->createAttributeObject( + $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; + $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id; + $kind_attribute_normal_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $normal_term_id ] + array( $normal_term_id ) ); $kind_attribute_special_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $special_term_id ] + array( $special_term_id ) ); - $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id; - $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id; + $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id; + $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id; $pattern_attribute_polka_dot_only = $this->factory->product->createAttributeObject( $pattern_attribute['attribute_id'], $pattern_attribute['attribute_taxonomy'], - [ $polka_dot_term_id ] + array( $polka_dot_term_id ) ); - $pattern_attribute_striped_only = $this->factory->product->createAttributeObject( + $pattern_attribute_striped_only = $this->factory->product->createAttributeObject( $pattern_attribute['attribute_id'], $pattern_attribute['attribute_taxonomy'], - [ $striped_term_id ] + array( $striped_term_id ) ); // Create taxonomies. @@ -570,54 +575,60 @@ public function testCollectionStatsQueryWithAndTaxQueries() { // Create products. $this->factory->product->createManySimple( 3, - [ - 'category_ids' => [ $clothing_category_id ], - 'attributes' => [ $kind_attribute_normal_only ], - 'default_attributes' => [ 'pa_kind' => 'normal' ], - ] + array( + 'category_ids' => array( $clothing_category_id ), + 'attributes' => array( $kind_attribute_normal_only ), + 'default_attributes' => array( 'pa_kind' => 'normal' ), + ) ); $this->factory->product->createManySimple( 7, - [ - 'attributes' => [ $kind_attribute_special_only ], - 'default_attributes' => [ 'pa_kind' => 'special' ], - ] + array( + 'attributes' => array( $kind_attribute_special_only ), + 'default_attributes' => array( 'pa_kind' => 'special' ), + ) ); $this->factory->product->createManySimple( 4, - [ - 'category_ids' => [ $clothing_category_id ], - 'attributes' => [ $pattern_attribute_polka_dot_only ], - 'default_attributes' => [ 'pa_pattern' => 'polka-dot' ], - ] + array( + 'category_ids' => array( $clothing_category_id ), + 'attributes' => array( $pattern_attribute_polka_dot_only ), + 'default_attributes' => array( 'pa_pattern' => 'polka-dot' ), + ) ); $this->factory->product->createManySimple( 6, - [ - 'attributes' => [ $pattern_attribute_striped_only ], - 'default_attributes' => [ 'pa_pattern' => 'striped' ], - ] + array( + 'attributes' => array( $pattern_attribute_striped_only ), + 'default_attributes' => array( 'pa_pattern' => 'striped' ), + ) ); $this->factory->product->createManySimple( 2, - [ - 'attributes' => [ + array( + 'attributes' => array( $kind_attribute_normal_only, $pattern_attribute_polka_dot_only, - ], - 'default_attributes' => [ 'pa_kind' => 'normal', 'pa_pattern' => 'polka-dot' ], - ] + ), + 'default_attributes' => array( + 'pa_kind' => 'normal', + 'pa_pattern' => 'polka-dot', + ), + ) ); $this->factory->product->createManySimple( 8, - [ - 'category_ids' => [ $clothing_category_id ], - 'attributes' => [ + array( + 'category_ids' => array( $clothing_category_id ), + 'attributes' => array( $kind_attribute_special_only, $pattern_attribute_striped_only, - ], - 'default_attributes' => [ 'pa_kind' => 'special', 'pa_pattern' => 'striped' ], - ] + ), + 'default_attributes' => array( + 'pa_kind' => 'special', + 'pa_pattern' => 'striped', + ), + ) ); $query = ' @@ -641,72 +652,72 @@ public function testCollectionStatsQueryWithAndTaxQueries() { } '; - $variables = [ - 'where' => [ - 'categoryIn' => [ 'clothing' ], - ], - 'taxonomies' => [ - [ + $variables = array( + 'where' => array( + 'categoryIn' => array( 'clothing' ), + ), + 'taxonomies' => array( + array( 'taxonomy' => 'PA_PATTERN', 'relation' => 'OR', - ], - [ + ), + array( 'taxonomy' => 'PA_KIND', 'relation' => 'AND', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_KIND' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'normal' ), $this->expectedField( 'count', 3 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 0 ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'special' ), $this->expectedField( 'count', 8 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 1 ), - ], + ), ), $this->expectedNode( - 'collectionStats.attributeCounts', - [ + 'collectionStats.attributeCounts', + array( $this->expectedField( 'slug', 'PA_PATTERN' ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'polka-dot' ), $this->expectedField( 'count', 4 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 0 ), $this->expectedNode( 'terms', - [ + array( $this->expectedField( 'node.slug', 'striped' ), $this->expectedField( 'count', 8 ), $this->expectedField( 'termId', static::NOT_FALSY ), - ], + ), 1 ), - ], + ), ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ConnectionPaginationTest.php b/tests/wpunit/ConnectionPaginationTest.php index 687cd34cf..4b3eeea0b 100644 --- a/tests/wpunit/ConnectionPaginationTest.php +++ b/tests/wpunit/ConnectionPaginationTest.php @@ -13,13 +13,13 @@ public function toCursor( $id ) { // tests public function testCouponsPagination() { - $coupons = [ + $coupons = array( $this->factory->coupon->create(), $this->factory->coupon->create(), $this->factory->coupon->create(), $this->factory->coupon->create(), $this->factory->coupon->create(), - ]; + ); usort( $coupons, @@ -51,16 +51,16 @@ static function ( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = [ 'first' => 2 ]; + $variables = array( 'first' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'coupons.pageInfo.hasPreviousPage', false ), $this->expectedField( 'coupons.pageInfo.hasNextPage', true ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[0] ) ), $this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[1] ) ), $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[0] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -69,12 +69,12 @@ static function ( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $coupons[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ), $this->expectedField( 'coupons.pageInfo.hasNextPage', false ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[2] ) ), @@ -82,7 +82,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[2] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[3] ), $this->expectedField( 'coupons.nodes.2.databaseId', $coupons[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -92,18 +92,18 @@ static function ( $key_a, $key_b ) { * Test "last" parameter. */ \WPGraphQL::set_is_graphql_request( true ); - $variables = [ + $variables = array( 'last' => 2, - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ), $this->expectedField( 'coupons.pageInfo.hasNextPage', false ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[3] ) ), $this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[4] ) ), $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[3] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -112,31 +112,31 @@ static function ( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $coupons[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ), $this->expectedField( 'coupons.pageInfo.hasNextPage', true ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[1] ) ), $this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[2] ) ), $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[1] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductsPagination() { - $products = [ - $this->factory->product->createSimple( [ 'menu_order' => 0 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 1 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 2 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 3 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 4 ] ), - ]; + $products = array( + $this->factory->product->createSimple( array( 'menu_order' => 0 ) ), + $this->factory->product->createSimple( array( 'menu_order' => 1 ) ), + $this->factory->product->createSimple( array( 'menu_order' => 2 ) ), + $this->factory->product->createSimple( array( 'menu_order' => 3 ) ), + $this->factory->product->createSimple( array( 'menu_order' => 4 ) ), + ); usort( $products, @@ -167,9 +167,9 @@ static function ( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = [ 'first' => 2 ]; + $variables = array( 'first' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', 5 ), $this->expectedField( 'products.pageInfo.hasPreviousPage', false ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), @@ -177,7 +177,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[0] ), $this->expectedField( 'products.nodes.1.databaseId', $products[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -186,12 +186,12 @@ static function ( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $products[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', static::IS_NULL ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), @@ -200,7 +200,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.nodes.0.databaseId', $products[2] ), $this->expectedField( 'products.nodes.1.databaseId', $products[3] ), $this->expectedField( 'products.nodes.2.databaseId', $products[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -209,9 +209,9 @@ static function ( $key_a, $key_b ) { * * Test "last" parameter. */ - $variables = [ 'last' => 2 ]; + $variables = array( 'last' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', 5 ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), @@ -219,7 +219,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[4] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[3] ), $this->expectedField( 'products.nodes.1.databaseId', $products[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -228,12 +228,12 @@ static function ( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $products[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', static::IS_NULL ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), @@ -241,19 +241,45 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[1] ), $this->expectedField( 'products.nodes.1.databaseId', $products[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductsPaginationWithOrderby() { - $products = [ - $this->factory->product->createSimple( [ 'menu_order' => 0, 'regular_price' => 5 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 1, 'regular_price' => 4 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 2, 'regular_price' => 3, 'sale_price' => 0.50 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 3, 'regular_price' => 2 ] ), - $this->factory->product->createSimple( [ 'menu_order' => 4, 'regular_price' => 1 ] ), - ]; + $products = array( + $this->factory->product->createSimple( + array( + 'menu_order' => 0, + 'regular_price' => 5, + ) + ), + $this->factory->product->createSimple( + array( + 'menu_order' => 1, + 'regular_price' => 4, + ) + ), + $this->factory->product->createSimple( + array( + 'menu_order' => 2, + 'regular_price' => 3, + 'sale_price' => 0.50, + ) + ), + $this->factory->product->createSimple( + array( + 'menu_order' => 3, + 'regular_price' => 2, + ) + ), + $this->factory->product->createSimple( + array( + 'menu_order' => 4, + 'regular_price' => 1, + ) + ), + ); usort( $products, @@ -285,9 +311,19 @@ static function ( $key_a, $key_b ) { * * Test "first" parameter with the "orderby.MENU_ORDER". */ - $variables = [ 'first' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ] ]; + $variables = array( + 'first' => 2, + 'where' => array( + 'orderby' => array( + array( + 'field' => 'MENU_ORDER', + 'order' => 'DESC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', 5 ), $this->expectedField( 'products.pageInfo.hasPreviousPage', false ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), @@ -295,7 +331,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[0] ), $this->expectedField( 'products.nodes.1.databaseId', $products[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -304,13 +340,20 @@ static function ( $key_a, $key_b ) { * * Test "after" parameter with the "orderby.MENU_ORDER". */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $products[1] ), - 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ], - ]; + 'where' => array( + 'orderby' => array( + array( + 'field' => 'MENU_ORDER', + 'order' => 'DESC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', static::IS_NULL ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), @@ -319,7 +362,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.nodes.0.databaseId', $products[2] ), $this->expectedField( 'products.nodes.1.databaseId', $products[3] ), $this->expectedField( 'products.nodes.2.databaseId', $products[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -328,9 +371,19 @@ static function ( $key_a, $key_b ) { * * Test "last" parameter with the "orderby.MENU_ORDER". */ - $variables = [ 'last' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ] ]; + $variables = array( + 'last' => 2, + 'where' => array( + 'orderby' => array( + array( + 'field' => 'MENU_ORDER', + 'order' => 'DESC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', 5 ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), @@ -338,7 +391,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[0] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[1] ), $this->expectedField( 'products.nodes.1.databaseId', $products[0] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -347,13 +400,20 @@ static function ( $key_a, $key_b ) { * * Test "before" parameter with the "orderby.MENU_ORDER". */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $products[1] ), - 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ] - ]; + 'where' => array( + 'orderby' => array( + array( + 'field' => 'MENU_ORDER', + 'order' => 'DESC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', static::IS_NULL ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), @@ -361,7 +421,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[3] ), $this->expectedField( 'products.nodes.1.databaseId', $products[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -370,9 +430,19 @@ static function ( $key_a, $key_b ) { * * Test "first" parameter with the "orderby.PRICE". */ - $variables = [ 'first' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'DESC' ] ] ] ]; + $variables = array( + 'first' => 2, + 'where' => array( + 'orderby' => array( + array( + 'field' => 'PRICE', + 'order' => 'DESC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', 5 ), $this->expectedField( 'products.pageInfo.hasPreviousPage', false ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), @@ -380,7 +450,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[3] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[4] ), $this->expectedField( 'products.nodes.1.databaseId', $products[3] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -389,13 +459,20 @@ static function ( $key_a, $key_b ) { * * Test "after" parameter with the "orderby.PRICE". */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $products[3] ), - 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'DESC' ] ] ], - ]; + 'where' => array( + 'orderby' => array( + array( + 'field' => 'PRICE', + 'order' => 'DESC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', static::IS_NULL ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), @@ -404,7 +481,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.nodes.0.databaseId', $products[1] ), $this->expectedField( 'products.nodes.1.databaseId', $products[0] ), $this->expectedField( 'products.nodes.2.databaseId', $products[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -413,9 +490,19 @@ static function ( $key_a, $key_b ) { * * Test "last" parameter with the "orderby.PRICE". */ - $variables = [ 'last' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'ASC' ] ] ] ]; + $variables = array( + 'last' => 2, + 'where' => array( + 'orderby' => array( + array( + 'field' => 'PRICE', + 'order' => 'ASC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', 5 ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), @@ -423,7 +510,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[0] ), $this->expectedField( 'products.nodes.1.databaseId', $products[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -432,13 +519,20 @@ static function ( $key_a, $key_b ) { * * Test "before" parameter with the "orderby.PRICE". */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $products[0] ), - 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'ASC' ] ] ] - ]; + 'where' => array( + 'orderby' => array( + array( + 'field' => 'PRICE', + 'order' => 'ASC', + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.found', static::IS_NULL ), $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), @@ -446,7 +540,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[3] ), $this->expectedField( 'products.nodes.1.databaseId', $products[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -462,13 +556,13 @@ public function testOrdersPagination() { unset( $old_orders ); unset( $query ); - $orders = [ + $orders = array( $this->factory->order->createNew(), $this->factory->order->createNew(), $this->factory->order->createNew(), $this->factory->order->createNew(), $this->factory->order->createNew(), - ]; + ); usort( $orders, @@ -499,16 +593,16 @@ static function ( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = [ 'first' => 2 ]; + $variables = array( 'first' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'orders.pageInfo.hasPreviousPage', false ), $this->expectedField( 'orders.pageInfo.hasNextPage', true ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[0] ) ), $this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[1] ) ), $this->expectedField( 'orders.nodes.0.databaseId', $orders[0] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -517,12 +611,12 @@ static function ( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $orders[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'orders.pageInfo.hasPreviousPage', true ), $this->expectedField( 'orders.pageInfo.hasNextPage', false ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[2] ) ), @@ -530,7 +624,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'orders.nodes.0.databaseId', $orders[2] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[3] ), $this->expectedField( 'orders.nodes.2.databaseId', $orders[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -539,16 +633,16 @@ static function ( $key_a, $key_b ) { * * Test "last" parameter. */ - $variables = [ 'last' => 2 ]; + $variables = array( 'last' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'orders.pageInfo.hasPreviousPage', true ), $this->expectedField( 'orders.pageInfo.hasNextPage', false ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[3] ) ), $this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[4] ) ), $this->expectedField( 'orders.nodes.0.databaseId', $orders[3] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -557,32 +651,32 @@ static function ( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $orders[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'orders.pageInfo.hasPreviousPage', true ), $this->expectedField( 'orders.pageInfo.hasNextPage', true ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[1] ) ), $this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[2] ) ), $this->expectedField( 'orders.nodes.0.databaseId', $orders[1] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testRefundsPagination() { $order = $this->factory->order->createNew(); - $refunds = [ - $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), - $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), - $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), - $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), - $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), - ]; + $refunds = array( + $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), + $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), + $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), + $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), + $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), + ); usort( $refunds, @@ -614,16 +708,16 @@ static function ( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = [ 'first' => 2 ]; + $variables = array( 'first' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'refunds.pageInfo.hasPreviousPage', false ), $this->expectedField( 'refunds.pageInfo.hasNextPage', true ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[0] ) ), $this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[1] ) ), $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[0] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -632,12 +726,12 @@ static function ( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $refunds[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ), $this->expectedField( 'refunds.pageInfo.hasNextPage', false ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[2] ) ), @@ -645,7 +739,7 @@ static function ( $key_a, $key_b ) { $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[2] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[3] ), $this->expectedField( 'refunds.nodes.2.databaseId', $refunds[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -654,16 +748,16 @@ static function ( $key_a, $key_b ) { * * Test "last" parameter. */ - $variables = [ 'last' => 2 ]; + $variables = array( 'last' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ), $this->expectedField( 'refunds.pageInfo.hasNextPage', false ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[3] ) ), $this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[4] ) ), $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[3] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -672,39 +766,39 @@ static function ( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $refunds[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ), $this->expectedField( 'refunds.pageInfo.hasNextPage', true ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[1] ) ), $this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[2] ) ), $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[1] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCustomersPagination() { - $some_customers = [ + $some_customers = array( $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), - ]; + ); $customers = get_users( - [ + array( 'fields' => 'id', 'role' => 'customer', 'orderby' => 'user_login', 'order' => 'ASC', - ] + ) ); $customers = array_map( 'absint', $customers ); @@ -733,16 +827,16 @@ public function testCustomersPagination() { * * Test "first" parameter. */ - $variables = [ 'first' => 2 ]; + $variables = array( 'first' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.pageInfo.hasPreviousPage', false ), $this->expectedField( 'customers.pageInfo.hasNextPage', true ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[0] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[1] ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[0] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[1] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -751,19 +845,19 @@ public function testCustomersPagination() { * * Test "after" parameter. */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $customers[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[2] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[4] ) ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[2] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[3] ), $this->expectedField( 'customers.nodes.2.databaseId', $customers[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -772,16 +866,16 @@ public function testCustomersPagination() { * * Test "last" parameter. */ - $variables = [ 'last' => 2 ]; + $variables = array( 'last' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customers.pageInfo.hasNextPage', false ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[3] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[4] ) ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[3] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[4] ), - ]; + ); // $this->assertQuerySuccessful( $response, $expected ); @@ -790,19 +884,19 @@ public function testCustomersPagination() { * * Test "before" parameter. */ - $variables = [ + $variables = array( 'last' => 2, 'before' => $this->toCursor( $customers[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customers.pageInfo.hasNextPage', true ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[1] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[2] ) ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[1] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[2] ), - ]; + ); // $this->assertQuerySuccessful( $response, $expected ); } @@ -810,42 +904,42 @@ public function testCustomersPagination() { public function testDownloadableItemsPagination() { $customer_id = $this->factory->customer->create(); - $downloads = [ + $downloads = array( $this->factory->product->createDownload(), $this->factory->product->createDownload(), $this->factory->product->createDownload(), $this->factory->product->createDownload(), $this->factory->product->createDownload(), - ]; + ); $products = array_map( function ( $download ) { return $this->factory->product->createSimple( - [ + array( 'downloadable' => true, - 'downloads' => [ $download ], - ] + 'downloads' => array( $download ), + ) ); }, $downloads ); $order_id = $this->factory->order->createNew( - [ + array( 'status' => 'completed', 'customer_id' => $customer_id, - ], - [ + ), + array( 'line_items' => array_map( static function ( $product_id ) { - return [ + return array( 'product' => $product_id, 'qty' => 1, - ]; + ); }, $products ), - ] + ) ); $order = \wc_get_order( $order_id ); @@ -885,16 +979,16 @@ static function ( $product_id ) { * * Test "first" parameter. */ - $variables = [ 'first' => 2 ]; + $variables = array( 'first' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[0] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.endCursor', $this->toCursor( $downloads[1] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[0] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[1] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -903,12 +997,12 @@ static function ( $product_id ) { * * Test "after" parameter. */ - $variables = [ + $variables = array( 'first' => 3, 'after' => $this->toCursor( $downloads[1] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[2] ) ), @@ -916,7 +1010,7 @@ static function ( $product_id ) { $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[2] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[3] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.2.product.databaseId', $products[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -925,16 +1019,16 @@ static function ( $product_id ) { * * Test "last" parameter. */ - $variables = [ 'last' => 2 ]; + $variables = array( 'last' => 2 ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[3] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.endCursor', $this->toCursor( $downloads[4] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[3] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[4] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -943,12 +1037,12 @@ static function ( $product_id ) { * * Test "before" parameter. */ - $variables = [ + $variables = array( 'last' => 3, 'before' => $this->toCursor( $downloads[3] ), - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[0] ) ), @@ -956,7 +1050,7 @@ static function ( $product_id ) { $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[0] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[1] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.2.product.databaseId', $products[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CoreInterfaceQueriesTest.php b/tests/wpunit/CoreInterfaceQueriesTest.php index b7d610d55..5a7306dac 100644 --- a/tests/wpunit/CoreInterfaceQueriesTest.php +++ b/tests/wpunit/CoreInterfaceQueriesTest.php @@ -25,14 +25,14 @@ public function testProductAsNodeWithComments() { // Create product and review to be queried. $product_id = $this->products->create_simple(); $comment_id = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $product_id, 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $comment_id, 'rating', 1 ); @@ -48,21 +48,21 @@ public function testProductAsNodeWithComments() { } } '; - $variables = [ 'id' => $product_id ]; + $variables = array( 'id' => $product_id ); // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'product' => [ + $expected = array( + 'data' => array( + 'product' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ), 'commentCount' => 1, 'commentStatus' => 'open', - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -87,26 +87,26 @@ public function testOrderAsNodeWithComments() { } } '; - $variables = [ 'id' => $order_id ]; + $variables = array( 'id' => $order_id ); /** * Assertion One * * Authenticate as a shop manager and execute query and validate response. */ - wp_set_current_user( $this->factory->user->create( [ 'role' => 'shop_manager' ] ) ); + wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'order' => [ + $expected = array( + 'data' => array( + 'order' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'order', $order_id ), 'commentCount' => 2, 'commentStatus' => 'open', - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -120,15 +120,15 @@ public function testOrderAsNodeWithComments() { $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'order' => [ + $expected = array( + 'data' => array( + 'order' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'order', $order_id ), 'commentCount' => 1, 'commentStatus' => 'closed', - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -140,7 +140,7 @@ public function testProductAsNodeWithContentEditor() { $product = \wc_get_product( $product_id ); // Authenticate to view RAW content. - wp_set_current_user( $this->factory->user->create( [ 'role' => 'shop_manager' ] ) ); + wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) ); // Define query and variables. $query = ' @@ -153,23 +153,23 @@ public function testProductAsNodeWithContentEditor() { } } '; - $variables = [ + $variables = array( 'id' => $product_id, 'format' => 'RAW', - ]; + ); // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'product' => [ + $expected = array( + 'data' => array( + 'product' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ), 'content' => $product->get_description(), - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -178,12 +178,12 @@ public function testProductAsNodeWithContentEditor() { public function testProductAsNodeWithFeaturedImage() { // Create product to be queried. $attachment_id = $this->factory()->attachment->create( - [ + array( 'post_mime_type' => 'image/gif', 'post_author' => $this->admin, - ] + ) ); - $product_id = $this->products->create_simple( [ 'image_id' => $attachment_id ] ); + $product_id = $this->products->create_simple( array( 'image_id' => $attachment_id ) ); // Define query and variables. $query = ' @@ -197,21 +197,21 @@ public function testProductAsNodeWithFeaturedImage() { } } '; - $variables = [ 'id' => $product_id ]; + $variables = array( 'id' => $product_id ); // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'product' => [ + $expected = array( + 'data' => array( + 'product' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ), 'featuredImageId' => \GraphQLRelay\Relay::toGlobalId( 'post', $attachment_id ), 'featuredImageDatabaseId' => $attachment_id, - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -250,15 +250,15 @@ public function testProductAsContentNode() { } } '; - $variables = [ 'id' => $product_id ]; + $variables = array( 'id' => $product_id ); // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'product' => [ + $expected = array( + 'data' => array( + 'product' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ), 'databaseId' => $wp_product->ID, 'date' => (string) $wc_product->get_date_created(), @@ -276,9 +276,9 @@ public function testProductAsContentNode() { 'isPreview' => null, 'previewRevisionDatabaseId' => null, 'previewRevisionId' => null, - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -301,20 +301,20 @@ public function testProductAsUniformResourceIdentifiable() { } } '; - $variables = [ 'id' => $product_id ]; + $variables = array( 'id' => $product_id ); // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'product' => [ + $expected = array( + 'data' => array( + 'product' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ), 'uri' => str_ireplace( home_url(), '', get_permalink( $wp_product->ID ) ), - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -357,15 +357,15 @@ public function testNodeInterfacesOnProductVariation() { } } '; - $variables = [ 'id' => $variation_id ]; + $variables = array( 'id' => $variation_id ); // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = [ - 'data' => [ - 'productVariation' => [ + $expected = array( + 'data' => array( + 'productVariation' => array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $variation_id ), 'databaseId' => $wp_product->ID, 'date' => (string) $wc_product->get_date_created(), @@ -385,9 +385,9 @@ public function testNodeInterfacesOnProductVariation() { 'previewRevisionId' => null, 'featuredImageId' => \GraphQLRelay\Relay::toGlobalId( 'post', $wc_product->get_image_id() ), 'featuredImageDatabaseId' => $wc_product->get_image_id(), - ], - ], - ]; + ), + ), + ); // Assert query response valid. $this->assertEquals( $expected, $response ); diff --git a/tests/wpunit/CouponMutationsTest.php b/tests/wpunit/CouponMutationsTest.php index c8e0211c8..e967a246f 100644 --- a/tests/wpunit/CouponMutationsTest.php +++ b/tests/wpunit/CouponMutationsTest.php @@ -17,14 +17,14 @@ public function testCreateCoupon() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'some_id', 'code' => 'testcode', 'amount' => 0.25, 'discountType' => 'PERCENT', - ], - ]; + ), + ); /** * Assertion One @@ -32,10 +32,10 @@ public function testCreateCoupon() { * Expect mutation to failed due to lack of capabilities */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedErrorPath( 'createCoupon' ), $this->expectedField( 'createCoupon', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -55,18 +55,18 @@ public function testCreateCoupon() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'createCoupon.coupon', - [ + array( $this->expectedField( 'id', static::NOT_FALSY ), $this->expectedField( 'databaseId', static::NOT_FALSY ), $this->expectedField( 'code', 'testcode' ), $this->expectedField( 'amount', 0.25 ), $this->expectedField( 'discountType', 'PERCENT' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -88,15 +88,15 @@ public function testUpdateCoupon() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'some_id', 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), 'code' => 'blahblah', 'amount' => 0.25, 'discountType' => 'PERCENT', - ], - ]; + ), + ); /** * Assertion One @@ -104,10 +104,10 @@ public function testUpdateCoupon() { * Expect mutation to failed due to lack of capabilities */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedErrorPath( 'updateCoupon' ), $this->expectedField( 'updateCoupon', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -127,18 +127,18 @@ public function testUpdateCoupon() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'updateCoupon.coupon', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'shop_coupon', $coupon_id ) ), $this->expectedField( 'databaseId', $coupon_id ), $this->expectedField( 'code', 'blahblah' ), $this->expectedField( 'amount', 0.25 ), $this->expectedField( 'discountType', 'PERCENT' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -157,12 +157,12 @@ public function testDeleteCoupon() { } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'some_id', 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), - ], - ]; + ), + ); /** * Assertion One @@ -170,10 +170,10 @@ public function testDeleteCoupon() { * Expect mutation to failed due to lack of capabilities */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedErrorPath( 'deleteCoupon' ), $this->expectedField( 'deleteCoupon', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -193,15 +193,15 @@ public function testDeleteCoupon() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'deleteCoupon.coupon', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'shop_coupon', $coupon_id ) ), $this->expectedField( 'databaseId', $coupon_id ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CouponQueriesTest.php b/tests/wpunit/CouponQueriesTest.php index e5fc9623f..2dbc7da41 100644 --- a/tests/wpunit/CouponQueriesTest.php +++ b/tests/wpunit/CouponQueriesTest.php @@ -4,7 +4,7 @@ class CouponQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQL public function expectedCouponData( $coupon_id ) { $coupon = new \WC_Coupon( $coupon_id ); - $expected = [ + $expected = array( $this->expectedField( 'coupon.id', $this->toRelayId( 'shop_coupon', $coupon_id ) ), $this->expectedField( 'coupon.databaseId', $coupon->get_id() ), $this->expectedField( 'coupon.code', $coupon->get_code() ), @@ -24,26 +24,26 @@ public function expectedCouponData( $coupon_id ) { $this->expectedField( 'coupon.minimumAmount', $this->maybe( $coupon->get_minimum_amount(), static::IS_NULL ) ), $this->expectedField( 'coupon.maximumAmount', $this->maybe( $coupon->get_maximum_amount(), static::IS_NULL ) ), $this->expectedField( 'coupon.emailRestrictions', $this->maybe( $coupon->get_email_restrictions(), static::IS_NULL ) ), - ]; + ); foreach ( $coupon->get_product_ids() as $product_id ) { - $expected[] = $this->expectedNode( 'coupon.products.nodes', [ 'databaseId' => $product_id ] ); + $expected[] = $this->expectedNode( 'coupon.products.nodes', array( 'databaseId' => $product_id ) ); } foreach ( $coupon->get_excluded_product_ids() as $product_id ) { - $expected[] = $this->expectedNode( 'coupon.excludedProducts.nodes', [ 'databaseId' => $product_id ] ); + $expected[] = $this->expectedNode( 'coupon.excludedProducts.nodes', array( 'databaseId' => $product_id ) ); } foreach ( $coupon->get_product_categories() as $category_id ) { - $expected[] = $this->expectedNode( 'coupon.productCategories.nodes', [ 'productCategoryId' => $category_id ] ); + $expected[] = $this->expectedNode( 'coupon.productCategories.nodes', array( 'productCategoryId' => $category_id ) ); } foreach ( $coupon->get_excluded_product_categories() as $category_id ) { - $expected[] = $this->expectedNode( 'coupon.excludedProductCategories.nodes', [ 'productCategoryId' => $category_id ] ); + $expected[] = $this->expectedNode( 'coupon.excludedProductCategories.nodes', array( 'productCategoryId' => $category_id ) ); } foreach ( $coupon->get_used_by() as $customer_id ) { - $expected[] = $this->expectedNode( 'coupon.usedBy.nodes', [ 'databaseId' => $customer_id ] ); + $expected[] = $this->expectedNode( 'coupon.usedBy.nodes', array( 'databaseId' => $customer_id ) ); } return $expected; @@ -52,13 +52,13 @@ public function expectedCouponData( $coupon_id ) { // tests public function testCouponQuery() { $coupon_id = $this->factory->coupon->create( - [ + array( 'code' => '10off', 'amount' => 10, 'discount_type' => 'percent', - 'product_ids' => [ $this->factory->product->createSimple() ], - 'excluded_product_ids' => [ $this->factory->product->createSimple() ], - ] + 'product_ids' => array( $this->factory->product->createSimple() ), + 'excluded_product_ids' => array( $this->factory->product->createSimple() ), + ) ); $query = ' @@ -122,9 +122,9 @@ public function testCouponQuery() { * Confirm customer's can't query coupons by ID. */ $this->loginAsCustomer(); - $variables = [ 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'coupon', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'coupon', static::IS_NULL ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -157,12 +157,12 @@ public function testCouponQueryAndIds() { * Testing "ID" ID type. */ $this->loginAsShopManager(); - $variables = [ + $variables = array( 'id' => $relay_id, 'idType' => 'ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'coupon.id', $relay_id ) ]; + $expected = array( $this->expectedField( 'coupon.id', $relay_id ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -171,10 +171,10 @@ public function testCouponQueryAndIds() { * * Testing "DATABASE_ID" ID type */ - $variables = [ + $variables = array( 'id' => $coupon_id, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -184,33 +184,33 @@ public function testCouponQueryAndIds() { * * Testing "CODE" ID type. */ - $variables = [ + $variables = array( 'id' => $coupon->get_code(), 'idType' => 'CODE', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); } public function testCouponsQueryAndWhereArgs() { - $coupons = [ + $coupons = array( $this->factory->coupon->create(), $this->factory->coupon->create( - [ + array( 'code' => '20off', 'amount' => 20, 'discount_type' => 'percent', - ] + ) ), $this->factory->coupon->create( - [ + array( 'code' => 'testcode', 'amount' => 30, 'discount_type' => 'percent', - ] + ) ), - ]; + ); $query = ' query ($code: String, $include: [Int], $exclude: [Int]) { @@ -229,9 +229,9 @@ public function testCouponsQueryAndWhereArgs() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'coupons.nodes', static::IS_FALSY ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -244,11 +244,11 @@ public function testCouponsQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), - ]; + $expected = array( + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), + ); $this->assertQuerySuccessful( $response, $expected ); @@ -259,13 +259,13 @@ public function testCouponsQueryAndWhereArgs() { * * Tests 'code' where argument */ - $variables = [ 'code' => 'testcode' ]; + $variables = array( 'code' => 'testcode' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), - $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), - $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), - ]; + $expected = array( + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), + $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), + $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), + ); $this->assertQuerySuccessful( $response, $expected ); @@ -276,13 +276,13 @@ public function testCouponsQueryAndWhereArgs() { * * Tests 'include' where argument */ - $variables = [ 'include' => $coupons[0] ]; + $variables = array( 'include' => $coupons[0] ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), - $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), - $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), - ]; + $expected = array( + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), + $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), + $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), + ); $this->assertQuerySuccessful( $response, $expected ); @@ -291,14 +291,14 @@ public function testCouponsQueryAndWhereArgs() { * * Tests 'exclude' where argument */ - $variables = [ 'exclude' => $coupons[0] ]; + $variables = array( 'exclude' => $coupons[0] ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), - $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), + $expected = array( + $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), + $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CustomerMutationsTest.php b/tests/wpunit/CustomerMutationsTest.php index 57d71fe5f..0c4493ab3 100644 --- a/tests/wpunit/CustomerMutationsTest.php +++ b/tests/wpunit/CustomerMutationsTest.php @@ -43,13 +43,13 @@ public function generateCustomerInput() { $postcode = $this->faker->postcode(); $country = 'US'; - return [ + return array( 'firstName' => $first_name, 'lastName' => $last_name, 'username' => $username, 'password' => $password, 'email' => $email, - 'billing' => [ + 'billing' => array( 'firstName' => $first_name, 'lastName' => $last_name, 'address1' => $address, @@ -59,8 +59,8 @@ public function generateCustomerInput() { 'country' => $country, 'email' => $email, 'phone' => $phone, - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => $first_name, 'lastName' => $last_name, 'address1' => $address, @@ -69,12 +69,12 @@ public function generateCustomerInput() { 'postcode' => $postcode, 'country' => $country, 'phone' => $phone, - ], - ]; + ), + ); } private function empty_shipping() { - return [ + return array( 'firstName' => null, 'lastName' => null, 'company' => null, @@ -85,11 +85,11 @@ private function empty_shipping() { 'postcode' => null, 'country' => null, 'phone' => null, - ]; + ); } private function empty_billing() { - return [ + return array( 'firstName' => null, 'lastName' => null, 'company' => null, @@ -101,7 +101,7 @@ private function empty_billing() { 'country' => null, 'email' => null, 'phone' => null, - ]; + ); } private function executeRegisterCustomerMutation( $input ) { @@ -150,7 +150,7 @@ private function executeRegisterCustomerMutation( $input ) { } '; - $variables = [ 'input' => $input ]; + $variables = array( 'input' => $input ); return $this->graphql( compact( 'query', 'variables' ) ); } @@ -194,7 +194,7 @@ private function executeUpdateCustomerMutation( $input ) { } '; - $variables = [ 'input' => $input ]; + $variables = array( 'input' => $input ); return $this->graphql( compact( 'query', 'variables' ) ); } @@ -212,10 +212,10 @@ public function testRegisterMutationWithoutCustomerInfo() { $response = $this->executeRegisterCustomerMutation( array_merge( $customer_input, - [ - 'billing' => [], - 'shipping' => [], - ] + array( + 'billing' => array(), + 'shipping' => array(), + ) ) ); @@ -223,12 +223,12 @@ public function testRegisterMutationWithoutCustomerInfo() { $user = get_user_by( 'email', $customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ), $this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ), $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $customer_input['username'] ), @@ -236,10 +236,10 @@ public function testRegisterMutationWithoutCustomerInfo() { $this->expectedField( 'lastName', $customer_input['lastName'] ), $this->expectedField( 'billing', $this->empty_billing() ), $this->expectedField( 'shipping', $this->empty_shipping() ), - ] + ) ), $this->expectedField( 'registerCustomer.viewer.userId', $user->ID ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -258,21 +258,21 @@ public function testRegisterMutationWithBillingInfo() { $response = $this->executeRegisterCustomerMutation( array_merge( $customer_input, - [ - 'shipping' => [], - ] + array( + 'shipping' => array(), + ) ) ); $user = get_user_by( 'email', $customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ), $this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ), $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $customer_input['username'] ), @@ -280,10 +280,10 @@ public function testRegisterMutationWithBillingInfo() { $this->expectedField( 'lastName', $customer_input['lastName'] ), $this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ), $this->expectedField( 'shipping', $this->empty_shipping() ), - ] + ) ), $this->expectedField( 'registerCustomer.viewer.userId', $user->ID ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -302,22 +302,22 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() { $response = $this->executeRegisterCustomerMutation( array_merge( $customer_input, - [ - 'shipping' => [], + array( + 'shipping' => array(), 'shippingSameAsBilling' => true, - ] + ) ) ); $user = get_user_by( 'email', $customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ), $this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ), $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $customer_input['username'] ), @@ -331,10 +331,10 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() { array_intersect_key( $customer_input['billing'], $this->empty_shipping() ) ) ), - ] + ) ), $this->expectedField( 'registerCustomer.viewer.userId', $user->ID ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -355,12 +355,12 @@ public function testRegisterMutationWithBillingAndShippingInfo() { $user = get_user_by( 'email', $customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ), $this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ), $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $customer_input['username'] ), @@ -368,10 +368,10 @@ public function testRegisterMutationWithBillingAndShippingInfo() { $this->expectedField( 'lastName', $customer_input['lastName'] ), $this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ), $this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $customer_input['shipping'] ) ), - ] + ) ), $this->expectedField( 'registerCustomer.viewer.userId', $user->ID ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -392,10 +392,10 @@ public function testUpdateMutation() { $user = get_user_by( 'email', $initial_customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $initial_customer_input['email'] ), $this->expectedField( 'username', $initial_customer_input['username'] ), @@ -403,9 +403,9 @@ public function testUpdateMutation() { $this->expectedField( 'lastName', $initial_customer_input['lastName'] ), $this->expectedField( 'billing', array_merge( $this->empty_billing(), $initial_customer_input['billing'] ) ), $this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $initial_customer_input['shipping'] ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -417,16 +417,16 @@ public function testUpdateMutation() { $response = $this->executeUpdateCustomerMutation( array_merge( $customer_input, - [ + array( 'id' => $this->toRelayId( 'customer', $user->ID ), - ] + ) ) ); - $expected = [ + $expected = array( $this->expectedObject( 'updateCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $initial_customer_input['username'] ), @@ -434,9 +434,9 @@ public function testUpdateMutation() { $this->expectedField( 'lastName', $customer_input['lastName'] ), $this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ), $this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $customer_input['shipping'] ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -457,10 +457,10 @@ public function testUpdateMutationWithoutID() { $user = get_user_by( 'email', $initial_customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $initial_customer_input['email'] ), $this->expectedField( 'username', $initial_customer_input['username'] ), @@ -468,9 +468,9 @@ public function testUpdateMutationWithoutID() { $this->expectedField( 'lastName', $initial_customer_input['lastName'] ), $this->expectedField( 'billing', array_merge( $this->empty_billing(), $initial_customer_input['billing'] ) ), $this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $initial_customer_input['shipping'] ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -483,10 +483,10 @@ public function testUpdateMutationWithoutID() { unset( $customer_input['username'] ); $response = $this->executeUpdateCustomerMutation( $customer_input ); - $expected = [ + $expected = array( $this->expectedObject( 'updateCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $initial_customer_input['username'] ), @@ -494,9 +494,9 @@ public function testUpdateMutationWithoutID() { $this->expectedField( 'lastName', $customer_input['lastName'] ), $this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ), $this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $customer_input['shipping'] ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -515,9 +515,9 @@ public function testUpdateMutationWithShippingSameAsBilling() { $this->executeRegisterCustomerMutation( array_merge( $customer_input, - [ - 'shipping' => [], - ] + array( + 'shipping' => array(), + ) ) ); @@ -525,17 +525,17 @@ public function testUpdateMutationWithShippingSameAsBilling() { $this->assertTrue( is_a( $user, WP_User::class ) ); $response = $this->executeUpdateCustomerMutation( - [ + array( 'clientMutationId' => 'someId', 'id' => $this->toRelayId( 'customer', $user->ID ), 'shippingSameAsBilling' => true, - ] + ) ); - $expected = [ + $expected = array( $this->expectedObject( 'updateCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'username', $customer_input['username'] ), @@ -549,9 +549,9 @@ public function testUpdateMutationWithShippingSameAsBilling() { array_intersect_key( $customer_input['billing'], $this->empty_shipping() ) ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -568,29 +568,29 @@ public function testRegisterMutationWithoutAnyInfo() { * Tests mutation without a providing an username and password. */ $response = $this->executeRegisterCustomerMutation( - [ + array( 'email' => $customer_input['email'], 'firstName' => $customer_input['firstName'], 'lastName' => $customer_input['lastName'], - ] + ) ); $user = get_user_by( 'email', $customer_input['email'] ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', $customer_input['email'] ), $this->expectedField( 'firstName', $customer_input['firstName'] ), $this->expectedField( 'lastName', $customer_input['lastName'] ), $this->expectedField( 'billing', $this->empty_billing() ), $this->expectedField( 'shipping', $this->empty_shipping() ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -615,40 +615,40 @@ public function testCustomerMutationsWithMeta() { } } '; - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'some_id', 'email' => 'user@woographql.test', - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_meta_key', 'value' => 'test_meta_value', - ], - ], - ], - ]; + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $user = get_user_by( 'email', 'user@woographql.test' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = [ + $expected = array( $this->expectedObject( 'registerCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', 'user@woographql.test' ), $this->expectedNode( 'metaData', - [ + array( $this->expectedField( 'key', 'test_meta_key' ), $this->expectedField( 'value', 'test_meta_value' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -673,36 +673,36 @@ public function testCustomerMutationsWithMeta() { '; $this->loginAs( $user->ID ); \WC()->initialize_session(); - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'some_id', 'id' => $this->toRelayId( 'customer', $user->ID ), - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_meta_key', 'value' => 'new_meta_value', - ], - ], - ], - ]; + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'updateCustomer.customer', - [ + array( $this->expectedField( 'databaseId', $user->ID ), $this->expectedField( 'email', 'user@woographql.test' ), $this->expectedNode( 'metaData', - [ + array( $this->expectedField( 'key', 'test_meta_key' ), $this->expectedField( 'value', 'new_meta_value' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -726,34 +726,34 @@ public function testCustomerMutationsWithMeta() { '; $this->loginAs( 0 ); \WC()->initialize_session(); - $variables = [ - 'input' => [ + $variables = array( + 'input' => array( 'clientMutationId' => 'some_id', - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_meta_key', 'value' => 'test_meta_value', - ], - ], - ], - ]; + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'updateCustomer.customer', - [ + array( $this->expectedField( 'id', 'guest' ), $this->expectedNode( 'metaData', - [ + array( $this->expectedField( 'key', 'test_meta_key' ), $this->expectedField( 'value', 'test_meta_value' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CustomerQueriesTest.php b/tests/wpunit/CustomerQueriesTest.php index 4e7fa34ac..711fbdc08 100644 --- a/tests/wpunit/CustomerQueriesTest.php +++ b/tests/wpunit/CustomerQueriesTest.php @@ -14,10 +14,10 @@ public function expectedCustomerData( $id ) { $billing = $customer->get_billing(); $shipping = $customer->get_shipping(); - return [ + return array( $this->expectedObject( 'customer', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'user', $id ) ), $this->expectedField( 'databaseId', $id ), $this->expectedField( 'isVatExempt', $customer->get_is_vat_exempt() ), @@ -41,7 +41,7 @@ public function expectedCustomerData( $id ) { ), $this->expectedObject( 'billing', - [ + array( $this->expectedField( 'firstName', $this->maybe( $billing['first_name'] ) ), $this->expectedField( 'lastName', $this->maybe( $billing['last_name'] ) ), $this->expectedField( 'company', $this->maybe( $billing['company'] ) ), @@ -51,11 +51,11 @@ public function expectedCustomerData( $id ) { $this->expectedField( 'postcode', $this->maybe( $billing['postcode'] ) ), $this->expectedField( 'email', $this->maybe( $billing['email'] ) ), $this->expectedField( 'phone', $this->maybe( $billing['phone'] ) ), - ] + ) ), $this->expectedObject( 'shipping', - [ + array( $this->expectedField( 'firstName', $this->maybe( $shipping['first_name'] ) ), $this->expectedField( 'lastName', $this->maybe( $shipping['last_name'] ) ), $this->expectedField( 'company', $this->maybe( $shipping['company'] ) ), @@ -63,7 +63,7 @@ public function expectedCustomerData( $id ) { $this->expectedField( 'address2', $this->maybe( $shipping['address_2'] ) ), $this->expectedField( 'city', $this->maybe( $shipping['city'] ) ), $this->expectedField( 'postcode', $this->maybe( $shipping['postcode'] ) ), - ] + ) ), $this->expectedField( 'isPayingCustomer', $customer->get_is_paying_customer() ), $this->expectedField( @@ -78,9 +78,9 @@ public function expectedCustomerData( $id ) { ? \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $wp_user ) : static::IS_NULL ), - ] + ) ), - ]; + ); } // tests @@ -142,12 +142,12 @@ public function testCustomerQueryAndArgs() { * Query should return null value due to lack of permissions. */ $this->loginAsCustomer(); - $variables = [ 'id' => $this->toRelayId( 'user', $new_customer_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'user', $new_customer_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedErrorPath( 'customer' ), $this->expectedField( 'customer', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -159,7 +159,7 @@ public function testCustomerQueryAndArgs() { * * Query should return requested data because user queried themselves. */ - $variables = [ 'id' => $this->toRelayId( 'user', $this->customer ) ]; + $variables = array( 'id' => $this->toRelayId( 'user', $this->customer ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expectedCustomerData( $this->customer ); @@ -175,15 +175,15 @@ public function testCustomerQueryAndArgs() { * but should not have access to JWT fields. */ $this->loginAsShopManager(); - $variables = [ 'id' => $this->toRelayId( 'user', $new_customer_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'user', $new_customer_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_merge( - [ + array( $this->expectedErrorPath( 'customer.jwtAuthToken' ), $this->expectedField( 'customer.jwtAuthToken', static::IS_NULL ), $this->expectedErrorPath( 'customer.jwtRefreshToken' ), $this->expectedField( 'customer.jwtRefreshToken', static::IS_NULL ), - ], + ), $this->expectedCustomerData( $new_customer_id ) ); @@ -212,7 +212,7 @@ public function testCustomerQueryAndArgs() { * Query should return requested data because user queried themselves. */ $this->loginAs( $new_customer_id ); - $variables = [ 'customerId' => $new_customer_id ]; + $variables = array( 'customerId' => $new_customer_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -226,12 +226,12 @@ public function testCustomerQueryAndArgs() { * Query should return null value due to lack of permissions.. */ $this->loginAsCustomer(); - $variables = [ 'customerId' => $new_customer_id ]; + $variables = array( 'customerId' => $new_customer_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedErrorPath( 'customer' ), $this->expectedField( 'customer', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -240,17 +240,17 @@ public function testCustomerQueryAndArgs() { } public function testCustomersQueryAndWhereArgs() { - $users = [ + $users = array( $this->factory->customer->create( - [ + array( 'email' => 'gotcha@example.com', 'username' => 'megaman8080', - ] + ) ), $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), - ]; + ); $query = ' query ( @@ -284,7 +284,7 @@ public function testCustomersQueryAndWhereArgs() { */ $this->loginAs( $users[0] ); $response = $this->graphql( compact( 'query' ) ); - $expected = [ $this->expectedField( 'customers.nodes', [] ) ]; + $expected = array( $this->expectedField( 'customers.nodes', array() ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -295,7 +295,7 @@ public function testCustomersQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.nodes.#.databaseId', $users[0] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[1] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[2] ), @@ -304,7 +304,7 @@ public function testCustomersQueryAndWhereArgs() { $this->expectedField( 'customers.nodes.1.billing.email', static::NOT_NULL ), $this->expectedField( 'customers.nodes.2.billing.email', static::NOT_NULL ), $this->expectedField( 'customers.nodes.3.billing.email', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -313,12 +313,12 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "search" where argument. */ - $variables = [ 'search' => 'megaman8080' ]; + $variables = array( 'search' => 'megaman8080' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.nodes.0.databaseId', $users[0] ), $this->expectedField( 'customers.nodes.0.billing.email', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -327,12 +327,12 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "include" where argument. */ - $variables = [ 'include' => [ $users[2] ] ]; + $variables = array( 'include' => array( $users[2] ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.nodes.0.databaseId', $users[2] ), $this->expectedField( 'customers.nodes.0.billing.email', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -341,9 +341,9 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "exclude" where argument. */ - $variables = [ 'exclude' => [ $users[2] ] ]; + $variables = array( 'exclude' => array( $users[2] ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.nodes.#.databaseId', $users[0] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[1] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[3] ), @@ -351,7 +351,7 @@ public function testCustomersQueryAndWhereArgs() { $this->expectedField( 'customers.nodes.1.billing.email', static::NOT_NULL ), $this->expectedField( 'customers.nodes.2.billing.email', static::NOT_NULL ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[2] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -360,14 +360,14 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "email" where argument. */ - $variables = [ 'email' => 'gotcha@example.com' ]; + $variables = array( 'email' => 'gotcha@example.com' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customers.nodes.0.databaseId', $users[0] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[1] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[2] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[3] ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -376,21 +376,21 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "orderby" and "order" where arguments. */ - $variables = [ + $variables = array( 'orderby' => 'USERNAME', 'order' => 'ASC', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $all_users = get_users( - [ + array( 'fields' => 'ID', 'role' => 'customer', 'orderby' => 'username', 'order' => 'ASC', - ] + ) ); - $expected = []; + $expected = array(); foreach ( $all_users as $index => $user_id ) { $expected[] = $this->expectedField( "customers.nodes.{$index}.databaseId", @@ -405,19 +405,19 @@ public function testCustomerToOrdersConnection() { $new_customer_id = $this->factory->customer->create(); $order_1 = $this->factory->order->createNew( - [ 'customer_id' => $this->customer ] + array( 'customer_id' => $this->customer ) ); $order_2 = $this->factory->order->createNew( - [ 'customer_id' => $new_customer_id ] + array( 'customer_id' => $new_customer_id ) ); $guest_customer = new \WC_Customer(); $guest_customer->set_billing_email( 'test@test.com' ); $order_3 = $this->factory->order->createNew( - [ + array( 'customer_id' => $guest_customer->get_id(), 'billing_email' => $guest_customer->get_billing_email(), - ] + ) ); $query = ' @@ -441,9 +441,9 @@ public function testCustomerToOrdersConnection() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.orders.nodes.#.databaseId', $order_1 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -458,9 +458,9 @@ public function testCustomerToOrdersConnection() { $this->loginAs( 0 ); WC()->customer = $guest_customer; $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.orders.nodes.#.databaseId', $order_3 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -474,20 +474,20 @@ public function testCustomerAvailablePaymentMethodsField() { $expiry_year = gmdate( 'Y', strtotime( '+1 year' ) ); $token_cc = $this->factory->payment_token->createCCToken( $customer_id, - [ + array( 'last4' => 1234, 'expiry_month' => $expiry_month, 'expiry_year' => $expiry_year, 'card_type' => 'visa', 'token' => time(), - ] + ) ); $token_ec = $this->factory->payment_token->createECheckToken( $customer_id, - [ + array( 'last4' => 4567, 'token' => time(), - ] + ) ); // Create query. @@ -528,19 +528,19 @@ public function testCustomerAvailablePaymentMethodsField() { /** * Assert tokens are inaccessible as guest or admin */ - $variables = [ 'id' => $this->toRelayId( 'user', $customer_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'user', $customer_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'customer', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'customer', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); // Again, as admin. $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ), $this->expectedField( 'customer.availablePaymentMethods', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -549,66 +549,66 @@ public function testCustomerAvailablePaymentMethodsField() { */ $this->loginAs( $customer_id ); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ), $this->expectedNode( 'customer.availablePaymentMethods', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ), $this->expectedField( 'tokenId', $token_cc->get_id() ), $this->expectedField( 'last4', 1234 ), $this->expectedField( 'expiryMonth', $expiry_month ), $this->expectedField( 'expiryYear', $expiry_year ), $this->expectedField( 'cardType', 'visa' ), - ] + ) ), $this->expectedNode( 'customer.availablePaymentMethodsCC', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ), $this->expectedField( 'tokenId', $token_cc->get_id() ), $this->expectedField( 'last4', 1234 ), $this->expectedField( 'expiryMonth', $expiry_month ), $this->expectedField( 'expiryYear', $expiry_year ), $this->expectedField( 'cardType', 'visa' ), - ] + ) ), $this->expectedNode( 'customer.availablePaymentMethodsEC', - [ + array( $this->not()->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ), $this->not()->expectedField( 'tokenId', $token_cc->get_id() ), $this->not()->expectedField( 'last4', 1234 ), $this->not()->expectedField( 'expiryMonth', $expiry_month ), $this->not()->expectedField( 'expiryYear', $expiry_year ), $this->not()->expectedField( 'cardType', 'visa' ), - ] + ) ), $this->expectedNode( 'customer.availablePaymentMethods', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ), $this->expectedField( 'tokenId', $token_ec->get_id() ), $this->expectedField( 'last4', 4567 ), - ] + ) ), $this->expectedNode( 'customer.availablePaymentMethodsCC', - [ + array( $this->not()->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ), $this->not()->expectedField( 'tokenId', $token_ec->get_id() ), $this->not()->expectedField( 'last4', 4567 ), - ] + ) ), $this->expectedNode( 'customer.availablePaymentMethodsEC', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ), $this->expectedField( 'tokenId', $token_ec->get_id() ), $this->expectedField( 'last4', 4567 ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -645,9 +645,9 @@ static function ( $session_class ) { * Assert NULL values when querying as admin */ $this->loginAsShopManager(); - $variables = [ 'id' => $this->toRelayId( 'user', $customer_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'user', $customer_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ), $this->expectedField( 'customer.cartUrl', static::IS_NULL ), $this->expectedField( 'customer.cartNonce', static::IS_NULL ), @@ -655,7 +655,7 @@ static function ( $session_class ) { $this->expectedField( 'customer.checkoutNonce', static::IS_NULL ), $this->expectedField( 'customer.addPaymentMethodUrl', static::IS_NULL ), $this->expectedField( 'customer.addPaymentMethodNonce', static::IS_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); /** @@ -663,7 +663,7 @@ static function ( $session_class ) { */ $this->loginAs( $customer_id ); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ), $this->expectedField( 'customer.cartUrl', static::NOT_NULL ), $this->expectedField( 'customer.cartNonce', static::NOT_NULL ), @@ -671,7 +671,7 @@ static function ( $session_class ) { $this->expectedField( 'customer.checkoutNonce', static::NOT_NULL ), $this->expectedField( 'customer.addPaymentMethodUrl', static::NOT_NULL ), $this->expectedField( 'customer.addPaymentMethodNonce', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } } diff --git a/tests/wpunit/DownloadableItemQueriesTest.php b/tests/wpunit/DownloadableItemQueriesTest.php index 76bd11b1c..ad684b0fa 100644 --- a/tests/wpunit/DownloadableItemQueriesTest.php +++ b/tests/wpunit/DownloadableItemQueriesTest.php @@ -11,24 +11,24 @@ public function setUp(): void { // tests public function testOrderToDownloadableItemsQuery() { $downloadable_product = $this->factory->product->createSimple( - [ + array( 'downloadable' => true, - 'downloads' => [ $this->factory->product->createDownload() ], - ] + 'downloads' => array( $this->factory->product->createDownload() ), + ) ); $order_id = $this->factory->order->createNew( - [ + array( 'status' => 'completed', 'customer_id' => $this->customer, - ], - [ - 'line_items' => [ - [ + ), + array( + 'line_items' => array( + array( 'product' => $downloadable_product, 'qty' => 1, - ], - ], - ] + ), + ), + ) ); // Force download permission updated. @@ -74,10 +74,10 @@ public function testOrderToDownloadableItemsQuery() { function ( $item ) { return $this->expectedNode( 'customer.orders.nodes', - [ + array( $this->expectedNode( 'downloadableItems.nodes', - [ + array( $this->expectedField( 'url', $item['download_url'] ), $this->expectedField( 'accessExpires', $item['access_expires'] ), $this->expectedField( 'downloadId', $item['download_id'] ), @@ -90,9 +90,9 @@ function ( $item ) { $this->expectedField( 'name', $item['download_name'] ), $this->expectedField( 'product.databaseId', $item['product_id'] ), $this->expectedField( 'download.downloadId', $item['download_id'] ), - ] + ) ), - ], + ), 0 ); }, @@ -104,48 +104,48 @@ function ( $item ) { public function testOrderToDownloadableItemsQueryArgs() { $valid_product = $this->factory->product->createSimple( - [ + array( 'downloadable' => true, - 'downloads' => [ $this->factory->product->createDownload() ], - ] + 'downloads' => array( $this->factory->product->createDownload() ), + ) ); $downloadable_product = $this->factory->product->createSimple( - [ + array( 'download_expiry' => 5, 'download_limit' => 3, 'downloadable' => true, - 'downloads' => [ $this->factory->product->createDownload() ], - ] + 'downloads' => array( $this->factory->product->createDownload() ), + ) ); $downloaded_product = $this->factory->product->createSimple( - [ + array( 'download_limit' => 0, 'downloadable' => true, - 'downloads' => [ $this->factory->product->createDownload() ], - ] + 'downloads' => array( $this->factory->product->createDownload() ), + ) ); $order_id = $this->factory->order->createNew( - [ + array( 'status' => 'completed', 'customer_id' => $this->customer, - ], - [ - 'line_items' => [ - [ + ), + array( + 'line_items' => array( + array( 'product' => $valid_product, 'qty' => 1, - ], - [ + ), + array( 'product' => $downloadable_product, 'qty' => 1, - ], - [ + ), + array( 'product' => $downloaded_product, 'qty' => 1, - ], - ], - ] + ), + ), + ) ); // Force download permission updated. @@ -175,28 +175,28 @@ public function testOrderToDownloadableItemsQueryArgs() { * Tests "active" whereArg */ $this->loginAsCustomer(); - $variables = [ 'active' => true ]; + $variables = array( 'active' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'customer.orders.nodes', - [ + array( $this->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $valid_product ) ] + array( $this->expectedField( 'product.databaseId', $valid_product ) ) ), $this->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] + array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) ), $this->not()->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] + array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) ), - ], + ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -205,28 +205,28 @@ public function testOrderToDownloadableItemsQueryArgs() { * * Tests "active" whereArg reversed */ - $variables = [ 'active' => false ]; + $variables = array( 'active' => false ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'customer.orders.nodes', - [ + array( $this->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] + array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) ), $this->not()->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $valid_product ) ] + array( $this->expectedField( 'product.databaseId', $valid_product ) ) ), $this->not()->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] + array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) ), - ], + ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -235,28 +235,28 @@ public function testOrderToDownloadableItemsQueryArgs() { * * Tests "hasDownloadsRemaining" whereArg */ - $variables = [ 'hasDownloadsRemaining' => true ]; + $variables = array( 'hasDownloadsRemaining' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'customer.orders.nodes', - [ + array( $this->not()->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] + array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) ), $this->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $valid_product ) ] + array( $this->expectedField( 'product.databaseId', $valid_product ) ) ), $this->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] + array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) ), - ], + ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -265,52 +265,52 @@ public function testOrderToDownloadableItemsQueryArgs() { * * Tests "hasDownloadsRemaining" whereArg reversed */ - $variables = [ 'hasDownloadsRemaining' => false ]; + $variables = array( 'hasDownloadsRemaining' => false ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'customer.orders.nodes', - [ + array( $this->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] + array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) ), $this->not()->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $valid_product ) ] + array( $this->expectedField( 'product.databaseId', $valid_product ) ) ), $this->not()->expectedNode( 'downloadableItems.nodes', - [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] + array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) ), - ], + ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCustomerToDownloadableItemsQuery() { $downloadable_product = $this->factory->product->createSimple( - [ + array( 'downloadable' => true, - 'downloads' => [ $this->factory->product->createDownload() ], - ] + 'downloads' => array( $this->factory->product->createDownload() ), + ) ); $order_id = $this->factory->order->createNew( - [ + array( 'status' => 'completed', 'customer_id' => $this->customer, - ], - [ - 'line_items' => [ - [ + ), + array( + 'line_items' => array( + array( 'product' => $downloadable_product, 'qty' => 1, - ], - ], - ] + ), + ), + ) ); // Force download permission updated. @@ -351,7 +351,7 @@ public function testCustomerToDownloadableItemsQuery() { function ( $item ) { return $this->expectedNode( 'customer.downloadableItems.nodes', - [ + array( $this->expectedField( 'url', $item['download_url'] ), $this->expectedField( 'accessExpires', @@ -367,7 +367,7 @@ function ( $item ) { $this->expectedField( 'name', $item['download_name'] ), $this->expectedField( 'product.databaseId', $item['product_id'] ), $this->expectedField( 'download.downloadId', $item['download_id'] ), - ], + ), 0 ); }, diff --git a/tests/wpunit/IntrospectionQueryTest.php b/tests/wpunit/IntrospectionQueryTest.php index 34ec34d75..d9f3629e1 100644 --- a/tests/wpunit/IntrospectionQueryTest.php +++ b/tests/wpunit/IntrospectionQueryTest.php @@ -7,7 +7,7 @@ public function setUp(): void { $settings = get_option( 'graphql_general_settings' ); if ( ! $settings ) { - $settings = []; + $settings = array(); } $settings['public_introspection_enabled'] = 'on'; update_option( 'graphql_general_settings', $settings ); @@ -36,7 +36,7 @@ public function testSchema() { // Test introspection query. public function testIntrospectionQuery() { $query = \GraphQL\Type\Introspection::getIntrospectionQuery(); - $results = graphql( [ 'query' => $query ] ); + $results = graphql( array( 'query' => $query ) ); $this->assertArrayNotHasKey( 'errors', $results ); } diff --git a/tests/wpunit/MetaDataQueriesTest.php b/tests/wpunit/MetaDataQueriesTest.php index ba0682c89..b0cc47496 100644 --- a/tests/wpunit/MetaDataQueriesTest.php +++ b/tests/wpunit/MetaDataQueriesTest.php @@ -7,20 +7,20 @@ public function testCartMetaDataQueries() { // Create Variation Product. $product_ids = $this->factory->product_variation->createSome(); // Create Cart Item with meta data. - $meta_data = [ + $meta_data = array( 'meta_1' => 'test_meta_1', 'meta_2' => 'test_meta_2', - ]; + ); // Add item to cart. $cart_item_key = $this->factory->cart->add( - [ + array( 'product_id' => $product_ids['product'], 'quantity' => 2, 'variation_id' => $product_ids['variations'][0], - 'variation' => [ 'attribute_pa_color' => 'red' ], + 'variation' => array( 'attribute_pa_color' => 'red' ), 'cart_item_data' => $meta_data, - ] + ) )[0]; $query = ' @@ -45,28 +45,28 @@ public function testCartMetaDataQueries() { * Query w/o filter */ $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'cart.contents.nodes.0', - [ + array( $this->expectedField( 'key', $cart_item_key ), $this->expectedObject( 'extraData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'extraData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -75,30 +75,30 @@ public function testCartMetaDataQueries() { * * Query w/ "key" filter */ - $variables = [ 'key' => 'meta_2' ]; + $variables = array( 'key' => 'meta_2' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'cart.contents.nodes.0', - [ + array( $this->expectedField( 'key', $cart_item_key ), $this->expectedObject( 'extraData.0', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), $this->expectedObject( 'extraData.#', - [ + array( $this->not()->expectedField( 'key', 'meta_1' ), $this->not()->expectedField( 'value', 'test_meta_1' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -107,30 +107,30 @@ public function testCartMetaDataQueries() { * * Query w/ "keysIn" filter */ - $variables = [ 'keysIn' => [ 'meta_2' ] ]; + $variables = array( 'keysIn' => array( 'meta_2' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'cart.contents.nodes.0', - [ + array( $this->expectedField( 'key', $cart_item_key ), $this->expectedObject( 'extraData.0', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), $this->expectedObject( 'extraData.#', - [ + array( $this->not()->expectedField( 'key', 'meta_1' ), $this->not()->expectedField( 'value', 'test_meta_1' ), - ] + ) ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -138,25 +138,25 @@ public function testCartMetaDataQueries() { public function testCouponMetaDataQueries() { // Create Coupon with meta data. $coupon_id = $this->factory->coupon->create( - [ - 'meta_data' => [ - [ + array( + 'meta_data' => array( + array( 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_1', 'value' => 75, - ], - ], - ] + ), + ), + ) ); $query = ' query ($id: ID!, $key: String, $keysIn: [String], $multiple: Boolean) { @@ -176,25 +176,25 @@ public function testCouponMetaDataQueries() { * Query w/o filters */ wp_set_current_user( $this->shop_manager ); - $variables = [ 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), $this->not()->expectedField( 'value', 75 ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -203,28 +203,28 @@ public function testCouponMetaDataQueries() { * * Query w/ "key" filter */ - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), 'key' => 'meta_2', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'coupon.metaData.0', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->not()->expectedField( 'key', 'meta_1' ), $this->not()->expectedField( 'value', 'test_meta_1' ), $this->not()->expectedField( 'value', '75' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -233,28 +233,28 @@ public function testCouponMetaDataQueries() { * * Query w/ "keysIn" filter */ - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), - 'keysIn' => [ 'meta_2' ], - ]; + 'keysIn' => array( 'meta_2' ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'coupon.metaData.0', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->not()->expectedField( 'key', 'meta_1' ), $this->not()->expectedField( 'value', 'test_meta_1' ), $this->not()->expectedField( 'value', '75' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -263,35 +263,35 @@ public function testCouponMetaDataQueries() { * * Query w/ "key" filter and "multiple" set to true to get non-unique results. */ - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), 'key' => 'meta_1', 'multiple' => true, - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', '75' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->not()->expectedField( 'key', 'meta_2' ), $this->not()->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -300,35 +300,35 @@ public function testCouponMetaDataQueries() { * * Query w/ "keysIn" filter and "multiple" set to true to get non-unique results. */ - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), - 'keysIn' => [ 'meta_1' ], + 'keysIn' => array( 'meta_1' ), 'multiple' => true, - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', '75' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->not()->expectedField( 'key', 'meta_2' ), $this->not()->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -337,34 +337,34 @@ public function testCouponMetaDataQueries() { * * Query w/o filters and "multiple" set to true to get non-unique results. */ - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), 'multiple' => true, - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), $this->expectedObject( 'coupon.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', '75' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -372,20 +372,20 @@ public function testCouponMetaDataQueries() { public function testCustomerMetaDataQueries() { // Create Customer with meta data. $customer_id = $this->factory->customer->create( - [ - 'meta_data' => [ - [ + array( + 'meta_data' => array( + array( 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ], - ], - ] + ), + ), + ) ); $query = ' query { @@ -404,47 +404,47 @@ public function testCustomerMetaDataQueries() { */ $this->loginAs( $customer_id ); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ), $this->expectedObject( 'customer.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'customer.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testOrderMetaDataQueries() { // Create Order with meta data. - $meta_data = [ - [ + $meta_data = array( + array( 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ], - ]; - $customer_id = $this->factory->customer->create( [ 'meta_data' => $meta_data ] ); + ), + ); + $customer_id = $this->factory->customer->create( array( 'meta_data' => $meta_data ) ); $order_id = $this->factory->order->createNew( - [ + array( 'customer_id' => $customer_id, 'meta_data' => $meta_data, - ] + ) ); $this->factory->order->add_fee( $order_id, compact( 'meta_data' ) ); $query = ' @@ -472,57 +472,57 @@ public function testOrderMetaDataQueries() { /** * Assertion One */ - $variables = [ 'id' => $this->toRelayId( 'order', $order_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'order', $order_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'order.id', $this->toRelayId( 'order', $order_id ) ), $this->expectedObject( 'order.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'order.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), $this->expectedObject( 'order.feeLines.nodes.0.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'order.feeLines.nodes.0.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductMetaDataQueries() { // Create Product with meta data. - $meta_data = [ - [ + $meta_data = array( + array( 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ], - ]; + ), + ); $product_id = $this->factory->product->createVariable( compact( 'meta_data' ) ); $query = ' query ($id: ID!) { @@ -541,43 +541,43 @@ public function testProductMetaDataQueries() { /** * Assertion One */ - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedObject( 'product.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'product.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductVariationMetaDataQueries() { // Create Product with meta data. - $meta_data = [ - [ + $meta_data = array( + array( 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ], - ]; + ), + ); $product_id = $this->factory->product->createVariable( compact( 'meta_data' ) ); $product_ids = $this->factory->product_variation->createSome( $product_id, compact( 'meta_data' ) ); $variation_id = $product_ids['variations'][0]; @@ -596,48 +596,48 @@ public function testProductVariationMetaDataQueries() { /** * Assertion One */ - $variables = [ 'id' => $this->toRelayId( 'post', $variation_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $variation_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'productVariation.id', $this->toRelayId( 'post', $variation_id ) ), $this->expectedObject( 'productVariation.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'productVariation.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testRefundMetaDataQueries() { - $meta_data = [ - [ + $meta_data = array( + array( 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ], - [ + ), + array( 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ], - ]; - $customer_id = $this->factory->customer->create( [ 'meta_data' => $meta_data ] ); + ), + ); + $customer_id = $this->factory->customer->create( array( 'meta_data' => $meta_data ) ); $order_id = $this->factory->order->createNew( - [ + array( 'customer_id' => $customer_id, 'meta_data' => $meta_data, - ] + ) ); $refund_id = $this->factory->refund->createNew( $order_id, compact( 'meta_data' ) ); $query = ' @@ -656,25 +656,25 @@ public function testRefundMetaDataQueries() { * Assertion One */ $this->loginAs( $customer_id ); - $variables = [ 'id' => $this->toRelayId( 'order', $refund_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'order', $refund_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'refund.id', $this->toRelayId( 'order', $refund_id ) ), $this->expectedObject( 'refund.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_1' ), $this->expectedField( 'value', 'test_meta_1' ), - ] + ) ), $this->expectedObject( 'refund.metaData.#', - [ + array( $this->expectedField( 'key', 'meta_2' ), $this->expectedField( 'value', 'test_meta_2' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/OrderItemQueriesTest.php b/tests/wpunit/OrderItemQueriesTest.php index 978f6c4c5..2833a688f 100644 --- a/tests/wpunit/OrderItemQueriesTest.php +++ b/tests/wpunit/OrderItemQueriesTest.php @@ -36,20 +36,20 @@ public function testCouponLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $item ) { return $this->expectedNode( 'order.couponLines.nodes', - [ + array( $this->expectedField( 'databaseId', $item->get_id() ), $this->expectedField( 'orderId', $item->get_order_id() ), $this->expectedField( 'code', $item->get_code() ), $this->expectedField( 'discount', $this->maybe( $item->get_discount(), static::IS_NULL ) ), $this->expectedField( 'discountTax', $this->maybe( $item->get_discount_tax(), static::IS_NULL ) ), $this->expectedField( 'coupon.id', $this->toRelayId( 'shop_coupon', \wc_get_coupon_id_by_code( $item->get_code() ) ) ), - ] + ) ); }, $coupon_lines @@ -90,13 +90,13 @@ public function testFeeLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $item ) { return $this->expectedNode( 'order.feeLines.nodes', - [ + array( $this->expectedField( 'databaseId', $item->get_id() ), $this->expectedField( 'orderId', $item->get_order_id() ), $this->expectedField( 'amount', $item->get_amount() ), @@ -110,7 +110,7 @@ function ( $item ) { ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD' ), - ] + ) ); }, $fee_lines @@ -148,13 +148,13 @@ public function testShippingLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $item ) { return $this->expectedNode( 'order.shippingLines.nodes', - [ + array( $this->expectedField( 'databaseId', $item->get_id() ), $this->expectedField( 'orderId', $item->get_order_id() ), $this->expectedField( 'methodTitle', $item->get_method_title() ), @@ -168,7 +168,7 @@ function ( $item ) { : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD' ), - ] + ) ); }, $shipping_lines @@ -209,20 +209,20 @@ public function testTaxLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $item ) { return $this->expectedNode( 'order.taxLines.nodes', - [ + array( $this->expectedField( 'rateCode', $item->get_rate_code() ), $this->expectedField( 'label', $item->get_label() ), $this->expectedField( 'taxTotal', $item->get_tax_total() ), $this->expectedField( 'shippingTaxTotal', $item->get_shipping_tax_total() ), $this->expectedField( 'isCompound', $item->is_compound() ), $this->expectedField( 'taxRate.databaseId', $item->get_rate_id() ), - ] + ) ); }, $tax_lines @@ -279,13 +279,13 @@ public function testLineItemsQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $item ) { return $this->expectedNode( 'order.lineItems.nodes', - [ + array( $this->expectedField( 'productId', $item->get_product_id() ), $this->expectedField( 'variationId', $this->maybe( $item->get_variation_id(), static::IS_NULL ) ), $this->expectedField( 'quantity', $item->get_quantity() ), @@ -308,7 +308,7 @@ function ( $item ) { ? $this->toRelayId( 'post', $item->get_variation_id() ) : static::IS_NULL ), - ] + ) ); }, $line_items diff --git a/tests/wpunit/OrderMutationsTest.php b/tests/wpunit/OrderMutationsTest.php index b3977f82c..e56056448 100644 --- a/tests/wpunit/OrderMutationsTest.php +++ b/tests/wpunit/OrderMutationsTest.php @@ -8,8 +8,8 @@ public function setUp(): void { parent::setUp(); // Create users. - $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); - $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); + $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); + $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); // Get helper instances $this->order = $this->getModule( '\Helper\Wpunit' )->order(); @@ -26,7 +26,7 @@ public function setUp(): void { // Create a tax rate. $this->tax->create( - [ + array( 'country' => '', 'state' => '', 'rate' => 20.000, @@ -35,7 +35,7 @@ public function setUp(): void { 'compound' => '0', 'shipping' => '1', 'class' => '', - ] + ) ); // Create sample order to be used as a parent order. $this->order_id = $this->order->create(); @@ -206,36 +206,36 @@ private function orderMutation( $input, $operation_name = 'createOrder', $input_ "; return graphql( - [ + array( 'query' => $mutation, 'operation_name' => $operation_name, - 'variables' => [ 'input' => $input ], - ] + 'variables' => array( 'input' => $input ), + ) ); } // tests public function testCreateOrderMutation() { $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = [ + $product_ids = array( $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( - $this->coupon->create( [ 'product_ids' => $product_ids ] ) + $this->coupon->create( array( 'product_ids' => $product_ids ) ) ); - $input = [ + $input = array( 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => [ + 'coupons' => array( $coupon->get_code(), - ], + ), 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -245,8 +245,8 @@ public function testCreateOrderMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -254,52 +254,52 @@ public function testCreateOrderMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ], - 'lineItems' => [ - [ + ), + 'lineItems' => array( + array( 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_product_key', 'value' => 'test product value', - ], - ], - ], - [ + ), + ), + ), + array( 'productId' => $product_ids[1], 'quantity' => 2, - ], - [ + ), + array( 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ], - ], - 'shippingLines' => [ - [ + ), + ), + 'shippingLines' => array( + array( 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ], - ], - 'feeLines' => [ - [ + ), + ), + 'feeLines' => array( + array( 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ], - ], - 'metaData' => [ - [ + ), + ), + 'metaData' => array( + array( 'key' => 'test_key', 'value' => 'test value', - ], - ], - 'currency' => 'VND', + ), + ), + 'currency' => 'VND', 'isPaid' => true, - ]; + ); /** * Assertion One @@ -331,37 +331,37 @@ public function testCreateOrderMutation() { $this->assertArrayHasKey( 'id', $actual['data']['createOrder']['order'] ); $order = \WC_Order_Factory::get_order( $actual['data']['createOrder']['order']['databaseId'] ); - $expected = [ - 'data' => [ - 'createOrder' => [ + $expected = array( + 'data' => array( + 'createOrder' => array( 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - [ - 'couponLines' => [ + array( + 'couponLines' => array( 'nodes' => array_reverse( array_map( function ( $item ) { - return [ + return array( 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, - 'coupon' => [ + 'coupon' => array( 'id' => $this->coupon->to_relay_id( \wc_get_coupon_id_by_code( $item->get_code() ) ), - ], - ]; + ), + ); }, $order->get_items( 'coupon' ) ) ), - ], - 'feeLines' => [ + ), + 'feeLines' => array( 'nodes' => array_reverse( array_map( static function ( $item ) { - return [ + return array( 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => $item->get_amount(), @@ -372,17 +372,17 @@ static function ( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ]; + ); }, $order->get_items( 'fee' ) ) ), - ], - 'shippingLines' => [ + ), + 'shippingLines' => array( 'nodes' => array_reverse( array_map( static function ( $item ) { - return [ + return array( 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -395,34 +395,34 @@ static function ( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ]; + ); }, $order->get_items( 'shipping' ) ) ), - ], - 'taxLines' => [ + ), + 'taxLines' => array( 'nodes' => array_reverse( array_map( static function ( $item ) { - return [ + return array( 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], - ]; + 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), + ); }, $order->get_items( 'tax' ) ) ), - ], - 'lineItems' => [ + ), + 'lineItems' => array( 'nodes' => array_values( array_map( function ( $item ) { - return [ + return array( 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -436,25 +436,25 @@ function ( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], + 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), 'variation' => ! empty( $item->get_variation_id() ) - ? [ - 'node' => [ + ? array( + 'node' => array( 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ], - ] + ), + ) : null, - ]; + ); }, $order->get_items() ) ), - ], - ] + ), + ) ), - ], - ], - ]; + ), + ), + ); $this->assertEquals( $expected, $actual ); } @@ -462,26 +462,26 @@ function ( $item ) { public function testUpdateOrderMutation() { // Create products and coupons to be used in order creation. $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = [ + $product_ids = array( $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( - $this->coupon->create( [ 'product_ids' => $product_ids ] ) + $this->coupon->create( array( 'product_ids' => $product_ids ) ) ); // Create initial order input. - $initial_input = [ + $initial_input = array( 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => [ + 'coupons' => array( $coupon->get_code(), - ], + ), 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -491,8 +491,8 @@ public function testUpdateOrderMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -500,51 +500,51 @@ public function testUpdateOrderMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ], - 'lineItems' => [ - [ + ), + 'lineItems' => array( + array( 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_product_key', 'value' => 'test product value', - ], - ], - ], - [ + ), + ), + ), + array( 'productId' => $product_ids[1], 'quantity' => 2, - ], - [ + ), + array( 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ], - ], - 'shippingLines' => [ - [ + ), + ), + 'shippingLines' => array( + array( 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ], - ], - 'feeLines' => [ - [ + ), + ), + 'feeLines' => array( + array( 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ], - ], - 'metaData' => [ - [ + ), + ), + 'metaData' => array( + array( 'key' => 'test_key', 'value' => 'test value', - ], - ], + ), + ), 'isPaid' => false, - ]; + ); // Create order to update. wp_set_current_user( $this->shop_manager ); @@ -560,72 +560,72 @@ public function testUpdateOrderMutation() { $fee_lines = $order->get_items( 'fee' ); // Create update order input. - $updated_input = [ + $updated_input = array( 'id' => $this->order->to_relay_id( $order->get_id() ), 'clientMutationId' => 'someId', 'customerNote' => 'Customer test note', - 'coupons' => [ + 'coupons' => array( $coupon->get_code(), - ], - 'billing' => [ + ), + 'billing' => array( 'firstName' => 'Ben', - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'Ben', - ], - 'lineItems' => [ - [ + ), + 'lineItems' => array( + array( 'id' => array_keys( $line_items )[0], 'quantity' => 6, - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_product_key', 'value' => 'updated test product value', - ], - ], - ], - [ + ), + ), + ), + array( 'id' => array_keys( $line_items )[1], 'quantity' => 1, - ], - [ + ), + array( 'id' => array_keys( $line_items )[2], 'quantity' => 10, - ], - ], - 'shippingLines' => [ - [ + ), + ), + 'shippingLines' => array( + array( 'id' => array_keys( $shipping_lines )[0], 'methodId' => 'reduced_rate_shipping', 'methodTitle' => 'reduced Rate shipping', 'total' => '7', - ], - ], - 'feeLines' => [ - [ + ), + ), + 'feeLines' => array( + array( 'id' => array_keys( $fee_lines )[0], 'name' => 'Some Updated Fee', 'taxStatus' => 'TAXABLE', 'total' => '125', 'taxClass' => 'STANDARD', - ], - ], - 'metaData' => [ - [ + ), + ), + 'metaData' => array( + array( 'key' => 'test_key', 'value' => 'new test value', - ], - ], + ), + ), 'isPaid' => true, - ]; + ); /** * Assertion One * * User without necessary capabilities cannot update order an order. */ - wp_set_current_user( $this->factory->user->create( [ 'role' => 'customer' ] ) ); + wp_set_current_user( $this->factory->user->create( array( 'role' => 'customer' ) ) ); $actual = $this->orderMutation( $updated_input, 'updateOrder', @@ -655,37 +655,37 @@ public function testUpdateOrderMutation() { // Apply new changes to order instances. $order = \WC_Order_Factory::get_order( $order->get_id() ); - $expected = [ - 'data' => [ - 'updateOrder' => [ + $expected = array( + 'data' => array( + 'updateOrder' => array( 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - [ - 'couponLines' => [ + array( + 'couponLines' => array( 'nodes' => array_reverse( array_map( function ( $item ) { - return [ + return array( 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, - 'coupon' => [ + 'coupon' => array( 'id' => $this->coupon->to_relay_id( \wc_get_coupon_id_by_code( $item->get_code() ) ), - ], - ]; + ), + ); }, $order->get_items( 'coupon' ) ) ), - ], - 'feeLines' => [ + ), + 'feeLines' => array( 'nodes' => array_reverse( array_map( static function ( $item ) { - return [ + return array( 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => ! empty( $item->get_amount() ) ? $item->get_amount() : null, @@ -696,17 +696,17 @@ static function ( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ]; + ); }, $order->get_items( 'fee' ) ) ), - ], - 'shippingLines' => [ + ), + 'shippingLines' => array( 'nodes' => array_reverse( array_map( static function ( $item ) { - return [ + return array( 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -719,34 +719,34 @@ static function ( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ]; + ); }, $order->get_items( 'shipping' ) ) ), - ], - 'taxLines' => [ + ), + 'taxLines' => array( 'nodes' => array_reverse( array_map( static function ( $item ) { - return [ + return array( 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], - ]; + 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), + ); }, $order->get_items( 'tax' ) ) ), - ], - 'lineItems' => [ + ), + 'lineItems' => array( 'nodes' => array_values( array_map( function ( $item ) { - return [ + return array( 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -760,25 +760,25 @@ function ( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], + 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), 'variation' => ! empty( $item->get_variation_id() ) - ? [ - 'node' => [ + ? array( + 'node' => array( 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ], - ] + ), + ) : null, - ]; + ); }, $order->get_items() ) ), - ], - ] + ), + ) ), - ], - ], - ]; + ), + ), + ); $this->assertEquals( $expected, $actual ); $this->assertNotEquals( $initial_response, $actual ); @@ -787,26 +787,26 @@ function ( $item ) { public function testDeleteOrderMutation() { // Create products and coupons to be used in order creation. $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = [ + $product_ids = array( $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( - $this->coupon->create( [ 'product_ids' => $product_ids ] ) + $this->coupon->create( array( 'product_ids' => $product_ids ) ) ); // Create initial order input. - $initial_input = [ + $initial_input = array( 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => [ + 'coupons' => array( $coupon->get_code(), - ], + ), 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -816,8 +816,8 @@ public function testDeleteOrderMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -825,51 +825,51 @@ public function testDeleteOrderMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ], - 'lineItems' => [ - [ + ), + 'lineItems' => array( + array( 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_product_key', 'value' => 'test product value', - ], - ], - ], - [ + ), + ), + ), + array( 'productId' => $product_ids[1], 'quantity' => 2, - ], - [ + ), + array( 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ], - ], - 'shippingLines' => [ - [ + ), + ), + 'shippingLines' => array( + array( 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ], - ], - 'feeLines' => [ - [ + ), + ), + 'feeLines' => array( + array( 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ], - ], - 'metaData' => [ - [ + ), + ), + 'metaData' => array( + array( 'key' => 'test_key', 'value' => 'test value', - ], - ], + ), + ), 'isPaid' => false, - ]; + ); // Create order to delete. wp_set_current_user( $this->shop_manager ); @@ -891,18 +891,18 @@ public function testDeleteOrderMutation() { $tax_lines = $order->get_items( 'tax' ); // Create DeleteOrderInput. - $deleted_input = [ + $deleted_input = array( 'clientMutationId' => 'someId', 'id' => $this->order->to_relay_id( $order->get_id() ), 'forceDelete' => true, - ]; + ); /** * Assertion One * * User without necessary capabilities cannot delete order an order. */ - wp_set_current_user( $this->factory->user->create( [ 'role' => 'customer' ] ) ); + wp_set_current_user( $this->factory->user->create( array( 'role' => 'customer' ) ) ); $actual = $this->orderMutation( $deleted_input, 'deleteOrder', @@ -938,26 +938,26 @@ public function testDeleteOrderMutation() { public function testDeleteOrderItemsMutation() { // Create products and coupons to be used in order creation. $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = [ + $product_ids = array( $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ]; + ); $coupon = new WC_Coupon( - $this->coupon->create( [ 'product_ids' => $product_ids ] ) + $this->coupon->create( array( 'product_ids' => $product_ids ) ) ); // Create initial order input. - $initial_input = [ + $initial_input = array( 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => [ + 'coupons' => array( $coupon->get_code(), - ], + ), 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => [ + 'billing' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -967,8 +967,8 @@ public function testDeleteOrderItemsMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ], - 'shipping' => [ + ), + 'shipping' => array( 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -976,51 +976,51 @@ public function testDeleteOrderItemsMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ], - 'lineItems' => [ - [ + ), + 'lineItems' => array( + array( 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => [ - [ + 'metaData' => array( + array( 'key' => 'test_product_key', 'value' => 'test product value', - ], - ], - ], - [ + ), + ), + ), + array( 'productId' => $product_ids[1], 'quantity' => 2, - ], - [ + ), + array( 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ], - ], - 'shippingLines' => [ - [ + ), + ), + 'shippingLines' => array( + array( 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ], - ], - 'feeLines' => [ - [ + ), + ), + 'feeLines' => array( + array( 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ], - ], - 'metaData' => [ - [ + ), + ), + 'metaData' => array( + array( 'key' => 'test_key', 'value' => 'test value', - ], - ], + ), + ), 'isPaid' => false, - ]; + ); // Create order to delete. wp_set_current_user( $this->shop_manager ); @@ -1042,21 +1042,21 @@ public function testDeleteOrderItemsMutation() { $tax_lines = $order->get_items( 'tax' ); // Create DeleteOrderInput. - $deleted_items_input = [ + $deleted_items_input = array( 'clientMutationId' => 'someId', 'orderId' => $order->get_id(), - 'itemIds' => [ + 'itemIds' => array( current( $line_items )->get_id(), current( $coupon_lines )->get_id(), - ], - ]; + ), + ); /** * Assertion One * * User without necessary capabilities cannot delete order an order. */ - wp_set_current_user( $this->factory->user->create( [ 'role' => 'customer' ] ) ); + wp_set_current_user( $this->factory->user->create( array( 'role' => 'customer' ) ) ); $actual = $this->orderMutation( $deleted_items_input, 'deleteOrderItems', diff --git a/tests/wpunit/OrderQueriesTest.php b/tests/wpunit/OrderQueriesTest.php index 62fafcbc4..d7d296057 100644 --- a/tests/wpunit/OrderQueriesTest.php +++ b/tests/wpunit/OrderQueriesTest.php @@ -6,10 +6,10 @@ class OrderQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLT public function expectedOrderData( $order_id ) { $order = \wc_get_order( $order_id ); - return [ + return array( $this->expectedObject( 'order', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'order', $order_id ) ), $this->expectedField( 'databaseId', $order->get_id() ), $this->expectedField( 'currency', $this->maybe( $order->get_currency() ) ), @@ -17,14 +17,14 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'date', $order->get_date_created()->__toString() ), $this->expectedField( 'modified', $order->get_date_modified()->__toString() ), $this->expectedField( 'status', WPEnumType::get_safe_name( $order->get_status() ) ), - $this->expectedField( 'discountTotal', \wc_graphql_price( $order->get_discount_total(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'discountTax', \wc_graphql_price( $order->get_discount_tax(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'shippingTotal', \wc_graphql_price( $order->get_shipping_total(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'shippingTax', \wc_graphql_price( $order->get_shipping_tax(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'cartTax', \wc_graphql_price( $order->get_cart_tax(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'total', \wc_graphql_price( $order->get_total(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'totalTax', \wc_graphql_price( $order->get_total_tax(), [ 'currency' => $order->get_currency() ] ) ), - $this->expectedField( 'subtotal', \wc_graphql_price( $order->get_subtotal(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'discountTotal', \wc_graphql_price( $order->get_discount_total(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'discountTax', \wc_graphql_price( $order->get_discount_tax(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'shippingTotal', \wc_graphql_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'shippingTax', \wc_graphql_price( $order->get_shipping_tax(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'cartTax', \wc_graphql_price( $order->get_cart_tax(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'total', \wc_graphql_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'totalTax', \wc_graphql_price( $order->get_total_tax(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'subtotal', \wc_graphql_price( $order->get_subtotal(), array( 'currency' => $order->get_currency() ) ) ), $this->expectedField( 'orderNumber', $order->get_order_number() ), $this->expectedField( 'orderKey', $order->get_order_key() ), $this->expectedField( 'createdVia', $this->maybe( $order->get_created_via() ) ), @@ -33,10 +33,10 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'customer', $this->maybe( - [ + array( $order->get_customer_id(), - [ 'id' => $this->toRelayId( 'user', $order->get_customer_id() ) ], - ], + array( 'id' => $this->toRelayId( 'user', $order->get_customer_id() ) ), + ), static::IS_NULL ) ), @@ -45,7 +45,7 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'customerNote', $this->maybe( $order->get_customer_note() ) ), $this->expectedObject( 'billing', - [ + array( $this->expectedField( 'firstName', $this->maybe( $order->get_billing_first_name() ) ), $this->expectedField( 'lastName', $this->maybe( $order->get_billing_last_name() ) ), $this->expectedField( 'company', $this->maybe( $order->get_billing_company() ) ), @@ -57,11 +57,11 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'country', $this->maybe( $order->get_billing_country() ) ), $this->expectedField( 'email', $this->maybe( $order->get_billing_email() ) ), $this->expectedField( 'phone', $this->maybe( $order->get_billing_phone() ) ), - ] + ) ), $this->expectedObject( 'shipping', - [ + array( $this->expectedField( 'firstName', $this->maybe( $order->get_shipping_first_name() ) ), $this->expectedField( 'lastName', $this->maybe( $order->get_shipping_last_name() ) ), $this->expectedField( 'company', $this->maybe( $order->get_shipping_company() ) ), @@ -71,7 +71,7 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'state', $this->maybe( $order->get_shipping_state() ) ), $this->expectedField( 'postcode', $this->maybe( $order->get_shipping_postcode() ) ), $this->expectedField( 'country', $this->maybe( $order->get_shipping_country() ) ), - ] + ) ), $this->expectedField( 'paymentMethod', $this->maybe( $order->get_payment_method() ) ), $this->expectedField( 'paymentMethodTitle', $this->maybe( $order->get_payment_method_title() ) ), @@ -87,9 +87,9 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'hasDownloadableItem', $order->has_downloadable_item() ), $this->expectedField( 'needsPayment', $order->needs_payment() ), $this->expectedField( 'needsProcessing', $order->needs_processing() ), - ] + ) ), - ]; + ); } // tests @@ -191,9 +191,9 @@ public function testOrderQuery() { * Tests query as customer, should return "null" because the customer isn't authorized. */ $this->loginAsCustomer(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'order', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'order', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); @@ -229,12 +229,12 @@ public function testOrderQueryAndIds() { * * Tests "ID" ID type. */ - $variables = [ + $variables = array( 'id' => $id, 'idType' => 'ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'order.id', $id ) ]; + $expected = array( $this->expectedField( 'order.id', $id ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -243,10 +243,10 @@ public function testOrderQueryAndIds() { * * Tests "DATABASE_ID" ID type. */ - $variables = [ + $variables = array( 'id' => $order_id, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -256,10 +256,10 @@ public function testOrderQueryAndIds() { * * Tests "ORDER_KEY" ID type */ - $variables = [ + $variables = array( 'id' => $this->factory->order->get_order_key( $order_id ), 'idType' => 'ORDER_KEY', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -278,35 +278,35 @@ public function testOrdersQueryAndWhereArgs() { // Create order for query response. $customer = $this->factory->customer->create(); $product = $this->factory->product->createSimple(); - $orders = [ + $orders = array( $this->factory->order->createNew( - [ + array( 'billing_email' => 'test@example.com', - ], - [ - 'line_items' => [ - [ + ), + array( + 'line_items' => array( + array( 'product' => $product, 'qty' => 4, - ], - ], - ] + ), + ), + ) ), $this->factory->order->createNew( - [ + array( 'status' => 'completed', 'customer_id' => $customer, - ], - [ - 'line_items' => [ - [ + ), + array( + 'line_items' => array( + array( 'product' => $product, 'qty' => 2, - ], - ], - ] + ), + ), + ) ), - ]; + ); $query = ' query ($statuses: [OrderStatusEnum], $customerId: Int, $customersIn: [Int], $billingEmail: String, $productId: Int) { @@ -335,7 +335,7 @@ public function testOrdersQueryAndWhereArgs() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ $this->expectedField( 'orders.nodes', [] ) ]; + $expected = array( $this->expectedField( 'orders.nodes', array() ) ); $this->assertQuerySuccessful( $response, $expected ); $this->clearLoaderCache( 'wc_post' ); @@ -347,11 +347,11 @@ public function testOrdersQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[0] ) ), $this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[1] ) ), $this->not()->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $old_orders[0]->get_id() ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); $this->clearLoaderCache( 'wc_post' ); @@ -361,11 +361,11 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "statuses" where argument */ - $variables = [ 'statuses' => [ 'COMPLETED' ] ]; + $variables = array( 'statuses' => array( 'COMPLETED' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[1] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); $this->clearLoaderCache( 'wc_post' ); @@ -375,7 +375,7 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "customerId" where argument */ - $variables = [ 'customerId' => $customer ]; + $variables = array( 'customerId' => $customer ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -386,7 +386,7 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "customerIn" where argument */ - $variables = [ 'customersIn' => [ $customer ] ]; + $variables = array( 'customersIn' => array( $customer ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -397,16 +397,16 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "billingEmail" where argument */ - $variables = [ 'billingEmail' => 'test@example.com' ]; + $variables = array( 'billingEmail' => 'test@example.com' ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[0] ) ), $this->not()->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[1] ) ), $this->not()->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $old_orders[0] ) ), - ] + ) ); $this->clearLoaderCache( 'wc_post' ); @@ -415,7 +415,7 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "productId" where argument */ - $variables = [ 'productId' => $product ]; + $variables = array( 'productId' => $product ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); diff --git a/tests/wpunit/PaymentGatewayQueriesTest.php b/tests/wpunit/PaymentGatewayQueriesTest.php index 73607214e..97b7ec9b2 100644 --- a/tests/wpunit/PaymentGatewayQueriesTest.php +++ b/tests/wpunit/PaymentGatewayQueriesTest.php @@ -8,29 +8,29 @@ public function setUp(): void { // Enable payment gateway. update_option( 'woocommerce_bacs_settings', - [ + array( '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' => '', - ] + ) ); update_option( 'woocommerce_cheque_settings', - [ + array( 'enabled' => 'no', 'title' => 'Check payments', 'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'instructions' => 'Instructions that will be added to the thank you page and emails.', 'account' => '', - ] + ) ); delete_option( 'woocommerce_stripe_settings', - [ + array( 'enabled' => 'no', 'title' => 'Credit Card (Stripe)', 'description' => 'Pay with your credit card via Stripe', @@ -55,7 +55,7 @@ public function setUp(): void { 'payment_request_button_height' => '44', 'saved_cards' => 'yes', 'logging' => 'no', - ] + ) ); // Reload gateways. @@ -82,16 +82,16 @@ public function testPaymentGatewaysQueryAndWhereArgs() { * Tests query. */ $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'paymentGateways.nodes', - [ + array( $this->expectedField( 'id', 'bacs' ), $this->expectedField( 'title', 'Direct bank transfer' ), $this->expectedField( 'icon', static::IS_NULL ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -100,12 +100,12 @@ public function testPaymentGatewaysQueryAndWhereArgs() { * * Tests query and "all" where argument response, expects errors due lack of capabilities. */ - $variables = [ 'all' => true ]; + $variables = array( 'all' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedErrorPath( 'paymentGateways' ), $this->expectedField( 'paymentGateways', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -115,43 +115,43 @@ public function testPaymentGatewaysQueryAndWhereArgs() { * Tests query and "all" where argument response with proper capabilities. */ $this->loginAsShopManager(); - $variables = [ 'all' => true ]; + $variables = array( 'all' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'paymentGateways.nodes', - [ + array( $this->expectedField( 'id', 'bacs' ), $this->expectedField( 'title', 'Direct bank transfer' ), $this->expectedField( 'icon', static::IS_NULL ), - ] + ) ), $this->expectedNode( 'paymentGateways.nodes', - [ + array( $this->expectedField( 'id', 'cheque' ), $this->expectedField( 'title', 'Check payments' ), $this->expectedField( 'icon', static::IS_NULL ), - ] + ) ), $this->expectedNode( 'paymentGateways.nodes', - [ + array( $this->expectedField( 'id', 'cod' ), $this->expectedField( 'title', 'Cash on delivery' ), $this->expectedField( 'icon', static::IS_NULL ), - ] + ) ), $this->expectedNode( 'paymentGateways.nodes', - [ + array( $this->expectedField( 'id', 'stripe' ), $this->expectedField( 'title', 'Credit Card (Stripe)' ), $this->expectedField( 'icon', static::IS_NULL ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/PaymentMethodMutationsTest.php b/tests/wpunit/PaymentMethodMutationsTest.php index 8c591de8b..2b14f3111 100644 --- a/tests/wpunit/PaymentMethodMutationsTest.php +++ b/tests/wpunit/PaymentMethodMutationsTest.php @@ -11,20 +11,20 @@ public function testSetDefaultPaymentMethodMutation() { $expiry_year = gmdate( 'Y', strtotime( '+1 year' ) ); $token_cc = $this->factory->payment_token->createCCToken( $customer_id, - [ + array( 'last4' => 1234, 'expiry_month' => $expiry_month, 'expiry_year' => $expiry_year, 'card_type' => 'visa', 'token' => time(), - ] + ) ); $token_ec = $this->factory->payment_token->createECheckToken( $customer_id, - [ + array( 'last4' => 4567, 'token' => time(), - ] + ) ); // Create query and variables. @@ -39,21 +39,21 @@ public function testSetDefaultPaymentMethodMutation() { } } '; - $variables = [ 'tokenId' => $token_ec->get_id() ]; + $variables = array( 'tokenId' => $token_ec->get_id() ); /** * Assert default payment method can't be set by guests or admin. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); // Again, as admin. $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); @@ -62,32 +62,32 @@ public function testSetDefaultPaymentMethodMutation() { */ $this->loginAs( $customer_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'setDefaultPaymentMethod.status', 'SUCCESS' ), $this->expectedObject( 'setDefaultPaymentMethod.token', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ), $this->expectedField( 'isDefault', true ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); // Change default payment method back to credit card token. - $variables = [ 'tokenId' => $token_cc->get_id() ]; + $variables = array( 'tokenId' => $token_cc->get_id() ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'setDefaultPaymentMethod.status', 'SUCCESS' ), $this->expectedObject( 'setDefaultPaymentMethod.token', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ), $this->expectedField( 'isDefault', true ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -101,20 +101,20 @@ public function testDeletePaymentMethodMutation() { $expiry_year = gmdate( 'Y', strtotime( '+1 year' ) ); $token_cc = $this->factory->payment_token->createCCToken( $customer_id, - [ + array( 'last4' => 1234, 'expiry_month' => $expiry_month, 'expiry_year' => $expiry_year, 'card_type' => 'visa', 'token' => time(), - ] + ) ); $token_ec = $this->factory->payment_token->createECheckToken( $customer_id, - [ + array( 'last4' => 4567, 'token' => time(), - ] + ) ); // Create query and variables. @@ -125,21 +125,21 @@ public function testDeletePaymentMethodMutation() { } } '; - $variables = [ 'tokenId' => $token_cc->get_id() ]; + $variables = array( 'tokenId' => $token_cc->get_id() ); /** * Assert payment method can't be deleted by guests or admin. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); // Again, as admin. $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) ]; + $expected = array( $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) ); $this->assertQueryError( $response, $expected ); @@ -148,7 +148,7 @@ public function testDeletePaymentMethodMutation() { */ $this->loginAs( $customer_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'deletePaymentMethod.status', 'SUCCESS' ) ]; + $expected = array( $this->expectedField( 'deletePaymentMethod.status', 'SUCCESS' ) ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ProductAttributeQueriesTest.php b/tests/wpunit/ProductAttributeQueriesTest.php index acd201ca6..e22f1e3c9 100644 --- a/tests/wpunit/ProductAttributeQueriesTest.php +++ b/tests/wpunit/ProductAttributeQueriesTest.php @@ -5,12 +5,12 @@ public function expectedProductAttributeData( $product_id, $path ) { $product = wc_get_product( $product_id ); $attributes = $product->get_attributes(); - $expected = []; + $expected = array(); foreach ( $attributes as $attribute_name => $attribute ) { $expected[] = $this->expectedNode( $path, - [ + array( $this->expectedField( 'id', base64_encode( $attribute_name . ':' . $product_id . ':' . $attribute->get_name() ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $this->expectedField( 'attributeId', $attribute->get_id() ), $this->expectedField( 'name', $attribute->get_name() ), @@ -24,7 +24,7 @@ public function expectedProductAttributeData( $product_id, $path ) { $this->expectedField( 'position', $attribute->get_position() ), $this->expectedField( 'visible', $attribute->get_visible() ), $this->expectedField( 'variation', $attribute->get_variation() ), - ] + ) ); } @@ -58,10 +58,10 @@ public function testProductAttributeQuery() { } '; - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_merge( - [ $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ], + array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ), $this->expectedProductAttributeData( $product_id, 'product.attributes.nodes' ) ); @@ -69,37 +69,36 @@ public function testProductAttributeQuery() { } public function testProductAttributeToProductConnectionQuery() { - // Create noise products. $product_id = $this->factory->product->createVariable( - [ - 'attribute_data' => [ $this->factory->product->createAttribute( 'pattern', [ 'polka-dot', 'stripe', 'flames' ] ) ], - ], + array( + 'attribute_data' => array( $this->factory->product->createAttribute( 'pattern', array( 'polka-dot', 'stripe', 'flames' ) ) ), + ), ); $variation_id = $this->factory->product_variation->create( - [ + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pattern' => 'polka-dot', - ], + ), 'image_id' => null, 'regular_price' => 10, - ] + ) ); // Create variable product with attribute. $other_product_id = $this->factory->product->createVariable(); $other_variation_id = $this->factory->product_variation->create( - [ + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pattern' => 'stripe', - ], + ), 'image_id' => null, 'regular_price' => 10, - ] - ); + ) + ); $other_product_id_2 = $this->factory->product->createSimple(); $this->clearSchema(); @@ -120,11 +119,11 @@ public function testProductAttributeToProductConnectionQuery() { /** * Assert correct products are queried. */ - $variables = [ 'pattern' => 'polka-dot' ]; + $variables = array( 'pattern' => 'polka-dot' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'allPaPattern.nodes.0.products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -147,7 +146,7 @@ public function testProductAttributeToVariationConnectionQuery() { } '; - $variables = [ 'size' => 'small' ]; + $variables = array( 'size' => 'small' ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $id ) { @@ -206,33 +205,33 @@ public function testProductAttributeMatchesVariationAttributeCounterpart() { } '; - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); /** * Assert that the product attributes match the variation attributes * without modification to confirm variations can be identified by product attribute. */ - $attributes = $this->lodashGet( $response, 'data.product.attributes.nodes', [] ); - $variations = $this->lodashGet( $response, 'data.product.variations.nodes', [] ); + $attributes = $this->lodashGet( $response, 'data.product.attributes.nodes', array() ); + $variations = $this->lodashGet( $response, 'data.product.variations.nodes', array() ); - foreach( $variations as $variation ) { - $variation_attributes = $this->lodashGet( $variation, 'attributes.nodes', [] ); - foreach( $variation_attributes as $variation_attribute ) { + foreach ( $variations as $variation ) { + $variation_attributes = $this->lodashGet( $variation, 'attributes.nodes', array() ); + foreach ( $variation_attributes as $variation_attribute ) { $attribute_name = $variation_attribute['name']; - $attribute = array_search( $attribute_name, array_column( $attributes, 'name' ) ); + $attribute = array_search( $attribute_name, array_column( $attributes, 'name' ) ); $this->assertNotFalse( $attribute, sprintf( 'Variation attribute not found in product attributes for %s', $attribute_name ) ); - if ( "" === $variation_attribute['value'] ) { + if ( '' === $variation_attribute['value'] ) { continue; } $this->assertContains( $variation_attribute['value'], $attributes[ $attribute ]['options'] ); } } - + $this->assertQuerySuccessful( $response, - [ $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ] + array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ) ); } } diff --git a/tests/wpunit/ProductDateModifiedTest.php b/tests/wpunit/ProductDateModifiedTest.php new file mode 100644 index 000000000..abaffd19e --- /dev/null +++ b/tests/wpunit/ProductDateModifiedTest.php @@ -0,0 +1,48 @@ +product_id = $this->factory->product->create( + array( + 'name' => 'Test Product', + ) + ); + + // Modify the product so we know date_modified is set + $product = wc_get_product( $this->product_id ); + $product->set_name( 'Updated Test Product' ); + $product->save(); + } + + public function tearDown(): void { + parent::tearDown(); + wp_delete_post( $this->product_id, true ); + } + + public function testProductHasDateModifiedField() { + $query = ' + { + product(id: "' . $this->product_id . '", idType: DATABASE_ID) { + ... on SimpleProduct { + id + name + dateModified + } + } + }'; + + $response = $this->graphql( array( 'query' => $query ) ); + + $this->assertArrayNotHasKey( 'errors', $response, print_r( $response, true ) ); + $this->assertArrayHasKey( 'data', $response ); + $this->assertArrayHasKey( 'product', $response['data'] ); + $this->assertNotNull( $response['data']['product']['dateModified'] ); + } +} diff --git a/tests/wpunit/ProductDateModifiedTesterTest.php b/tests/wpunit/ProductDateModifiedTesterTest.php new file mode 100644 index 000000000..385a8a422 --- /dev/null +++ b/tests/wpunit/ProductDateModifiedTesterTest.php @@ -0,0 +1,30 @@ +post->create_and_get(); + + $this->assertInstanceOf( \WP_Post::class, $post ); + } +} diff --git a/tests/wpunit/ProductQueriesTest.php b/tests/wpunit/ProductQueriesTest.php index b4607c15e..589bfbb58 100644 --- a/tests/wpunit/ProductQueriesTest.php +++ b/tests/wpunit/ProductQueriesTest.php @@ -8,7 +8,7 @@ public function getExpectedProductData( $product_id ) { $is_shop_manager = true; } - return [ + return array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'product.databaseId', $product->get_id() ), $this->expectedField( 'product.name', $product->get_name() ), @@ -19,20 +19,20 @@ public function getExpectedProductData( $product_id ) { $this->expectedField( 'product.description', $this->maybe( - [ $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ], + array( $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ), static::IS_NULL ) ), $this->expectedField( 'product.shortDescription', $this->maybe( - [ + array( $product->get_short_description(), apply_filters( 'get_the_excerpt', apply_filters( 'the_excerpt', $product->get_short_description() ) ), - ], + ), static::IS_NULL ) ), @@ -40,21 +40,21 @@ public function getExpectedProductData( $product_id ) { $this->expectedField( 'product.price', $this->maybe( - [ $product->get_price(), \wc_graphql_price( $product->get_price() ) ], + array( $product->get_price(), \wc_graphql_price( $product->get_price() ) ), static::IS_NULL ) ), $this->expectedField( 'product.regularPrice', $this->maybe( - [ $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ], + array( $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ), static::IS_NULL ) ), $this->expectedField( 'product.salePrice', $this->maybe( - [ $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ], + array( $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ), static::IS_NULL ) ), @@ -151,24 +151,24 @@ public function getExpectedProductData( $product_id ) { $this->expectedField( 'product.totalSales', $this->maybe( - [ + array( $is_shop_manager && $product->get_total_sales(), $product->get_total_sales(), - ], + ), static::IS_FALSY ) ), $this->expectedField( 'product.catalogVisibility', $this->maybe( - [ + array( $is_shop_manager && ! empty( $product->get_catalog_visibility() ), strtoupper( $product->get_catalog_visibility() ), - ], + ), static::IS_NULL ) ), - ]; + ); } public function getExpectedProductDownloadData( $product_id ) { @@ -178,9 +178,9 @@ public function getExpectedProductDownloadData( $product_id ) { return null; } - $results = []; + $results = array(); foreach ( $downloads as $download ) { - $results[] = [ + $results[] = array( 'name' => $download->get_name(), 'downloadId' => $download->get_id(), 'filePathType' => $download->get_type_of_file_path(), @@ -189,7 +189,7 @@ public function getExpectedProductDownloadData( $product_id ) { 'allowedFileType' => $download->is_allowed_filetype(), 'fileExists' => $download->file_exists(), 'file' => $download->get_file(), - ]; + ); } return $results; @@ -258,7 +258,7 @@ public function testSimpleProductQuery() { * * Test querying product. */ - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->getExpectedProductData( $product_id ); @@ -273,17 +273,17 @@ public function testSimpleProductQuery() { * Test querying product with unformatted content (edit-product cap required). */ $this->loginAsShopManager(); - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ), 'format' => 'RAW', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.description', $product->get_description() ), $this->expectedField( 'product.shortDescription', $product->get_short_description() ), $this->expectedField( 'product.totalSales', $product->get_total_sales() ), $this->expectedField( 'product.catalogVisibility', strtoupper( $product->get_catalog_visibility() ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -294,19 +294,19 @@ public function testProductTaxonomies() { $category_6 = $this->factory->product->createProductCategory( 'category-six', $category_5 ); $tag_2 = $this->factory->product->createProductTag( 'tag-two' ); $attachment_id = $this->factory->attachment->create( - [ + array( 'post_mime_type' => 'image/gif', 'post_author' => $this->admin, - ] + ) ); $product_id = $this->factory->product->createSimple( - [ + array( 'price' => 10, 'regular_price' => 10, - 'category_ids' => [ $category_5 ], - 'tag_ids' => [ $tag_2 ], + 'category_ids' => array( $category_5 ), + 'tag_ids' => array( $tag_2 ), 'image_id' => $attachment_id, - ] + ) ); $query = ' @@ -345,30 +345,30 @@ public function testProductTaxonomies() { * * Test querying product with "productId" argument. */ - $variables = [ + $variables = array( 'id' => $product_id, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'product.image.id', $this->toRelayId( 'post', $attachment_id ) ), $this->expectedNode( 'product.productCategories.nodes', - [ + array( 'name' => 'category-five', 'image' => null, 'display' => 'DEFAULT', 'menuOrder' => 0, - 'children' => [ - 'nodes' => [ - [ 'name' => 'category-six' ], - ], - ], - ] + 'children' => array( + 'nodes' => array( + array( 'name' => 'category-six' ), + ), + ), + ) ), - $this->expectedNode( 'product.productTags.nodes', [ 'name' => 'tag-two' ] ), - ]; + $this->expectedNode( 'product.productTags.nodes', array( 'name' => 'tag-two' ) ), + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -386,19 +386,19 @@ public function testProductQueryAndIds() { '; // Define expected data for coming assertions. - $expected = [ + $expected = array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), - ]; + ); /** * Assertion One * * Test querying product with 'DATABASE_ID' set as the "idType". */ - $variables = [ + $variables = array( 'id' => $product_id, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -407,10 +407,10 @@ public function testProductQueryAndIds() { * * Test querying product with "ID" set as the "idType". */ - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ), 'idType' => 'ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -419,10 +419,10 @@ public function testProductQueryAndIds() { * * Test querying product with "SLUG" set as the "idType". */ - $variables = [ + $variables = array( 'id' => get_post_field( 'post_name', $product_id ), 'idType' => 'SLUG', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -431,10 +431,10 @@ public function testProductQueryAndIds() { * * Test querying product with "SKU" set as the "idType". */ - $variables = [ + $variables = array( 'id' => get_post_meta( $product_id, '_sku', true ), 'idType' => 'SKU', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); } @@ -443,10 +443,10 @@ public function testProductToTermConnection() { $test_category = $this->factory->product->createProductCategory( 'test-product-category-1' ); $test_tag = $this->factory->product->createProductTag( 'test-product-tag-1' ); $product_id = $this->factory->product->createSimple( - [ - 'tag_ids' => [ $test_tag ], - 'category_ids' => [ $test_category ], - ] + array( + 'tag_ids' => array( $test_tag ), + 'category_ids' => array( $test_category ), + ) ); $relay_id = $this->toRelayId( 'post', $product_id ); @@ -470,21 +470,21 @@ public function testProductToTermConnection() { } '; - $variables = [ 'id' => $relay_id ]; + $variables = array( 'id' => $relay_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $relay_id ), $this->expectedNode( 'product.productTags.nodes', - [ 'name' => 'test-product-tag-1' ], + array( 'name' => 'test-product-tag-1' ), 0 ), $this->expectedNode( 'product.productCategories.nodes', - [ 'name' => 'test-product-category-1' ], + array( 'name' => 'test-product-category-1' ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -492,31 +492,31 @@ public function testProductToTermConnection() { public function testTermToProductConnection() { $test_tag = $this->factory->product->createProductTag( 'test-product-tag-2' ); $image_id = $this->factory->post->create( - [ + array( 'post_author' => $this->shop_manager, 'post_status' => 'publish', 'post_title' => 'Product Image', 'post_type' => 'attachment', - ] + ) ); $test_category = $this->factory->product->createProductCategory( 'test-product-category-2' ); update_term_meta( $test_category, 'thumbnail_id', $image_id ); $product_id = $this->factory->product->createSimple( - [ - 'tag_ids' => [ $test_tag ], - 'category_ids' => [ $test_category ], + array( + 'tag_ids' => array( $test_tag ), + 'category_ids' => array( $test_category ), 'price' => 10, 'regular_price' => 10, - ] + ) ); $expensive_product_id = $this->factory->product->createSimple( - [ - 'tag_ids' => [ $test_tag ], - 'category_ids' => [ $test_category ], + array( + 'tag_ids' => array( $test_tag ), + 'category_ids' => array( $test_category ), 'price' => 100, 'regular_price' => 100, - ] + ) ); $query = ' @@ -553,60 +553,60 @@ public function testTermToProductConnection() { } '; - $variables = [ - 'orderby' => [ - [ + $variables = array( + 'orderby' => array( + array( 'field' => 'PRICE', 'order' => 'ASC', - ], - ], - 'orderby2' => [ - [ + ), + ), + 'orderby2' => array( + array( 'field' => 'PRICE', 'order' => 'DESC', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'productTags.nodes', - [ + array( $this->expectedField( 'name', 'test-product-tag-2' ), $this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'products.nodes.1.id', $this->toRelayId( 'post', $expensive_product_id ) ), - ], + ), 0 ), $this->expectedNode( 'productCategories.nodes', - [ + array( $this->expectedField( 'name', 'test-product-category-2' ), $this->expectedField( 'image.id', $this->toRelayId( 'post', $image_id ) ), $this->expectedField( 'products.nodes.1.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $expensive_product_id ) ), - ], + ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductToMediaItemConnections() { $image_id = $this->factory->post->create( - [ + array( 'post_author' => $this->shop_manager, 'post_status' => 'publish', 'post_title' => 'Product Image', 'post_type' => 'attachment', - ] + ) ); $product_id = $this->factory->product->createSimple( - [ + array( 'image_id' => $image_id, - 'gallery_image_ids' => [ $image_id ], - ] + 'gallery_image_ids' => array( $image_id ), + ) ); $product_relay_id = $this->toRelayId( 'post', $product_id ); @@ -630,23 +630,23 @@ public function testProductToMediaItemConnections() { } '; - $variables = [ 'id' => $product_relay_id ]; + $variables = array( 'id' => $product_relay_id ); $response = graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $product_relay_id ), $this->expectedField( 'product.image.id', $image_relay_id ), - $this->expectedNode( 'product.galleryImages.nodes', [ 'id' => $image_relay_id ] ), - ]; + $this->expectedNode( 'product.galleryImages.nodes', array( 'id' => $image_relay_id ) ), + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductDownloads() { $product_id = $this->factory->product->createSimple( - [ + array( 'downloadable' => true, - 'downloads' => [ $this->factory->product->createDownload() ], - ] + 'downloads' => array( $this->factory->product->createDownload() ), + ) ); $relay_id = $this->toRelayId( 'post', $product_id ); @@ -671,22 +671,22 @@ public function testProductDownloads() { } '; - $variables = [ 'id' => $relay_id ]; + $variables = array( 'id' => $relay_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.downloads', $this->getExpectedProductDownloadData( $product_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testExternalProductQuery() { $product_id = $this->factory->product->createExternal( - [ + array( 'product_url' => 'http://woographql.com', 'button_text' => 'Buy a external product', - ] + ) ); $relay_id = $this->toRelayId( 'post', $product_id ); @@ -702,34 +702,34 @@ public function testExternalProductQuery() { } '; - $variables = [ 'id' => $relay_id ]; + $variables = array( 'id' => $relay_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.buttonText', 'Buy a external product' ), $this->expectedField( 'product.externalUrl', 'http://woographql.com' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testGroupProductConnections() { $product_id = $this->factory->product->createGrouped( - [ + array( 'name' => 'Test Group', - 'children' => [], - ] + 'children' => array(), + ) + ); + $grouped_product_ids = array( + $this->factory->product->createSimple( array( 'regular_price' => '1.00' ) ), + $this->factory->product->createSimple( array( 'regular_price' => '5.00' ) ), + $this->factory->product->createSimple( array( 'regular_price' => '10.00' ) ), ); - $grouped_product_ids = [ - $this->factory->product->createSimple( [ 'regular_price' => '1.00' ] ), - $this->factory->product->createSimple( [ 'regular_price' => '5.00' ] ), - $this->factory->product->createSimple( [ 'regular_price' => '10.00' ] ), - ]; $product = \wc_get_product( $product_id ); $this->factory->product->update_object( $product, - [ 'children' => $grouped_product_ids ] + array( 'children' => $grouped_product_ids ) ); $relay_id = $this->toRelayId( 'post', $product_id ); @@ -749,9 +749,9 @@ public function testGroupProductConnections() { } '; - $variables = [ 'id' => $relay_id ]; + $variables = array( 'id' => $relay_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.addToCartText', 'View products' ), $this->expectedField( @@ -759,12 +759,12 @@ public function testGroupProductConnections() { /* translators: %s: Group name */ sprintf( __( 'View products in the “%s” group', 'wp-graphql-woocommerce' ), 'Test Group' ) ), - ]; + ); foreach ( $product->get_children() as $grouped_product_id ) { $expected[] = $this->expectedNode( 'product.products.nodes', - [ 'id' => $this->toRelayId( 'post', $grouped_product_id ) ] + array( 'id' => $this->toRelayId( 'post', $grouped_product_id ) ) ); } @@ -781,7 +781,7 @@ public function testGroupProductConnections() { '; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'product.price', '$1.00 - $10.00' ) ]; + $expected = array( $this->expectedField( 'product.price', '$1.00 - $10.00' ) ); $this->assertQuerySuccessful( $response, $expected ); } @@ -819,25 +819,25 @@ public function testRelatedProductConnections() { } '; - $variables = [ 'id' => $this->toRelayId( 'post', $products['product'] ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $products['product'] ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = []; + $expected = array(); foreach ( $products['related'] + $products['cross_sell'] + $products['upsell'] as $product_id ) { $expected[] = $this->expectedNode( 'product.related.nodes', - [ 'id' => $this->toRelayId( 'post', $product_id ) ] + array( 'id' => $this->toRelayId( 'post', $product_id ) ) ); } foreach ( $products['cross_sell'] as $product_id ) { $expected[] = $this->expectedNode( 'product.crossSell.nodes', - [ 'id' => $this->toRelayId( 'post', $product_id ) ] + array( 'id' => $this->toRelayId( 'post', $product_id ) ) ); } foreach ( $products['upsell'] as $product_id ) { $expected[] = $this->expectedNode( 'product.upsell.nodes', - [ 'id' => $this->toRelayId( 'post', $product_id ) ] + array( 'id' => $this->toRelayId( 'post', $product_id ) ) ); } @@ -846,13 +846,13 @@ public function testRelatedProductConnections() { public function testProductToReviewConnections() { $product_id = $this->factory->product->createSimple(); - $reviews = [ + $reviews = array( $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), - ]; + ); $relay_id = $this->toRelayId( 'post', $product_id ); $product = \wc_get_product( $product_id ); @@ -873,20 +873,20 @@ public function testProductToReviewConnections() { } '; - $variables = [ 'id' => $relay_id ]; + $variables = array( 'id' => $relay_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.reviews.averageRating', floatval( $product->get_average_rating() ) ), - ]; + ); foreach ( $reviews as $review_id ) { $expected[] = $this->expectedEdge( 'product.reviews.edges', - [ + array( 'rating' => floatval( get_comment_meta( $review_id, 'rating', true ) ), - 'node' => [ 'id' => $this->toRelayId( 'comment', $review_id ) ], - ] + 'node' => array( 'id' => $this->toRelayId( 'comment', $review_id ) ), + ) ); } @@ -895,13 +895,13 @@ public function testProductToReviewConnections() { public function testProductGalleryImagesConnection() { $image_id = $this->factory->post->create( - [ + array( 'post_type' => 'attachment', 'post_content' => 'Lorem ipsum dolor...', - ] + ) ); $product_id = $this->factory->product->createSimple( - [ 'gallery_image_ids' => [ $image_id ] ] + array( 'gallery_image_ids' => array( $image_id ) ) ); $query = ' @@ -916,16 +916,16 @@ public function testProductGalleryImagesConnection() { } '; - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'product.galleryImages.nodes', - [ 'id' => $this->toRelayId( 'post', $image_id ) ] + array( 'id' => $this->toRelayId( 'post', $image_id ) ) ), - ] + ) ); } @@ -999,7 +999,7 @@ public function testProductQueryWithInterfaces() { * * Test querying product. */ - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->getExpectedProductData( $product_id ); @@ -1014,63 +1014,63 @@ public function testProductQueryWithInterfaces() { * Test querying product with unformatted content (edit-product cap required). */ $this->loginAsShopManager(); - $variables = [ + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ), 'format' => 'RAW', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.description', $product->get_description() ), $this->expectedField( 'product.shortDescription', $product->get_short_description() ), $this->expectedField( 'product.totalSales', $product->get_total_sales() ), $this->expectedField( 'product.catalogVisibility', strtoupper( $product->get_catalog_visibility() ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testProductsQueryWithAttributesFilter() { // Create product attributes. - $kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'special', 'normal' ], 'Product type' ); - $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; + $kind_attribute = $this->factory->product->createAttribute( 'kind', array( 'special', 'normal' ), 'Product type' ); + $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id; $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id; // Create attribute objects. $kind_attribute_normal_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $normal_term_id ] + array( $normal_term_id ) ); - + $kind_attribute_special_only = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $special_term_id ] + array( $special_term_id ) ); $kind_attribute_both = $this->factory->product->createAttributeObject( $kind_attribute['attribute_id'], $kind_attribute['attribute_taxonomy'], - [ $normal_term_id, $special_term_id ] + array( $normal_term_id, $special_term_id ) ); // Create products. $normal_product_id = $this->factory->product->createSimple( - [ - 'attributes' => [ $kind_attribute_normal_only ], - 'default_attributes' => [ 'pa_kind' => 'normal' ], - ] + array( + 'attributes' => array( $kind_attribute_normal_only ), + 'default_attributes' => array( 'pa_kind' => 'normal' ), + ) ); $special_product_id = $this->factory->product->createSimple( - [ - 'attributes' => [ $kind_attribute_special_only ], - 'default_attributes' => [ 'pa_kind' => 'special' ], - ] + array( + 'attributes' => array( $kind_attribute_special_only ), + 'default_attributes' => array( 'pa_kind' => 'special' ), + ) ); $both_product_id = $this->factory->product->createSimple( - [ - 'attributes' => [ $kind_attribute_both ], - ] + array( + 'attributes' => array( $kind_attribute_both ), + ) ); // Create query. @@ -1086,141 +1086,141 @@ public function testProductsQueryWithAttributesFilter() { } '; - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'normal' ], - ], - ], - ], - ], - ]; + 'terms' => array( 'normal' ), + ), + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'products.nodes', - [ 'id' => $this->toRelayId( 'post', $normal_product_id ) ] + array( 'id' => $this->toRelayId( 'post', $normal_product_id ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'special' ], - ], - ], - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + 'terms' => array( 'special' ), + ), + ), + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( $this->expectedNode( 'products.nodes', - [ 'id' => $this->toRelayId( 'post', $special_product_id ) ] + array( 'id' => $this->toRelayId( 'post', $special_product_id ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'normal', 'special' ], - ], - ], - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + 'terms' => array( 'normal', 'special' ), + ), + ), + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( $this->expectedNode( 'products.nodes', - [ 'id' => $this->toRelayId( 'post', $both_product_id ) ] + array( 'id' => $this->toRelayId( 'post', $both_product_id ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'normal', 'special' ], + 'terms' => array( 'normal', 'special' ), 'operator' => 'NOT_IN', - ], - ], - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + ), + ), + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( $this->expectedField( 'products.nodes', static::IS_FALSY ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'normal' ], + 'terms' => array( 'normal' ), 'operator' => 'NOT_IN', - ], - ] - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + ), + ), + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( $this->expectedNode( 'products.nodes', - [ 'id' => $this->toRelayId( 'post', $special_product_id ) ] + array( 'id' => $this->toRelayId( 'post', $special_product_id ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ - 'where' => [ - 'attributes' => [ - 'queries' => [ - [ + $variables = array( + 'where' => array( + 'attributes' => array( + 'queries' => array( + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'normal' ], - ], - [ + 'terms' => array( 'normal' ), + ), + array( 'taxonomy' => 'PA_KIND', - 'terms' => [ 'special' ], - ], - ], - 'relation' => 'AND', - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + 'terms' => array( 'special' ), + ), + ), + 'relation' => 'AND', + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( $this->expectedNode( 'products.nodes', - [ 'id' => $this->toRelayId( 'post', $both_product_id ) ] + array( 'id' => $this->toRelayId( 'post', $both_product_id ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ProductReviewMutationsTest.php b/tests/wpunit/ProductReviewMutationsTest.php index 0992403c2..c04fbe865 100644 --- a/tests/wpunit/ProductReviewMutationsTest.php +++ b/tests/wpunit/ProductReviewMutationsTest.php @@ -8,8 +8,8 @@ public function setUp(): void { parent::setUp(); // your set up methods here - $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); - $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); + $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); + $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); $this->products = $this->getModule( '\Helper\Wpunit' )->product(); } @@ -28,10 +28,10 @@ private function run_mutation( $mutation_name, $input = null ) { "; $results = graphql( - [ + array( 'query' => $mutation, - 'variables' => [ 'input' => $input ], - ] + 'variables' => array( 'input' => $input ), + ) ); // Use --debug flag to view @@ -43,134 +43,134 @@ private function run_mutation( $mutation_name, $input = null ) { // tests public function testCreateNewReviewMutation() { wp_set_current_user( $this->shop_manager ); - $input = [ + $input = array( 'clientMutationId' => 'some_id', 'rating' => 1, 'commentOn' => $this->products->create_simple(), 'content' => 'It came covered in poop!!!', 'author' => 'Rude customer', 'authorEmail' => 'rude-guy@example.com', - ]; + ); $actual = $this->run_mutation( 'writeReview', $input ); - $expected = [ - 'data' => [ - 'writeReview' => [ + $expected = array( + 'data' => array( + 'writeReview' => array( 'clientMutationId' => 'some_id', 'rating' => 1.0, - 'review' => [ + 'review' => array( 'content' => 'It came covered in poop!!!', - ], - ], - ], - ]; + ), + ), + ), + ); $this->assertEquals( $expected, $actual ); } public function testUpdateReviewMutation() { wp_set_current_user( $this->shop_manager ); $comment_id = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $this->products->create_simple(), 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $comment_id, 'rating', 1 ); - $input = [ + $input = array( 'clientMutationId' => 'some_id', 'rating' => 5, 'id' => Relay::toGlobalId( 'comment', $comment_id ), 'content' => 'Turns out it was Nutella. My bad =P', - ]; + ); $actual = $this->run_mutation( 'updateReview', $input ); - $expected = [ - 'data' => [ - 'updateReview' => [ + $expected = array( + 'data' => array( + 'updateReview' => array( 'clientMutationId' => 'some_id', 'rating' => 5.0, - 'review' => [ + 'review' => array( 'content' => 'Turns out it was Nutella. My bad =P', - ], - ], - ], - ]; + ), + ), + ), + ); $this->assertEquals( $expected, $actual ); } public function testDeleteReviewMutation() { wp_set_current_user( $this->shop_manager ); $comment_id = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $this->products->create_simple(), 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $comment_id, 'rating', 1 ); - $input = [ + $input = array( 'clientMutationId' => 'some_id', 'id' => Relay::toGlobalID( 'comment', $comment_id ), - ]; + ); $actual = $this->run_mutation( 'deleteReview', $input ); - $expected = [ - 'data' => [ - 'deleteReview' => [ + $expected = array( + 'data' => array( + 'deleteReview' => array( 'clientMutationId' => 'some_id', 'rating' => 1.0, - 'review' => [ + 'review' => array( 'content' => 'It came covered in poop!!!', - ], - ], - ], - ]; + ), + ), + ), + ); $this->assertEquals( $expected, $actual ); } public function testRestoreReviewMutation() { wp_set_current_user( $this->shop_manager ); $comment_id = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $this->products->create_simple(), 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $comment_id, 'rating', 1 ); // Trash comment wp_delete_comment( $comment_id ); - $input = [ + $input = array( 'clientMutationId' => 'some_id', 'id' => Relay::toGlobalID( 'comment', $comment_id ), - ]; + ); $actual = $this->run_mutation( 'restoreReview', $input ); - $expected = [ - 'data' => [ - 'restoreReview' => [ + $expected = array( + 'data' => array( + 'restoreReview' => array( 'clientMutationId' => 'some_id', 'rating' => 1.0, - 'review' => [ + 'review' => array( 'content' => 'It came covered in poop!!!', - ], - ], - ], - ]; + ), + ), + ), + ); $this->assertEquals( $expected, $actual ); } } diff --git a/tests/wpunit/ProductTaxonomyQueriesTest.php b/tests/wpunit/ProductTaxonomyQueriesTest.php index 146f3d488..0ef6c15d9 100644 --- a/tests/wpunit/ProductTaxonomyQueriesTest.php +++ b/tests/wpunit/ProductTaxonomyQueriesTest.php @@ -1,24 +1,24 @@ factory->product->createProductCategory( 'clothing' ); - $shoes_id = $this->factory->product->createProductCategory( 'shoes', [ 'parent' => $clothing_category_id ] ); - $accessories_id = $this->factory->product->createProductCategory( 'accessories', [ 'parent' => $clothing_category_id ] ); - $electronics_category_id = $this->factory->product->createProductCategory( 'electronics' ); - $smartphones_id = $this->factory->product->createProductCategory( 'smartphones', [ 'parent' => $electronics_category_id ] ); - $laptops_id = $this->factory->product->createProductCategory( 'laptops', [ 'parent' => $electronics_category_id ] ); - - // Create products. - $clothing_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $clothing_category_id ] ] ); - $shoes_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $shoes_id, $accessories_id ] ] ); - $accessories_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $accessories_id ] ] ); - $electronics_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $electronics_category_id ] ] ); - $smartphones_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $smartphones_id ] ] ); - $laptops_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $laptops_id, $electronics_category_id ] ] ); - - $query = 'query ($id: ID!) { + public function testProductCategoriesToProductsQuery() { + // Create categories. + $clothing_category_id = $this->factory->product->createProductCategory( 'clothing' ); + $shoes_id = $this->factory->product->createProductCategory( 'shoes', array( 'parent' => $clothing_category_id ) ); + $accessories_id = $this->factory->product->createProductCategory( 'accessories', array( 'parent' => $clothing_category_id ) ); + $electronics_category_id = $this->factory->product->createProductCategory( 'electronics' ); + $smartphones_id = $this->factory->product->createProductCategory( 'smartphones', array( 'parent' => $electronics_category_id ) ); + $laptops_id = $this->factory->product->createProductCategory( 'laptops', array( 'parent' => $electronics_category_id ) ); + + // Create products. + $clothing_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $clothing_category_id ) ) ); + $shoes_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $shoes_id, $accessories_id ) ) ); + $accessories_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $accessories_id ) ) ); + $electronics_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $electronics_category_id ) ) ); + $smartphones_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $smartphones_id ) ) ); + $laptops_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $laptops_id, $electronics_category_id ) ) ); + + $query = 'query ($id: ID!) { productCategory(id: $id idType: SLUG) { id slug @@ -36,97 +36,97 @@ public function testProductCategoriesToProductsQuery() { } }'; - $variables = [ - 'id' => 'clothing' - ]; - - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array_merge( - [ - $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $clothing_category_id ) ), - $this->expectedField( 'productCategory.slug', 'clothing' ), - ], - array_map( - function( $id ) { - return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); - }, - $clothing_ids - ), - array_map( - function( $id ) { - return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); - }, - array_merge( $smartphones_ids, $shoes_ids, $accessories_ids ) - ), - ); - - $this->assertQuerySuccessful( $response, $expected ); - - $variables = [ - 'id' => 'accessories' - ]; - - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array_merge( - [ - $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $accessories_id ) ), - $this->expectedField( 'productCategory.slug', 'accessories' ), - ], - array_map( - function( $id ) { - return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); - }, - array_merge( $accessories_ids, $shoes_ids ) - ), - array_map( - function( $id ) { - return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); - }, - array_merge( $clothing_ids, $smartphones_ids, $laptops_ids ) - ), - ); - - $this->assertQuerySuccessful( $response, $expected ); - - $variables = [ - 'id' => 'electronics' - ]; - - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array_merge( - [ - $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $electronics_category_id ) ), - $this->expectedField( 'productCategory.slug', 'electronics' ), - ], - array_map( - function( $id ) { - return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); - }, - array_merge( $electronics_ids, $laptops_ids ) - ), - array_map( - function( $id ) { - return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); - }, - array_merge( $clothing_ids, $shoes_ids, $accessories_ids, $smartphones_ids ) - ), - ); - - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testProductTagsToProductsQuery() { - // Create tags. - $tag1_id = $this->factory->product->createProductTag( 'tag1' ); - $tag2_id = $this->factory->product->createProductTag( 'tag2' ); - $tag3_id = $this->factory->product->createProductTag( 'tag3' ); - - // Create products. - $tag1_product_ids = $this->factory->product->create_many( 5, [ 'tag_ids' => [ $tag1_id ] ] ); - $tag2_product_ids = $this->factory->product->create_many( 5, [ 'tag_ids' => [ $tag2_id, $tag3_id ] ] ); - $tag3_product_ids = $this->factory->product->create_many( 5, [ 'tag_ids' => [ $tag3_id ] ] ); - - $query = 'query ($id: ID!) { + $variables = array( + 'id' => 'clothing', + ); + + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array_merge( + array( + $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $clothing_category_id ) ), + $this->expectedField( 'productCategory.slug', 'clothing' ), + ), + array_map( + function ( $id ) { + return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); + }, + $clothing_ids + ), + array_map( + function ( $id ) { + return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); + }, + array_merge( $smartphones_ids, $shoes_ids, $accessories_ids ) + ), + ); + + $this->assertQuerySuccessful( $response, $expected ); + + $variables = array( + 'id' => 'accessories', + ); + + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array_merge( + array( + $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $accessories_id ) ), + $this->expectedField( 'productCategory.slug', 'accessories' ), + ), + array_map( + function ( $id ) { + return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); + }, + array_merge( $accessories_ids, $shoes_ids ) + ), + array_map( + function ( $id ) { + return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); + }, + array_merge( $clothing_ids, $smartphones_ids, $laptops_ids ) + ), + ); + + $this->assertQuerySuccessful( $response, $expected ); + + $variables = array( + 'id' => 'electronics', + ); + + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array_merge( + array( + $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $electronics_category_id ) ), + $this->expectedField( 'productCategory.slug', 'electronics' ), + ), + array_map( + function ( $id ) { + return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); + }, + array_merge( $electronics_ids, $laptops_ids ) + ), + array_map( + function ( $id ) { + return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id ); + }, + array_merge( $clothing_ids, $shoes_ids, $accessories_ids, $smartphones_ids ) + ), + ); + + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testProductTagsToProductsQuery() { + // Create tags. + $tag1_id = $this->factory->product->createProductTag( 'tag1' ); + $tag2_id = $this->factory->product->createProductTag( 'tag2' ); + $tag3_id = $this->factory->product->createProductTag( 'tag3' ); + + // Create products. + $tag1_product_ids = $this->factory->product->create_many( 5, array( 'tag_ids' => array( $tag1_id ) ) ); + $tag2_product_ids = $this->factory->product->create_many( 5, array( 'tag_ids' => array( $tag2_id, $tag3_id ) ) ); + $tag3_product_ids = $this->factory->product->create_many( 5, array( 'tag_ids' => array( $tag3_id ) ) ); + + $query = 'query ($id: ID!) { productTag(id: $id idType: SLUG) { id slug @@ -144,82 +144,82 @@ public function testProductTagsToProductsQuery() { } }'; - $variables = [ - 'id' => 'tag1' - ]; - - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array_merge( - [ - $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag1_id ) ), - $this->expectedField( 'productTag.slug', 'tag1' ), - ], - array_map( - function( $id ) { - return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id ); - }, - $tag1_product_ids, - ), - array_map( - function( $id ) { - return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id ); - }, - array_merge( $tag2_product_ids, $tag3_product_ids ) - ), - ); - - $this->assertQuerySuccessful( $response, $expected ); - - $variables = [ - 'id' => 'tag2' - ]; - - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array_merge( - [ - $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag2_id ) ), - $this->expectedField( 'productTag.slug', 'tag2' ), - ], - array_map( - function( $id ) { - return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id ); - }, - $tag2_product_ids, - ), - array_map( - function( $id ) { - return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id ); - }, - array_merge( $tag1_product_ids, $tag3_product_ids ) - ), - ); - - $this->assertQuerySuccessful( $response, $expected ); - - $variables = [ - 'id' => 'tag3' - ]; - - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array_merge( - [ - $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag3_id ) ), - $this->expectedField( 'productTag.slug', 'tag3' ), - ], - array_map( - function( $id ) { - return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id ); - }, - array_merge( $tag2_product_ids, $tag3_product_ids ) - ), - array_map( - function( $id ) { - return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id ); - }, - $tag1_product_ids, - ), - ); - - $this->assertQuerySuccessful( $response, $expected ); - } + $variables = array( + 'id' => 'tag1', + ); + + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array_merge( + array( + $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag1_id ) ), + $this->expectedField( 'productTag.slug', 'tag1' ), + ), + array_map( + function ( $id ) { + return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id ); + }, + $tag1_product_ids, + ), + array_map( + function ( $id ) { + return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id ); + }, + array_merge( $tag2_product_ids, $tag3_product_ids ) + ), + ); + + $this->assertQuerySuccessful( $response, $expected ); + + $variables = array( + 'id' => 'tag2', + ); + + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array_merge( + array( + $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag2_id ) ), + $this->expectedField( 'productTag.slug', 'tag2' ), + ), + array_map( + function ( $id ) { + return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id ); + }, + $tag2_product_ids, + ), + array_map( + function ( $id ) { + return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id ); + }, + array_merge( $tag1_product_ids, $tag3_product_ids ) + ), + ); + + $this->assertQuerySuccessful( $response, $expected ); + + $variables = array( + 'id' => 'tag3', + ); + + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array_merge( + array( + $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag3_id ) ), + $this->expectedField( 'productTag.slug', 'tag3' ), + ), + array_map( + function ( $id ) { + return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id ); + }, + array_merge( $tag2_product_ids, $tag3_product_ids ) + ), + array_map( + function ( $id ) { + return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id ); + }, + $tag1_product_ids, + ), + ); + + $this->assertQuerySuccessful( $response, $expected ); + } } diff --git a/tests/wpunit/ProductVariationQueriesTest.php b/tests/wpunit/ProductVariationQueriesTest.php index a3e70e8f0..6da0b488a 100644 --- a/tests/wpunit/ProductVariationQueriesTest.php +++ b/tests/wpunit/ProductVariationQueriesTest.php @@ -6,7 +6,7 @@ class ProductVariationQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\ public function expectedProductVariationData( $id ) { $data = new WC_Product_Variation( $id ); - return [ + return array( $this->expectedField( 'productVariation.id', $this->toRelayId( 'post', $id ) ), $this->expectedField( 'productVariation.databaseId', $data->get_id() ), $this->expectedField( 'productVariation.name', $data->get_name() ), @@ -79,7 +79,7 @@ public function expectedProductVariationData( $id ) { $this->expectedField( 'productVariation.hasAttributes', ! empty( $data->has_attributes() ) ? $data->has_attributes() : static::IS_NULL ), $this->expectedField( 'productVariation.type', WPEnumType::get_safe_name( $data->get_type() ) ), $this->expectedField( 'productVariation.parent.node.id', $this->toRelayId( 'post', $data->get_parent_id() ) ), - ]; + ); } // tests @@ -143,10 +143,10 @@ public function testVariationQuery() { * * Tests "ID" ID type. */ - $variables = [ + $variables = array( 'id' => $id, 'idType' => 'ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expectedProductVariationData( $variation_id ); @@ -159,11 +159,11 @@ public function testVariationQuery() { * * Tests "DATABASE_ID" ID type. */ - $variables = [ + $variables = array( 'id' => $variation_id, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expectedProductVariationData( $variation_id ); @@ -191,12 +191,12 @@ public function testProductVariationToMediaItemConnections() { } '; - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'productVariation.id', $id ), $this->expectedField( 'productVariation.image.id', $this->toRelayId( 'post', $product->get_image_id() ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -230,13 +230,13 @@ public function testProductVariationDownloads() { } '; - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'productVariation.id', $id ), $this->expectedNode( 'productVariation.downloads', - [ + array( $this->expectedField( 'name', $downloads[0]->get_name() ), $this->expectedField( 'downloadId', $downloads[0]->get_id() ), $this->expectedField( 'filePathType', $downloads[0]->get_type_of_file_path() ), @@ -245,9 +245,9 @@ public function testProductVariationDownloads() { $this->expectedField( 'allowedFileType', $downloads[0]->is_allowed_filetype() ), $this->expectedField( 'fileExists', $downloads[0]->file_exists() ), $this->expectedField( 'file', $downloads[0]->get_file() ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -255,31 +255,30 @@ public function testProductVariationDownloads() { public function testProductsQueriesWithVariations() { // Create noise products. $product_id = $this->factory->product->createVariable( - [ - 'attribute_data' => [ $this->factory->product->createAttribute( 'print', [ 'polka-dot', 'stripe', 'flames' ] ) ], - ], + array( + 'attribute_data' => array( $this->factory->product->createAttribute( 'print', array( 'polka-dot', 'stripe', 'flames' ) ) ), + ), ); $variation_id = $this->factory->product_variation->create( - [ + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pattern' => 'polka-dot', - ], + ), 'image_id' => null, 'regular_price' => 10, - ] + ) ); - $other_variation_id = $this->factory->product_variation->create( - [ + array( 'parent_id' => $product_id, - 'attributes' => [ + 'attributes' => array( 'pattern' => 'stripe', - ], + ), 'image_id' => null, 'regular_price' => 10, - ] + ) ); $query = ' @@ -296,37 +295,37 @@ public function testProductsQueriesWithVariations() { * Assert default results without "type", or "typeIn" excludes product variations. */ $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ), $this->not()->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $variation_id ) ), $this->not()->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $other_variation_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); /** * Assert result with "type" set to "VARIATION" only return variations. */ - $variables = [ 'type' => 'VARIATION' ]; + $variables = array( 'type' => 'VARIATION' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->not()->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $variation_id ) ), $this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $other_variation_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); /** * Assert result with "typeIn" set to "VARIATION" & "VARIATION" products and variations are returned. */ - $variables = [ 'includeVariations' => true ]; + $variables = array( 'includeVariations' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $variation_id ) ), $this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $other_variation_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ProductsQueriesTest.php b/tests/wpunit/ProductsQueriesTest.php index 5c6cddb73..43acdbd70 100644 --- a/tests/wpunit/ProductsQueriesTest.php +++ b/tests/wpunit/ProductsQueriesTest.php @@ -2,98 +2,108 @@ class ProductsQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase { private function createProducts() { - $products = [ - $this->factory->product->createSimple([ - 'name' => 'Product Blue', - 'slug' => 'product-blue', - 'description' => 'A peach description', - 'price' => 100, - 'regular_price' => 100, - 'sale_price' => 90, - 'stock_status' => 'instock', - 'stock_quantity' => 10, - 'reviews_allowed' => true, - 'average_rating' => 4.5, - ]), - $this->factory->product->createSimple([ - 'name' => 'Product Green', - 'slug' => 'product-green', - 'description' => 'A turquoise description', - 'sku' => 'green-sku', - 'price' => 200, - 'regular_price' => 200, - 'sale_price' => 180, - 'stock_status' => 'instock', - 'stock_quantity' => 20, - 'reviews_allowed' => true, - 'average_rating' => 4.0, - ]), - $this->factory->product->createSimple([ - 'name' => 'Product Red', - 'slug' => 'product-red', - 'description' => 'A maroon description', - 'price' => 300, - 'regular_price' => 300, - 'sale_price' => 270, - 'stock_status' => 'instock', - 'stock_quantity' => 30, - 'reviews_allowed' => true, - 'average_rating' => 3.5, - ]), - $this->factory->product->createSimple([ - 'name' => 'Product Yellow', - 'slug' => 'product-yellow', - 'description' => 'A teal description', - 'price' => 400, - 'regular_price' => 400, - 'sale_price' => 360, - 'stock_status' => 'instock', - 'stock_quantity' => 40, - 'reviews_allowed' => true, - 'average_rating' => 3.0, - ]), - $this->factory->product->createSimple([ - 'name' => 'Product Purple', - 'slug' => 'product-purple', - 'description' => 'A magenta description', - 'price' => 500, - 'regular_price' => 500, - 'sale_price' => 450, - 'stock_status' => 'instock', - 'stock_quantity' => 50, - 'reviews_allowed' => true, - 'average_rating' => 2.5, - ]), - ]; + $products = array( + $this->factory->product->createSimple( + array( + 'name' => 'Product Blue', + 'slug' => 'product-blue', + 'description' => 'A peach description', + 'price' => 100, + 'regular_price' => 100, + 'sale_price' => 90, + 'stock_status' => 'instock', + 'stock_quantity' => 10, + 'reviews_allowed' => true, + 'average_rating' => 4.5, + ) + ), + $this->factory->product->createSimple( + array( + 'name' => 'Product Green', + 'slug' => 'product-green', + 'description' => 'A turquoise description', + 'sku' => 'green-sku', + 'price' => 200, + 'regular_price' => 200, + 'sale_price' => 180, + 'stock_status' => 'instock', + 'stock_quantity' => 20, + 'reviews_allowed' => true, + 'average_rating' => 4.0, + ) + ), + $this->factory->product->createSimple( + array( + 'name' => 'Product Red', + 'slug' => 'product-red', + 'description' => 'A maroon description', + 'price' => 300, + 'regular_price' => 300, + 'sale_price' => 270, + 'stock_status' => 'instock', + 'stock_quantity' => 30, + 'reviews_allowed' => true, + 'average_rating' => 3.5, + ) + ), + $this->factory->product->createSimple( + array( + 'name' => 'Product Yellow', + 'slug' => 'product-yellow', + 'description' => 'A teal description', + 'price' => 400, + 'regular_price' => 400, + 'sale_price' => 360, + 'stock_status' => 'instock', + 'stock_quantity' => 40, + 'reviews_allowed' => true, + 'average_rating' => 3.0, + ) + ), + $this->factory->product->createSimple( + array( + 'name' => 'Product Purple', + 'slug' => 'product-purple', + 'description' => 'A magenta description', + 'price' => 500, + 'regular_price' => 500, + 'sale_price' => 450, + 'stock_status' => 'instock', + 'stock_quantity' => 50, + 'reviews_allowed' => true, + 'average_rating' => 2.5, + ) + ), + ); $order_id = $this->factory->order->createNew( - [ + array( 'payment_method' => 'cod', - ], - [ - 'line_items' => [ - [ + ), + array( + 'line_items' => array( + array( 'product' => $products[0], 'qty' => 10, - ], - [ + ), + array( 'product' => $products[1], 'qty' => 8, - ], - [ + ), + array( 'product' => $products[2], 'qty' => 6, - ], - [ + ), + array( 'product' => $products[3], 'qty' => 4, - ], - [ + ), + array( 'product' => $products[4], 'qty' => 2, - ], - ], - ] + ), + ), + ) ); $order = \wc_get_order( $order_id ); @@ -103,140 +113,140 @@ private function createProducts() { wc_update_total_sales_counts( $order_id ); $review_one = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[0], 'comment_content' => 'It worked great!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_one, 'rating', 5.0 ); $review_one = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[0], 'comment_content' => 'It worked great!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_one, 'rating', 5.0 ); $review_two = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[2], 'comment_content' => 'It was basic', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_two, 'rating', 3.0 ); $review_three = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[2], 'comment_content' => 'Overpriced', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_three, 'rating', 2.0 ); $review_four = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[4], 'comment_content' => 'Overpriced', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_four, 'rating', 3.5 ); $review_five = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[4], 'comment_content' => 'Overpriced and ugly', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_five, 'rating', 2.5 ); $review_six = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[1], 'comment_content' => 'It was cheap!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_six, 'rating', 4.2 ); $review_six = $this->factory()->comment->create( - [ + array( 'comment_author' => 'Customer', 'comment_author_email' => 'customer@example.com', 'comment_post_ID' => $products[1], 'comment_content' => 'It was cheap!', 'comment_approved' => 1, 'comment_type' => 'review', - ] + ) ); update_comment_meta( $review_six, 'rating', 4.2 ); wc_update_product_lookup_tables(); return $products; - } + } // Tests - public function testProductsQueryAndWhereArgs() { + public function testProductsQueryAndWhereArgs() { $category_3 = $this->factory->product->createProductCategory( 'category-three' ); $category_4 = $this->factory->product->createProductCategory( 'category-four' ); - $product_ids = [ + $product_ids = array( $this->factory->product->createSimple( - [ + array( 'slug' => 'test-product-1', 'price' => 6000, 'regular_price' => 6000, - ] + ) ), $this->factory->product->createSimple( - [ + array( 'price' => 2, 'regular_price' => 2, - 'category_ids' => [ $category_3, $category_4 ], - ] + 'category_ids' => array( $category_3, $category_4 ), + ) ), $this->factory->product->createSimple( - [ + array( 'featured' => 'true', - 'category_ids' => [ $category_3 ], - ] + 'category_ids' => array( $category_3 ), + ) ), $this->factory->product->createExternal(), $this->factory->product->createSimple( - [ + array( 'price' => 200, 'regular_price' => 300, 'sale_price' => 200, 'date_on_sale_from' => ( new \DateTime( 'yesterday' ) )->format( 'Y-m-d H:i:s' ), 'date_on_sale_to' => ( new \DateTime( 'tomorrow' ) )->format( 'Y-m-d H:i:s' ), 'stock_status' => 'outofstock', - ] + ) ), - ]; + ); $query = ' query ( @@ -297,7 +307,7 @@ public function testProductsQueryAndWhereArgs() { function ( $product_id ) { return $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_id ) ) ] + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_id ) ) ) ); }, $product_ids @@ -317,7 +327,7 @@ function ( $product_id ) { * Tests query with "slug" where argument, and expect the product with * the slug "test-product-1" to be returned. */ - $variables = [ 'slugIn' => [ 'test-product-1' ] ]; + $variables = array( 'slugIn' => array( 'test-product-1' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -337,9 +347,9 @@ static function ( $node, $index ) use ( $product_ids ) { * a status of "pending" to be returned, which there are none among the test * product with that status. */ - $variables = [ 'status' => 'pending' ]; + $variables = array( 'status' => 'pending' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'products.nodes', [] ) ]; + $expected = array( $this->expectedField( 'products.nodes', array() ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -349,7 +359,7 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "type" where argument, and expect only "simple" products * to be returned. */ - $variables = [ 'type' => 'SIMPLE' ]; + $variables = array( 'type' => 'SIMPLE' ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -368,7 +378,7 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "typeIn" where argument, and expect only "simple" products * to be returned. */ - $variables = [ 'typeIn' => [ 'SIMPLE' ] ]; + $variables = array( 'typeIn' => array( 'SIMPLE' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion. @@ -380,7 +390,7 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "typeNotIn" where argument, and expect all types of products * with except "simple" to be returned. */ - $variables = [ 'typeNotIn' => [ 'SIMPLE' ] ]; + $variables = array( 'typeNotIn' => array( 'SIMPLE' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -399,7 +409,7 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "featured" where argument, expect only featured products * to be returned. */ - $variables = [ 'featured' => true ]; + $variables = array( 'featured' => true ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -418,7 +428,7 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "maxPrice" where argument, and expect all product * with a price of 10.00+ to be returned. */ - $variables = [ 'maxPrice' => 10.00 ]; + $variables = array( 'maxPrice' => 10.00 ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -437,28 +447,28 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "orderby" where argument, and expect products to * be return in descending order by "price". */ - $variables = [ - 'orderby' => [ - [ + $variables = array( + 'orderby' => array( + array( 'field' => 'PRICE', 'order' => 'DESC', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ], + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ), 0 ), $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[1] ) ) ], + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[1] ) ) ), 4 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -468,7 +478,7 @@ static function ( $node, $index ) use ( $product_ids ) { * Tests query with "category" where argument, and expect products in * the "category-three" category to be returned. */ - $variables = [ 'category' => 'category-three' ]; + $variables = array( 'category' => 'category-three' ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -489,7 +499,7 @@ static function ( $node, $index ) use ( $product_ids, $category_3 ) { * Tests query with "categoryIn" where argument, and expect products in * the "category-three" category to be returned. */ - $variables = [ 'categoryIn' => [ 'category-three' ] ]; + $variables = array( 'categoryIn' => array( 'category-three' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion. @@ -501,7 +511,7 @@ static function ( $node, $index ) use ( $product_ids, $category_3 ) { * Tests query with "categoryId" where argument, and expect products in * the "category-three" category to be returned. */ - $variables = [ 'categoryId' => $category_3 ]; + $variables = array( 'categoryId' => $category_3 ); $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion either. @@ -513,7 +523,7 @@ static function ( $node, $index ) use ( $product_ids, $category_3 ) { * Tests query with "categoryNotIn" where argument, and expect all products * except products in the "category-four" category to be returned. */ - $variables = [ 'categoryNotIn' => [ 'category-four' ] ]; + $variables = array( 'categoryNotIn' => array( 'category-four' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -532,7 +542,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4 ) { * Tests query with "categoryIdNotIn" where argument, and expect all products * except products in the "category-four" category to be returned. */ - $variables = [ 'categoryIdNotIn' => [ $category_4 ] ]; + $variables = array( 'categoryIdNotIn' => array( $category_4 ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion. @@ -544,7 +554,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4 ) { * Tests query with "categoryIdIn" where argument, and expect products in * the "category-four" category to be returned. */ - $variables = [ 'categoryIdIn' => [ $category_4 ] ]; + $variables = array( 'categoryIdIn' => array( $category_4 ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -562,22 +572,22 @@ static function ( $node, $index ) use ( $product_ids, $category_4 ) { * * Tests "taxonomyFilter" where argument */ - $variables = [ - 'taxonomyFilter' => [ + $variables = array( + 'taxonomyFilter' => array( 'relation' => 'AND', - 'filters' => [ - [ + 'filters' => array( + array( 'taxonomy' => 'PRODUCT_CAT', - 'terms' => [ 'category-three' ], - ], - [ + 'terms' => array( 'category-three' ), + ), + array( 'taxonomy' => 'PRODUCT_CAT', - 'terms' => [ 'category-four' ], + 'terms' => array( 'category-four' ), 'operator' => 'NOT_IN', - ], - ], - ], - ]; + ), + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -596,28 +606,28 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) * * Tests "include" where argument */ - $variables = [ - 'include' => [ $product_ids[0] ], - ]; + $variables = array( + 'include' => array( $product_ids[0] ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ] + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ - 'include' => [ 1000 ], - ]; + $variables = array( + 'include' => array( 1000 ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.nodes', self::IS_FALSY ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); /** @@ -625,26 +635,26 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) * * Tests "exclude" where argument */ - $variables = [ - 'exclude' => [ $product_ids[0] ], - ]; + $variables = array( + 'exclude' => array( $product_ids[0] ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->not()->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ] + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ 'exclude' => $product_ids ]; + $variables = array( 'exclude' => $product_ids ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'products.nodes', self::IS_FALSY ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); /** @@ -652,25 +662,25 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) * * Tests "stockStatus" where argument */ - $variables = [ 'stockStatus' => 'IN_STOCK' ]; + $variables = array( 'stockStatus' => 'IN_STOCK' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->not()->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ] + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ 'stockStatus' => 'OUT_OF_STOCK' ]; + $variables = array( 'stockStatus' => 'OUT_OF_STOCK' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ], + array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ), 0 ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -720,9 +730,9 @@ public function testVariationsQueryAndWhereArgs() { * Test query with no arguments */ $this->loginAsShopManager(); - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[0] ) ), $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[1] ) ), $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[2] ) ), @@ -739,7 +749,7 @@ public function testVariationsQueryAndWhereArgs() { . \wc_graphql_price( end( $prices['regular_price'] ) ) ), $this->expectedField( 'product.salePrice', self::IS_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -750,16 +760,16 @@ public function testVariationsQueryAndWhereArgs() { * * Test "minPrice" where argument */ - $variables = [ + $variables = array( 'id' => $id, 'minPrice' => 15, - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->not()->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[0] ) ), $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[1] ) ), $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[2] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -799,34 +809,34 @@ public function testProductsOrderbyArg() { /** * Assert sorting by price functions correctly. */ - $variables = [ + $variables = array( 'first' => 2, - 'orderby' => [ - [ + 'orderby' => array( + array( 'field' => 'PRICE', 'order' => 'ASC', - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ), + ), 0 ), $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ), + ), 1 ), - ], + ), 'Failed to sort products by price in ascending order.' ); @@ -835,71 +845,71 @@ public function testProductsOrderbyArg() { */ $endCursor = $this->lodashGet( $response, 'data.products.pageInfo.endCursor' ); $this->logData( $endCursor ); - $variables = [ + $variables = array( 'first' => 2, 'after' => $endCursor, - 'orderby' => [ - [ + 'orderby' => array( + array( 'field' => 'PRICE', 'order' => 'ASC', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ), + ), 0 ), $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ), + ), 1 ), - ], + ), 'Failed to sort products by price in ascending order with pagination.' ); /** * Assert sorting by popularity functions correctly. */ - $variables = [ + $variables = array( 'first' => 2, - 'orderby' => [ - [ + 'orderby' => array( + array( 'field' => 'POPULARITY', 'order' => 'DESC', - ], - ], - ]; + ), + ), + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ), + ), 0 ), $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ), + ), 1 ), - ], + ), 'Failed to sort products by popularity in ascending order.' ); @@ -907,69 +917,69 @@ public function testProductsOrderbyArg() { * Assert sorting by popularity functions correctly w/ pagination. */ $endCursor = $this->lodashGet( $response, 'data.products.pageInfo.endCursor' ); - $variables = [ + $variables = array( 'first' => 2, 'after' => $endCursor, - 'orderby' => [ - [ + 'orderby' => array( + array( 'field' => 'POPULARITY', 'order' => 'DESC', - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ), + ), 0 ), $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ), + ), 1 ), - ], + ), 'Failed to sort products by popularity in ascending order with pagination.' ); /** * Assert sorting by rating functions correctly. */ - $variables = [ + $variables = array( 'first' => 2, - 'orderby' => [ - [ + 'orderby' => array( + array( 'field' => 'RATING', 'order' => 'DESC', - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ), + ), 0 ), $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ), + ), 1 ), - ], + ), 'Failed to sort products by rating in ascending order.' ); @@ -977,35 +987,35 @@ public function testProductsOrderbyArg() { * Assert sorting by rating functions correctly w/ pagination. */ $endCursor = $this->lodashGet( $response, 'data.products.pageInfo.endCursor' ); - $variables = [ + $variables = array( 'first' => 2, 'after' => $endCursor, - 'orderby' => [ - [ + 'orderby' => array( + array( 'field' => 'RATING', 'order' => 'DESC', - ], - ], - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + ), + ), + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ), + ), 0 ), $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ), + ), 1 ), - ], + ), 'Failed to sort products by rating in ascending order with pagination.' ); } @@ -1042,74 +1052,74 @@ public function testProductsSearchArg() { /** * Assert search by product title functions correctly. */ - $variables = [ + $variables = array( 'search' => 'Green', - ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ), + ), 0 ), - ], + ), 'Failed to search products by product title.' ); /** * Assert search by product sku. */ - $variables = [ 'search' => 'green-sku' ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + $variables = array( 'search' => 'green-sku' ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ), + ), 0 ), - ], + ), 'Failed to search products by product sku.' ); // Search by product description. - $variables = [ 'search' => 'magenta' ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + $variables = array( 'search' => 'magenta' ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ), + ), 0 ), - ], + ), 'Failed to search products by product description content.' ); // Search by slug. - $variables = [ 'search' => 'product-red' ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); + $variables = array( 'search' => 'product-red' ); + $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - [ + array( $this->expectedNode( 'products.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) - ], + array( + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ), + ), 0 ), - ], + ), 'Failed to search products by product slug.' ); } diff --git a/tests/wpunit/ProtectedRouterTest.php b/tests/wpunit/ProtectedRouterTest.php index 2a3fb2e92..0635f0501 100644 --- a/tests/wpunit/ProtectedRouterTest.php +++ b/tests/wpunit/ProtectedRouterTest.php @@ -18,21 +18,21 @@ public function testGraphQLRewriteRule() { } public function testAddQueryVar() { - $query_vars = []; + $query_vars = array(); $router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance(); $actual = $router->add_query_var( $query_vars ); - $this->assertEquals( $actual, [ apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route ) ] ); + $this->assertEquals( $actual, array( apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route ) ) ); } public function testGetNonceNames() { $router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance(); $this->assertEquals( - [ + array( 'cart_url' => '_wc_cart', 'checkout_url' => '_wc_checkout', 'account_url' => '_wc_account', 'add_payment_method_url' => '_wc_payment', - ], + ), $router->get_nonce_names() ); } diff --git a/tests/wpunit/QLSessionHandlerTest.php b/tests/wpunit/QLSessionHandlerTest.php index 569b90705..81bd41d62 100644 --- a/tests/wpunit/QLSessionHandlerTest.php +++ b/tests/wpunit/QLSessionHandlerTest.php @@ -12,7 +12,7 @@ } class QLSessionHandlerTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase { - + public function setUp(): void { parent::setUp(); @@ -67,9 +67,9 @@ public function test_init_on_graphql_request() { usleep( 1000000 ); // Initialize session token for next request. - remove_action( 'woocommerce_set_cart_cookies', [ $session, 'set_customer_session_token' ] ); - remove_action( 'woographql_update_session', [ $session, 'set_customer_session_token' ] ); - remove_action( 'shutdown', [ $session, 'save_data' ] ); + remove_action( 'woocommerce_set_cart_cookies', array( $session, 'set_customer_session_token' ) ); + remove_action( 'woographql_update_session', array( $session, 'set_customer_session_token' ) ); + remove_action( 'shutdown', array( $session, 'save_data' ) ); // Create new session handler. $session = new QL_Session_Handler(); @@ -222,12 +222,12 @@ public function test_set_customer_session_token() { // Should fail to set headers if run before initialization. $session->set_customer_session_token( true ); - $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', [] ); + $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', array() ); $this->assertArrayNotHasKey( 'woocommerce-session', $graphql_response_headers ); // Should success when run after initialization. $session->init_session_token(); - $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', [] ); + $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', array() ); $this->assertArrayHasKey( 'woocommerce-session', $graphql_response_headers ); } diff --git a/tests/wpunit/RefundQueriesTest.php b/tests/wpunit/RefundQueriesTest.php index cd173260b..3be69012a 100644 --- a/tests/wpunit/RefundQueriesTest.php +++ b/tests/wpunit/RefundQueriesTest.php @@ -4,21 +4,21 @@ class RefundQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQL public function expectedRefundData( $refund_id ) { $refund = \wc_get_order( $refund_id ); - return [ + return array( $this->expectedField( 'refund.id', $this->toRelayId( 'order', $refund_id ) ), $this->expectedField( 'refund.databaseId', $refund->get_id() ), $this->expectedField( 'refund.title', $refund->get_post_title() ), $this->expectedField( 'refund.reason', $refund->get_reason() ), $this->expectedField( 'refund.amount', floatval( $refund->get_amount() ) ), $this->expectedField( 'refund.date', (string) $refund->get_date_modified() ), - ]; + ); } // tests public function testRefundQuery() { $customer_id = $this->factory->customer->create(); $invalid_customer_id = $this->factory->customer->create(); - $order_id = $this->factory->order->createNew( [ 'customer_id' => $customer_id ] ); + $order_id = $this->factory->order->createNew( array( 'customer_id' => $customer_id ) ); $this->loginAsShopManager(); $refund_id = $this->factory->refund->createNew( $order_id ); $refund = \wc_get_order( $refund_id ); @@ -46,11 +46,11 @@ public function testRefundQuery() { * Test query and failed results for users lacking required caps */ $this->loginAs( $invalid_customer_id ); - $variables = [ 'id' => $relay_id ]; + $variables = array( 'id' => $relay_id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'refund', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); @@ -86,7 +86,7 @@ public function testRefundQuery() { public function testRefundQueryAndIds() { $customer_id = $this->factory->customer->create(); - $order_id = $this->factory->order->createNew( [ 'customer_id' => $customer_id ] ); + $order_id = $this->factory->order->createNew( array( 'customer_id' => $customer_id ) ); $refund_id = $this->factory->refund->createNew( $order_id ); $relay_id = $this->toRelayId( 'order', $refund_id ); @@ -104,12 +104,12 @@ public function testRefundQueryAndIds() { * Test query and "id" argument */ $this->loginAs( $customer_id ); - $variables = [ + $variables = array( 'id' => $relay_id, 'idType' => 'ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ $this->expectedField( 'refund.id', $relay_id ) ]; + $expected = array( $this->expectedField( 'refund.id', $relay_id ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -120,10 +120,10 @@ public function testRefundQueryAndIds() { * * Test query and "refundId" argument */ - $variables = [ + $variables = array( 'id' => $refund_id, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); // Same $expected as last assertion. @@ -132,12 +132,12 @@ public function testRefundQueryAndIds() { public function testRefundsQueryAndWhereArgs() { $order_id = $this->factory->order->createNew(); - $refunds = [ + $refunds = array( $this->factory->refund->createNew( $order_id ), $this->factory->refund->createNew( $this->factory->order->createNew() ), - $this->factory->refund->createNew( $this->factory->order->createNew(), [ 'status' => 'pending' ] ), + $this->factory->refund->createNew( $this->factory->order->createNew(), array( 'status' => 'pending' ) ), $this->factory->refund->createNew( $this->factory->order->createNew() ), - ]; + ); $query = ' query ( $statuses: [String], $orderIn: [Int] ) { @@ -159,9 +159,9 @@ public function testRefundsQueryAndWhereArgs() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedField( 'refunds.nodes', [] ), - ]; + $expected = array( + $this->expectedField( 'refunds.nodes', array() ), + ); $this->assertQuerySuccessful( $response, $expected ); @@ -174,12 +174,12 @@ public function testRefundsQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ), - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[1] ] ), - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[2] ] ), - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[3] ] ), - ]; + $expected = array( + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ), + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[1] ) ), + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[2] ) ), + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[3] ) ), + ); $this->assertQuerySuccessful( $response, $expected ); @@ -191,14 +191,14 @@ public function testRefundsQueryAndWhereArgs() { * Test "statuses" where argument results should be empty * Note: This argument is functionally useless Refunds' "post_status" is always set to "completed". */ - $variables = [ 'statuses' => [ 'completed' ] ]; + $variables = array( 'statuses' => array( 'completed' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ), - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[1] ] ), - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[3] ] ), - ]; + $expected = array( + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ), + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[1] ) ), + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[3] ) ), + ); $this->assertQuerySuccessful( $response, $expected ); @@ -209,29 +209,29 @@ public function testRefundsQueryAndWhereArgs() { * * Test "orderIn" where argument */ - $variables = [ 'orderIn' => [ $order_id ] ]; + $variables = array( 'orderIn' => array( $order_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ), - ]; + $expected = array( + $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ), + ); $this->assertQuerySuccessful( $response, $expected ); } public function testOrderToRefundsConnection() { $order_id = $this->factory->order->createNew(); - $refunds = [ - $this->factory->refund->createNew( $order_id, [ 'amount' => 0.5 ] ), + $refunds = array( + $this->factory->refund->createNew( $order_id, array( 'amount' => 0.5 ) ), $this->factory->refund->createNew( $order_id, - [ + array( 'status' => 'pending', 'amount' => 0.5, - ] + ) ), $this->factory->refund->createNew( $this->factory->order->createNew() ), - ]; + ); $query = ' query ( $id: ID! ) { @@ -246,30 +246,30 @@ public function testOrderToRefundsConnection() { '; $this->loginAsShopManager(); - $variables = [ 'id' => $this->toRelayId( 'order', $order_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'order', $order_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedNode( 'order.refunds.nodes', [ 'databaseId' => $refunds[0] ] ), - $this->expectedNode( 'order.refunds.nodes', [ 'databaseId' => $refunds[1] ] ), - ]; + $expected = array( + $this->expectedNode( 'order.refunds.nodes', array( 'databaseId' => $refunds[0] ) ), + $this->expectedNode( 'order.refunds.nodes', array( 'databaseId' => $refunds[1] ) ), + ); $this->assertQuerySuccessful( $response, $expected ); } public function testCustomerToRefundsConnection() { - $order_id = $this->factory->order->createNew( [ 'customer_id' => $this->customer ] ); - $refunds = [ + $order_id = $this->factory->order->createNew( array( 'customer_id' => $this->customer ) ); + $refunds = array( $this->factory->refund->createNew( $this->factory->order->createNew() ), - $this->factory->refund->createNew( $order_id, [ 'amount' => 0.5 ] ), + $this->factory->refund->createNew( $order_id, array( 'amount' => 0.5 ) ), $this->factory->refund->createNew( $order_id, - [ + array( 'status' => 'pending', 'amount' => 0.5, - ] + ) ), - ]; + ); $query = ' query { @@ -286,11 +286,11 @@ public function testCustomerToRefundsConnection() { $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->not()->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[0] ] ), - $this->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[1] ] ), - $this->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[2] ] ), - ]; + $expected = array( + $this->not()->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[0] ) ), + $this->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[1] ) ), + $this->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[2] ) ), + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/RootQueriesTest.php b/tests/wpunit/RootQueriesTest.php index bd83277dc..202d377f4 100644 --- a/tests/wpunit/RootQueriesTest.php +++ b/tests/wpunit/RootQueriesTest.php @@ -4,7 +4,7 @@ class RootQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTe public function testBillingCountriesQuery() { // Create shipping zones and shipping rates. update_option( 'woocommerce_allowed_countries', 'specific' ); - update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] ); + update_option( 'woocommerce_specific_allowed_countries', array( 'US', 'CA' ) ); // Create query $query = ' @@ -14,12 +14,12 @@ public function testBillingCountriesQuery() { '; $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'countries.#', 'US' ), $this->expectedField( 'countries.#', 'CA' ), $this->expectedField( 'countries.#', 'GB' ), $this->expectedField( 'countries.#', 'JP' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -27,7 +27,7 @@ public function testBillingCountriesQuery() { public function testShippingCountriesQuery() { // Create shipping zones and shipping rates. update_option( 'woocommerce_allowed_countries', 'specific' ); - update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] ); + update_option( 'woocommerce_specific_allowed_countries', array( 'US', 'CA' ) ); // Create query $query = ' @@ -37,11 +37,11 @@ public function testShippingCountriesQuery() { '; $response = $this->graphql( compact( 'query' ) ); - $expected = [ + $expected = array( $this->expectedField( 'allowedCountries.#', 'US' ), $this->expectedField( 'allowedCountries.#', 'CA' ), $this->not()->expectedField( 'allowedCountries.#', 'GB' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -49,7 +49,7 @@ public function testShippingCountriesQuery() { public function testShippingCountryStatesQuery() { // Create shipping zones and shipping rates. update_option( 'woocommerce_allowed_countries', 'specific' ); - update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] ); + update_option( 'woocommerce_specific_allowed_countries', array( 'US', 'CA' ) ); // Create query $query = ' @@ -61,45 +61,45 @@ public function testShippingCountryStatesQuery() { } '; - $variables = [ 'country' => 'US' ]; + $variables = array( 'country' => 'US' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'countryStates.#', - [ + array( $this->expectedField( 'name', 'Alaska' ), $this->expectedField( 'code', 'AL' ), - ] + ) ), $this->expectedObject( 'countryStates.#', - [ + array( $this->not()->expectedField( 'name', 'Ontario' ), $this->not()->expectedField( 'code', 'ON' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); - $variables = [ 'country' => 'CA' ]; + $variables = array( 'country' => 'CA' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'countryStates.#', - [ + array( $this->expectedField( 'name', 'Ontario' ), $this->expectedField( 'code', 'ON' ), - ] + ) ), $this->expectedObject( 'countryStates.#', - [ + array( $this->not()->expectedField( 'name', 'Alaska' ), $this->not()->expectedField( 'code', 'AL' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/SessionMutationsTest.php b/tests/wpunit/SessionMutationsTest.php index 182e42636..5bffa8cdc 100644 --- a/tests/wpunit/SessionMutationsTest.php +++ b/tests/wpunit/SessionMutationsTest.php @@ -27,38 +27,38 @@ public function testUpdateSessionMutation() { } '; - $variables = [ - 'input' => [ - 'sessionData' => [ - [ + $variables = array( + 'input' => array( + 'sessionData' => array( + array( 'key' => 'test-2', 'value' => 'test-value', - ], - ], - ], - ]; + ), + ), + ), + ); /** * Assert working. */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedObject( 'updateSession.session.#', - [ + array( $this->expectedField( 'key', 'test-2' ), $this->expectedField( 'value', 'test-value' ), - ] + ) ), $this->expectedField( 'updateSession.customer.id', $this->toRelayId( 'user', $registered ) ), $this->expectedObject( 'updateSession.customer.session.#', - [ + array( $this->expectedField( 'key', 'test-2' ), $this->expectedField( 'value', 'test-value' ), - ] + ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -72,14 +72,14 @@ public function testForgetSessionMutation() { // Add products to cart. $this->factory->cart->add( - [ + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ], - [ + ), + array( 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ] + ) ); // Save session. @@ -101,10 +101,10 @@ public function testForgetSessionMutation() { } '; - $response = $this->graphql( [ 'query' => $cart_query ] ); + $response = $this->graphql( array( 'query' => $cart_query ) ); $this->assertQuerySuccessful( $response, - [ $this->expectedField( 'cart.contents.nodes', static::NOT_FALSY ) ] + array( $this->expectedField( 'cart.contents.nodes', static::NOT_FALSY ) ) ); // Forget session. @@ -125,10 +125,10 @@ public function testForgetSessionMutation() { \WC()->session->init(); // Confirm cart is empty. - $response = $this->graphql( [ 'query' => $cart_query ] ); + $response = $this->graphql( array( 'query' => $cart_query ) ); $this->assertQuerySuccessful( $response, - [ $this->expectedField( 'cart.contents.nodes', static::IS_FALSY ) ] + array( $this->expectedField( 'cart.contents.nodes', static::IS_FALSY ) ) ); } -} \ No newline at end of file +} diff --git a/tests/wpunit/ShippingMethodQueriesTest.php b/tests/wpunit/ShippingMethodQueriesTest.php index 6484ec0bd..df63d158b 100644 --- a/tests/wpunit/ShippingMethodQueriesTest.php +++ b/tests/wpunit/ShippingMethodQueriesTest.php @@ -23,7 +23,7 @@ public function testShippingMethodQueryAndArgs() { * * Confirm permission check is working */ - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQueryError( $response ); @@ -36,14 +36,14 @@ public function testShippingMethodQueryAndArgs() { * * Test "ID" ID type. */ - $variables = [ 'id' => $id ]; + $variables = array( 'id' => $id ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'shippingMethod.id', $id ), $this->expectedField( 'shippingMethod.databaseId', 'flat_rate' ), $this->expectedField( 'shippingMethod.title', static::NOT_NULL ), $this->expectedField( 'shippingMethod.description', static::NOT_NULL ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -52,7 +52,10 @@ public function testShippingMethodQueryAndArgs() { * * Test "DATABASE_ID" ID type. */ - $variables = [ 'id' => 'flat_rate', 'idType' => 'DATABASE_ID' ]; + $variables = array( + 'id' => 'flat_rate', + 'idType' => 'DATABASE_ID', + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -74,8 +77,8 @@ public function testShippingMethodsQuery() { * * Confirm permission check is working */ - $response = $this->graphql( compact( 'query' ) ); - $this->assertQuerySuccessful( $response, [ $this->expectedField( 'shippingMethods.nodes', static::IS_FALSY ) ] ); + $response = $this->graphql( compact( 'query' ) ); + $this->assertQuerySuccessful( $response, array( $this->expectedField( 'shippingMethods.nodes', static::IS_FALSY ) ) ); // Login as shop manager. $this->loginAsShopManager(); @@ -87,12 +90,11 @@ public function testShippingMethodsQuery() { */ $response = $this->graphql( compact( 'query' ) ); $expected = array_map( - function( $method ) { + function ( $method ) { return $this->expectedField( 'shippingMethods.nodes.#.id', $this->toRelayId( 'shipping_method', $method->id ) ); }, array_values( WC_Shipping::instance()->get_shipping_methods() ) ); - $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ShippingZoneMutationsTest.php b/tests/wpunit/ShippingZoneMutationsTest.php index 79ced9f16..05b6f363d 100644 --- a/tests/wpunit/ShippingZoneMutationsTest.php +++ b/tests/wpunit/ShippingZoneMutationsTest.php @@ -1,9 +1,9 @@ [ - 'name' => 'Test Shipping Zone', - 'order' => 0 - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'createShippingZone.shippingZone', - [ - $this->expectedField( 'id', static::NOT_NULL ), - $this->expectedField( 'name', 'Test Shipping Zone' ), - $this->expectedField( 'order', 0 ), - ] - ), - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testUpdateShippingZoneMutation() { - // Create a shipping zone. - $shipping_zone_id = $this->factory->shipping_zone->create( - [ - 'zone_name' => 'Test Shipping Zone', - 'zone_order' => 0, - ] - ); - - // Prepare the request. - $query = 'mutation ($input: UpdateShippingZoneInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'name' => 'Test Shipping Zone', + 'order' => 0, + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'createShippingZone.shippingZone', + array( + $this->expectedField( 'id', static::NOT_NULL ), + $this->expectedField( 'name', 'Test Shipping Zone' ), + $this->expectedField( 'order', 0 ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testUpdateShippingZoneMutation() { + // Create a shipping zone. + $shipping_zone_id = $this->factory->shipping_zone->create( + array( + 'zone_name' => 'Test Shipping Zone', + 'zone_order' => 0, + ) + ); + + // Prepare the request. + $query = 'mutation ($input: UpdateShippingZoneInput!) { updateShippingZone(input: $input) { shippingZone { id @@ -66,46 +66,46 @@ public function testUpdateShippingZoneMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'id' => $shipping_zone_id, - 'name' => 'Updated Shipping Zone', - 'order' => 1 - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'updateShippingZone.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ), - $this->expectedField( 'databaseId', $shipping_zone_id ), - $this->expectedField( 'name', 'Updated Shipping Zone' ), - $this->expectedField( 'order', 1 ), - ] - ), - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testDeleteShippingZoneMutation() { - // Create a shipping zone. - $shipping_zone = $this->factory->shipping_zone->create_and_get(); - - // Prepare the request. - $query = 'mutation ($input: DeleteShippingZoneInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'id' => $shipping_zone_id, + 'name' => 'Updated Shipping Zone', + 'order' => 1, + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'updateShippingZone.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ), + $this->expectedField( 'databaseId', $shipping_zone_id ), + $this->expectedField( 'name', 'Updated Shipping Zone' ), + $this->expectedField( 'order', 1 ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testDeleteShippingZoneMutation() { + // Create a shipping zone. + $shipping_zone = $this->factory->shipping_zone->create_and_get(); + + // Prepare the request. + $query = 'mutation ($input: DeleteShippingZoneInput!) { deleteShippingZone(input: $input) { shippingZone { id @@ -116,44 +116,44 @@ public function testDeleteShippingZoneMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'id' => $shipping_zone->get_id() - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'deleteShippingZone.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), - $this->expectedField( 'databaseId', $shipping_zone->get_id() ), - $this->expectedField( 'name', $shipping_zone->get_zone_name() ), - $this->expectedField( 'order', $shipping_zone->get_zone_order() ), - ] - ), - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testUpdateShippingZoneLocationsMutation() { - // Create a shipping zone. - $shipping_zone_id = $this->factory->shipping_zone->create(); - - // Prepare the request. - $query = 'mutation ($input: UpdateShippingZoneLocationsInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'id' => $shipping_zone->get_id(), + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'deleteShippingZone.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), + $this->expectedField( 'databaseId', $shipping_zone->get_id() ), + $this->expectedField( 'name', $shipping_zone->get_zone_name() ), + $this->expectedField( 'order', $shipping_zone->get_zone_order() ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testUpdateShippingZoneLocationsMutation() { + // Create a shipping zone. + $shipping_zone_id = $this->factory->shipping_zone->create(); + + // Prepare the request. + $query = 'mutation ($input: UpdateShippingZoneLocationsInput!) { updateShippingZoneLocations(input: $input) { shippingZone { id @@ -169,118 +169,118 @@ public function testUpdateShippingZoneLocationsMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'zoneId' => $shipping_zone_id, - 'locations' => [ - [ - 'code' => 'US', - ], - [ - 'code' => 'CALIFORNIA', - 'type' => 'STATE', - ], - [ - 'code' => '12345', - 'type' => 'POSTCODE', - ], - [ - 'code' => 'NA', - 'type' => 'CONTINENT', - ], - ] - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'updateShippingZoneLocations.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ), - $this->expectedObject( - 'locations.0', - [ - $this->expectedField( 'code', 'US' ), - $this->expectedField( 'type', 'COUNTRY' ) - ] - ), - $this->expectedObject( - 'locations.1', - [ - $this->expectedField( 'code', 'CALIFORNIA' ), - $this->expectedField( 'type', 'STATE' ) - ] - ), - $this->expectedObject( - 'locations.2', - [ - $this->expectedField( 'code', '12345' ), - $this->expectedField( 'type', 'POSTCODE' ) - ] - ), - $this->expectedObject( - 'locations.3', - [ - $this->expectedField( 'code', 'NA' ), - $this->expectedField( 'type', 'CONTINENT' ) - ] - ) - ] - ), - $this->expectedObject( - 'updateShippingZoneLocations.locations.0', - [ - $this->expectedField( 'code', 'US' ), - $this->expectedField( 'type', 'COUNTRY' ) - ] - ), - $this->expectedObject( - 'updateShippingZoneLocations.locations.1', - [ - $this->expectedField( 'code', 'CALIFORNIA' ), - $this->expectedField( 'type', 'STATE' ) - ] - ), - $this->expectedObject( - 'updateShippingZoneLocations.locations.2', - [ - $this->expectedField( 'code', '12345' ), - $this->expectedField( 'type', 'POSTCODE' ) - ] - ), - $this->expectedObject( - 'updateShippingZoneLocations.locations.3', - [ - $this->expectedField( 'code', 'NA' ), - $this->expectedField( 'type', 'CONTINENT' ) - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testClearShippingZoneLocationsMutation() { - // Create a shipping zone. - $shipping_zone = $this->factory->shipping_zone->create_and_get(); - - // Add a location to the shipping zone. - $shipping_zone->add_location( 'US', 'country' ); - $shipping_zone->save(); - - // Prepare the request. - $query = 'mutation ($input: ClearShippingZoneLocationsInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'zoneId' => $shipping_zone_id, + 'locations' => array( + array( + 'code' => 'US', + ), + array( + 'code' => 'CALIFORNIA', + 'type' => 'STATE', + ), + array( + 'code' => '12345', + 'type' => 'POSTCODE', + ), + array( + 'code' => 'NA', + 'type' => 'CONTINENT', + ), + ), + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'updateShippingZoneLocations.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ), + $this->expectedObject( + 'locations.0', + array( + $this->expectedField( 'code', 'US' ), + $this->expectedField( 'type', 'COUNTRY' ), + ) + ), + $this->expectedObject( + 'locations.1', + array( + $this->expectedField( 'code', 'CALIFORNIA' ), + $this->expectedField( 'type', 'STATE' ), + ) + ), + $this->expectedObject( + 'locations.2', + array( + $this->expectedField( 'code', '12345' ), + $this->expectedField( 'type', 'POSTCODE' ), + ) + ), + $this->expectedObject( + 'locations.3', + array( + $this->expectedField( 'code', 'NA' ), + $this->expectedField( 'type', 'CONTINENT' ), + ) + ), + ) + ), + $this->expectedObject( + 'updateShippingZoneLocations.locations.0', + array( + $this->expectedField( 'code', 'US' ), + $this->expectedField( 'type', 'COUNTRY' ), + ) + ), + $this->expectedObject( + 'updateShippingZoneLocations.locations.1', + array( + $this->expectedField( 'code', 'CALIFORNIA' ), + $this->expectedField( 'type', 'STATE' ), + ) + ), + $this->expectedObject( + 'updateShippingZoneLocations.locations.2', + array( + $this->expectedField( 'code', '12345' ), + $this->expectedField( 'type', 'POSTCODE' ), + ) + ), + $this->expectedObject( + 'updateShippingZoneLocations.locations.3', + array( + $this->expectedField( 'code', 'NA' ), + $this->expectedField( 'type', 'CONTINENT' ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testClearShippingZoneLocationsMutation() { + // Create a shipping zone. + $shipping_zone = $this->factory->shipping_zone->create_and_get(); + + // Add a location to the shipping zone. + $shipping_zone->add_location( 'US', 'country' ); + $shipping_zone->save(); + + // Prepare the request. + $query = 'mutation ($input: ClearShippingZoneLocationsInput!) { clearShippingZoneLocations(input: $input) { shippingZone { id @@ -295,47 +295,47 @@ public function testClearShippingZoneLocationsMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ 'zoneId' => $shipping_zone->get_id() ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'clearShippingZoneLocations.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), - $this->expectedField( 'locations', static::IS_FALSY ) - ] - ), - $this->expectedObject( - 'clearShippingZoneLocations.removedLocations.0', - [ - $this->expectedField( 'code', 'US' ), - $this->expectedField( 'type', 'COUNTRY' ) - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testAddMethodToShippingZoneMutation() { - // Create a shipping zone. - $shipping_zone_id = $this->factory->shipping_zone->create(); - - // Prepare the request. - $query = 'mutation ($input: AddMethodToShippingZoneInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( 'zoneId' => $shipping_zone->get_id() ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'clearShippingZoneLocations.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), + $this->expectedField( 'locations', static::IS_FALSY ), + ) + ), + $this->expectedObject( + 'clearShippingZoneLocations.removedLocations.0', + array( + $this->expectedField( 'code', 'US' ), + $this->expectedField( 'type', 'COUNTRY' ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testAddMethodToShippingZoneMutation() { + // Create a shipping zone. + $shipping_zone_id = $this->factory->shipping_zone->create(); + + // Prepare the request. + $query = 'mutation ($input: AddMethodToShippingZoneInput!) { addMethodToShippingZone(input: $input) { shippingZone { id @@ -389,100 +389,100 @@ public function testAddMethodToShippingZoneMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'zoneId' => $shipping_zone_id, - 'methodId' => 'flat_rate', - 'order' => 0, - 'enabled' => true, - 'settings' => [ - [ - 'id' => 'cost', - 'value' => '10' - ] - ] - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'addMethodToShippingZone.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ), - $this->expectedNode( - 'methods.edges', - [ - $this->expectedField( 'id', static::NOT_NULL ), - $this->expectedField( 'instanceId', static::NOT_NULL ), - $this->expectedField( 'order', 0 ), - $this->expectedField( 'enabled', true ), - $this->expectedNode( - 'settings', - [ - $this->expectedField( 'id', 'cost' ), - $this->expectedField( 'value', '10' ) - ] - ), - $this->expectedObject( - 'node', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), - $this->expectedField( 'databaseId', static::NOT_NULL ), - $this->expectedField( 'title', static::NOT_NULL ), - ] - ) - ], - 0 - ), - ] - ), - $this->expectedObject( - 'addMethodToShippingZone.method', - [ - $this->expectedField( 'id', static::NOT_NULL ), - $this->expectedField( 'instanceId', static::NOT_NULL ), - $this->expectedField( 'order', 0 ), - $this->expectedField( 'enabled', true ), - $this->expectedNode( - 'settings', - [ - $this->expectedField( 'id', 'cost' ), - $this->expectedField( 'value', '10' ) - ] - ), - $this->expectedObject( - 'node', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), - $this->expectedField( 'databaseId', static::NOT_NULL ), - $this->expectedField( 'title', static::NOT_NULL ), - ] - ) - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testUpdateMethodOnShippingZoneMutation() { - // Create a shipping zone. - $shipping_zone = $this->factory->shipping_zone->create_and_get(); - $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' ); - - // Prepare the request. - $query = 'mutation ($input: UpdateMethodOnShippingZoneInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'zoneId' => $shipping_zone_id, + 'methodId' => 'flat_rate', + 'order' => 0, + 'enabled' => true, + 'settings' => array( + array( + 'id' => 'cost', + 'value' => '10', + ), + ), + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'addMethodToShippingZone.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ), + $this->expectedNode( + 'methods.edges', + array( + $this->expectedField( 'id', static::NOT_NULL ), + $this->expectedField( 'instanceId', static::NOT_NULL ), + $this->expectedField( 'order', 0 ), + $this->expectedField( 'enabled', true ), + $this->expectedNode( + 'settings', + array( + $this->expectedField( 'id', 'cost' ), + $this->expectedField( 'value', '10' ), + ) + ), + $this->expectedObject( + 'node', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), + $this->expectedField( 'databaseId', static::NOT_NULL ), + $this->expectedField( 'title', static::NOT_NULL ), + ) + ), + ), + 0 + ), + ) + ), + $this->expectedObject( + 'addMethodToShippingZone.method', + array( + $this->expectedField( 'id', static::NOT_NULL ), + $this->expectedField( 'instanceId', static::NOT_NULL ), + $this->expectedField( 'order', 0 ), + $this->expectedField( 'enabled', true ), + $this->expectedNode( + 'settings', + array( + $this->expectedField( 'id', 'cost' ), + $this->expectedField( 'value', '10' ), + ) + ), + $this->expectedObject( + 'node', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), + $this->expectedField( 'databaseId', static::NOT_NULL ), + $this->expectedField( 'title', static::NOT_NULL ), + ) + ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testUpdateMethodOnShippingZoneMutation() { + // Create a shipping zone. + $shipping_zone = $this->factory->shipping_zone->create_and_get(); + $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' ); + + // Prepare the request. + $query = 'mutation ($input: UpdateMethodOnShippingZoneInput!) { updateMethodOnShippingZone(input: $input) { shippingZone { id @@ -534,86 +534,86 @@ public function testUpdateMethodOnShippingZoneMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'zoneId' => $shipping_zone->get_id(), - 'instanceId' => $instance_id, - 'settings' => [ - [ - 'id' => 'cost', - 'value' => '10' - ] - ], - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - - $expected = [ - $this->expectedObject( - 'updateMethodOnShippingZone.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), - $this->expectedNode( - 'methods.edges', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ), - $this->expectedField( 'instanceId', $instance_id ), - $this->expectedField( 'order', static::NOT_NULL ), - $this->expectedField( 'enabled', true ), - $this->expectedNode( - 'settings', - [ - $this->expectedField( 'id', 'cost' ), - $this->expectedField( 'value', '10' ) - ] - ), - $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), - ], - 0 - ), - ] - ), - $this->expectedObject( - 'updateMethodOnShippingZone.method', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ), - $this->expectedField( 'instanceId', $instance_id ), - $this->expectedField( 'order', static::NOT_NULL ), - $this->expectedField( 'enabled', true ), - $this->expectedNode( - 'settings', - [ - $this->expectedField( 'id', 'cost' ), - $this->expectedField( 'value', '10' ) - ] - ), - $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testRemoveMethodFromShippingZoneMutation() { - // Create a shipping zone and add the shipping method. - $shipping_zone = $this->factory->shipping_zone->create_and_get(); - $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' ); - $shipping_method = new \WC_Shipping_Flat_Rate( $instance_id ); - - // Prepare the request. - $query = 'mutation ($input: RemoveMethodFromShippingZoneInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'zoneId' => $shipping_zone->get_id(), + 'instanceId' => $instance_id, + 'settings' => array( + array( + 'id' => 'cost', + 'value' => '10', + ), + ), + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + + $expected = array( + $this->expectedObject( + 'updateMethodOnShippingZone.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), + $this->expectedNode( + 'methods.edges', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ), + $this->expectedField( 'instanceId', $instance_id ), + $this->expectedField( 'order', static::NOT_NULL ), + $this->expectedField( 'enabled', true ), + $this->expectedNode( + 'settings', + array( + $this->expectedField( 'id', 'cost' ), + $this->expectedField( 'value', '10' ), + ) + ), + $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), + ), + 0 + ), + ) + ), + $this->expectedObject( + 'updateMethodOnShippingZone.method', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ), + $this->expectedField( 'instanceId', $instance_id ), + $this->expectedField( 'order', static::NOT_NULL ), + $this->expectedField( 'enabled', true ), + $this->expectedNode( + 'settings', + array( + $this->expectedField( 'id', 'cost' ), + $this->expectedField( 'value', '10' ), + ) + ), + $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testRemoveMethodFromShippingZoneMutation() { + // Create a shipping zone and add the shipping method. + $shipping_zone = $this->factory->shipping_zone->create_and_get(); + $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' ); + $shipping_method = new \WC_Shipping_Flat_Rate( $instance_id ); + + // Prepare the request. + $query = 'mutation ($input: RemoveMethodFromShippingZoneInput!) { removeMethodFromShippingZone(input: $input) { shippingZone { id @@ -633,44 +633,44 @@ public function testRemoveMethodFromShippingZoneMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'zoneId' => $shipping_zone->get_id(), - 'instanceId' => $instance_id - ] - ]; - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - - // Confirm permissions error. - $this->assertQueryError( $response ); - - // Login as admin and re-execute expecting success. - $this->loginAsShopManager(); - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'removeMethodFromShippingZone.shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), - $this->expectedField( 'methods.edges', static::IS_FALSY ), - ] - ), - $this->expectedObject( - 'removeMethodFromShippingZone.removedMethod', - [ - $this->expectedField( 'enabled', $shipping_method->is_enabled() ), - $this->expectedNode( - 'node', - [ $this->expectedField( 'id', $this->toRelayId( 'shipping_method', $shipping_method->id ) ) ] - ) - ] - ), - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } + // Prepare the variables. + $variables = array( + 'input' => array( + 'zoneId' => $shipping_zone->get_id(), + 'instanceId' => $instance_id, + ), + ); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + + // Confirm permissions error. + $this->assertQueryError( $response ); + + // Login as admin and re-execute expecting success. + $this->loginAsShopManager(); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'removeMethodFromShippingZone.shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), + $this->expectedField( 'methods.edges', static::IS_FALSY ), + ) + ), + $this->expectedObject( + 'removeMethodFromShippingZone.removedMethod', + array( + $this->expectedField( 'enabled', $shipping_method->is_enabled() ), + $this->expectedNode( + 'node', + array( $this->expectedField( 'id', $this->toRelayId( 'shipping_method', $shipping_method->id ) ) ) + ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } } diff --git a/tests/wpunit/ShippingZoneQueriesTest.php b/tests/wpunit/ShippingZoneQueriesTest.php index c689e0344..762cdd170 100644 --- a/tests/wpunit/ShippingZoneQueriesTest.php +++ b/tests/wpunit/ShippingZoneQueriesTest.php @@ -1,30 +1,29 @@ factory->shipping_zone->create_and_get(); - - // Add location. - $shipping_zone->add_location( 'US', 'country' ); - $shipping_zone->save(); - - - // Add shipping method. - $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' ); - $shipping_method = null; - foreach ( $shipping_zone->get_shipping_methods() as $method ) { - if ( $method->instance_id === $instance_id ) { - $shipping_method = $method; - break; - } - } - $instance_settings = $shipping_method->instance_settings; - $instance_settings['cost'] = 10.00; - update_option( $shipping_method->get_instance_option_key(), $instance_settings ); - - // Prepare the request. - $query = 'query ($id: ID!) { + public function testShippingZoneQuery() { + // Create a shipping zone. + $shipping_zone = $this->factory->shipping_zone->create_and_get(); + + // Add location. + $shipping_zone->add_location( 'US', 'country' ); + $shipping_zone->save(); + + // Add shipping method. + $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' ); + $shipping_method = null; + foreach ( $shipping_zone->get_shipping_methods() as $method ) { + if ( $method->instance_id === $instance_id ) { + $shipping_method = $method; + break; + } + } + $instance_settings = $shipping_method->instance_settings; + $instance_settings['cost'] = 10.00; + update_option( $shipping_method->get_instance_option_key(), $instance_settings ); + + // Prepare the request. + $query = 'query ($id: ID!) { shippingZone(id: $id) { id name @@ -59,68 +58,68 @@ public function testShippingZoneQuery() { } }'; - // Prepare the variables. - $variables = [ 'id' => $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ]; - - // Execute the request expecting failure. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); + // Prepare the variables. + $variables = array( 'id' => $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ); - // Login as shop manager. - $this->loginAsShopManager(); + // Execute the request expecting failure. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); - // Execute the request expecting success. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'shippingZone', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), - $this->expectedField( 'name', $shipping_zone->get_zone_name() ), - $this->expectedField( 'order', $shipping_zone->get_zone_order() ), - $this->expectedNode( - 'locations', - [ - $this->expectedField( 'code', 'US' ), - $this->expectedField( 'type', 'COUNTRY' ) - ] - ), - $this->expectedNode( - 'methods.edges', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ), - $this->expectedField( 'instanceId', $instance_id ), - $this->expectedField( 'order', $shipping_method->method_order ), - $this->expectedField( 'enabled', $shipping_method->is_enabled() ), - $this->expectedNode( - 'settings', - [ - $this->expectedField( 'id', 'cost' ), - $this->expectedField( 'label', 'Cost' ), - $this->expectedField( 'description', static::NOT_FALSY ), - $this->expectedField( 'type', 'TEXT' ), - $this->expectedField( 'value', '10' ), - $this->expectedField( 'default', static::IS_NULL ), - $this->expectedField( 'placeholder', static::IS_NULL ), - ], - ) - ], - 0 - ) - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testShippingZonesQuery() { - // Create a shipping zones. - $shipping_zones = $this->factory->shipping_zone->create_many( 3 ); + // Login as shop manager. + $this->loginAsShopManager(); - // Prepare the request. - $query = 'query { + // Execute the request expecting success. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'shippingZone', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ), + $this->expectedField( 'name', $shipping_zone->get_zone_name() ), + $this->expectedField( 'order', $shipping_zone->get_zone_order() ), + $this->expectedNode( + 'locations', + array( + $this->expectedField( 'code', 'US' ), + $this->expectedField( 'type', 'COUNTRY' ), + ) + ), + $this->expectedNode( + 'methods.edges', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ), + $this->expectedField( 'instanceId', $instance_id ), + $this->expectedField( 'order', $shipping_method->method_order ), + $this->expectedField( 'enabled', $shipping_method->is_enabled() ), + $this->expectedNode( + 'settings', + array( + $this->expectedField( 'id', 'cost' ), + $this->expectedField( 'label', 'Cost' ), + $this->expectedField( 'description', static::NOT_FALSY ), + $this->expectedField( 'type', 'TEXT' ), + $this->expectedField( 'value', '10' ), + $this->expectedField( 'default', static::IS_NULL ), + $this->expectedField( 'placeholder', static::IS_NULL ), + ), + ), + ), + 0 + ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testShippingZonesQuery() { + // Create a shipping zones. + $shipping_zones = $this->factory->shipping_zone->create_many( 3 ); + + // Prepare the request. + $query = 'query { shippingZones { nodes { id @@ -128,41 +127,41 @@ public function testShippingZonesQuery() { } }'; - /** + /** * Assertion One * * Confirm permission check is working */ - $response = $this->graphql( compact( 'query' ) ); - $this->assertQuerySuccessful( $response, [ $this->expectedField( 'shippingZones.nodes', static::IS_FALSY ) ] ); + $response = $this->graphql( compact( 'query' ) ); + $this->assertQuerySuccessful( $response, array( $this->expectedField( 'shippingZones.nodes', static::IS_FALSY ) ) ); // Login as shop manager. $this->loginAsShopManager(); - // Execute the request. - $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedNode( - 'shippingZones.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[0] ) ) - ] - ), - $this->expectedNode( - 'shippingZones.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[1] ) ) - ] - ), - $this->expectedNode( - 'shippingZones.nodes', - [ - $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[2] ) ) - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } + // Execute the request. + $response = $this->graphql( compact( 'query' ) ); + $expected = array( + $this->expectedNode( + 'shippingZones.nodes', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[0] ) ), + ) + ), + $this->expectedNode( + 'shippingZones.nodes', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[1] ) ), + ) + ), + $this->expectedNode( + 'shippingZones.nodes', + array( + $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[2] ) ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } } diff --git a/tests/wpunit/TaxClassMutationsTest.php b/tests/wpunit/TaxClassMutationsTest.php index a272902ea..730ce4ef1 100644 --- a/tests/wpunit/TaxClassMutationsTest.php +++ b/tests/wpunit/TaxClassMutationsTest.php @@ -1,9 +1,9 @@ [ - 'name' => 'Test Tax Class', - 'slug' => 'test-tax-class' - ] - ]; + // Prepare the variables. + $variables = array( + 'input' => array( + 'name' => 'Test Tax Class', + 'slug' => 'test-tax-class', + ), + ); - // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); + // Execute the request expecting failure due to missing permissions. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); - // Login as shop manager. - $this->loginAsShopManager(); + // Login as shop manager. + $this->loginAsShopManager(); - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'createTaxClass.taxClass', - [ - $this->expectedField( 'name', 'Test Tax Class' ), - $this->expectedField( 'slug', 'test-tax-class' ) - ] - ), - ]; + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'createTaxClass.taxClass', + array( + $this->expectedField( 'name', 'Test Tax Class' ), + $this->expectedField( 'slug', 'test-tax-class' ), + ) + ), + ); - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } - public function testDeleteTaxClassMutation() { - // Create a tax class. - $tax_class = $this->factory->tax_class->create(); + public function testDeleteTaxClassMutation() { + // Create a tax class. + $tax_class = $this->factory->tax_class->create(); - // Prepare the request. - $query = 'mutation ($input: DeleteTaxClassInput!) { + // Prepare the request. + $query = 'mutation ($input: DeleteTaxClassInput!) { deleteTaxClass(input: $input) { taxClass { name @@ -57,37 +57,37 @@ public function testDeleteTaxClassMutation() { } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'slug' => $tax_class['slug'] - ] - ]; + // Prepare the variables. + $variables = array( + 'input' => array( + 'slug' => $tax_class['slug'], + ), + ); - // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); + // Execute the request expecting failure due to missing permissions. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); - // Login as shop manager. - $this->loginAsShopManager(); + // Login as shop manager. + $this->loginAsShopManager(); - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'deleteTaxClass.taxClass', - [ - $this->expectedField( 'name', $tax_class['name'] ), - $this->expectedField( 'slug', $tax_class['slug'] ) - ] - ), - ]; + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'deleteTaxClass.taxClass', + array( + $this->expectedField( 'name', $tax_class['name'] ), + $this->expectedField( 'slug', $tax_class['slug'] ), + ) + ), + ); - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); - // Ensure the tax class was deleted. - $tax_class = $this->factory->tax_class->get_object_by_id( $tax_class['slug'] ); - $this->assertNull( $tax_class ); - } + // Ensure the tax class was deleted. + $tax_class = $this->factory->tax_class->get_object_by_id( $tax_class['slug'] ); + $this->assertNull( $tax_class ); + } } diff --git a/tests/wpunit/TaxClassQueriesTest.php b/tests/wpunit/TaxClassQueriesTest.php index ba3740435..304dd88c8 100644 --- a/tests/wpunit/TaxClassQueriesTest.php +++ b/tests/wpunit/TaxClassQueriesTest.php @@ -1,12 +1,12 @@ factory->tax_class->create_many( 2 ); + public function testTaxClassesQuery() { + // Create tax classes. + $tax_classes = $this->factory->tax_class->create_many( 2 ); - // Prepare the request. - $query = '{ + // Prepare the request. + $query = '{ taxClasses { nodes { name @@ -14,34 +14,34 @@ public function testTaxClassesQuery() { } } }'; - - // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query' ) ); - $this->assertQuerySuccessful( $response, [ $this->expectedField( 'taxClasses.nodes', static::IS_FALSY ) ] ); - // Login as shop manager. - $this->loginAsShopManager(); + // Execute the request expecting failure due to missing permissions. + $response = $this->graphql( compact( 'query' ) ); + $this->assertQuerySuccessful( $response, array( $this->expectedField( 'taxClasses.nodes', static::IS_FALSY ) ) ); - // Execute the request. - $response = $this->graphql( compact( 'query' ) ); - $expected = [ - $this->expectedNode( - 'taxClasses.nodes', - [ - $this->expectedField( 'name', $tax_classes[0]['name'] ), - $this->expectedField( 'slug', $tax_classes[0]['slug'] ), - ] - ), - $this->expectedNode( - 'taxClasses.nodes', - [ - $this->expectedField( 'name', $tax_classes[1]['name'] ), - $this->expectedField( 'slug', $tax_classes[1]['slug'] ), - ] - ), - ]; + // Login as shop manager. + $this->loginAsShopManager(); - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } + // Execute the request. + $response = $this->graphql( compact( 'query' ) ); + $expected = array( + $this->expectedNode( + 'taxClasses.nodes', + array( + $this->expectedField( 'name', $tax_classes[0]['name'] ), + $this->expectedField( 'slug', $tax_classes[0]['slug'] ), + ) + ), + $this->expectedNode( + 'taxClasses.nodes', + array( + $this->expectedField( 'name', $tax_classes[1]['name'] ), + $this->expectedField( 'slug', $tax_classes[1]['slug'] ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } } diff --git a/tests/wpunit/TaxRateMutationsTest.php b/tests/wpunit/TaxRateMutationsTest.php index 99e25165a..44fd33122 100644 --- a/tests/wpunit/TaxRateMutationsTest.php +++ b/tests/wpunit/TaxRateMutationsTest.php @@ -3,12 +3,12 @@ use WPGraphQL\Type\WPEnumType; class TaxRateMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase { - public function testCreateTaxRateMutation() { - // Create tax class. - $tax_class = $this->factory->tax_class->create(); + public function testCreateTaxRateMutation() { + // Create tax class. + $tax_class = $this->factory->tax_class->create(); - // Prepare the request. - $query = 'mutation ($input: CreateTaxRateInput!) { + // Prepare the request. + $query = 'mutation ($input: CreateTaxRateInput!) { createTaxRate(input: $input) { taxRate { id @@ -28,68 +28,68 @@ class } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'rate' => '10', - 'country' => 'US', - 'state' => 'CA', - 'postcodes' => [ '12345', '67890' ], - 'cities' => [ 'Los Angeles', 'San Francisco' ], - 'priority' => 1, - 'compound' => false, - 'shipping' => false, - 'order' => 0, - 'class' => WPEnumType::get_safe_name( $tax_class['slug'] ) - ] - ]; - - // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); - - // Login as shop manager. - $this->loginAsShopManager(); - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'createTaxRate.taxRate', - [ - $this->expectedField( 'id', self::NOT_NULL ), - $this->expectedField( 'rate', static::NOT_FALSY ), - $this->expectedField( 'country', 'US' ), - $this->expectedField( 'state', 'CA' ), - $this->expectedField( 'postcode', '67890' ), - $this->expectedField( 'postcodes.0', '12345' ), - $this->expectedField( 'postcodes.1', '67890' ), - $this->expectedField( 'city', 'SAN FRANCISCO' ), - $this->expectedField( 'cities.0', 'LOS ANGELES' ), - $this->expectedField( 'cities.1', 'SAN FRANCISCO' ), - $this->expectedField( 'priority', 1 ), - $this->expectedField( 'compound', false ), - $this->expectedField( 'shipping', false ), - $this->expectedField( 'order', 0 ), - $this->expectedField( 'class', WPEnumType::get_safe_name( $tax_class['slug'] ) ) - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testUpdateTaxRateMutation() { - // Create a tax class. - $old_tax_class = $this->factory->tax_class->create(); - $new_tax_class = $this->factory->tax_class->create(); - - // Create a tax rate. - $tax_rate_id = $this->factory->tax_rate->create( [ 'class' => $old_tax_class['slug'] ] ); - - // Prepare the request. - $query = 'mutation ($input: UpdateTaxRateInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'rate' => '10', + 'country' => 'US', + 'state' => 'CA', + 'postcodes' => array( '12345', '67890' ), + 'cities' => array( 'Los Angeles', 'San Francisco' ), + 'priority' => 1, + 'compound' => false, + 'shipping' => false, + 'order' => 0, + 'class' => WPEnumType::get_safe_name( $tax_class['slug'] ), + ), + ); + + // Execute the request expecting failure due to missing permissions. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); + + // Login as shop manager. + $this->loginAsShopManager(); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'createTaxRate.taxRate', + array( + $this->expectedField( 'id', self::NOT_NULL ), + $this->expectedField( 'rate', static::NOT_FALSY ), + $this->expectedField( 'country', 'US' ), + $this->expectedField( 'state', 'CA' ), + $this->expectedField( 'postcode', '67890' ), + $this->expectedField( 'postcodes.0', '12345' ), + $this->expectedField( 'postcodes.1', '67890' ), + $this->expectedField( 'city', 'SAN FRANCISCO' ), + $this->expectedField( 'cities.0', 'LOS ANGELES' ), + $this->expectedField( 'cities.1', 'SAN FRANCISCO' ), + $this->expectedField( 'priority', 1 ), + $this->expectedField( 'compound', false ), + $this->expectedField( 'shipping', false ), + $this->expectedField( 'order', 0 ), + $this->expectedField( 'class', WPEnumType::get_safe_name( $tax_class['slug'] ) ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testUpdateTaxRateMutation() { + // Create a tax class. + $old_tax_class = $this->factory->tax_class->create(); + $new_tax_class = $this->factory->tax_class->create(); + + // Create a tax rate. + $tax_rate_id = $this->factory->tax_rate->create( array( 'class' => $old_tax_class['slug'] ) ); + + // Prepare the request. + $query = 'mutation ($input: UpdateTaxRateInput!) { updateTaxRate(input: $input) { taxRate { id @@ -107,70 +107,70 @@ class } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'id' => $tax_rate_id, - 'rate' => '20', - 'country' => 'US', - 'state' => 'NY', - 'postcodes' => [ '54321', '09876' ], - 'cities' => [ 'New York', 'Buffalo' ], - 'priority' => 2, - 'compound' => true, - 'shipping' => true, - 'order' => 1, - 'class' => WPEnumType::get_safe_name( $new_tax_class['slug'] ) - ] - ]; - - // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); - - // Login as shop manager. - $this->loginAsShopManager(); - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'updateTaxRate.taxRate', - [ - $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate_id ) ), - $this->expectedField( 'rate', static::NOT_FALSY ), - $this->expectedField( 'country', 'US' ), - $this->expectedField( 'state', 'NY' ), - $this->expectedField( 'postcodes.0', '54321' ), - $this->expectedField( 'postcodes.1', '09876' ), - $this->expectedField( 'cities.0', 'NEW YORK' ), - $this->expectedField( 'cities.1', 'BUFFALO' ), - $this->expectedField( 'priority', 2 ), - $this->expectedField( 'compound', true ), - $this->expectedField( 'shipping', true ), - $this->expectedField( 'order', 1 ), - $this->expectedField( 'class', WPEnumType::get_safe_name( $new_tax_class['slug'] ) ), - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - } - - public function testDeleteTaxRateMutation() { - // Create a tax rate. - $tax_rate = $this->factory->tax_rate->create_and_get( - [ - 'rate' => '30', - 'country' => 'US', - 'state' => 'TX', - 'class' => 'zero-rate', - ] - ); - - // Prepare the request. - $query = 'mutation ($input: DeleteTaxRateInput!) { + // Prepare the variables. + $variables = array( + 'input' => array( + 'id' => $tax_rate_id, + 'rate' => '20', + 'country' => 'US', + 'state' => 'NY', + 'postcodes' => array( '54321', '09876' ), + 'cities' => array( 'New York', 'Buffalo' ), + 'priority' => 2, + 'compound' => true, + 'shipping' => true, + 'order' => 1, + 'class' => WPEnumType::get_safe_name( $new_tax_class['slug'] ), + ), + ); + + // Execute the request expecting failure due to missing permissions. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); + + // Login as shop manager. + $this->loginAsShopManager(); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'updateTaxRate.taxRate', + array( + $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate_id ) ), + $this->expectedField( 'rate', static::NOT_FALSY ), + $this->expectedField( 'country', 'US' ), + $this->expectedField( 'state', 'NY' ), + $this->expectedField( 'postcodes.0', '54321' ), + $this->expectedField( 'postcodes.1', '09876' ), + $this->expectedField( 'cities.0', 'NEW YORK' ), + $this->expectedField( 'cities.1', 'BUFFALO' ), + $this->expectedField( 'priority', 2 ), + $this->expectedField( 'compound', true ), + $this->expectedField( 'shipping', true ), + $this->expectedField( 'order', 1 ), + $this->expectedField( 'class', WPEnumType::get_safe_name( $new_tax_class['slug'] ) ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + } + + public function testDeleteTaxRateMutation() { + // Create a tax rate. + $tax_rate = $this->factory->tax_rate->create_and_get( + array( + 'rate' => '30', + 'country' => 'US', + 'state' => 'TX', + 'class' => 'zero-rate', + ) + ); + + // Prepare the request. + $query = 'mutation ($input: DeleteTaxRateInput!) { deleteTaxRate(input: $input) { taxRate { id @@ -182,40 +182,40 @@ class } }'; - // Prepare the variables. - $variables = [ - 'input' => [ - 'id' => absint( $tax_rate->tax_rate_id ), - ] - ]; - - // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); - - // Login as shop manager. - $this->loginAsShopManager(); - - // Execute the request. - $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ - $this->expectedObject( - 'deleteTaxRate.taxRate', - [ - $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate->tax_rate_id ) ), - $this->expectedField( 'rate', static::NOT_FALSY ), - $this->expectedField( 'country', 'US' ), - $this->expectedField( 'state', 'TX' ), - $this->expectedField( 'class', 'ZERO_RATE' ), - ] - ) - ]; - - // Validate the response. - $this->assertQuerySuccessful( $response, $expected ); - - // Ensure the tax rate has been deleted. - $tax_rate = $this->factory->tax_rate->get_object_by_id( $tax_rate->tax_rate_id ); - $this->assertNull( $tax_rate ); - } + // Prepare the variables. + $variables = array( + 'input' => array( + 'id' => absint( $tax_rate->tax_rate_id ), + ), + ); + + // Execute the request expecting failure due to missing permissions. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); + + // Login as shop manager. + $this->loginAsShopManager(); + + // Execute the request. + $response = $this->graphql( compact( 'query', 'variables' ) ); + $expected = array( + $this->expectedObject( + 'deleteTaxRate.taxRate', + array( + $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate->tax_rate_id ) ), + $this->expectedField( 'rate', static::NOT_FALSY ), + $this->expectedField( 'country', 'US' ), + $this->expectedField( 'state', 'TX' ), + $this->expectedField( 'class', 'ZERO_RATE' ), + ) + ), + ); + + // Validate the response. + $this->assertQuerySuccessful( $response, $expected ); + + // Ensure the tax rate has been deleted. + $tax_rate = $this->factory->tax_rate->get_object_by_id( $tax_rate->tax_rate_id ); + $this->assertNull( $tax_rate ); + } } diff --git a/tests/wpunit/TaxRateQueriesTest.php b/tests/wpunit/TaxRateQueriesTest.php index 53913fa2a..f456ef175 100644 --- a/tests/wpunit/TaxRateQueriesTest.php +++ b/tests/wpunit/TaxRateQueriesTest.php @@ -4,7 +4,7 @@ class TaxRateQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ public function expectedTaxRateData( $rate_id ) { $rate = $this->factory->tax_rate->get_object_by_id( $rate_id ); - return [ + return array( $this->expectedField( 'taxRate.id', $this->toRelayId( 'tax_rate', $rate_id ) ), $this->expectedField( 'taxRate.databaseId', absint( $rate->tax_rate_id ) ), $this->expectedField( 'taxRate.country', ! empty( $rate->tax_rate_country ) ? $rate->tax_rate_country : static::IS_NULL ), @@ -23,7 +23,7 @@ public function expectedTaxRateData( $rate_id ) { ? WPEnumType::get_safe_name( $rate->tax_rate_class ) : 'STANDARD' ), - ]; + ); } // tests @@ -51,19 +51,19 @@ class '; // Execute the request expecting failure due to missing permissions. - $variables = [ 'id' => $this->toRelayId( 'tax_rate', $rate ) ]; - $response = $this->graphql( compact( 'query', 'variables' ) ); - $this->assertQueryError( $response ); + $variables = array( 'id' => $this->toRelayId( 'tax_rate', $rate ) ); + $response = $this->graphql( compact( 'query', 'variables' ) ); + $this->assertQueryError( $response ); - // Login as shop manager. - $this->loginAsShopManager(); + // Login as shop manager. + $this->loginAsShopManager(); /** * Assertion One * * Tests query, "id" query arg, and results */ - $variables = [ 'id' => $this->toRelayId( 'tax_rate', $rate ) ]; + $variables = array( 'id' => $this->toRelayId( 'tax_rate', $rate ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expectedTaxRateData( $rate ); @@ -74,20 +74,20 @@ class * * Tests query, "rateId" query arg, and results */ - $variables = [ + $variables = array( 'id' => $rate, 'idType' => 'DATABASE_ID', - ]; + ); $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); } public function testTaxesQuery() { - $rates = [ + $rates = array( $this->factory->tax_rate->create(), $this->factory->tax_rate->create( - [ + array( 'country' => 'US', 'state' => 'AL', 'city' => 'Montgomery', @@ -98,10 +98,10 @@ public function testTaxesQuery() { 'compound' => '1', 'shipping' => '1', 'class' => 'reduced-rate', - ] + ) ), $this->factory->tax_rate->create( - [ + array( 'country' => 'US', 'state' => 'VA', 'city' => 'Norfolk', @@ -112,9 +112,9 @@ public function testTaxesQuery() { 'compound' => '1', 'shipping' => '1', 'class' => 'zero-rate', - ] + ) ), - ]; + ); $query = ' query ( $class: TaxClassEnum, $postCode: String, $postCodeIn: [String] ) { @@ -128,11 +128,11 @@ class '; // Execute the request expecting failure due to missing permissions. - $response = $this->graphql( compact( 'query' ) ); - $this->assertQuerySuccessful( $response, [ $this->expectedField( 'taxRates.nodes', static::IS_FALSY ) ] ); + $response = $this->graphql( compact( 'query' ) ); + $this->assertQuerySuccessful( $response, array( $this->expectedField( 'taxRates.nodes', static::IS_FALSY ) ) ); - // Login as shop manager. - $this->loginAsShopManager(); + // Login as shop manager. + $this->loginAsShopManager(); /** * Assertion One @@ -144,9 +144,9 @@ class function ( $id ) { return $this->expectedNode( 'taxRates.nodes', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $id ) ), - ] + ) ); }, $rates @@ -168,15 +168,15 @@ function ( $id ) { } ) ); - $variables = [ 'class' => 'REDUCED_RATE' ]; + $variables = array( 'class' => 'REDUCED_RATE' ); $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function ( $id ) { return $this->expectedNode( 'taxRates.nodes', - [ + array( $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $id ) ), - ] + ) ); }, $reduced_tax_rates, @@ -191,13 +191,13 @@ function ( $id ) { * * Tests "postCode" where arg */ - $variables = [ 'postCode' => '23451' ]; + $variables = array( 'postCode' => '23451' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'taxRates.nodes.0.id', $this->toRelayId( 'tax_rate', $rates[2] ) ), $this->not()->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[0] ) ), $this->not()->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[1] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -206,13 +206,13 @@ function ( $id ) { * * Tests "postCodeIn" where arg */ - $variables = [ 'postCodeIn' => [ '123456', '23451' ] ]; + $variables = array( 'postCodeIn' => array( '123456', '23451' ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[1] ) ), $this->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[2] ) ), $this->not()->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[0] ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -220,7 +220,7 @@ function ( $id ) { public function testTaxIncludedOptionEffect() { // Create tax rate. $this->factory->tax_rate->create( - [ + array( 'country' => 'US', 'state' => '', 'rate' => 10, @@ -229,7 +229,7 @@ public function testTaxIncludedOptionEffect() { 'compound' => '0', 'shipping' => '1', 'class' => '', - ] + ) ); // Set customer address. @@ -242,10 +242,10 @@ public function testTaxIncludedOptionEffect() { // Create product to query. $product_id = $this->factory->product->createSimple( - [ + array( 'price' => 10, 'regular_price' => 10, - ] + ) ); $query = ' query( $id: ID! ) { @@ -257,7 +257,7 @@ public function testTaxIncludedOptionEffect() { } } '; - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); /** * Assertion One @@ -266,9 +266,9 @@ public function testTaxIncludedOptionEffect() { */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.price', '$10.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -287,9 +287,9 @@ public function testTaxIncludedOptionEffect() { $this->logData( \wc_prices_include_tax() ? 'included' : 'excluded' ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.price', '$11.00' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/TransferSessionHandlerTest.php b/tests/wpunit/TransferSessionHandlerTest.php index 380eb4e35..8ddb78491 100644 --- a/tests/wpunit/TransferSessionHandlerTest.php +++ b/tests/wpunit/TransferSessionHandlerTest.php @@ -23,7 +23,7 @@ public function tearDown(): void { // after parent::tearDown(); - $_REQUEST = []; + $_REQUEST = array(); } public function testInitSessionCookie() { diff --git a/tests/wpunit/UnsupportedProductTypeTest.php b/tests/wpunit/UnsupportedProductTypeTest.php index 700278c64..d4c92f91a 100644 --- a/tests/wpunit/UnsupportedProductTypeTest.php +++ b/tests/wpunit/UnsupportedProductTypeTest.php @@ -2,9 +2,9 @@ class UnsupportedProductTypeTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase { public function testUnsupportedProductTypeFailsWhenDisabled() { $product_id = $this->factory->product->createSimple( - [ + array( 'product_class' => '\WC_Product_Advanced', - ] + ) ); $query = ' @@ -15,11 +15,11 @@ public function testUnsupportedProductTypeFailsWhenDisabled() { } '; - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'post', static::IS_NULL ), - ]; + ); $this->assertQueryError( $response, $expected ); } @@ -27,11 +27,11 @@ public function testUnsupportedProductTypeFailsWhenDisabled() { public function testUnsupportedProductTypePassesWhenEnabled() { update_option( 'woographql_settings', - [ 'enable_unsupported_product_type' => 'on' ] + array( 'enable_unsupported_product_type' => 'on' ) ); $product_id = $this->factory->product->createSimple( - [ 'product_class' => '\WC_Product_Advanced' ] + array( 'product_class' => '\WC_Product_Advanced' ) ); $query = ' @@ -43,12 +43,12 @@ public function testUnsupportedProductTypePassesWhenEnabled() { } '; - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'product.type', 'UNSUPPORTED' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); @@ -62,10 +62,10 @@ public function testUnsupportedProductTypePassesWhenEnabled() { '; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'unsupportedProduct.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedField( 'unsupportedProduct.type', 'UNSUPPORTED' ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/VariationAttributeQueriesTest.php b/tests/wpunit/VariationAttributeQueriesTest.php index 62b04d2f6..51d1bdf3d 100644 --- a/tests/wpunit/VariationAttributeQueriesTest.php +++ b/tests/wpunit/VariationAttributeQueriesTest.php @@ -7,29 +7,29 @@ public function expectedAttributes( $id ) { ? $product->get_default_attributes() : $product->get_attributes(); - $expected = []; + $expected = array(); foreach ( $attributes as $name => $value ) { $term = \get_term_by( 'slug', $value, $name ); $expected_id = base64_encode( $id . '||' . $name . '||' . $value ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode if ( ! $term instanceof \WP_Term ) { $expected[] = $this->expectedNode( 'nodes', - [ + array( $this->expectedField( 'id', $expected_id ), $this->expectedField( 'attributeId', 0 ), $this->expectedField( 'name', $name ), $this->expectedField( 'value', $value ), - ] + ) ); } else { $expected[] = $this->expectedNode( 'nodes', - [ + array( $this->expectedField( 'id', $expected_id ), $this->expectedField( 'attributeId', $term->term_id ), $this->expectedField( 'name', $term->taxonomy ), $this->expectedField( 'value', $term->name ), - ] + ) ); } } @@ -41,20 +41,20 @@ public function expectedDefaultAttributes( $id ) { $product = wc_get_product( $id ); $attributes = $product->get_attributes(); - $expected = []; + $expected = array(); foreach ( $attributes as $attribute ) { $name = $attribute->get_name(); if ( $attribute->is_taxonomy() ) { - $attribute_values = wc_get_product_terms( $id, $attribute->get_name(), [ 'fields' => 'all' ] ); + $attribute_values = wc_get_product_terms( $id, $attribute->get_name(), array( 'fields' => 'all' ) ); foreach ( $attribute_values as $attribute_value ) { $expected[] = $this->expectedNode( 'nodes', - [ + array( $this->expectedField( 'id', base64_encode( $id . '|' . $name . '|' . $attribute_value->name ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $this->expectedField( 'attributeId', $attribute_value->term_id ), $this->expectedField( 'name', $name ), $this->expectedField( 'value', $attribute_value->name ), - ] + ) ); } } else { @@ -62,12 +62,12 @@ public function expectedDefaultAttributes( $id ) { foreach ( $values as $attribute_value ) { $expected[] = $this->expectedNode( 'nodes', - [ + array( $this->expectedField( 'id', base64_encode( $id . '|' . $name . '|' . $attribute_value ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $this->expectedField( 'attributeId', 0 ), $this->expectedField( 'name', $name ), $this->expectedField( 'value', $attribute_value ), - ] + ) ); } } @@ -103,12 +103,12 @@ public function testProductVariationToVariationAttributeQuery() { * * Test query and results */ - $variables = [ 'id' => $this->toRelayId( 'post', $variation_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $variation_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'productVariation.id', $this->toRelayId( 'post', $variation_id ) ), $this->expectedObject( 'productVariation.attributes', $this->expectedAttributes( $variation_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } @@ -142,27 +142,27 @@ public function testVariableProductToVariationAttributeQuery() { * * Test query and results */ - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedObject( 'product.defaultAttributes', $this->expectedAttributes( $product_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } public function testSimpleProductToVariationAttributeQuery() { // Create a product w/ default attributes. - $attribute_data = [ - $this->factory->product->createAttribute( 'size', [ 'small' ] ), - $this->factory->product->createAttribute( 'color', [ 'red' ] ), - [ + $attribute_data = array( + $this->factory->product->createAttribute( 'size', array( 'small' ) ), + $this->factory->product->createAttribute( 'color', array( 'red' ) ), + array( 'attribute_id' => 0, 'attribute_taxonomy' => 'logo', - 'term_ids' => [ 'Yes' ], - ], - ]; + 'term_ids' => array( 'Yes' ), + ), + ); $attributes = array_map( static function ( $data, $index ) { $attribute = new \WC_Product_Attribute(); @@ -178,14 +178,14 @@ static function ( $data, $index ) { array_keys( $attribute_data ) ); $product_id = $this->factory->product->createSimple( - [ + array( 'attributes' => $attributes, - 'default_attributes' => [ + 'default_attributes' => array( 'pa_size' => 'small', 'pa_color' => 'red', 'logo' => 'Yes', - ], - ] + ), + ) ); // Create a query. @@ -212,12 +212,12 @@ static function ( $data, $index ) { * * Test query and results */ - $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ]; + $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = [ + $expected = array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ), $this->expectedObject( 'product.defaultAttributes', $this->expectedDefaultAttributes( $product_id ) ), - ]; + ); $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/bootstrap.php b/tests/wpunit/bootstrap.php index 3bf063e42..f0dcb46fa 100644 --- a/tests/wpunit/bootstrap.php +++ b/tests/wpunit/bootstrap.php @@ -79,5 +79,5 @@ function initialize_hpos() { if ( defined( 'HPOS' ) ) { \codecept_debug( 'HPOS activated!!!' ); - //add_action( 'woocommerce_init', 'initialize_hpos' ); + // add_action( 'woocommerce_init', 'initialize_hpos' ); } diff --git a/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php b/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php index 110dbc845..7912e8a0a 100644 --- a/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php +++ b/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php @@ -8,17 +8,15 @@ namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT; -class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface -{ - private object $payload; +class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface { - public function setPayload(object $payload): void - { - $this->payload = $payload; - } + private object $payload; - public function getPayload(): object - { - return $this->payload; - } + public function setPayload( object $payload ): void { + $this->payload = $payload; + } + + public function getPayload(): object { + return $this->payload; + } } diff --git a/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php b/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php index c2a2f0e5a..c471c4544 100644 --- a/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php +++ b/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php @@ -22,259 +22,256 @@ /** * @implements ArrayAccess */ -class CachedKeySet implements ArrayAccess -{ - /** - * @var string - */ - private $jwksUri; - /** - * @var ClientInterface - */ - private $httpClient; - /** - * @var RequestFactoryInterface - */ - private $httpFactory; - /** - * @var CacheItemPoolInterface - */ - private $cache; - /** - * @var ?int - */ - private $expiresAfter; - /** - * @var ?CacheItemInterface - */ - private $cacheItem; - /** - * @var array> - */ - private $keySet; - /** - * @var string - */ - private $cacheKey; - /** - * @var string - */ - private $cacheKeyPrefix = 'jwks'; - /** - * @var int - */ - private $maxKeyLength = 64; - /** - * @var bool - */ - private $rateLimit; - /** - * @var string - */ - private $rateLimitCacheKey; - /** - * @var int - */ - private $maxCallsPerMinute = 10; - /** - * @var string|null - */ - private $defaultAlg; - - public function __construct( - string $jwksUri, - ClientInterface $httpClient, - RequestFactoryInterface $httpFactory, - CacheItemPoolInterface $cache, - ?int $expiresAfter = null, - bool $rateLimit = false, - ?string $defaultAlg = null - ) { - $this->jwksUri = $jwksUri; - $this->httpClient = $httpClient; - $this->httpFactory = $httpFactory; - $this->cache = $cache; - $this->expiresAfter = $expiresAfter; - $this->rateLimit = $rateLimit; - $this->defaultAlg = $defaultAlg; - $this->setCacheKeys(); - } - - /** - * @param string $keyId - * @return Key - */ - public function offsetGet($keyId): Key - { - if (!$this->keyIdExists($keyId)) { - throw new OutOfBoundsException('Key ID not found'); - } - return JWK::parseKey($this->keySet[$keyId], $this->defaultAlg); - } - - /** - * @param string $keyId - * @return bool - */ - public function offsetExists($keyId): bool - { - return $this->keyIdExists($keyId); - } - - /** - * @param string $offset - * @param Key $value - */ - public function offsetSet($offset, $value): void - { - throw new LogicException('Method not implemented'); - } - - /** - * @param string $offset - */ - public function offsetUnset($offset): void - { - throw new LogicException('Method not implemented'); - } - - /** - * @return array - */ - private function formatJwksForCache(string $jwks): array - { - $jwks = json_decode($jwks, true); - - if (!isset($jwks['keys'])) { - throw new UnexpectedValueException('"keys" member must exist in the JWK Set'); - } - - if (empty($jwks['keys'])) { - throw new InvalidArgumentException('JWK Set did not contain any keys'); - } - - $keys = []; - foreach ($jwks['keys'] as $k => $v) { - $kid = isset($v['kid']) ? $v['kid'] : $k; - $keys[(string) $kid] = $v; - } - - return $keys; - } - - private function keyIdExists(string $keyId): bool - { - if (null === $this->keySet) { - $item = $this->getCacheItem(); - // Try to load keys from cache - if ($item->isHit()) { - // item found! retrieve it - $this->keySet = $item->get(); - // If the cached item is a string, the JWKS response was cached (previous behavior). - // Parse this into expected format array instead. - if (\is_string($this->keySet)) { - $this->keySet = $this->formatJwksForCache($this->keySet); - } - } - } - - if (!isset($this->keySet[$keyId])) { - if ($this->rateLimitExceeded()) { - return false; - } - $request = $this->httpFactory->createRequest('GET', $this->jwksUri); - $jwksResponse = $this->httpClient->sendRequest($request); - if ($jwksResponse->getStatusCode() !== 200) { - throw new UnexpectedValueException( - \sprintf('HTTP Error: %d %s for URI "%s"', - $jwksResponse->getStatusCode(), - $jwksResponse->getReasonPhrase(), - $this->jwksUri, - ), - $jwksResponse->getStatusCode() - ); - } - $this->keySet = $this->formatJwksForCache((string) $jwksResponse->getBody()); - - if (!isset($this->keySet[$keyId])) { - return false; - } - - $item = $this->getCacheItem(); - $item->set($this->keySet); - if ($this->expiresAfter) { - $item->expiresAfter($this->expiresAfter); - } - $this->cache->save($item); - } - - return true; - } - - private function rateLimitExceeded(): bool - { - if (!$this->rateLimit) { - return false; - } - - $cacheItem = $this->cache->getItem($this->rateLimitCacheKey); - - $cacheItemData = []; - if ($cacheItem->isHit() && \is_array($data = $cacheItem->get())) { - $cacheItemData = $data; - } - - $callsPerMinute = $cacheItemData['callsPerMinute'] ?? 0; - $expiry = $cacheItemData['expiry'] ?? new \DateTime('+60 seconds', new \DateTimeZone('UTC')); - - if (++$callsPerMinute > $this->maxCallsPerMinute) { - return true; - } - - $cacheItem->set(['expiry' => $expiry, 'callsPerMinute' => $callsPerMinute]); - $cacheItem->expiresAt($expiry); - $this->cache->save($cacheItem); - return false; - } - - private function getCacheItem(): CacheItemInterface - { - if (\is_null($this->cacheItem)) { - $this->cacheItem = $this->cache->getItem($this->cacheKey); - } - - return $this->cacheItem; - } - - private function setCacheKeys(): void - { - if (empty($this->jwksUri)) { - throw new RuntimeException('JWKS URI is empty'); - } - - // ensure we do not have illegal characters - $key = preg_replace('|[^a-zA-Z0-9_\.!]|', '', $this->jwksUri); - - // add prefix - $key = $this->cacheKeyPrefix . $key; - - // Hash keys if they exceed $maxKeyLength of 64 - if (\strlen($key) > $this->maxKeyLength) { - $key = substr(hash('sha256', $key), 0, $this->maxKeyLength); - } - - $this->cacheKey = $key; - - if ($this->rateLimit) { - // add prefix - $rateLimitKey = $this->cacheKeyPrefix . 'ratelimit' . $key; - - // Hash keys if they exceed $maxKeyLength of 64 - if (\strlen($rateLimitKey) > $this->maxKeyLength) { - $rateLimitKey = substr(hash('sha256', $rateLimitKey), 0, $this->maxKeyLength); - } - - $this->rateLimitCacheKey = $rateLimitKey; - } - } +class CachedKeySet implements ArrayAccess { + + /** + * @var string + */ + private $jwksUri; + /** + * @var ClientInterface + */ + private $httpClient; + /** + * @var RequestFactoryInterface + */ + private $httpFactory; + /** + * @var CacheItemPoolInterface + */ + private $cache; + /** + * @var ?int + */ + private $expiresAfter; + /** + * @var ?CacheItemInterface + */ + private $cacheItem; + /** + * @var array> + */ + private $keySet; + /** + * @var string + */ + private $cacheKey; + /** + * @var string + */ + private $cacheKeyPrefix = 'jwks'; + /** + * @var int + */ + private $maxKeyLength = 64; + /** + * @var bool + */ + private $rateLimit; + /** + * @var string + */ + private $rateLimitCacheKey; + /** + * @var int + */ + private $maxCallsPerMinute = 10; + /** + * @var string|null + */ + private $defaultAlg; + + public function __construct( + string $jwksUri, + ClientInterface $httpClient, + RequestFactoryInterface $httpFactory, + CacheItemPoolInterface $cache, + ?int $expiresAfter = null, + bool $rateLimit = false, + ?string $defaultAlg = null + ) { + $this->jwksUri = $jwksUri; + $this->httpClient = $httpClient; + $this->httpFactory = $httpFactory; + $this->cache = $cache; + $this->expiresAfter = $expiresAfter; + $this->rateLimit = $rateLimit; + $this->defaultAlg = $defaultAlg; + $this->setCacheKeys(); + } + + /** + * @param string $keyId + * @return Key + */ + public function offsetGet( $keyId ): Key { + if ( ! $this->keyIdExists( $keyId ) ) { + throw new OutOfBoundsException( 'Key ID not found' ); + } + return JWK::parseKey( $this->keySet[ $keyId ], $this->defaultAlg ); + } + + /** + * @param string $keyId + * @return bool + */ + public function offsetExists( $keyId ): bool { + return $this->keyIdExists( $keyId ); + } + + /** + * @param string $offset + * @param Key $value + */ + public function offsetSet( $offset, $value ): void { + throw new LogicException( 'Method not implemented' ); + } + + /** + * @param string $offset + */ + public function offsetUnset( $offset ): void { + throw new LogicException( 'Method not implemented' ); + } + + /** + * @return array + */ + private function formatJwksForCache( string $jwks ): array { + $jwks = json_decode( $jwks, true ); + + if ( ! isset( $jwks['keys'] ) ) { + throw new UnexpectedValueException( '"keys" member must exist in the JWK Set' ); + } + + if ( empty( $jwks['keys'] ) ) { + throw new InvalidArgumentException( 'JWK Set did not contain any keys' ); + } + + $keys = array(); + foreach ( $jwks['keys'] as $k => $v ) { + $kid = isset( $v['kid'] ) ? $v['kid'] : $k; + $keys[ (string) $kid ] = $v; + } + + return $keys; + } + + private function keyIdExists( string $keyId ): bool { + if ( null === $this->keySet ) { + $item = $this->getCacheItem(); + // Try to load keys from cache + if ( $item->isHit() ) { + // item found! retrieve it + $this->keySet = $item->get(); + // If the cached item is a string, the JWKS response was cached (previous behavior). + // Parse this into expected format array instead. + if ( \is_string( $this->keySet ) ) { + $this->keySet = $this->formatJwksForCache( $this->keySet ); + } + } + } + + if ( ! isset( $this->keySet[ $keyId ] ) ) { + if ( $this->rateLimitExceeded() ) { + return false; + } + $request = $this->httpFactory->createRequest( 'GET', $this->jwksUri ); + $jwksResponse = $this->httpClient->sendRequest( $request ); + if ( $jwksResponse->getStatusCode() !== 200 ) { + throw new UnexpectedValueException( + \sprintf( + 'HTTP Error: %d %s for URI "%s"', + $jwksResponse->getStatusCode(), + $jwksResponse->getReasonPhrase(), + $this->jwksUri, + ), + $jwksResponse->getStatusCode() + ); + } + $this->keySet = $this->formatJwksForCache( (string) $jwksResponse->getBody() ); + + if ( ! isset( $this->keySet[ $keyId ] ) ) { + return false; + } + + $item = $this->getCacheItem(); + $item->set( $this->keySet ); + if ( $this->expiresAfter ) { + $item->expiresAfter( $this->expiresAfter ); + } + $this->cache->save( $item ); + } + + return true; + } + + private function rateLimitExceeded(): bool { + if ( ! $this->rateLimit ) { + return false; + } + + $cacheItem = $this->cache->getItem( $this->rateLimitCacheKey ); + + $cacheItemData = array(); + if ( $cacheItem->isHit() && \is_array( $data = $cacheItem->get() ) ) { + $cacheItemData = $data; + } + + $callsPerMinute = $cacheItemData['callsPerMinute'] ?? 0; + $expiry = $cacheItemData['expiry'] ?? new \DateTime( '+60 seconds', new \DateTimeZone( 'UTC' ) ); + + if ( ++$callsPerMinute > $this->maxCallsPerMinute ) { + return true; + } + + $cacheItem->set( + array( + 'expiry' => $expiry, + 'callsPerMinute' => $callsPerMinute, + ) + ); + $cacheItem->expiresAt( $expiry ); + $this->cache->save( $cacheItem ); + return false; + } + + private function getCacheItem(): CacheItemInterface { + if ( \is_null( $this->cacheItem ) ) { + $this->cacheItem = $this->cache->getItem( $this->cacheKey ); + } + + return $this->cacheItem; + } + + private function setCacheKeys(): void { + if ( empty( $this->jwksUri ) ) { + throw new RuntimeException( 'JWKS URI is empty' ); + } + + // ensure we do not have illegal characters + $key = preg_replace( '|[^a-zA-Z0-9_\.!]|', '', $this->jwksUri ); + + // add prefix + $key = $this->cacheKeyPrefix . $key; + + // Hash keys if they exceed $maxKeyLength of 64 + if ( \strlen( $key ) > $this->maxKeyLength ) { + $key = substr( hash( 'sha256', $key ), 0, $this->maxKeyLength ); + } + + $this->cacheKey = $key; + + if ( $this->rateLimit ) { + // add prefix + $rateLimitKey = $this->cacheKeyPrefix . 'ratelimit' . $key; + + // Hash keys if they exceed $maxKeyLength of 64 + if ( \strlen( $rateLimitKey ) > $this->maxKeyLength ) { + $rateLimitKey = substr( hash( 'sha256', $rateLimitKey ), 0, $this->maxKeyLength ); + } + + $this->rateLimitCacheKey = $rateLimitKey; + } + } } diff --git a/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php b/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php index aad64d76a..f2e43d1b1 100644 --- a/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php +++ b/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php @@ -8,17 +8,15 @@ namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT; -class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface -{ - private object $payload; +class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface { - public function setPayload(object $payload): void - { - $this->payload = $payload; - } + private object $payload; - public function getPayload(): object - { - return $this->payload; - } + public function setPayload( object $payload ): void { + $this->payload = $payload; + } + + public function getPayload(): object { + return $this->payload; + } } diff --git a/vendor-prefixed/firebase/php-jwt/src/JWK.php b/vendor-prefixed/firebase/php-jwt/src/JWK.php index c6674c428..9d5beb3ac 100644 --- a/vendor-prefixed/firebase/php-jwt/src/JWK.php +++ b/vendor-prefixed/firebase/php-jwt/src/JWK.php @@ -24,338 +24,332 @@ * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD * @link https://github.com/firebase/php-jwt */ -class JWK -{ - private const OID = '1.2.840.10045.2.1'; - private const ASN1_OBJECT_IDENTIFIER = 0x06; - private const ASN1_SEQUENCE = 0x10; // also defined in JWT - private const ASN1_BIT_STRING = 0x03; - private const EC_CURVES = [ - 'P-256' => '1.2.840.10045.3.1.7', // Len: 64 - 'secp256k1' => '1.3.132.0.10', // Len: 64 - 'P-384' => '1.3.132.0.34', // Len: 96 - // 'P-521' => '1.3.132.0.35', // Len: 132 (not supported) - ]; - - // For keys with "kty" equal to "OKP" (Octet Key Pair), the "crv" parameter must contain the key subtype. - // This library supports the following subtypes: - private const OKP_SUBTYPES = [ - 'Ed25519' => true, // RFC 8037 - ]; - - /** - * Parse a set of JWK keys - * - * @param array $jwks The JSON Web Key Set as an associative array - * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the - * JSON Web Key Set - * - * @return array An associative array of key IDs (kid) to Key objects - * - * @throws InvalidArgumentException Provided JWK Set is empty - * @throws UnexpectedValueException Provided JWK Set was invalid - * @throws DomainException OpenSSL failure - * - * @uses parseKey - */ - public static function parseKeySet(array $jwks, ?string $defaultAlg = null): array - { - $keys = []; - - if (!isset($jwks['keys'])) { - throw new UnexpectedValueException('"keys" member must exist in the JWK Set'); - } - - if (empty($jwks['keys'])) { - throw new InvalidArgumentException('JWK Set did not contain any keys'); - } - - foreach ($jwks['keys'] as $k => $v) { - $kid = isset($v['kid']) ? $v['kid'] : $k; - if ($key = self::parseKey($v, $defaultAlg)) { - $keys[(string) $kid] = $key; - } - } - - if (0 === \count($keys)) { - throw new UnexpectedValueException('No supported algorithms found in JWK Set'); - } - - return $keys; - } - - /** - * Parse a JWK key - * - * @param array $jwk An individual JWK - * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the - * JSON Web Key Set - * - * @return Key The key object for the JWK - * - * @throws InvalidArgumentException Provided JWK is empty - * @throws UnexpectedValueException Provided JWK was invalid - * @throws DomainException OpenSSL failure - * - * @uses createPemFromModulusAndExponent - */ - public static function parseKey(array $jwk, ?string $defaultAlg = null): ?Key - { - if (empty($jwk)) { - throw new InvalidArgumentException('JWK must not be empty'); - } - - if (!isset($jwk['kty'])) { - throw new UnexpectedValueException('JWK must contain a "kty" parameter'); - } - - if (!isset($jwk['alg'])) { - if (\is_null($defaultAlg)) { - // The "alg" parameter is optional in a KTY, but an algorithm is required - // for parsing in this library. Use the $defaultAlg parameter when parsing the - // key set in order to prevent this error. - // @see https://datatracker.ietf.org/doc/html/rfc7517#section-4.4 - throw new UnexpectedValueException('JWK must contain an "alg" parameter'); - } - $jwk['alg'] = $defaultAlg; - } - - switch ($jwk['kty']) { - case 'RSA': - if (!empty($jwk['d'])) { - throw new UnexpectedValueException('RSA private keys are not supported'); - } - if (!isset($jwk['n']) || !isset($jwk['e'])) { - throw new UnexpectedValueException('RSA keys must contain values for both "n" and "e"'); - } - - $pem = self::createPemFromModulusAndExponent($jwk['n'], $jwk['e']); - $publicKey = \openssl_pkey_get_public($pem); - if (false === $publicKey) { - throw new DomainException( - 'OpenSSL error: ' . \openssl_error_string() - ); - } - return new Key($publicKey, $jwk['alg']); - case 'EC': - if (isset($jwk['d'])) { - // The key is actually a private key - throw new UnexpectedValueException('Key data must be for a public key'); - } - - if (empty($jwk['crv'])) { - throw new UnexpectedValueException('crv not set'); - } - - if (!isset(self::EC_CURVES[$jwk['crv']])) { - throw new DomainException('Unrecognised or unsupported EC curve'); - } - - if (empty($jwk['x']) || empty($jwk['y'])) { - throw new UnexpectedValueException('x and y not set'); - } - - $publicKey = self::createPemFromCrvAndXYCoordinates($jwk['crv'], $jwk['x'], $jwk['y']); - return new Key($publicKey, $jwk['alg']); - case 'OKP': - if (isset($jwk['d'])) { - // The key is actually a private key - throw new UnexpectedValueException('Key data must be for a public key'); - } - - if (!isset($jwk['crv'])) { - throw new UnexpectedValueException('crv not set'); - } - - if (empty(self::OKP_SUBTYPES[$jwk['crv']])) { - throw new DomainException('Unrecognised or unsupported OKP key subtype'); - } - - if (empty($jwk['x'])) { - throw new UnexpectedValueException('x not set'); - } - - // This library works internally with EdDSA keys (Ed25519) encoded in standard base64. - $publicKey = JWT::convertBase64urlToBase64($jwk['x']); - return new Key($publicKey, $jwk['alg']); - case 'oct': - if (!isset($jwk['k'])) { - throw new UnexpectedValueException('k not set'); - } - - return new Key(JWT::urlsafeB64Decode($jwk['k']), $jwk['alg']); - default: - break; - } - - return null; - } - - /** - * Converts the EC JWK values to pem format. - * - * @param string $crv The EC curve (only P-256 & P-384 is supported) - * @param string $x The EC x-coordinate - * @param string $y The EC y-coordinate - * - * @return string - */ - private static function createPemFromCrvAndXYCoordinates(string $crv, string $x, string $y): string - { - $pem = - self::encodeDER( - self::ASN1_SEQUENCE, - self::encodeDER( - self::ASN1_SEQUENCE, - self::encodeDER( - self::ASN1_OBJECT_IDENTIFIER, - self::encodeOID(self::OID) - ) - . self::encodeDER( - self::ASN1_OBJECT_IDENTIFIER, - self::encodeOID(self::EC_CURVES[$crv]) - ) - ) . - self::encodeDER( - self::ASN1_BIT_STRING, - \chr(0x00) . \chr(0x04) - . JWT::urlsafeB64Decode($x) - . JWT::urlsafeB64Decode($y) - ) - ); - - return \sprintf( - "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", - wordwrap(base64_encode($pem), 64, "\n", true) - ); - } - - /** - * Create a public key represented in PEM format from RSA modulus and exponent information - * - * @param string $n The RSA modulus encoded in Base64 - * @param string $e The RSA exponent encoded in Base64 - * - * @return string The RSA public key represented in PEM format - * - * @uses encodeLength - */ - private static function createPemFromModulusAndExponent( - string $n, - string $e - ): string { - $mod = JWT::urlsafeB64Decode($n); - $exp = JWT::urlsafeB64Decode($e); - - $modulus = \pack('Ca*a*', 2, self::encodeLength(\strlen($mod)), $mod); - $publicExponent = \pack('Ca*a*', 2, self::encodeLength(\strlen($exp)), $exp); - - $rsaPublicKey = \pack( - 'Ca*a*a*', - 48, - self::encodeLength(\strlen($modulus) + \strlen($publicExponent)), - $modulus, - $publicExponent - ); - - // sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption. - $rsaOID = \pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA - $rsaPublicKey = \chr(0) . $rsaPublicKey; - $rsaPublicKey = \chr(3) . self::encodeLength(\strlen($rsaPublicKey)) . $rsaPublicKey; - - $rsaPublicKey = \pack( - 'Ca*a*', - 48, - self::encodeLength(\strlen($rsaOID . $rsaPublicKey)), - $rsaOID . $rsaPublicKey - ); - - return "-----BEGIN PUBLIC KEY-----\r\n" . - \chunk_split(\base64_encode($rsaPublicKey), 64) . - '-----END PUBLIC KEY-----'; - } - - /** - * DER-encode the length - * - * DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See - * {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information. - * - * @param int $length - * @return string - */ - private static function encodeLength(int $length): string - { - if ($length <= 0x7F) { - return \chr($length); - } - - $temp = \ltrim(\pack('N', $length), \chr(0)); - - return \pack('Ca*', 0x80 | \strlen($temp), $temp); - } - - /** - * Encodes a value into a DER object. - * Also defined in Firebase\JWT\JWT - * - * @param int $type DER tag - * @param string $value the value to encode - * @return string the encoded object - */ - private static function encodeDER(int $type, string $value): string - { - $tag_header = 0; - if ($type === self::ASN1_SEQUENCE) { - $tag_header |= 0x20; - } - - // Type - $der = \chr($tag_header | $type); - - // Length - $der .= \chr(\strlen($value)); - - return $der . $value; - } - - /** - * Encodes a string into a DER-encoded OID. - * - * @param string $oid the OID string - * @return string the binary DER-encoded OID - */ - private static function encodeOID(string $oid): string - { - $octets = explode('.', $oid); - - // Get the first octet - $first = (int) array_shift($octets); - $second = (int) array_shift($octets); - $oid = \chr($first * 40 + $second); - - // Iterate over subsequent octets - foreach ($octets as $octet) { - if ($octet == 0) { - $oid .= \chr(0x00); - continue; - } - $bin = ''; - - while ($octet) { - $bin .= \chr(0x80 | ($octet & 0x7f)); - $octet >>= 7; - } - $bin[0] = $bin[0] & \chr(0x7f); - - // Convert to big endian if necessary - if (pack('V', 65534) == pack('L', 65534)) { - $oid .= strrev($bin); - } else { - $oid .= $bin; - } - } - - return $oid; - } +class JWK { + + private const OID = '1.2.840.10045.2.1'; + private const ASN1_OBJECT_IDENTIFIER = 0x06; + private const ASN1_SEQUENCE = 0x10; // also defined in JWT + private const ASN1_BIT_STRING = 0x03; + private const EC_CURVES = array( + 'P-256' => '1.2.840.10045.3.1.7', // Len: 64 + 'secp256k1' => '1.3.132.0.10', // Len: 64 + 'P-384' => '1.3.132.0.34', // Len: 96 + // 'P-521' => '1.3.132.0.35', // Len: 132 (not supported) + ); + + // For keys with "kty" equal to "OKP" (Octet Key Pair), the "crv" parameter must contain the key subtype. + // This library supports the following subtypes: + private const OKP_SUBTYPES = array( + 'Ed25519' => true, // RFC 8037 + ); + + /** + * Parse a set of JWK keys + * + * @param array $jwks The JSON Web Key Set as an associative array + * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the + * JSON Web Key Set + * + * @return array An associative array of key IDs (kid) to Key objects + * + * @throws InvalidArgumentException Provided JWK Set is empty + * @throws UnexpectedValueException Provided JWK Set was invalid + * @throws DomainException OpenSSL failure + * + * @uses parseKey + */ + public static function parseKeySet( array $jwks, ?string $defaultAlg = null ): array { + $keys = array(); + + if ( ! isset( $jwks['keys'] ) ) { + throw new UnexpectedValueException( '"keys" member must exist in the JWK Set' ); + } + + if ( empty( $jwks['keys'] ) ) { + throw new InvalidArgumentException( 'JWK Set did not contain any keys' ); + } + + foreach ( $jwks['keys'] as $k => $v ) { + $kid = isset( $v['kid'] ) ? $v['kid'] : $k; + if ( $key = self::parseKey( $v, $defaultAlg ) ) { + $keys[ (string) $kid ] = $key; + } + } + + if ( 0 === \count( $keys ) ) { + throw new UnexpectedValueException( 'No supported algorithms found in JWK Set' ); + } + + return $keys; + } + + /** + * Parse a JWK key + * + * @param array $jwk An individual JWK + * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the + * JSON Web Key Set + * + * @return Key The key object for the JWK + * + * @throws InvalidArgumentException Provided JWK is empty + * @throws UnexpectedValueException Provided JWK was invalid + * @throws DomainException OpenSSL failure + * + * @uses createPemFromModulusAndExponent + */ + public static function parseKey( array $jwk, ?string $defaultAlg = null ): ?Key { + if ( empty( $jwk ) ) { + throw new InvalidArgumentException( 'JWK must not be empty' ); + } + + if ( ! isset( $jwk['kty'] ) ) { + throw new UnexpectedValueException( 'JWK must contain a "kty" parameter' ); + } + + if ( ! isset( $jwk['alg'] ) ) { + if ( \is_null( $defaultAlg ) ) { + // The "alg" parameter is optional in a KTY, but an algorithm is required + // for parsing in this library. Use the $defaultAlg parameter when parsing the + // key set in order to prevent this error. + // @see https://datatracker.ietf.org/doc/html/rfc7517#section-4.4 + throw new UnexpectedValueException( 'JWK must contain an "alg" parameter' ); + } + $jwk['alg'] = $defaultAlg; + } + + switch ( $jwk['kty'] ) { + case 'RSA': + if ( ! empty( $jwk['d'] ) ) { + throw new UnexpectedValueException( 'RSA private keys are not supported' ); + } + if ( ! isset( $jwk['n'] ) || ! isset( $jwk['e'] ) ) { + throw new UnexpectedValueException( 'RSA keys must contain values for both "n" and "e"' ); + } + + $pem = self::createPemFromModulusAndExponent( $jwk['n'], $jwk['e'] ); + $publicKey = \openssl_pkey_get_public( $pem ); + if ( false === $publicKey ) { + throw new DomainException( + 'OpenSSL error: ' . \openssl_error_string() + ); + } + return new Key( $publicKey, $jwk['alg'] ); + case 'EC': + if ( isset( $jwk['d'] ) ) { + // The key is actually a private key + throw new UnexpectedValueException( 'Key data must be for a public key' ); + } + + if ( empty( $jwk['crv'] ) ) { + throw new UnexpectedValueException( 'crv not set' ); + } + + if ( ! isset( self::EC_CURVES[ $jwk['crv'] ] ) ) { + throw new DomainException( 'Unrecognised or unsupported EC curve' ); + } + + if ( empty( $jwk['x'] ) || empty( $jwk['y'] ) ) { + throw new UnexpectedValueException( 'x and y not set' ); + } + + $publicKey = self::createPemFromCrvAndXYCoordinates( $jwk['crv'], $jwk['x'], $jwk['y'] ); + return new Key( $publicKey, $jwk['alg'] ); + case 'OKP': + if ( isset( $jwk['d'] ) ) { + // The key is actually a private key + throw new UnexpectedValueException( 'Key data must be for a public key' ); + } + + if ( ! isset( $jwk['crv'] ) ) { + throw new UnexpectedValueException( 'crv not set' ); + } + + if ( empty( self::OKP_SUBTYPES[ $jwk['crv'] ] ) ) { + throw new DomainException( 'Unrecognised or unsupported OKP key subtype' ); + } + + if ( empty( $jwk['x'] ) ) { + throw new UnexpectedValueException( 'x not set' ); + } + + // This library works internally with EdDSA keys (Ed25519) encoded in standard base64. + $publicKey = JWT::convertBase64urlToBase64( $jwk['x'] ); + return new Key( $publicKey, $jwk['alg'] ); + case 'oct': + if ( ! isset( $jwk['k'] ) ) { + throw new UnexpectedValueException( 'k not set' ); + } + + return new Key( JWT::urlsafeB64Decode( $jwk['k'] ), $jwk['alg'] ); + default: + break; + } + + return null; + } + + /** + * Converts the EC JWK values to pem format. + * + * @param string $crv The EC curve (only P-256 & P-384 is supported) + * @param string $x The EC x-coordinate + * @param string $y The EC y-coordinate + * + * @return string + */ + private static function createPemFromCrvAndXYCoordinates( string $crv, string $x, string $y ): string { + $pem = + self::encodeDER( + self::ASN1_SEQUENCE, + self::encodeDER( + self::ASN1_SEQUENCE, + self::encodeDER( + self::ASN1_OBJECT_IDENTIFIER, + self::encodeOID( self::OID ) + ) + . self::encodeDER( + self::ASN1_OBJECT_IDENTIFIER, + self::encodeOID( self::EC_CURVES[ $crv ] ) + ) + ) . + self::encodeDER( + self::ASN1_BIT_STRING, + \chr( 0x00 ) . \chr( 0x04 ) + . JWT::urlsafeB64Decode( $x ) + . JWT::urlsafeB64Decode( $y ) + ) + ); + + return \sprintf( + "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", + wordwrap( base64_encode( $pem ), 64, "\n", true ) + ); + } + + /** + * Create a public key represented in PEM format from RSA modulus and exponent information + * + * @param string $n The RSA modulus encoded in Base64 + * @param string $e The RSA exponent encoded in Base64 + * + * @return string The RSA public key represented in PEM format + * + * @uses encodeLength + */ + private static function createPemFromModulusAndExponent( + string $n, + string $e + ): string { + $mod = JWT::urlsafeB64Decode( $n ); + $exp = JWT::urlsafeB64Decode( $e ); + + $modulus = \pack( 'Ca*a*', 2, self::encodeLength( \strlen( $mod ) ), $mod ); + $publicExponent = \pack( 'Ca*a*', 2, self::encodeLength( \strlen( $exp ) ), $exp ); + + $rsaPublicKey = \pack( + 'Ca*a*a*', + 48, + self::encodeLength( \strlen( $modulus ) + \strlen( $publicExponent ) ), + $modulus, + $publicExponent + ); + + // sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption. + $rsaOID = \pack( 'H*', '300d06092a864886f70d0101010500' ); // hex version of MA0GCSqGSIb3DQEBAQUA + $rsaPublicKey = \chr( 0 ) . $rsaPublicKey; + $rsaPublicKey = \chr( 3 ) . self::encodeLength( \strlen( $rsaPublicKey ) ) . $rsaPublicKey; + + $rsaPublicKey = \pack( + 'Ca*a*', + 48, + self::encodeLength( \strlen( $rsaOID . $rsaPublicKey ) ), + $rsaOID . $rsaPublicKey + ); + + return "-----BEGIN PUBLIC KEY-----\r\n" . + \chunk_split( \base64_encode( $rsaPublicKey ), 64 ) . + '-----END PUBLIC KEY-----'; + } + + /** + * DER-encode the length + * + * DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See + * {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information. + * + * @param int $length + * @return string + */ + private static function encodeLength( int $length ): string { + if ( $length <= 0x7F ) { + return \chr( $length ); + } + + $temp = \ltrim( \pack( 'N', $length ), \chr( 0 ) ); + + return \pack( 'Ca*', 0x80 | \strlen( $temp ), $temp ); + } + + /** + * Encodes a value into a DER object. + * Also defined in Firebase\JWT\JWT + * + * @param int $type DER tag + * @param string $value the value to encode + * @return string the encoded object + */ + private static function encodeDER( int $type, string $value ): string { + $tag_header = 0; + if ( $type === self::ASN1_SEQUENCE ) { + $tag_header |= 0x20; + } + + // Type + $der = \chr( $tag_header | $type ); + + // Length + $der .= \chr( \strlen( $value ) ); + + return $der . $value; + } + + /** + * Encodes a string into a DER-encoded OID. + * + * @param string $oid the OID string + * @return string the binary DER-encoded OID + */ + private static function encodeOID( string $oid ): string { + $octets = explode( '.', $oid ); + + // Get the first octet + $first = (int) array_shift( $octets ); + $second = (int) array_shift( $octets ); + $oid = \chr( $first * 40 + $second ); + + // Iterate over subsequent octets + foreach ( $octets as $octet ) { + if ( $octet == 0 ) { + $oid .= \chr( 0x00 ); + continue; + } + $bin = ''; + + while ( $octet ) { + $bin .= \chr( 0x80 | ( $octet & 0x7f ) ); + $octet >>= 7; + } + $bin[0] = $bin[0] & \chr( 0x7f ); + + // Convert to big endian if necessary + if ( pack( 'V', 65534 ) == pack( 'L', 65534 ) ) { + $oid .= strrev( $bin ); + } else { + $oid .= $bin; + } + } + + return $oid; + } } diff --git a/vendor-prefixed/firebase/php-jwt/src/JWT.php b/vendor-prefixed/firebase/php-jwt/src/JWT.php index fd868c0c1..17a144ed6 100644 --- a/vendor-prefixed/firebase/php-jwt/src/JWT.php +++ b/vendor-prefixed/firebase/php-jwt/src/JWT.php @@ -31,643 +31,631 @@ * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD * @link https://github.com/firebase/php-jwt */ -class JWT -{ - private const ASN1_INTEGER = 0x02; - private const ASN1_SEQUENCE = 0x10; - private const ASN1_BIT_STRING = 0x03; - - /** - * When checking nbf, iat or expiration times, - * we want to provide some extra leeway time to - * account for clock skew. - * - * @var int - */ - public static $leeway = 0; - - /** - * Allow the current timestamp to be specified. - * Useful for fixing a value within unit testing. - * Will default to PHP time() value if null. - * - * @var ?int - */ - public static $timestamp = null; - - /** - * @var array - */ - public static $supported_algs = [ - 'ES384' => ['openssl', 'SHA384'], - 'ES256' => ['openssl', 'SHA256'], - 'ES256K' => ['openssl', 'SHA256'], - 'HS256' => ['hash_hmac', 'SHA256'], - 'HS384' => ['hash_hmac', 'SHA384'], - 'HS512' => ['hash_hmac', 'SHA512'], - 'RS256' => ['openssl', 'SHA256'], - 'RS384' => ['openssl', 'SHA384'], - 'RS512' => ['openssl', 'SHA512'], - 'EdDSA' => ['sodium_crypto', 'EdDSA'], - ]; - - /** - * Decodes a JWT string into a PHP object. - * - * @param string $jwt The JWT - * @param Key|ArrayAccess|array $keyOrKeyArray The Key or associative array of key IDs - * (kid) to Key objects. - * If the algorithm used is asymmetric, this is - * the public key. - * Each Key object contains an algorithm and - * matching key. - * Supported algorithms are 'ES384','ES256', - * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384' - * and 'RS512'. - * @param stdClass $headers Optional. Populates stdClass with headers. - * - * @return stdClass The JWT's payload as a PHP object - * - * @throws InvalidArgumentException Provided key/key-array was empty or malformed - * @throws DomainException Provided JWT is malformed - * @throws UnexpectedValueException Provided JWT was invalid - * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed - * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf' - * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat' - * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim - * - * @uses jsonDecode - * @uses urlsafeB64Decode - */ - public static function decode( - string $jwt, - $keyOrKeyArray, - ?stdClass &$headers = null - ): stdClass { - // Validate JWT - $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp; - - if (empty($keyOrKeyArray)) { - throw new InvalidArgumentException('Key may not be empty'); - } - $tks = \explode('.', $jwt); - if (\count($tks) !== 3) { - throw new UnexpectedValueException('Wrong number of segments'); - } - list($headb64, $bodyb64, $cryptob64) = $tks; - $headerRaw = static::urlsafeB64Decode($headb64); - if (null === ($header = static::jsonDecode($headerRaw))) { - throw new UnexpectedValueException('Invalid header encoding'); - } - if ($headers !== null) { - $headers = $header; - } - $payloadRaw = static::urlsafeB64Decode($bodyb64); - if (null === ($payload = static::jsonDecode($payloadRaw))) { - throw new UnexpectedValueException('Invalid claims encoding'); - } - if (\is_array($payload)) { - // prevent PHP Fatal Error in edge-cases when payload is empty array - $payload = (object) $payload; - } - if (!$payload instanceof stdClass) { - throw new UnexpectedValueException('Payload must be a JSON object'); - } - $sig = static::urlsafeB64Decode($cryptob64); - if (empty($header->alg)) { - throw new UnexpectedValueException('Empty algorithm'); - } - if (empty(static::$supported_algs[$header->alg])) { - throw new UnexpectedValueException('Algorithm not supported'); - } - - $key = self::getKey($keyOrKeyArray, property_exists($header, 'kid') ? $header->kid : null); - - // Check the algorithm - if (!self::constantTimeEquals($key->getAlgorithm(), $header->alg)) { - // See issue #351 - throw new UnexpectedValueException('Incorrect key for this algorithm'); - } - if (\in_array($header->alg, ['ES256', 'ES256K', 'ES384'], true)) { - // OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384 signatures - $sig = self::signatureToDER($sig); - } - if (!self::verify("{$headb64}.{$bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) { - throw new SignatureInvalidException('Signature verification failed'); - } - - // Check the nbf if it is defined. This is the time that the - // token can actually be used. If it's not yet that time, abort. - if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) { - $ex = new BeforeValidException( - 'Cannot handle token with nbf prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf) - ); - $ex->setPayload($payload); - throw $ex; - } - - // Check that this token has been created before 'now'. This prevents - // using tokens that have been created for later use (and haven't - // correctly used the nbf claim). - if (!isset($payload->nbf) && isset($payload->iat) && floor($payload->iat) > ($timestamp + static::$leeway)) { - $ex = new BeforeValidException( - 'Cannot handle token with iat prior to ' . \date(DateTime::ISO8601, (int) $payload->iat) - ); - $ex->setPayload($payload); - throw $ex; - } - - // Check if this token has expired. - if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { - $ex = new ExpiredException('Expired token'); - $ex->setPayload($payload); - throw $ex; - } - - return $payload; - } - - /** - * Converts and signs a PHP array into a JWT string. - * - * @param array $payload PHP array - * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key. - * @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K', 'HS256', - * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512' - * @param string $keyId - * @param array $head An array with header elements to attach - * - * @return string A signed JWT - * - * @uses jsonEncode - * @uses urlsafeB64Encode - */ - public static function encode( - array $payload, - $key, - string $alg, - ?string $keyId = null, - ?array $head = null - ): string { - $header = ['typ' => 'JWT']; - if (isset($head)) { - $header = \array_merge($header, $head); - } - $header['alg'] = $alg; - if ($keyId !== null) { - $header['kid'] = $keyId; - } - $segments = []; - $segments[] = static::urlsafeB64Encode((string) static::jsonEncode($header)); - $segments[] = static::urlsafeB64Encode((string) static::jsonEncode($payload)); - $signing_input = \implode('.', $segments); - - $signature = static::sign($signing_input, $key, $alg); - $segments[] = static::urlsafeB64Encode($signature); - - return \implode('.', $segments); - } - - /** - * Sign a string with a given key and algorithm. - * - * @param string $msg The message to sign - * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key. - * @param string $alg Supported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256', - * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512' - * - * @return string An encrypted message - * - * @throws DomainException Unsupported algorithm or bad key was specified - */ - public static function sign( - string $msg, - $key, - string $alg - ): string { - if (empty(static::$supported_algs[$alg])) { - throw new DomainException('Algorithm not supported'); - } - list($function, $algorithm) = static::$supported_algs[$alg]; - switch ($function) { - case 'hash_hmac': - if (!\is_string($key)) { - throw new InvalidArgumentException('key must be a string when using hmac'); - } - return \hash_hmac($algorithm, $msg, $key, true); - case 'openssl': - $signature = ''; - if (!\is_resource($key) && !openssl_pkey_get_private($key)) { - throw new DomainException('OpenSSL unable to validate key'); - } - $success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line - if (!$success) { - throw new DomainException('OpenSSL unable to sign data'); - } - if ($alg === 'ES256' || $alg === 'ES256K') { - $signature = self::signatureFromDER($signature, 256); - } elseif ($alg === 'ES384') { - $signature = self::signatureFromDER($signature, 384); - } - 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); - } catch (Exception $e) { - throw new DomainException($e->getMessage(), 0, $e); - } - } - - throw new DomainException('Algorithm not supported'); - } - - /** - * Verify a signature with the message, key and method. Not all methods - * are symmetric, so we must have a separate verify and sign method. - * - * @param string $msg The original message (header and body) - * @param string $signature The original signature - * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial For Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey - * @param string $alg The algorithm - * - * @return bool - * - * @throws DomainException Invalid Algorithm, bad key, or OpenSSL failure - */ - private static function verify( - string $msg, - string $signature, - $keyMaterial, - string $alg - ): bool { - if (empty(static::$supported_algs[$alg])) { - throw new DomainException('Algorithm not supported'); - } - - list($function, $algorithm) = static::$supported_algs[$alg]; - switch ($function) { - case 'openssl': - $success = \openssl_verify($msg, $signature, $keyMaterial, $algorithm); // @phpstan-ignore-line - if ($success === 1) { - return true; - } - if ($success === 0) { - return false; - } - // returns 1 on success, 0 on failure, -1 on error. - throw new DomainException( - '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'); - } - if (\strlen($signature) === 0) { - throw new DomainException('Signature cannot be empty string'); - } - return sodium_crypto_sign_verify_detached($signature, $msg, $key); - } catch (Exception $e) { - throw new DomainException($e->getMessage(), 0, $e); - } - case 'hash_hmac': - default: - if (!\is_string($keyMaterial)) { - throw new InvalidArgumentException('key must be a string when using hmac'); - } - $hash = \hash_hmac($algorithm, $msg, $keyMaterial, true); - return self::constantTimeEquals($hash, $signature); - } - } - - /** - * Decode a JSON string into a PHP object. - * - * @param string $input JSON string - * - * @return mixed The decoded JSON string - * - * @throws DomainException Provided string was invalid JSON - */ - public static function jsonDecode(string $input) - { - $obj = \json_decode($input, false, 512, JSON_BIGINT_AS_STRING); - - if ($errno = \json_last_error()) { - self::handleJsonError($errno); - } elseif ($obj === null && $input !== 'null') { - throw new DomainException('Null result with non-null input'); - } - return $obj; - } - - /** - * Encode a PHP array into a JSON string. - * - * @param array $input A PHP array - * - * @return string JSON representation of the PHP array - * - * @throws DomainException Provided object could not be encoded to valid JSON - */ - public static function jsonEncode(array $input): string - { - $json = \json_encode($input, \JSON_UNESCAPED_SLASHES); - if ($errno = \json_last_error()) { - self::handleJsonError($errno); - } elseif ($json === 'null') { - throw new DomainException('Null result with non-null input'); - } - if ($json === false) { - throw new DomainException('Provided object could not be encoded to valid JSON'); - } - return $json; - } - - /** - * Decode a string with URL-safe Base64. - * - * @param string $input A Base64 encoded string - * - * @return string A decoded string - * - * @throws InvalidArgumentException invalid base64 characters - */ - public static function urlsafeB64Decode(string $input): string - { - return \base64_decode(self::convertBase64UrlToBase64($input)); - } - - /** - * Convert a string in the base64url (URL-safe Base64) encoding to standard base64. - * - * @param string $input A Base64 encoded string with URL-safe characters (-_ and no padding) - * - * @return string A Base64 encoded string with standard characters (+/) and padding (=), when - * needed. - * - * @see https://www.rfc-editor.org/rfc/rfc4648 - */ - public static function convertBase64UrlToBase64(string $input): string - { - $remainder = \strlen($input) % 4; - if ($remainder) { - $padlen = 4 - $remainder; - $input .= \str_repeat('=', $padlen); - } - return \strtr($input, '-_', '+/'); - } - - /** - * Encode a string with URL-safe Base64. - * - * @param string $input The string you want encoded - * - * @return string The base64 encode of what you passed in - */ - public static function urlsafeB64Encode(string $input): string - { - return \str_replace('=', '', \strtr(\base64_encode($input), '+/', '-_')); - } - - - /** - * Determine if an algorithm has been provided for each Key - * - * @param Key|ArrayAccess|array $keyOrKeyArray - * @param string|null $kid - * - * @throws UnexpectedValueException - * - * @return Key - */ - private static function getKey( - $keyOrKeyArray, - ?string $kid - ): Key { - if ($keyOrKeyArray instanceof Key) { - return $keyOrKeyArray; - } - - if (empty($kid) && $kid !== '0') { - throw new UnexpectedValueException('"kid" empty, unable to lookup correct key'); - } - - if ($keyOrKeyArray instanceof CachedKeySet) { - // Skip "isset" check, as this will automatically refresh if not set - return $keyOrKeyArray[$kid]; - } - - if (!isset($keyOrKeyArray[$kid])) { - throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key'); - } - - return $keyOrKeyArray[$kid]; - } - - /** - * @param string $left The string of known length to compare against - * @param string $right The user-supplied string - * @return bool - */ - public static function constantTimeEquals(string $left, string $right): bool - { - if (\function_exists('hash_equals')) { - return \hash_equals($left, $right); - } - $len = \min(self::safeStrlen($left), self::safeStrlen($right)); - - $status = 0; - for ($i = 0; $i < $len; $i++) { - $status |= (\ord($left[$i]) ^ \ord($right[$i])); - } - $status |= (self::safeStrlen($left) ^ self::safeStrlen($right)); - - return ($status === 0); - } - - /** - * Helper method to create a JSON error. - * - * @param int $errno An error number from json_last_error() - * - * @throws DomainException - * - * @return void - */ - private static function handleJsonError(int $errno): void - { - $messages = [ - JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', - JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', - JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', - JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3 - ]; - throw new DomainException( - isset($messages[$errno]) - ? $messages[$errno] - : 'Unknown JSON error: ' . $errno - ); - } - - /** - * Get the number of bytes in cryptographic strings. - * - * @param string $str - * - * @return int - */ - private static function safeStrlen(string $str): int - { - if (\function_exists('mb_strlen')) { - return \mb_strlen($str, '8bit'); - } - return \strlen($str); - } - - /** - * Convert an ECDSA signature to an ASN.1 DER sequence - * - * @param string $sig The ECDSA signature to convert - * @return string The encoded DER object - */ - private static function signatureToDER(string $sig): string - { - // Separate the signature into r-value and s-value - $length = max(1, (int) (\strlen($sig) / 2)); - list($r, $s) = \str_split($sig, $length); - - // Trim leading zeros - $r = \ltrim($r, "\x00"); - $s = \ltrim($s, "\x00"); - - // Convert r-value and s-value from unsigned big-endian integers to - // signed two's complement - if (\ord($r[0]) > 0x7f) { - $r = "\x00" . $r; - } - if (\ord($s[0]) > 0x7f) { - $s = "\x00" . $s; - } - - return self::encodeDER( - self::ASN1_SEQUENCE, - self::encodeDER(self::ASN1_INTEGER, $r) . - self::encodeDER(self::ASN1_INTEGER, $s) - ); - } - - /** - * Encodes a value into a DER object. - * - * @param int $type DER tag - * @param string $value the value to encode - * - * @return string the encoded object - */ - private static function encodeDER(int $type, string $value): string - { - $tag_header = 0; - if ($type === self::ASN1_SEQUENCE) { - $tag_header |= 0x20; - } - - // Type - $der = \chr($tag_header | $type); - - // Length - $der .= \chr(\strlen($value)); - - return $der . $value; - } - - /** - * Encodes signature from a DER object. - * - * @param string $der binary signature in DER format - * @param int $keySize the number of bits in the key - * - * @return string the signature - */ - private static function signatureFromDER(string $der, int $keySize): string - { - // OpenSSL returns the ECDSA signatures as a binary ASN.1 DER SEQUENCE - list($offset, $_) = self::readDER($der); - list($offset, $r) = self::readDER($der, $offset); - list($offset, $s) = self::readDER($der, $offset); - - // Convert r-value and s-value from signed two's compliment to unsigned - // big-endian integers - $r = \ltrim($r, "\x00"); - $s = \ltrim($s, "\x00"); - - // Pad out r and s so that they are $keySize bits long - $r = \str_pad($r, $keySize / 8, "\x00", STR_PAD_LEFT); - $s = \str_pad($s, $keySize / 8, "\x00", STR_PAD_LEFT); - - return $r . $s; - } - - /** - * Reads binary DER-encoded data and decodes into a single object - * - * @param string $der the binary data in DER format - * @param int $offset the offset of the data stream containing the object - * to decode - * - * @return array{int, string|null} the new offset and the decoded object - */ - private static function readDER(string $der, int $offset = 0): array - { - $pos = $offset; - $size = \strlen($der); - $constructed = (\ord($der[$pos]) >> 5) & 0x01; - $type = \ord($der[$pos++]) & 0x1f; - - // Length - $len = \ord($der[$pos++]); - if ($len & 0x80) { - $n = $len & 0x1f; - $len = 0; - while ($n-- && $pos < $size) { - $len = ($len << 8) | \ord($der[$pos++]); - } - } - - // Value - if ($type === self::ASN1_BIT_STRING) { - $pos++; // Skip the first contents octet (padding indicator) - $data = \substr($der, $pos, $len - 1); - $pos += $len - 1; - } elseif (!$constructed) { - $data = \substr($der, $pos, $len); - $pos += $len; - } else { - $data = null; - } - - return [$pos, $data]; - } +class JWT { + + private const ASN1_INTEGER = 0x02; + private const ASN1_SEQUENCE = 0x10; + private const ASN1_BIT_STRING = 0x03; + + /** + * When checking nbf, iat or expiration times, + * we want to provide some extra leeway time to + * account for clock skew. + * + * @var int + */ + public static $leeway = 0; + + /** + * Allow the current timestamp to be specified. + * Useful for fixing a value within unit testing. + * Will default to PHP time() value if null. + * + * @var ?int + */ + public static $timestamp = null; + + /** + * @var array + */ + public static $supported_algs = array( + 'ES384' => array( 'openssl', 'SHA384' ), + 'ES256' => array( 'openssl', 'SHA256' ), + 'ES256K' => array( 'openssl', 'SHA256' ), + 'HS256' => array( 'hash_hmac', 'SHA256' ), + 'HS384' => array( 'hash_hmac', 'SHA384' ), + 'HS512' => array( 'hash_hmac', 'SHA512' ), + 'RS256' => array( 'openssl', 'SHA256' ), + 'RS384' => array( 'openssl', 'SHA384' ), + 'RS512' => array( 'openssl', 'SHA512' ), + 'EdDSA' => array( 'sodium_crypto', 'EdDSA' ), + ); + + /** + * Decodes a JWT string into a PHP object. + * + * @param string $jwt The JWT + * @param Key|ArrayAccess|array $keyOrKeyArray The Key or associative array of key IDs + * (kid) to Key objects. + * If the algorithm used is asymmetric, this is + * the public key. + * Each Key object contains an algorithm and + * matching key. + * Supported algorithms are 'ES384','ES256', + * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384' + * and 'RS512'. + * @param stdClass $headers Optional. Populates stdClass with headers. + * + * @return stdClass The JWT's payload as a PHP object + * + * @throws InvalidArgumentException Provided key/key-array was empty or malformed + * @throws DomainException Provided JWT is malformed + * @throws UnexpectedValueException Provided JWT was invalid + * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed + * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf' + * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat' + * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim + * + * @uses jsonDecode + * @uses urlsafeB64Decode + */ + public static function decode( + string $jwt, + $keyOrKeyArray, + ?stdClass &$headers = null + ): stdClass { + // Validate JWT + $timestamp = \is_null( static::$timestamp ) ? \time() : static::$timestamp; + + if ( empty( $keyOrKeyArray ) ) { + throw new InvalidArgumentException( 'Key may not be empty' ); + } + $tks = \explode( '.', $jwt ); + if ( \count( $tks ) !== 3 ) { + throw new UnexpectedValueException( 'Wrong number of segments' ); + } + list($headb64, $bodyb64, $cryptob64) = $tks; + $headerRaw = static::urlsafeB64Decode( $headb64 ); + if ( null === ( $header = static::jsonDecode( $headerRaw ) ) ) { + throw new UnexpectedValueException( 'Invalid header encoding' ); + } + if ( $headers !== null ) { + $headers = $header; + } + $payloadRaw = static::urlsafeB64Decode( $bodyb64 ); + if ( null === ( $payload = static::jsonDecode( $payloadRaw ) ) ) { + throw new UnexpectedValueException( 'Invalid claims encoding' ); + } + if ( \is_array( $payload ) ) { + // prevent PHP Fatal Error in edge-cases when payload is empty array + $payload = (object) $payload; + } + if ( ! $payload instanceof stdClass ) { + throw new UnexpectedValueException( 'Payload must be a JSON object' ); + } + $sig = static::urlsafeB64Decode( $cryptob64 ); + if ( empty( $header->alg ) ) { + throw new UnexpectedValueException( 'Empty algorithm' ); + } + if ( empty( static::$supported_algs[ $header->alg ] ) ) { + throw new UnexpectedValueException( 'Algorithm not supported' ); + } + + $key = self::getKey( $keyOrKeyArray, property_exists( $header, 'kid' ) ? $header->kid : null ); + + // Check the algorithm + if ( ! self::constantTimeEquals( $key->getAlgorithm(), $header->alg ) ) { + // See issue #351 + throw new UnexpectedValueException( 'Incorrect key for this algorithm' ); + } + if ( \in_array( $header->alg, array( 'ES256', 'ES256K', 'ES384' ), true ) ) { + // OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384 signatures + $sig = self::signatureToDER( $sig ); + } + if ( ! self::verify( "{$headb64}.{$bodyb64}", $sig, $key->getKeyMaterial(), $header->alg ) ) { + throw new SignatureInvalidException( 'Signature verification failed' ); + } + + // Check the nbf if it is defined. This is the time that the + // token can actually be used. If it's not yet that time, abort. + if ( isset( $payload->nbf ) && floor( $payload->nbf ) > ( $timestamp + static::$leeway ) ) { + $ex = new BeforeValidException( + 'Cannot handle token with nbf prior to ' . \date( DateTime::ISO8601, (int) $payload->nbf ) + ); + $ex->setPayload( $payload ); + throw $ex; + } + + // Check that this token has been created before 'now'. This prevents + // using tokens that have been created for later use (and haven't + // correctly used the nbf claim). + if ( ! isset( $payload->nbf ) && isset( $payload->iat ) && floor( $payload->iat ) > ( $timestamp + static::$leeway ) ) { + $ex = new BeforeValidException( + 'Cannot handle token with iat prior to ' . \date( DateTime::ISO8601, (int) $payload->iat ) + ); + $ex->setPayload( $payload ); + throw $ex; + } + + // Check if this token has expired. + if ( isset( $payload->exp ) && ( $timestamp - static::$leeway ) >= $payload->exp ) { + $ex = new ExpiredException( 'Expired token' ); + $ex->setPayload( $payload ); + throw $ex; + } + + return $payload; + } + + /** + * Converts and signs a PHP array into a JWT string. + * + * @param array $payload PHP array + * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key. + * @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K', 'HS256', + * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512' + * @param string $keyId + * @param array $head An array with header elements to attach + * + * @return string A signed JWT + * + * @uses jsonEncode + * @uses urlsafeB64Encode + */ + public static function encode( + array $payload, + $key, + string $alg, + ?string $keyId = null, + ?array $head = null + ): string { + $header = array( 'typ' => 'JWT' ); + if ( isset( $head ) ) { + $header = \array_merge( $header, $head ); + } + $header['alg'] = $alg; + if ( $keyId !== null ) { + $header['kid'] = $keyId; + } + $segments = array(); + $segments[] = static::urlsafeB64Encode( (string) static::jsonEncode( $header ) ); + $segments[] = static::urlsafeB64Encode( (string) static::jsonEncode( $payload ) ); + $signing_input = \implode( '.', $segments ); + + $signature = static::sign( $signing_input, $key, $alg ); + $segments[] = static::urlsafeB64Encode( $signature ); + + return \implode( '.', $segments ); + } + + /** + * Sign a string with a given key and algorithm. + * + * @param string $msg The message to sign + * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key. + * @param string $alg Supported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256', + * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512' + * + * @return string An encrypted message + * + * @throws DomainException Unsupported algorithm or bad key was specified + */ + public static function sign( + string $msg, + $key, + string $alg + ): string { + if ( empty( static::$supported_algs[ $alg ] ) ) { + throw new DomainException( 'Algorithm not supported' ); + } + list($function, $algorithm) = static::$supported_algs[ $alg ]; + switch ( $function ) { + case 'hash_hmac': + if ( ! \is_string( $key ) ) { + throw new InvalidArgumentException( 'key must be a string when using hmac' ); + } + return \hash_hmac( $algorithm, $msg, $key, true ); + case 'openssl': + $signature = ''; + if ( ! \is_resource( $key ) && ! openssl_pkey_get_private( $key ) ) { + throw new DomainException( 'OpenSSL unable to validate key' ); + } + $success = \openssl_sign( $msg, $signature, $key, $algorithm ); // @phpstan-ignore-line + if ( ! $success ) { + throw new DomainException( 'OpenSSL unable to sign data' ); + } + if ( $alg === 'ES256' || $alg === 'ES256K' ) { + $signature = self::signatureFromDER( $signature, 256 ); + } elseif ( $alg === 'ES384' ) { + $signature = self::signatureFromDER( $signature, 384 ); + } + 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 ); + } catch ( Exception $e ) { + throw new DomainException( $e->getMessage(), 0, $e ); + } + } + + throw new DomainException( 'Algorithm not supported' ); + } + + /** + * Verify a signature with the message, key and method. Not all methods + * are symmetric, so we must have a separate verify and sign method. + * + * @param string $msg The original message (header and body) + * @param string $signature The original signature + * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial For Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey + * @param string $alg The algorithm + * + * @return bool + * + * @throws DomainException Invalid Algorithm, bad key, or OpenSSL failure + */ + private static function verify( + string $msg, + string $signature, + $keyMaterial, + string $alg + ): bool { + if ( empty( static::$supported_algs[ $alg ] ) ) { + throw new DomainException( 'Algorithm not supported' ); + } + + list($function, $algorithm) = static::$supported_algs[ $alg ]; + switch ( $function ) { + case 'openssl': + $success = \openssl_verify( $msg, $signature, $keyMaterial, $algorithm ); // @phpstan-ignore-line + if ( $success === 1 ) { + return true; + } + if ( $success === 0 ) { + return false; + } + // returns 1 on success, 0 on failure, -1 on error. + throw new DomainException( + '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' ); + } + if ( \strlen( $signature ) === 0 ) { + throw new DomainException( 'Signature cannot be empty string' ); + } + return sodium_crypto_sign_verify_detached( $signature, $msg, $key ); + } catch ( Exception $e ) { + throw new DomainException( $e->getMessage(), 0, $e ); + } + case 'hash_hmac': + default: + if ( ! \is_string( $keyMaterial ) ) { + throw new InvalidArgumentException( 'key must be a string when using hmac' ); + } + $hash = \hash_hmac( $algorithm, $msg, $keyMaterial, true ); + return self::constantTimeEquals( $hash, $signature ); + } + } + + /** + * Decode a JSON string into a PHP object. + * + * @param string $input JSON string + * + * @return mixed The decoded JSON string + * + * @throws DomainException Provided string was invalid JSON + */ + public static function jsonDecode( string $input ) { + $obj = \json_decode( $input, false, 512, JSON_BIGINT_AS_STRING ); + + if ( $errno = \json_last_error() ) { + self::handleJsonError( $errno ); + } elseif ( $obj === null && $input !== 'null' ) { + throw new DomainException( 'Null result with non-null input' ); + } + return $obj; + } + + /** + * Encode a PHP array into a JSON string. + * + * @param array $input A PHP array + * + * @return string JSON representation of the PHP array + * + * @throws DomainException Provided object could not be encoded to valid JSON + */ + public static function jsonEncode( array $input ): string { + $json = \json_encode( $input, \JSON_UNESCAPED_SLASHES ); + if ( $errno = \json_last_error() ) { + self::handleJsonError( $errno ); + } elseif ( $json === 'null' ) { + throw new DomainException( 'Null result with non-null input' ); + } + if ( $json === false ) { + throw new DomainException( 'Provided object could not be encoded to valid JSON' ); + } + return $json; + } + + /** + * Decode a string with URL-safe Base64. + * + * @param string $input A Base64 encoded string + * + * @return string A decoded string + * + * @throws InvalidArgumentException invalid base64 characters + */ + public static function urlsafeB64Decode( string $input ): string { + return \base64_decode( self::convertBase64UrlToBase64( $input ) ); + } + + /** + * Convert a string in the base64url (URL-safe Base64) encoding to standard base64. + * + * @param string $input A Base64 encoded string with URL-safe characters (-_ and no padding) + * + * @return string A Base64 encoded string with standard characters (+/) and padding (=), when + * needed. + * + * @see https://www.rfc-editor.org/rfc/rfc4648 + */ + public static function convertBase64UrlToBase64( string $input ): string { + $remainder = \strlen( $input ) % 4; + if ( $remainder ) { + $padlen = 4 - $remainder; + $input .= \str_repeat( '=', $padlen ); + } + return \strtr( $input, '-_', '+/' ); + } + + /** + * Encode a string with URL-safe Base64. + * + * @param string $input The string you want encoded + * + * @return string The base64 encode of what you passed in + */ + public static function urlsafeB64Encode( string $input ): string { + return \str_replace( '=', '', \strtr( \base64_encode( $input ), '+/', '-_' ) ); + } + + + /** + * Determine if an algorithm has been provided for each Key + * + * @param Key|ArrayAccess|array $keyOrKeyArray + * @param string|null $kid + * + * @throws UnexpectedValueException + * + * @return Key + */ + private static function getKey( + $keyOrKeyArray, + ?string $kid + ): Key { + if ( $keyOrKeyArray instanceof Key ) { + return $keyOrKeyArray; + } + + if ( empty( $kid ) && $kid !== '0' ) { + throw new UnexpectedValueException( '"kid" empty, unable to lookup correct key' ); + } + + if ( $keyOrKeyArray instanceof CachedKeySet ) { + // Skip "isset" check, as this will automatically refresh if not set + return $keyOrKeyArray[ $kid ]; + } + + if ( ! isset( $keyOrKeyArray[ $kid ] ) ) { + throw new UnexpectedValueException( '"kid" invalid, unable to lookup correct key' ); + } + + return $keyOrKeyArray[ $kid ]; + } + + /** + * @param string $left The string of known length to compare against + * @param string $right The user-supplied string + * @return bool + */ + public static function constantTimeEquals( string $left, string $right ): bool { + if ( \function_exists( 'hash_equals' ) ) { + return \hash_equals( $left, $right ); + } + $len = \min( self::safeStrlen( $left ), self::safeStrlen( $right ) ); + + $status = 0; + for ( $i = 0; $i < $len; $i++ ) { + $status |= ( \ord( $left[ $i ] ) ^ \ord( $right[ $i ] ) ); + } + $status |= ( self::safeStrlen( $left ) ^ self::safeStrlen( $right ) ); + + return ( $status === 0 ); + } + + /** + * Helper method to create a JSON error. + * + * @param int $errno An error number from json_last_error() + * + * @throws DomainException + * + * @return void + */ + private static function handleJsonError( int $errno ): void { + $messages = array( + JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', + JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', + JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', + JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters', // PHP >= 5.3.3 + ); + throw new DomainException( + isset( $messages[ $errno ] ) + ? $messages[ $errno ] + : 'Unknown JSON error: ' . $errno + ); + } + + /** + * Get the number of bytes in cryptographic strings. + * + * @param string $str + * + * @return int + */ + private static function safeStrlen( string $str ): int { + if ( \function_exists( 'mb_strlen' ) ) { + return \mb_strlen( $str, '8bit' ); + } + return \strlen( $str ); + } + + /** + * Convert an ECDSA signature to an ASN.1 DER sequence + * + * @param string $sig The ECDSA signature to convert + * @return string The encoded DER object + */ + private static function signatureToDER( string $sig ): string { + // Separate the signature into r-value and s-value + $length = max( 1, (int) ( \strlen( $sig ) / 2 ) ); + list($r, $s) = \str_split( $sig, $length ); + + // Trim leading zeros + $r = \ltrim( $r, "\x00" ); + $s = \ltrim( $s, "\x00" ); + + // Convert r-value and s-value from unsigned big-endian integers to + // signed two's complement + if ( \ord( $r[0] ) > 0x7f ) { + $r = "\x00" . $r; + } + if ( \ord( $s[0] ) > 0x7f ) { + $s = "\x00" . $s; + } + + return self::encodeDER( + self::ASN1_SEQUENCE, + self::encodeDER( self::ASN1_INTEGER, $r ) . + self::encodeDER( self::ASN1_INTEGER, $s ) + ); + } + + /** + * Encodes a value into a DER object. + * + * @param int $type DER tag + * @param string $value the value to encode + * + * @return string the encoded object + */ + private static function encodeDER( int $type, string $value ): string { + $tag_header = 0; + if ( $type === self::ASN1_SEQUENCE ) { + $tag_header |= 0x20; + } + + // Type + $der = \chr( $tag_header | $type ); + + // Length + $der .= \chr( \strlen( $value ) ); + + return $der . $value; + } + + /** + * Encodes signature from a DER object. + * + * @param string $der binary signature in DER format + * @param int $keySize the number of bits in the key + * + * @return string the signature + */ + private static function signatureFromDER( string $der, int $keySize ): string { + // OpenSSL returns the ECDSA signatures as a binary ASN.1 DER SEQUENCE + list($offset, $_) = self::readDER( $der ); + list($offset, $r) = self::readDER( $der, $offset ); + list($offset, $s) = self::readDER( $der, $offset ); + + // Convert r-value and s-value from signed two's compliment to unsigned + // big-endian integers + $r = \ltrim( $r, "\x00" ); + $s = \ltrim( $s, "\x00" ); + + // Pad out r and s so that they are $keySize bits long + $r = \str_pad( $r, $keySize / 8, "\x00", STR_PAD_LEFT ); + $s = \str_pad( $s, $keySize / 8, "\x00", STR_PAD_LEFT ); + + return $r . $s; + } + + /** + * Reads binary DER-encoded data and decodes into a single object + * + * @param string $der the binary data in DER format + * @param int $offset the offset of the data stream containing the object + * to decode + * + * @return array{int, string|null} the new offset and the decoded object + */ + private static function readDER( string $der, int $offset = 0 ): array { + $pos = $offset; + $size = \strlen( $der ); + $constructed = ( \ord( $der[ $pos ] ) >> 5 ) & 0x01; + $type = \ord( $der[ $pos++ ] ) & 0x1f; + + // Length + $len = \ord( $der[ $pos++ ] ); + if ( $len & 0x80 ) { + $n = $len & 0x1f; + $len = 0; + while ( $n-- && $pos < $size ) { + $len = ( $len << 8 ) | \ord( $der[ $pos++ ] ); + } + } + + // Value + if ( $type === self::ASN1_BIT_STRING ) { + ++$pos; // Skip the first contents octet (padding indicator) + $data = \substr( $der, $pos, $len - 1 ); + $pos += $len - 1; + } elseif ( ! $constructed ) { + $data = \substr( $der, $pos, $len ); + $pos += $len; + } else { + $data = null; + } + + return array( $pos, $data ); + } } diff --git a/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php b/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php index 6c4392bbf..02c41d57d 100644 --- a/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php +++ b/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php @@ -7,20 +7,20 @@ */ namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT; -interface JWTExceptionWithPayloadInterface -{ - /** - * Get the payload that caused this exception. - * - * @return object - */ - public function getPayload(): object; +interface JWTExceptionWithPayloadInterface { - /** - * Get the payload that caused this exception. - * - * @param object $payload - * @return void - */ - public function setPayload(object $payload): void; + /** + * Get the payload that caused this exception. + * + * @return object + */ + public function getPayload(): object; + + /** + * Get the payload that caused this exception. + * + * @param object $payload + * @return void + */ + public function setPayload( object $payload ): void; } diff --git a/vendor-prefixed/firebase/php-jwt/src/Key.php b/vendor-prefixed/firebase/php-jwt/src/Key.php index 366f16ccf..fce9c4a21 100644 --- a/vendor-prefixed/firebase/php-jwt/src/Key.php +++ b/vendor-prefixed/firebase/php-jwt/src/Key.php @@ -13,49 +13,47 @@ use OpenSSLCertificate; use TypeError; -class Key -{ - /** - * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial - * @param string $algorithm - */ - public function __construct( - private $keyMaterial, - private string $algorithm - ) { - if ( - !\is_string($keyMaterial) - && !$keyMaterial instanceof OpenSSLAsymmetricKey - && !$keyMaterial instanceof OpenSSLCertificate - && !\is_resource($keyMaterial) - ) { - throw new TypeError('Key material must be a string, resource, or OpenSSLAsymmetricKey'); - } - - if (empty($keyMaterial)) { - throw new InvalidArgumentException('Key material must not be empty'); - } - - if (empty($algorithm)) { - throw new InvalidArgumentException('Algorithm must not be empty'); - } - } - - /** - * Return the algorithm valid for this key - * - * @return string - */ - public function getAlgorithm(): string - { - return $this->algorithm; - } - - /** - * @return string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate - */ - public function getKeyMaterial() - { - return $this->keyMaterial; - } +class Key { + + /** + * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial + * @param string $algorithm + */ + public function __construct( + private $keyMaterial, + private string $algorithm + ) { + if ( + ! \is_string( $keyMaterial ) + && ! $keyMaterial instanceof OpenSSLAsymmetricKey + && ! $keyMaterial instanceof OpenSSLCertificate + && ! \is_resource( $keyMaterial ) + ) { + throw new TypeError( 'Key material must be a string, resource, or OpenSSLAsymmetricKey' ); + } + + if ( empty( $keyMaterial ) ) { + throw new InvalidArgumentException( 'Key material must not be empty' ); + } + + if ( empty( $algorithm ) ) { + throw new InvalidArgumentException( 'Algorithm must not be empty' ); + } + } + + /** + * Return the algorithm valid for this key + * + * @return string + */ + public function getAlgorithm(): string { + return $this->algorithm; + } + + /** + * @return string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate + */ + public function getKeyMaterial() { + return $this->keyMaterial; + } } diff --git a/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php b/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php index 487ec9713..c9c132c89 100644 --- a/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php +++ b/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php @@ -8,6 +8,6 @@ namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT; -class SignatureInvalidException extends \UnexpectedValueException -{ +class SignatureInvalidException extends \UnexpectedValueException { + } diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php index 998d97d4d..5789500d1 100644 --- a/wp-graphql-woocommerce.php +++ b/wp-graphql-woocommerce.php @@ -101,7 +101,7 @@ function plugin_file_url( $filepath ) { * * @return array */ -function dependencies_not_ready( &$deps = [] ) { +function dependencies_not_ready( &$deps = array() ) { if ( ! class_exists( '\WPGraphQL' ) ) { $deps[] = 'WPGraphQL'; } @@ -119,7 +119,7 @@ function dependencies_not_ready( &$deps = [] ) { */ function init() { // We define this now and pass it as a reference. - $not_ready = []; + $not_ready = array(); if ( empty( dependencies_not_ready( $not_ready ) ) ) { require_once get_includes_directory() . 'class-wp-graphql-woocommerce.php';