From 80bf1cfb76d3cb27c86cd3ac17435fe20c859c28 Mon Sep 17 00:00:00 2001 From: Menaka S Date: Tue, 18 Jan 2022 14:22:42 +0400 Subject: [PATCH 01/25] Add WcPay settings info to WC Tracker --- plugins/woocommerce/includes/class-wc-tracker.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/woocommerce/includes/class-wc-tracker.php b/plugins/woocommerce/includes/class-wc-tracker.php index 9346ce8c987..a7e9c6fc082 100644 --- a/plugins/woocommerce/includes/class-wc-tracker.php +++ b/plugins/woocommerce/includes/class-wc-tracker.php @@ -151,6 +151,9 @@ class WC_Tracker { // Payment gateway info. $data['gateways'] = self::get_active_payment_gateways(); + // WcPay settings info. + $data['wcpay_settings'] = self::get_wcpay_settings(); + // Shipping method info. $data['shipping_methods'] = self::get_active_shipping_methods(); @@ -303,6 +306,15 @@ class WC_Tracker { ); } + /** + * Get the settings of WooCommerce Payments plugin + * + * @return array + */ + private static function get_wcpay_settings() { + return get_option( 'woocommerce_woocommerce_payments_settings' ); + } + /** * Check to see if the helper is connected to woocommerce.com * @@ -589,6 +601,7 @@ class WC_Tracker { return $active_gateways; } + /** * Get a list of all active shipping methods. * From cac95a34334026213041c848743d779bca5e2172 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 26 Jan 2022 13:13:18 -0300 Subject: [PATCH 02/25] Scaffold --force wip --- packages/js/e2e-environment/bin/scaffold.js | 34 +++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index bb4de0a9e61..cccc9faa5f0 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -24,25 +24,39 @@ const { } = require( '../utils/scaffold' ); const args = process.argv.slice( 2 ); -const [ command, packageName ] = args; + +const command = args[0]; + +let packageName = null; + +if (args[1].substr(0, 2) !== '--') { + packageName = args[1]; +} // Allow multiple spec file extensions and formats. let testExtension = 'test.js'; let testFormat = ''; -for ( let a = 2; a < args.length; a++ ) { - const nextArg = a + 1; - if ( nextArg >= args.length ) { - break; - } - switch ( args[ a ] ) { +let force = false; + +args.forEach((el) => { + console.log(el); + switch ( el ) { case '--format': - testFormat = args[ nextArg ]; + testFormat = el; break; case '--ext': - testExtension = args[ nextArg ]; + testExtension = el; + break; + case '--force': + force = true; break; } -} +}); + +console.log('Command: ' + command ); +console.log('Package Name: ' + packageName ); +console.log('Test Extension: ' + testExtension ); +console.log('Test Format: ' + testFormat ); /** * Install the test scripts and sample default.json configuration From 15291424e219e668c0fa3f00089147c59a0bb27b Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 26 Jan 2022 13:27:25 -0300 Subject: [PATCH 03/25] Add --force argument to scaffold test setup files without confirmation --- packages/js/e2e-environment/bin/scaffold.js | 35 +++++++++---------- packages/js/e2e-environment/utils/scaffold.js | 17 ++++----- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index cccc9faa5f0..9737e50ed61 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -28,7 +28,6 @@ const args = process.argv.slice( 2 ); const command = args[0]; let packageName = null; - if (args[1].substr(0, 2) !== '--') { packageName = args[1]; } @@ -37,26 +36,26 @@ if (args[1].substr(0, 2) !== '--') { let testExtension = 'test.js'; let testFormat = ''; let force = false; +for ( let a = 1; a < args.length; a++ ) { + if (args[a] === '--force') { + force = true; + continue; + } -args.forEach((el) => { - console.log(el); - switch ( el ) { + // These arguments take a value, eg: --format foo + const nextArg = a + 1; + if ( nextArg >= args.length ) { + break; + } + switch ( args[ a ] ) { case '--format': - testFormat = el; + testFormat = args[ nextArg ]; break; case '--ext': - testExtension = el; - break; - case '--force': - force = true; + testExtension = args[ nextArg ]; break; } -}); - -console.log('Command: ' + command ); -console.log('Package Name: ' + packageName ); -console.log('Test Extension: ' + testExtension ); -console.log('Test Format: ' + testFormat ); +} /** * Install the test scripts and sample default.json configuration @@ -64,7 +63,7 @@ console.log('Test Format: ' + testFormat ); if ( command == 'install' ) { // Install some environment defaults if no package is requested. if ( ! packageName ) { - installDefaults(); + installDefaults(force); return; } @@ -80,7 +79,7 @@ if ( command == 'install' ) { if ( defaultJson ) { const defaultJsonName = `config${path.sep}default-${packageSlug}.json`; createLocalE2ePath( 'config' ); - if ( confirmLocalCopy( defaultJsonName, defaultJson, pkg ) ) { + if ( confirmLocalCopy( defaultJsonName, defaultJson, pkg, force ) ) { console.log( `Created sample test configuration to 'tests/e2e/${defaultJsonName}'.` ); } } @@ -89,7 +88,7 @@ if ( command == 'install' ) { if ( initializeSh ) { const defaultInitName = `docker${path.sep}${packageSlug}.sh`; createLocalE2ePath( 'docker' ); - if ( confirmLocalCopy( defaultInitName, initializeSh, pkg ) ) { + if ( confirmLocalCopy( defaultInitName, initializeSh, pkg, force ) ) { console.log( `Created sample test container initialization script to 'tests/e2e/${defaultInitName}'.` ); } } diff --git a/packages/js/e2e-environment/utils/scaffold.js b/packages/js/e2e-environment/utils/scaffold.js index 212c35ec233..580e40a9b7c 100644 --- a/packages/js/e2e-environment/utils/scaffold.js +++ b/packages/js/e2e-environment/utils/scaffold.js @@ -46,19 +46,20 @@ const confirm = ( prompt, choices ) => { * @param {string} localE2ePath Destination path * @param {string} packageE2ePath Source path * @param {string} packageName Source package. Default @woocommerce/e2e-environment package. + * @param {boolean} force Whether to override files if they exist without confirmation. * @return {boolean} */ -const confirmLocalCopy = ( localE2ePath, packageE2ePath, packageName = '' ) => { +const confirmLocalCopy = ( localE2ePath, packageE2ePath, packageName = '', force = false ) => { const localPath = resolveLocalE2ePath( localE2ePath ); const packagePath = resolvePackagePath( packageE2ePath, packageName ); const confirmPrompt = `${localE2ePath} already exists. Overwrite? [Y]es/[n]o: `; let overwriteFiles; - if ( fs.existsSync( localPath ) ) { + if ( !fs.existsSync( localPath ) || force ) { + overwriteFiles = 'y'; + } else { overwriteFiles = confirm( confirmPrompt, 'ny' ); overwriteFiles = overwriteFiles.toLowerCase(); - } else { - overwriteFiles = 'y'; } if ( overwriteFiles == 'y' ) { fs.copyFileSync( packagePath, localPath ); @@ -102,16 +103,16 @@ const getPackageData = ( packageName ) => { /** * Install test runner and test container defaults */ -const installDefaults = () => { +const installDefaults = (force) => { createLocalE2ePath( 'docker' ); console.log( 'Writing tests/e2e/docker/initialize.sh' ); - confirmLocalCopy( `docker${path.sep}initialize.sh`, `installFiles${path.sep}initialize.sh` ); + confirmLocalCopy( `docker${path.sep}initialize.sh`, `installFiles${path.sep}initialize.sh`, '', force ); createLocalE2ePath( 'config' ); console.log( 'Writing tests/e2e/config/jest.config.js' ); - confirmLocalCopy( `config${path.sep}jest.config.js`, `installFiles${path.sep}jest.config.js.default` ); + confirmLocalCopy( `config${path.sep}jest.config.js`, `installFiles${path.sep}jest.config.js.default`, '', force ); console.log( 'Writing tests/e2e/config/jest.setup.js' ); - confirmLocalCopy( `config${path.sep}jest.setup.js`, `installFiles${path.sep}jest.setup.js.default` ); + confirmLocalCopy( `config${path.sep}jest.setup.js`, `installFiles${path.sep}jest.setup.js.default`, '', force ); }; module.exports = { From e1ca45e07d81294e6ddd9d9c0261edcab592724f Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 26 Jan 2022 13:35:03 -0300 Subject: [PATCH 04/25] Keep original if statement order --- packages/js/e2e-environment/utils/scaffold.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/js/e2e-environment/utils/scaffold.js b/packages/js/e2e-environment/utils/scaffold.js index 580e40a9b7c..1a3aa978bae 100644 --- a/packages/js/e2e-environment/utils/scaffold.js +++ b/packages/js/e2e-environment/utils/scaffold.js @@ -55,11 +55,11 @@ const confirmLocalCopy = ( localE2ePath, packageE2ePath, packageName = '', force const confirmPrompt = `${localE2ePath} already exists. Overwrite? [Y]es/[n]o: `; let overwriteFiles; - if ( !fs.existsSync( localPath ) || force ) { - overwriteFiles = 'y'; - } else { + if ( ! force && fs.existsSync( localPath ) ) { overwriteFiles = confirm( confirmPrompt, 'ny' ); overwriteFiles = overwriteFiles.toLowerCase(); + } else { + overwriteFiles = 'y'; } if ( overwriteFiles == 'y' ) { fs.copyFileSync( packagePath, localPath ); From 1703aeddc4f5b99c17ecb7f2ff491d0f1e06272b Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 26 Jan 2022 13:36:39 -0300 Subject: [PATCH 05/25] Code style --- packages/js/e2e-environment/bin/scaffold.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index 9737e50ed61..51915c2f155 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -24,10 +24,9 @@ const { } = require( '../utils/scaffold' ); const args = process.argv.slice( 2 ); - const command = args[0]; - let packageName = null; + if (args[1].substr(0, 2) !== '--') { packageName = args[1]; } From 933de44557a419964aec7e11ad5d4c8f7101f995 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 28 Jan 2022 12:34:49 -0400 Subject: [PATCH 06/25] remove pnpm rule, fix utils build --- packages/js/api-core-tests/package.json | 1 - packages/js/api/package.json | 1 - packages/js/e2e-core-tests/package.json | 1 - packages/js/e2e-utils/package.json | 1 - packages/js/e2e-utils/src/factories/simple-product.js | 4 ++-- 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/js/api-core-tests/package.json b/packages/js/api-core-tests/package.json index c9ee60af086..2fc58990a3a 100644 --- a/packages/js/api-core-tests/package.json +++ b/packages/js/api-core-tests/package.json @@ -4,7 +4,6 @@ "description": "API tests for WooCommerce", "main": "index.js", "scripts": { - "preinstall": "npx only-allow pnpm", "test": "jest", "test:api": "jest --group=api", "test:hello": "jest --group=hello", diff --git a/packages/js/api/package.json b/packages/js/api/package.json index eded9fafdd6..56388920230 100644 --- a/packages/js/api/package.json +++ b/packages/js/api/package.json @@ -26,7 +26,6 @@ ], "sideEffects": false, "scripts": { - "preinstall": "npx only-allow pnpm", "clean": "rm -rf ./dist ./tsconfig.tsbuildinfo", "compile": "tsc -b", "build": "pnpm run clean && npm run compile", diff --git a/packages/js/e2e-core-tests/package.json b/packages/js/e2e-core-tests/package.json index 64d805aedcc..72e6da077d4 100644 --- a/packages/js/e2e-core-tests/package.json +++ b/packages/js/e2e-core-tests/package.json @@ -45,7 +45,6 @@ "access": "public" }, "scripts": { - "preinstall": "npx only-allow pnpm", "prepare": "pnpm run build", "clean": "rm -rf ./build ./build-module", "compile": "node ./../bin/build.js", diff --git a/packages/js/e2e-utils/package.json b/packages/js/e2e-utils/package.json index 9ab299798d2..e277882b16f 100644 --- a/packages/js/e2e-utils/package.json +++ b/packages/js/e2e-utils/package.json @@ -41,7 +41,6 @@ "access": "public" }, "scripts": { - "preinstall": "npx only-allow pnpm", "clean": "rm -rf ./build ./build-module", "compile": "node ./../bin/build.js", "build": "pnpm run clean && pnpm run compile", diff --git a/packages/js/e2e-utils/src/factories/simple-product.js b/packages/js/e2e-utils/src/factories/simple-product.js index c9dd0315409..e6a8a545991 100644 --- a/packages/js/e2e-utils/src/factories/simple-product.js +++ b/packages/js/e2e-utils/src/factories/simple-product.js @@ -17,8 +17,8 @@ export function simpleProductFactory( httpClient ) { } ); return { - name: params.name ?? faker.commerce.productName(), - regularPrice: params.regularPrice ?? faker.commerce.price(), + name: params.name ? params.name : faker.commerce.productName(), + regularPrice: params.regularPrice ? params.regularPrice : faker.commerce.price(), }; } ); } From 57ad5e388a483f2dcf2f9a3e09fccd9f7d016249 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 28 Jan 2022 13:15:45 -0400 Subject: [PATCH 07/25] add puppeteer dependency --- packages/js/e2e-environment/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/package.json b/packages/js/e2e-environment/package.json index cc73b00b4dd..94d87eefc44 100644 --- a/packages/js/e2e-environment/package.json +++ b/packages/js/e2e-environment/package.json @@ -35,7 +35,8 @@ "jest-each": "25.5.0", "jest-puppeteer": "^4.4.0", "node-stream-zip": "^1.13.6", - "readline-sync": "^1.4.10", + "puppeteer": "2.1.1", + "readline-sync": "^1.4.10", "request": "^2.88.2", "sprintf-js": "^1.1.2" }, From c607bbfeb89491cf8581f4308caa74a462331b5a Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 1 Feb 2022 14:59:50 -0400 Subject: [PATCH 08/25] pre-release changelog fixes --- packages/js/e2e-core-tests/CHANGELOG.md | 7 ++----- packages/js/e2e-environment/CHANGELOG.md | 17 +++++++---------- packages/js/e2e-utils/CHANGELOG.md | 6 ------ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/js/e2e-core-tests/CHANGELOG.md b/packages/js/e2e-core-tests/CHANGELOG.md index 56c0e589bbb..65f185480e2 100644 --- a/packages/js/e2e-core-tests/CHANGELOG.md +++ b/packages/js/e2e-core-tests/CHANGELOG.md @@ -1,16 +1,13 @@ # Unreleased -## Changed - -- Updated top level menu css selectors - ## Fixed + - Moved `merchant.login()` out of `beforeAll()` block and into test body for retried runs. ## Added - A `specs/data` folder to store page element data. -- Tests to verify that different top-level menu and their associated sub-menus load successfully. +- Tests to verify that different top-level menus and their associated sub-menus load successfully. - Test scaffolding via `npx wc-e2e install @woocommerce/e2e-core-tests` ## Changed diff --git a/packages/js/e2e-environment/CHANGELOG.md b/packages/js/e2e-environment/CHANGELOG.md index 322eb524f22..92147037877 100644 --- a/packages/js/e2e-environment/CHANGELOG.md +++ b/packages/js/e2e-environment/CHANGELOG.md @@ -1,34 +1,31 @@ # Unreleased -## Changes -- Updated `deleteDownloadedPluginFiles()` to also be able to delete directories. - ## Added -- Added `post-results-to-github-pr.js` to post smoke test results to a GitHub PR. -- Added jest flags to generate a json test report +- Added `post-results-to-github-pr.js` to post test results to a GitHub PR. - Added more entries to `default.json` +- Added test retry support - Save `test-results.json` from test runs to the `tests/e2e` folder. -- Added `await` for every call to `shopper.logout` -- Updated `getLatestReleaseZipUrl()` to allow passing in an authorization token and simplified arguments to just the repository name - Added `upload.ini` which increases the limits for uploading files (such as for plugins) in the Docker environment - Test setup, scaffolding, and removal via `wc-e2e install` and `wc-e2e uninstall` -- Added quotes around `WORDPRESS_TITLE` value in .env file to address issue with docker compose 2 "key cannot contain a space" error. - Added `LATEST_WP_VERSION_MINUS` that allows setting a number to subtract from the current WordPress version for the WordPress Docker image. - Support for PHP_VERSION, MARIADB_VERSION environment variables for built in container initialization -- `resolveLocalE2ePath` to resolve path to local E2E file +- `resolveLocalE2ePath()` to resolve path to local E2E file +- `resolvePackagePath()` to resolve path to package file - `WC_E2E_FOLDER` for mapping plugin root to path within repo -- Added the `resolveSingleE2EPath` method which builds a path to a specific E2E test +- Added the `resolveSingleE2EPath()` method which builds a path to a specific E2E test - Added the ability to take screenshots from multiple test failures (when retried) in `utils/take-screenshot.js`. ## Changed - Updated `getLatestReleaseZipUrl()` to allow passing in an authorization token and simplified arguments to just the repository name +- Updated `deleteDownloadedPluginFiles()` to also be able to delete directories. ## Fixed - Updated the browserViewport in `jest.setup.js` to match the `defaultViewport` dimensions defined in `jest-puppeteer.config.js` - Use consistent `defaultViewport` in both headless and non-headless context +- Fixed issue with docker compose 2 "key cannot contain a space" error. - Add missing `config` dependency # 0.2.3 diff --git a/packages/js/e2e-utils/CHANGELOG.md b/packages/js/e2e-utils/CHANGELOG.md index d5f40537e1c..bae80153843 100644 --- a/packages/js/e2e-utils/CHANGELOG.md +++ b/packages/js/e2e-utils/CHANGELOG.md @@ -4,10 +4,6 @@ - Identified the default product category using `slug == 'uncategorized'` in `deleteAllProductCategories` -## Changes - -- Removed `page.waitForNavigation()` from `shopper.logout()` - ## Added - `utils.waitForTimeout( delay )` pause processing for `delay` milliseconds @@ -15,8 +11,6 @@ - Update `shopper.addToCartFromShopPage()` and `.removeFromCart()` to accept product Id or Title - Added `deleteAllProductAttributes()`, `deleteAllProductCategories()`, and `deleteAllProductTags()` to clean up meta data added when products are imported - Added `withRestApi.createProductCategory()` that creates a product category and returns the ID -- `deleteAllProductAttributes()`, `deleteAllProductCategories()`, and `deleteAllProductTags()` to clean up meta data added when products are imported -- `withRestApi.createProductCategory()` that creates a product category and returns the ID - `withRestApi.deleteCoupon()` that deletes a single coupon - `withRestApi.addTaxClasses()` that adds an array of tax classes if they do not exist - `withRestApi.addTaxRates()` that adds an array of tax rates if they do not exist From 5ba1ceefcc403c1a6df007f3158ee265b876c69d Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 2 Feb 2022 15:43:58 -0400 Subject: [PATCH 09/25] refresh pnpm lock --- pnpm-lock.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1159a4a69a..b1adb802284 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -163,6 +163,7 @@ importers: jest-puppeteer: ^4.4.0 ndb: ^1.1.5 node-stream-zip: ^1.13.6 + puppeteer: 2.1.1 readline-sync: ^1.4.10 request: ^2.88.2 semver: ^7.3.2 @@ -172,7 +173,7 @@ importers: '@jest/test-sequencer': 25.5.4 '@slack/web-api': 6.5.1 '@woocommerce/api': link:../api - '@wordpress/e2e-test-utils': 4.16.1_jest@25.5.4 + '@wordpress/e2e-test-utils': 4.16.1_jest@25.5.4+puppeteer@2.1.1 '@wordpress/jest-preset-default': 7.1.3_@babel+core@7.12.9+jest@25.5.4 app-root-path: 3.0.0 commander: 4.1.1 @@ -180,8 +181,9 @@ importers: jest: 25.5.4 jest-circus: 25.1.0 jest-each: 25.5.0 - jest-puppeteer: 4.4.0 + jest-puppeteer: 4.4.0_puppeteer@2.1.1 node-stream-zip: 1.15.0 + puppeteer: 2.1.1 readline-sync: 1.4.10 request: 2.88.2 sprintf-js: 1.1.2 @@ -5346,7 +5348,7 @@ packages: - react-native dev: false - /@wordpress/e2e-test-utils/4.16.1_jest@25.5.4: + /@wordpress/e2e-test-utils/4.16.1_jest@25.5.4+puppeteer@2.1.1: resolution: {integrity: sha512-Dpsq5m0VSvjIhro2MjACSzkOkOf1jGEryzgEMW1ikbT6YI+motspHfGtisKXgYhZJOnjV4PwuEg+9lPVnd971g==} engines: {node: '>=8'} peerDependencies: @@ -5359,6 +5361,7 @@ packages: jest: 25.5.4 lodash: 4.17.21 node-fetch: 2.6.5 + puppeteer: 2.1.1 transitivePeerDependencies: - react-native dev: false @@ -13271,13 +13274,14 @@ packages: jest-resolve: 27.3.1 dev: true - /jest-puppeteer/4.4.0: + /jest-puppeteer/4.4.0_puppeteer@2.1.1: resolution: {integrity: sha512-ZaiCTlPZ07B9HW0erAWNX6cyzBqbXMM7d2ugai4epBDKpKvRDpItlRQC6XjERoJELKZsPziFGS0OhhUvTvQAXA==} peerDependencies: puppeteer: '>= 1.5.0 < 3' dependencies: expect-puppeteer: 4.4.0 jest-environment-puppeteer: 4.4.0 + puppeteer: 2.1.1 transitivePeerDependencies: - supports-color dev: false From 779568223290690a56a1cfbe2947879ffe73588d Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Thu, 3 Feb 2022 09:47:54 +0100 Subject: [PATCH 10/25] Add database indices for the product attributes lookup table. These are intended to improve the performance of the table querying when there's a lot of products and attributes, see: https://github.com/woocommerce/woocommerce/issues/31688 The indices will be created during the database migration to v6.3, regardless of whether the lookup table already existed at that point or not. --- .../includes/wc-update-functions.php | 10 +++-- .../DataRegenerator.php | 38 ++++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/plugins/woocommerce/includes/wc-update-functions.php b/plugins/woocommerce/includes/wc-update-functions.php index dc2ba87b364..014f4a04a3f 100644 --- a/plugins/woocommerce/includes/wc-update-functions.php +++ b/plugins/woocommerce/includes/wc-update-functions.php @@ -2345,13 +2345,15 @@ function wc_update_600_db_version() { * @return false Always false, since the LookupDataStore class handles all the data filling process. */ function wc_update_630_create_product_attributes_lookup_table() { - $data_store = wc_get_container()->get( LookupDataStore::class ); + $data_store = wc_get_container()->get( LookupDataStore::class ); + $data_regenerator = wc_get_container()->get( DataRegenerator::class ); + if ( $data_store->check_lookup_table_exists() ) { - return false; + $data_regenerator->maybe_create_table_indices(); + } else { + $data_regenerator->initiate_regeneration(); } - $data_regenerator = wc_get_container()->get( DataRegenerator::class ); - $data_regenerator->initiate_regeneration(); return false; } diff --git a/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php b/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php index 45e9adb37bd..5ac0ba0f6a9 100644 --- a/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php +++ b/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php @@ -141,6 +141,8 @@ CREATE TABLE ' . $this->lookup_table_name . '( ); // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared + $this->maybe_create_table_indices(); + $last_existing_product_id = WC()->call_function( 'wc_get_products', @@ -165,6 +167,41 @@ CREATE TABLE ' . $this->lookup_table_name . '( return true; } + /** + * Create the indices for the lookup table unless they exist already. + */ + public function maybe_create_table_indices() { + global $wpdb; + + // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( + " +IF (SELECT COUNT(1) + FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_schema=' " . $wpdb->dbname . "' + AND table_name='" . $this->lookup_table_name . "' + AND index_name='product_or_parent_id_term_id')=0 +THEN + ALTER TABLE wp_wc_product_attributes_lookup + ADD INDEX product_or_parent_id_term_id (product_or_parent_id, term_id); +END IF;" + ); + + $wpdb->query( + " +IF (SELECT COUNT(1) + FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_schema=' " . $wpdb->dbname . "' + AND table_name='" . $this->lookup_table_name . "' + AND index_name='is_variation_attribute_term_id')=0 +THEN + ALTER TABLE wp_wc_product_attributes_lookup + ADD INDEX is_variation_attribute_term_id (is_variation_attribute, term_id); +END IF;" + ); + // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared + } + /** * Action scheduler callback, performs one regeneration step and then * schedules the next step if necessary. @@ -247,7 +284,6 @@ CREATE TABLE ' . $this->lookup_table_name . '( * Cleanup/final option setup after the regeneration has been completed. * * @param bool $enable_usage Whether the table usage should be enabled or not. - * */ private function finalize_regeneration( bool $enable_usage ) { delete_option( 'woocommerce_attribute_lookup_last_product_id_to_process' ); From 434de6aa19fe15a477a94862f9b5dfab8facf503 Mon Sep 17 00:00:00 2001 From: Philipp Bammes <8144115+tyrann0us@users.noreply.github.com> Date: Thu, 3 Feb 2022 20:05:46 +0100 Subject: [PATCH 11/25] Add states for Germany Source: https://github.com/unicode-org/cldr/blob/666bcce731281e5bbc45e342e427d7200ee6d363/common/subdivisions/en.xml#L1090-L1106 --- plugins/woocommerce/i18n/states.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce/i18n/states.php b/plugins/woocommerce/i18n/states.php index a0ebe7f452c..4d6ee012276 100644 --- a/plugins/woocommerce/i18n/states.php +++ b/plugins/woocommerce/i18n/states.php @@ -380,7 +380,24 @@ return array( 'CR-SJ' => __( 'San José', 'woocommerce' ), ), 'CZ' => array(), - 'DE' => array(), + 'DE' => array( + 'DE-BW' => __( 'Baden-Württemberg', 'woocommerce' ), + 'DE-BY' => __( 'Bavaria', 'woocommerce' ), + 'DE-BE' => __( 'Berlin', 'woocommerce' ), + 'DE-BB' => __( 'Brandenburg', 'woocommerce' ), + 'DE-HB' => __( 'Bremen', 'woocommerce' ), + 'DE-HH' => __( 'Hamburg', 'woocommerce' ), + 'DE-HE' => __( 'Hesse', 'woocommerce' ), + 'DE-MV' => __( 'Mecklenburg-Vorpommern', 'woocommerce' ), + 'DE-NI' => __( 'Lower Saxony', 'woocommerce' ), + 'DE-NW' => __( 'North Rhine-Westphalia', 'woocommerce' ), + 'DE-RP' => __( 'Rhineland-Palatinate', 'woocommerce' ), + 'DE-SL' => __( 'Saarland', 'woocommerce' ), + 'DE-SN' => __( 'Saxony', 'woocommerce' ), + 'DE-ST' => __( 'Saxony-Anhalt', 'woocommerce' ), + 'DE-SH' => __( 'Schleswig-Holstein', 'woocommerce' ), + 'DE-TH' => __( 'Thuringia', 'woocommerce' ), + ), 'DK' => array(), 'DO' => array( // Dominican Republic. 'DO-01' => __( 'Distrito Nacional', 'woocommerce' ), From 14ce6090b045b1b59d382651613d6c761a5be756 Mon Sep 17 00:00:00 2001 From: Philipp Bammes <8144115+tyrann0us@users.noreply.github.com> Date: Thu, 3 Feb 2022 20:35:13 +0100 Subject: [PATCH 12/25] Align notion for country states in PHP comments Use adjectival form of country names, lowercase "states" etc., end with period, remove reference links. --- plugins/woocommerce/i18n/states.php | 106 +++++++++++++--------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/plugins/woocommerce/i18n/states.php b/plugins/woocommerce/i18n/states.php index 4d6ee012276..764c42de999 100644 --- a/plugins/woocommerce/i18n/states.php +++ b/plugins/woocommerce/i18n/states.php @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; return array( 'AF' => array(), - 'AL' => array( // Albania states. + 'AL' => array( // Albanian states. 'AL-01' => __( 'Berat', 'woocommerce' ), 'AL-09' => __( 'Dibër', 'woocommerce' ), 'AL-02' => __( 'Durrës', 'woocommerce' ), @@ -29,7 +29,7 @@ return array( 'AL-11' => __( 'Tirana', 'woocommerce' ), 'AL-12' => __( 'Vlorë', 'woocommerce' ), ), - 'AO' => array( // Angola states. + 'AO' => array( // Angolan states. 'BGO' => __( 'Bengo', 'woocommerce' ), 'BLU' => __( 'Benguela', 'woocommerce' ), 'BIE' => __( 'Bié', 'woocommerce' ), @@ -87,7 +87,7 @@ return array( 'WA' => __( 'Western Australia', 'woocommerce' ), ), 'AX' => array(), - 'BD' => array( // Bangladeshi states (districts). + 'BD' => array( // Bangladeshi districts. 'BD-05' => __( 'Bagerhat', 'woocommerce' ), 'BD-01' => __( 'Bandarban', 'woocommerce' ), 'BD-02' => __( 'Barguna', 'woocommerce' ), @@ -186,7 +186,7 @@ return array( ), 'BH' => array(), 'BI' => array(), - 'BJ' => array( // Benin states. + 'BJ' => array( // Beninese states. 'AL' => __( 'Alibori', 'woocommerce' ), 'AK' => __( 'Atakora', 'woocommerce' ), 'AQ' => __( 'Atlantique', 'woocommerce' ), @@ -211,7 +211,7 @@ return array( 'BO-S' => __( 'Santa Cruz', 'woocommerce' ), 'BO-T' => __( 'Tarija', 'woocommerce' ), ), - 'BR' => array( // Brazillian states. + 'BR' => array( // Brazilian states. 'AC' => __( 'Acre', 'woocommerce' ), 'AL' => __( 'Alagoas', 'woocommerce' ), 'AP' => __( 'Amapá', 'woocommerce' ), @@ -255,7 +255,7 @@ return array( 'SK' => __( 'Saskatchewan', 'woocommerce' ), 'YT' => __( 'Yukon Territory', 'woocommerce' ), ), - 'CH' => array( // Cantons of Switzerland. + 'CH' => array( // Swiss cantons. 'AG' => __( 'Aargau', 'woocommerce' ), 'AR' => __( 'Appenzell Ausserrhoden', 'woocommerce' ), 'AI' => __( 'Appenzell Innerrhoden', 'woocommerce' ), @@ -283,7 +283,7 @@ return array( 'ZG' => __( 'Zug', 'woocommerce' ), 'ZH' => __( 'Zürich', 'woocommerce' ), ), - 'CL' => array( // Chile states. + 'CL' => array( // Chilean states. 'CL-AI' => __( 'Aisén del General Carlos Ibañez del Campo', 'woocommerce' ), 'CL-AN' => __( 'Antofagasta', 'woocommerce' ), 'CL-AP' => __( 'Arica y Parinacota', 'woocommerce' ), @@ -335,7 +335,7 @@ return array( 'CN31' => __( 'Tibet / 西藏', 'woocommerce' ), 'CN32' => __( 'Xinjiang / 新疆', 'woocommerce' ), ), - 'CO' => array( // Colombia States. + 'CO' => array( // Colombian states. 'CO-AMA' => __( 'Amazonas', 'woocommerce' ), 'CO-ANT' => __( 'Antioquia', 'woocommerce' ), 'CO-ARA' => __( 'Arauca', 'woocommerce' ), @@ -370,7 +370,7 @@ return array( 'CO-VAU' => __( 'Vaupés', 'woocommerce' ), 'CO-VID' => __( 'Vichada', 'woocommerce' ), ), - 'CR' => array( // Costa Rica states. + 'CR' => array( // Costa Rican states. 'CR-A' => __( 'Alajuela', 'woocommerce' ), 'CR-C' => __( 'Cartago', 'woocommerce' ), 'CR-G' => __( 'Guanacaste', 'woocommerce' ), @@ -380,7 +380,7 @@ return array( 'CR-SJ' => __( 'San José', 'woocommerce' ), ), 'CZ' => array(), - 'DE' => array( + 'DE' => array( // German states. 'DE-BW' => __( 'Baden-Württemberg', 'woocommerce' ), 'DE-BY' => __( 'Bavaria', 'woocommerce' ), 'DE-BE' => __( 'Berlin', 'woocommerce' ), @@ -399,7 +399,7 @@ return array( 'DE-TH' => __( 'Thuringia', 'woocommerce' ), ), 'DK' => array(), - 'DO' => array( // Dominican Republic. + 'DO' => array( // Dominican states. 'DO-01' => __( 'Distrito Nacional', 'woocommerce' ), 'DO-02' => __( 'Azua', 'woocommerce' ), 'DO-03' => __( 'Baoruco', 'woocommerce' ), @@ -443,7 +443,7 @@ return array( 'DO-27' => __( 'Valverde', 'woocommerce' ), 'DO-42' => __( 'Yuma', 'woocommerce' ), ), - 'DZ' => array( + 'DZ' => array( // Algerian states. 'DZ-01' => __( 'Adrar', 'woocommerce' ), 'DZ-02' => __( 'Chlef', 'woocommerce' ), 'DZ-03' => __( 'Laghouat', 'woocommerce' ), @@ -494,7 +494,7 @@ return array( 'DZ-48' => __( 'Relizane', 'woocommerce' ), ), 'EE' => array(), - 'EC' => array( // Ecuador states. + 'EC' => array( // Ecuadorian states. 'EC-A' => __( 'Azuay', 'woocommerce' ), 'EC-B' => __( 'Bolívar', 'woocommerce' ), 'EC-F' => __( 'Cañar', 'woocommerce' ), @@ -520,7 +520,7 @@ return array( 'EC-T' => __( 'Tungurahua', 'woocommerce' ), 'EC-Z' => __( 'Zamora-Chinchipe', 'woocommerce' ), ), - 'EG' => array( // Egypt states. + 'EG' => array( // Egyptian states. 'EGALX' => __( 'Alexandria', 'woocommerce' ), 'EGASN' => __( 'Aswan', 'woocommerce' ), 'EGAST' => __( 'Asyut', 'woocommerce' ), @@ -606,7 +606,7 @@ return array( 'FI' => array(), 'FR' => array(), 'GF' => array(), - 'GH' => array( // Ghanaian Regions. + 'GH' => array( // Ghanaian regions. 'AF' => __( 'Ahafo', 'woocommerce' ), 'AH' => __( 'Ashanti', 'woocommerce' ), 'BA' => __( 'Brong-Ahafo', 'woocommerce' ), @@ -626,7 +626,7 @@ return array( 'WN' => __( 'Western North', 'woocommerce' ), ), 'GP' => array(), - 'GR' => array( // Greek Regions. + 'GR' => array( // Greek regions. 'I' => __( 'Attica', 'woocommerce' ), 'A' => __( 'East Macedonia and Thrace', 'woocommerce' ), 'B' => __( 'Central Macedonia', 'woocommerce' ), @@ -670,7 +670,7 @@ return array( 'KOWLOON' => __( 'Kowloon', 'woocommerce' ), 'NEW TERRITORIES' => __( 'New Territories', 'woocommerce' ), ), - 'HN' => array( // Honduras states. + 'HN' => array( // Honduran states. 'HN-AT' => __( 'Atlántida', 'woocommerce' ), 'HN-IB' => __( 'Bay Islands', 'woocommerce' ), 'HN-CH' => __( 'Choluteca', 'woocommerce' ), @@ -690,7 +690,7 @@ return array( 'HN-VA' => __( 'Valle', 'woocommerce' ), 'HN-YO' => __( 'Yoro', 'woocommerce' ), ), - 'HU' => array( // Hungary states. + 'HU' => array( // Hungarian states. 'BK' => __( 'Bács-Kiskun', 'woocommerce' ), 'BE' => __( 'Békés', 'woocommerce' ), 'BA' => __( 'Baranya', 'woocommerce' ), @@ -712,7 +712,7 @@ return array( 'VE' => __( 'Veszprém', 'woocommerce' ), 'ZA' => __( 'Zala', 'woocommerce' ), ), - 'ID' => array( // Indonesia Provinces. + 'ID' => array( // Indonesian provinces. 'AC' => __( 'Daerah Istimewa Aceh', 'woocommerce' ), 'SU' => __( 'Sumatera Utara', 'woocommerce' ), 'SB' => __( 'Sumatera Barat', 'woocommerce' ), @@ -748,7 +748,7 @@ return array( 'PA' => __( 'Papua', 'woocommerce' ), 'PB' => __( 'Papua Barat', 'woocommerce' ), ), - 'IE' => array( // Republic of Ireland. + 'IE' => array( // Irish states. 'CW' => __( 'Carlow', 'woocommerce' ), 'CN' => __( 'Cavan', 'woocommerce' ), 'CE' => __( 'Clare', 'woocommerce' ), @@ -815,7 +815,7 @@ return array( 'LD' => __( 'Lakshadeep', 'woocommerce' ), 'PY' => __( 'Pondicherry (Puducherry)', 'woocommerce' ), ), - 'IR' => array( // Iran States. + 'IR' => array( // Irania states. 'KHZ' => __( 'Khuzestan (خوزستان)', 'woocommerce' ), 'THR' => __( 'Tehran (تهران)', 'woocommerce' ), 'ILM' => __( 'Ilaam (ایلام)', 'woocommerce' ), @@ -849,7 +849,7 @@ return array( 'SBN' => __( 'Sistan and Baluchestan (سیستان و بلوچستان)', 'woocommerce' ), ), 'IS' => array(), - 'IT' => array( // Italy Provinces. + 'IT' => array( // Italian provinces. 'AG' => __( 'Agrigento', 'woocommerce' ), 'AL' => __( 'Alessandria', 'woocommerce' ), 'AN' => __( 'Ancona', 'woocommerce' ), @@ -960,7 +960,7 @@ return array( ), 'IL' => array(), 'IM' => array(), - 'JM' => array( // Jamaica's Parishes. Ref: https://en.wikipedia.org/wiki/ISO_3166-2:JM. + 'JM' => array( // Jamaican parishes. 'JM-01' => __( 'Kingston', 'woocommerce' ), 'JM-02' => __( 'Saint Andrew', 'woocommerce' ), 'JM-03' => __( 'Saint Thomas', 'woocommerce' ), @@ -978,7 +978,7 @@ return array( ), /** - * Japan States. + * Japanese states. * * English notation of prefectures conform to the notation of Japan Post. * The suffix corresponds with the Japanese translation file. @@ -1032,7 +1032,7 @@ return array( 'JP46' => __( 'Kagoshima', 'woocommerce' ), 'JP47' => __( 'Okinawa', 'woocommerce' ), ), - 'KE' => array( // Kenya counties. + 'KE' => array( // Kenyan counties. 'KE01' => __( 'Baringo', 'woocommerce' ), 'KE02' => __( 'Bomet', 'woocommerce' ), 'KE03' => __( 'Bungoma', 'woocommerce' ), @@ -1083,7 +1083,7 @@ return array( ), 'KR' => array(), 'KW' => array(), - 'LA' => array( + 'LA' => array( // Laotian provinces. 'AT' => __( 'Attapeu', 'woocommerce' ), 'BK' => __( 'Bokeo', 'woocommerce' ), 'BL' => __( 'Bolikhamsai', 'woocommerce' ), @@ -1104,7 +1104,7 @@ return array( 'XS' => __( 'Xaisomboun', 'woocommerce' ), ), 'LB' => array(), - 'LR' => array( // Liberia provinces. + 'LR' => array( // Liberian provinces. 'BM' => __( 'Bomi', 'woocommerce' ), 'BN' => __( 'Bong', 'woocommerce' ), 'GA' => __( 'Gbarpolu', 'woocommerce' ), @@ -1122,7 +1122,7 @@ return array( 'SN' => __( 'Sinoe', 'woocommerce' ), ), 'LU' => array(), - 'MD' => array( // Moldova states. + 'MD' => array( // Moldovan states. 'C' => __( 'Chișinău', 'woocommerce' ), 'BL' => __( 'Bălți', 'woocommerce' ), 'AN' => __( 'Anenii Noi', 'woocommerce' ), @@ -1161,7 +1161,7 @@ return array( ), 'MQ' => array(), 'MT' => array(), - 'MX' => array( // Mexico States. + 'MX' => array( // Mexican states. 'DF' => __( 'Ciudad de México', 'woocommerce' ), 'JA' => __( 'Jalisco', 'woocommerce' ), 'NL' => __( 'Nuevo León', 'woocommerce' ), @@ -1213,7 +1213,7 @@ return array( 'PJY' => __( 'Putrajaya', 'woocommerce' ), 'KUL' => __( 'Kuala Lumpur', 'woocommerce' ), ), - 'MZ' => array( // Mozambique provinces. + 'MZ' => array( // Mozambican provinces. 'MZP' => __( 'Cabo Delgado', 'woocommerce' ), 'MZG' => __( 'Gaza', 'woocommerce' ), 'MZI' => __( 'Inhambane', 'woocommerce' ), @@ -1226,7 +1226,7 @@ return array( 'MZT' => __( 'Tete', 'woocommerce' ), 'MZQ' => __( 'Zambézia', 'woocommerce' ), ), - 'NA' => array( // Namibia regions. + 'NA' => array( // Namibian regions. 'ER' => __( 'Erongo', 'woocommerce' ), 'HA' => __( 'Hardap', 'woocommerce' ), 'KA' => __( 'Karas', 'woocommerce' ), @@ -1283,7 +1283,7 @@ return array( ), 'NL' => array(), 'NO' => array(), - 'NP' => array( // Nepal states (Zones). + 'NP' => array( // Nepalese zones. 'BAG' => __( 'Bagmati', 'woocommerce' ), 'BHE' => __( 'Bheri', 'woocommerce' ), 'DHA' => __( 'Dhaulagiri', 'woocommerce' ), @@ -1299,7 +1299,7 @@ return array( 'SAG' => __( 'Sagarmatha', 'woocommerce' ), 'SET' => __( 'Seti', 'woocommerce' ), ), - 'NI' => array( // Nicaragua states + 'NI' => array( // Nicaraguan states. 'NI-AN' => __( 'Atlántico Norte', 'woocommerce' ), 'NI-AS' => __( 'Atlántico Sur', 'woocommerce' ), 'NI-BO' => __( 'Boaco', 'woocommerce' ), @@ -1318,7 +1318,7 @@ return array( 'NI-RI' => __( 'Rivas', 'woocommerce' ), 'NI-SJ' => __( 'Río San Juan', 'woocommerce' ), ), - 'NZ' => array( // New Zealand States. + 'NZ' => array( // New Zealand states. 'NL' => __( 'Northland', 'woocommerce' ), 'AK' => __( 'Auckland', 'woocommerce' ), 'WA' => __( 'Waikato', 'woocommerce' ), @@ -1336,7 +1336,7 @@ return array( 'OT' => __( 'Otago', 'woocommerce' ), 'SL' => __( 'Southland', 'woocommerce' ), ), - 'PA' => array( // Panama states. + 'PA' => array( // Panamanian states. 'PA-1' => __( 'Bocas del Toro', 'woocommerce' ), 'PA-2' => __( 'Coclé', 'woocommerce' ), 'PA-3' => __( 'Colón', 'woocommerce' ), @@ -1351,7 +1351,7 @@ return array( 'PA-KY' => __( 'Guna Yala', 'woocommerce' ), 'PA-NB' => __( 'Ngöbe-Buglé', 'woocommerce' ), ), - 'PE' => array( // Peru states. + 'PE' => array( // Peruvian states. 'CAL' => __( 'El Callao', 'woocommerce' ), 'LMA' => __( 'Municipalidad Metropolitana de Lima', 'woocommerce' ), 'AMA' => __( 'Amazonas', 'woocommerce' ), @@ -1379,11 +1379,7 @@ return array( 'TUM' => __( 'Tumbes', 'woocommerce' ), 'UCA' => __( 'Ucayali', 'woocommerce' ), ), - - /** - * Philippine Provinces. - */ - 'PH' => array( + 'PH' => array( // Philippine provinces. 'ABR' => __( 'Abra', 'woocommerce' ), 'AGN' => __( 'Agusan del Norte', 'woocommerce' ), 'AGS' => __( 'Agusan del Sur', 'woocommerce' ), @@ -1467,7 +1463,7 @@ return array( 'ZSI' => __( 'Zamboanga Sibugay', 'woocommerce' ), '00' => __( 'Metro Manila', 'woocommerce' ), ), - 'PK' => array( // Pakistan's states. + 'PK' => array( // Pakistani states. 'JK' => __( 'Azad Kashmir', 'woocommerce' ), 'BA' => __( 'Balochistan', 'woocommerce' ), 'TA' => __( 'FATA', 'woocommerce' ), @@ -1480,7 +1476,7 @@ return array( 'PL' => array(), 'PR' => array(), 'PT' => array(), - 'PY' => array( // Paraguay states. + 'PY' => array( // Paraguayan states. 'PY-ASU' => __( 'Asunción', 'woocommerce' ), 'PY-1' => __( 'Concepción', 'woocommerce' ), 'PY-2' => __( 'San Pedro', 'woocommerce' ), @@ -1501,7 +1497,7 @@ return array( 'PY-17' => __( 'Boquerón', 'woocommerce' ), ), 'RE' => array(), - 'RO' => array( // Romania states. + 'RO' => array( // Romanian states. 'AB' => __( 'Alba', 'woocommerce' ), 'AR' => __( 'Arad', 'woocommerce' ), 'AG' => __( 'Argeș', 'woocommerce' ), @@ -1548,7 +1544,7 @@ return array( 'SG' => array(), 'SK' => array(), 'SI' => array(), - 'SV' => array( // El Salvador states. + 'SV' => array( // Salvadoran states. 'SV-AH' => __( 'Ahuachapán', 'woocommerce' ), 'SV-CA' => __( 'Cabañas', 'woocommerce' ), 'SV-CH' => __( 'Chalatenango', 'woocommerce' ), @@ -1564,7 +1560,7 @@ return array( 'SV-UN' => __( 'La Unión', 'woocommerce' ), 'SV-US' => __( 'Usulután', 'woocommerce' ), ), - 'TH' => array( // Thailand states. + 'TH' => array( // Thai states. 'TH-37' => __( 'Amnat Charoen', 'woocommerce' ), 'TH-15' => __( 'Ang Thong', 'woocommerce' ), 'TH-14' => __( 'Ayutthaya', 'woocommerce' ), @@ -1643,7 +1639,7 @@ return array( 'TH-95' => __( 'Yala', 'woocommerce' ), 'TH-35' => __( 'Yasothon', 'woocommerce' ), ), - 'TR' => array( // Turkey States. + 'TR' => array( // Turkish states. 'TR01' => __( 'Adana', 'woocommerce' ), 'TR02' => __( 'Adıyaman', 'woocommerce' ), 'TR03' => __( 'Afyon', 'woocommerce' ), @@ -1726,7 +1722,7 @@ return array( 'TR80' => __( 'Osmaniye', 'woocommerce' ), 'TR81' => __( 'Düzce', 'woocommerce' ), ), - 'TZ' => array( // Tanzania States. + 'TZ' => array( // Tanzanian states. 'TZ01' => __( 'Arusha', 'woocommerce' ), 'TZ02' => __( 'Dar es Salaam', 'woocommerce' ), 'TZ03' => __( 'Dodoma', 'woocommerce' ), @@ -1759,7 +1755,7 @@ return array( 'TZ30' => __( 'Simiyu', 'woocommerce' ), ), 'LK' => array(), - 'RS' => array( // Serbia districts. Ref: https://github.com/unicode-org/cldr/blob/release-37/common/subdivisions/en.xml#L4251-L4283. + 'RS' => array( // Serbian districts. 'RS00' => _x( 'Belgrade', 'district', 'woocommerce' ), 'RS14' => _x( 'Bor', 'district', 'woocommerce' ), 'RS11' => _x( 'Braničevo', 'district', 'woocommerce' ), @@ -1794,7 +1790,7 @@ return array( 'RSVO' => _x( 'Vojvodina', 'district', 'woocommerce' ), ), 'SE' => array(), - 'UA' => array( // Ukraine. Ref: https://en.wikipedia.org/wiki/Oblasts_of_Ukraine. + 'UA' => array( // Ukrainian oblasts. 'VN' => __( 'Vinnytsia Oblast', 'woocommerce' ), 'VL' => __( 'Volyn Oblast', 'woocommerce' ), 'DP' => __( 'Dnipropetrovsk Oblast', 'woocommerce' ), @@ -1820,7 +1816,7 @@ return array( 'CH' => __( 'Chernihiv Oblast', 'woocommerce' ), 'CV' => __( 'Chernivtsi Oblast', 'woocommerce' ), ), - 'UG' => array( // Uganda districts. Ref: https://en.wikipedia.org/wiki/ISO_3166-2:UG. + 'UG' => array( // Ugandan districts. 'UG314' => __( 'Abim', 'woocommerce' ), 'UG301' => __( 'Adjumani', 'woocommerce' ), 'UG322' => __( 'Agago', 'woocommerce' ), @@ -1961,7 +1957,7 @@ return array( '95' => __( 'Palmyra Atoll', 'woocommerce' ), '79' => __( 'Wake Island', 'woocommerce' ), ), - 'US' => array( // United States. + 'US' => array( // U.S. states. 'AL' => __( 'Alabama', 'woocommerce' ), 'AK' => __( 'Alaska', 'woocommerce' ), 'AZ' => __( 'Arizona', 'woocommerce' ), @@ -2017,7 +2013,7 @@ return array( 'AE' => __( 'Armed Forces (AE)', 'woocommerce' ), 'AP' => __( 'Armed Forces (AP)', 'woocommerce' ), ), - 'UY' => array( // Uruguay States. + 'UY' => array( // Uruguayan states. 'UY-AR' => __( 'Artigas', 'woocommerce' ), 'UY-CA' => __( 'Canelones', 'woocommerce' ), 'UY-CL' => __( 'Cerro Largo', 'woocommerce' ), @@ -2038,7 +2034,7 @@ return array( 'UY-TA' => __( 'Tacuarembó', 'woocommerce' ), 'UY-TT' => __( 'Treinta y Tres', 'woocommerce' ), ), - 'VE' => array( // Venezuela States. + 'VE' => array( // Venezuelan states. 'VE-A' => __( 'Capital', 'woocommerce' ), 'VE-B' => __( 'Anzoátegui', 'woocommerce' ), 'VE-C' => __( 'Apure', 'woocommerce' ), @@ -2078,7 +2074,7 @@ return array( 'NW' => __( 'North West', 'woocommerce' ), 'WC' => __( 'Western Cape', 'woocommerce' ), ), - 'ZM' => array( // Zambia's Provinces. Ref: https://en.wikipedia.org/wiki/ISO_3166-2:ZM. + 'ZM' => array( // Zambian provinces. 'ZM-01' => __( 'Western', 'woocommerce' ), 'ZM-02' => __( 'Central', 'woocommerce' ), 'ZM-03' => __( 'Eastern', 'woocommerce' ), From 1688d66484f1c6e10d69ae2e68b2f43ce0c9635f Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Thu, 3 Feb 2022 20:35:03 -0300 Subject: [PATCH 13/25] Avoid calling substr method on undefined Co-authored-by: Jamel Noel Reid --- packages/js/e2e-environment/bin/scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index 51915c2f155..db6a1ad111e 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -27,7 +27,7 @@ const args = process.argv.slice( 2 ); const command = args[0]; let packageName = null; -if (args[1].substr(0, 2) !== '--') { +if ( args[1] && args[1].substr(0, 2) !== '--') { packageName = args[1]; } From f9c90b87ef0412bc2483f0bfae1fff495405e5be Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Thu, 3 Feb 2022 20:36:18 -0300 Subject: [PATCH 14/25] Space for consistency --- packages/js/e2e-environment/bin/scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index db6a1ad111e..7384e9f5c41 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -27,7 +27,7 @@ const args = process.argv.slice( 2 ); const command = args[0]; let packageName = null; -if ( args[1] && args[1].substr(0, 2) !== '--') { +if ( args[1] && args[1].substr(0, 2) !== '--' ) { packageName = args[1]; } From 345faa6ea566df8dff4871638c0a106f8a3e9a5d Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Thu, 3 Feb 2022 20:47:14 -0300 Subject: [PATCH 15/25] Skip confirmation for test files as well with --force --- packages/js/e2e-environment/bin/scaffold.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index 7384e9f5c41..ca5f4491e05 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -107,13 +107,16 @@ if ( command == 'install' ) { const eol = "\n"; const autoGenerate = sprintf( '/* This file was auto-generated by the command `npx wc-e2e install %s`. */', packageName ); let importLineFormat; - let overwriteFiles; let confirmPrompt; if ( testFormat.toLowerCase() == 'cjs' ) { importLineFormat = sprintf( "const {%%s} = require( '%s' );", pkg ); } else { importLineFormat = sprintf( "import {%%s} from '%s';", pkg ); } + let overwriteFiles; + if (force) { + overwriteFiles = 'a'; + } // Create the specs folder if not present let specFolderPath = createLocalE2ePath( 'specs' ); From a2e3e31bd03b59c7674ba59dfa4eacb2762da631 Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Fri, 4 Feb 2022 10:27:51 +0100 Subject: [PATCH 16/25] Create indices in a stored procedure so that IF...THEN can be used. --- .../DataRegenerator.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php b/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php index 5ac0ba0f6a9..615aa18d317 100644 --- a/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php +++ b/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php @@ -174,31 +174,39 @@ CREATE TABLE ' . $this->lookup_table_name . '( global $wpdb; // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( 'DROP PROCEDURE IF EXISTS __create_wc_product_attributes_lookup_indices;' ); $wpdb->query( " +CREATE PROCEDURE __create_wc_product_attributes_lookup_indices() + +BEGIN + IF (SELECT COUNT(1) FROM INFORMATION_SCHEMA.STATISTICS - WHERE table_schema=' " . $wpdb->dbname . "' + WHERE table_schema='" . $wpdb->dbname . "' AND table_name='" . $this->lookup_table_name . "' AND index_name='product_or_parent_id_term_id')=0 THEN - ALTER TABLE wp_wc_product_attributes_lookup + ALTER TABLE " . $this->lookup_table_name . " ADD INDEX product_or_parent_id_term_id (product_or_parent_id, term_id); -END IF;" - ); +END IF; - $wpdb->query( - " IF (SELECT COUNT(1) FROM INFORMATION_SCHEMA.STATISTICS - WHERE table_schema=' " . $wpdb->dbname . "' + WHERE table_schema='" . $wpdb->dbname . "' AND table_name='" . $this->lookup_table_name . "' AND index_name='is_variation_attribute_term_id')=0 THEN - ALTER TABLE wp_wc_product_attributes_lookup + ALTER TABLE " . $this->lookup_table_name . ' ADD INDEX is_variation_attribute_term_id (is_variation_attribute, term_id); -END IF;" +END IF; + +END; +' ); + + $wpdb->query( 'CALL __create_wc_product_attributes_lookup_indices();' ); + $wpdb->query( 'DROP PROCEDURE IF EXISTS __create_wc_product_attributes_lookup_indices;' ); // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared } From 4c8c792869c058754886ef1ea379c2de1667a50d Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Fri, 4 Feb 2022 12:20:59 -0300 Subject: [PATCH 17/25] CR: Spacing --- packages/js/e2e-environment/bin/scaffold.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/js/e2e-environment/bin/scaffold.js b/packages/js/e2e-environment/bin/scaffold.js index ca5f4491e05..8e44b09fb57 100755 --- a/packages/js/e2e-environment/bin/scaffold.js +++ b/packages/js/e2e-environment/bin/scaffold.js @@ -24,11 +24,11 @@ const { } = require( '../utils/scaffold' ); const args = process.argv.slice( 2 ); -const command = args[0]; +const command = args[ 0 ]; let packageName = null; -if ( args[1] && args[1].substr(0, 2) !== '--' ) { - packageName = args[1]; +if ( args[ 1 ] && args[ 1 ].substr(0, 2) !== '--' ) { + packageName = args[ 1 ]; } // Allow multiple spec file extensions and formats. @@ -36,7 +36,7 @@ let testExtension = 'test.js'; let testFormat = ''; let force = false; for ( let a = 1; a < args.length; a++ ) { - if (args[a] === '--force') { + if ( args[ a ] === '--force' ) { force = true; continue; } @@ -62,7 +62,7 @@ for ( let a = 1; a < args.length; a++ ) { if ( command == 'install' ) { // Install some environment defaults if no package is requested. if ( ! packageName ) { - installDefaults(force); + installDefaults( force ); return; } @@ -114,7 +114,7 @@ if ( command == 'install' ) { importLineFormat = sprintf( "import {%%s} from '%s';", pkg ); } let overwriteFiles; - if (force) { + if ( force ) { overwriteFiles = 'a'; } From 6ec677643f6f76d8b7331cf94baa41ce2a9f1777 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Fri, 4 Feb 2022 12:21:57 -0300 Subject: [PATCH 18/25] CR: Spacing --- packages/js/e2e-environment/utils/scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/utils/scaffold.js b/packages/js/e2e-environment/utils/scaffold.js index 1a3aa978bae..0111959cc4f 100644 --- a/packages/js/e2e-environment/utils/scaffold.js +++ b/packages/js/e2e-environment/utils/scaffold.js @@ -103,7 +103,7 @@ const getPackageData = ( packageName ) => { /** * Install test runner and test container defaults */ -const installDefaults = (force) => { +const installDefaults = ( force ) => { createLocalE2ePath( 'docker' ); console.log( 'Writing tests/e2e/docker/initialize.sh' ); confirmLocalCopy( `docker${path.sep}initialize.sh`, `installFiles${path.sep}initialize.sh`, '', force ); From da49a03b52019300ff8e84dd073e79c463789d38 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 4 Feb 2022 12:36:45 -0400 Subject: [PATCH 19/25] bump e2e-environment to WP 5.9.X default --- packages/js/e2e-environment/bin/docker-compose.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/bin/docker-compose.sh b/packages/js/e2e-environment/bin/docker-compose.sh index ee0be868de2..45978b41019 100755 --- a/packages/js/e2e-environment/bin/docker-compose.sh +++ b/packages/js/e2e-environment/bin/docker-compose.sh @@ -10,7 +10,7 @@ if [[ $1 ]]; then if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+ ]]; then export WORDPRESS_VERSION=$WP_VERSION else - export WORDPRESS_VERSION="5.8.0" + export WORDPRESS_VERSION="5.9" fi if [[ $LATEST_WP_VERSION_MINUS ]]; then From 5c12aaa877fa852c9ba304be3c42b58dd5349748 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 4 Feb 2022 14:17:54 -0400 Subject: [PATCH 20/25] use OS path separator in installFiles --- packages/js/e2e-core-tests/installFiles/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/js/e2e-core-tests/installFiles/index.js b/packages/js/e2e-core-tests/installFiles/index.js index 6601661582c..2b77ea7cf4d 100644 --- a/packages/js/e2e-core-tests/installFiles/index.js +++ b/packages/js/e2e-core-tests/installFiles/index.js @@ -1,5 +1,12 @@ +/** + * External dependencies + */ +const path = require( 'path' ); + +const buildPath = ( filename ) => `installFiles${path.sep}${filename}`; + module.exports = { - testSpecs: 'installFiles/scaffold-tests.json', - defaultJson: 'installFiles/default-test-config.json', - initializeSh: 'installFiles/initialize.sh.default', + testSpecs: buildPath( 'scaffold-tests.json' ), + defaultJson: buildPath( 'default-test-config.json' ), + initializeSh: buildPath( 'initialize.sh.default' ), }; From 3bb27bdc795810d6b4da440ff6e81131c3d8f506 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 4 Feb 2022 14:48:56 -0400 Subject: [PATCH 21/25] update slack export to build version --- packages/js/e2e-environment/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/e2e-environment/index.js b/packages/js/e2e-environment/index.js index d7289c77e66..3d8fc201cc4 100644 --- a/packages/js/e2e-environment/index.js +++ b/packages/js/e2e-environment/index.js @@ -5,7 +5,7 @@ const babelConfig = require( './babel.config' ); const esLintConfig = require( './.eslintrc.js' ); const allE2EConfig = require( './config' ); const allE2EUtils = require( './utils' ); -const slackUtils = require( './src/slack' ); +const slackUtils = require( './build/slack' ); /** * External dependencies */ From 7428e264bdc4ed8ab5413b1d9de1b684a07f6c93 Mon Sep 17 00:00:00 2001 From: Oscar Gare Date: Sat, 5 Feb 2022 10:57:46 +0100 Subject: [PATCH 22/25] woocommerce_adjust_non_base_location_prices filter not work if there is no order --- plugins/woocommerce/includes/wc-product-functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php index 49bd021a15f..7a4811d9816 100644 --- a/plugins/woocommerce/includes/wc-product-functions.php +++ b/plugins/woocommerce/includes/wc-product-functions.php @@ -1085,10 +1085,10 @@ function wc_get_price_excluding_tax( $product, $args = array() ) { if ( $product->is_taxable() && wc_prices_include_tax() ) { $order = ArrayUtil::get_value_or_default( $args, 'order' ); $customer_id = $order ? $order->get_customer_id() : 0; - if ( apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) || ! $customer_id ) { + if ( apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ) { $tax_rates = WC_Tax::get_base_tax_rates( $product->get_tax_class( 'unfiltered' ) ); } else { - $customer = wc_get_container()->get( LegacyProxy::class )->get_instance_of( WC_Customer::class, $customer_id ); + $customer = $customer_id ? wc_get_container()->get( LegacyProxy::class )->get_instance_of( WC_Customer::class, $customer_id ) : null; $tax_rates = WC_Tax::get_rates( $product->get_tax_class(), $customer ); } $remove_taxes = WC_Tax::calc_tax( $line_price, $tax_rates, true ); From cf90bda3194cc5ad8aa743b02b0218e967321be9 Mon Sep 17 00:00:00 2001 From: Rodel Date: Wed, 9 Feb 2022 15:14:55 +0800 Subject: [PATCH 23/25] Added documentation --- packages/js/api-core-tests/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/js/api-core-tests/README.md b/packages/js/api-core-tests/README.md index 694e7e9a134..8d9f4220043 100644 --- a/packages/js/api-core-tests/README.md +++ b/packages/js/api-core-tests/README.md @@ -77,6 +77,15 @@ jest --group=api ## Writing tests +### Conventions + +1. All tests should be placed in the `tests` directory. +1. Always provide a JS doc in all tests, and tag them with `@group`. See the [Test groups](#test-groups) section for more info on grouping tests. +1. Use functions in the `data` folder when generating test data instead of constructing them from scratch within the test. +1. Use functions in the `endpoints` folder to send requests instead of directly using SuperTest's `request()` function. +1. Use `describe.each()` or `it.each()` when writing repetitive tests. +1. Always clean up all test data generated by the tests. + ### Test groups This package makes use of the `jest-runner-groups` package, which allows grouping tests together around semantic groups (such as `orders` API calls, or `coupons` API calls) to make running test suites more granular. @@ -116,6 +125,20 @@ const queryString = { const response = await getRequest('/orders', queryString); ``` +## Creating test data + +Most of the time, test data would be in the form of a request payload. Instead of building them from scratch inside the test, create a test data file inside the `data` directory. Create a model of the request payload within that file, and export it as an object or a function that generates this object. + +Afterwards, make sure to add the test data file to the `data/index.js` file. + +This way, the test data would be decoupled from the test itself, allowing for easier test data management, and more readable tests. + +## Creating endpoint functions + +All functions for sending requests to endpoints should be placed in the `endpoints` directory. + +Newly created files should be added to the `endpoints/index.js` file. + ## Debugging tests You can make use of the REST API log plugin to see how requests are being made, and check the request payload, response, and more. From cd410637fd0c36d7f2084faec0eb9ca674517aa8 Mon Sep 17 00:00:00 2001 From: Lourens Schep Date: Wed, 9 Feb 2022 15:26:14 -0400 Subject: [PATCH 24/25] Bump WooCommerce Admin version --- plugins/woocommerce/composer.json | 2 +- plugins/woocommerce/composer.lock | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/woocommerce/composer.json b/plugins/woocommerce/composer.json index bf52138f323..3f4e725bc1f 100644 --- a/plugins/woocommerce/composer.json +++ b/plugins/woocommerce/composer.json @@ -21,7 +21,7 @@ "pelago/emogrifier": "3.1.0", "psr/container": "1.0.0", "woocommerce/action-scheduler": "3.4.0", - "woocommerce/woocommerce-admin": "3.1.0", + "woocommerce/woocommerce-admin": "3.2.0-rc.1", "woocommerce/woocommerce-blocks": "6.7.3" }, "require-dev": { diff --git a/plugins/woocommerce/composer.lock b/plugins/woocommerce/composer.lock index 5c5bb94d846..c6b5e140352 100644 --- a/plugins/woocommerce/composer.lock +++ b/plugins/woocommerce/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d9b680722733ec1fae9414023f943830", + "content-hash": "c6e38b5cbb540e0f3bd563408d933541", "packages": [ { "name": "automattic/jetpack-autoloader", @@ -543,16 +543,16 @@ }, { "name": "woocommerce/woocommerce-admin", - "version": "3.1.0", + "version": "3.2.0-rc.1", "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce-admin.git", - "reference": "59dfff627d9b7b1d5396686e69b709a820f5e7e5" + "reference": "0e3d26c283f3cff3507469478a33b47ca7e70649" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/59dfff627d9b7b1d5396686e69b709a820f5e7e5", - "reference": "59dfff627d9b7b1d5396686e69b709a820f5e7e5", + "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/0e3d26c283f3cff3507469478a33b47ca7e70649", + "reference": "0e3d26c283f3cff3507469478a33b47ca7e70649", "shasum": "" }, "require": { @@ -608,9 +608,9 @@ "homepage": "https://github.com/woocommerce/woocommerce-admin", "support": { "issues": "https://github.com/woocommerce/woocommerce-admin/issues", - "source": "https://github.com/woocommerce/woocommerce-admin/tree/v3.1.0" + "source": "https://github.com/woocommerce/woocommerce-admin/tree/v3.2.0-rc.1" }, - "time": "2022-01-25T02:36:40+00:00" + "time": "2022-02-09T15:33:34+00:00" }, { "name": "woocommerce/woocommerce-blocks", @@ -2926,5 +2926,5 @@ "platform-overrides": { "php": "7.0.33" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.2.0" } From 6eaef89bdb97a6aaae93646c42390ae670e199ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Soriano?= Date: Thu, 10 Feb 2022 12:40:10 +0100 Subject: [PATCH 25/25] Fix unit tests related to wc_get_price_excluding_tax --- .../tests/php/includes/wc-product-functions-test.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php index 9bba492af6b..2a68d98f8c2 100644 --- a/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php +++ b/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php @@ -105,6 +105,10 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case { $this->assertEquals( $order->get_customer_id(), $customer_id_passed_to_wc_customer_constructor ); $this->assertFalse( $get_base_rates_invoked ); $this->assertSame( $customer, $customer_passed_to_get_rates ); + } elseif ( ! $customer_id && $set_filter ) { + $this->assertFalse( $customer_id_passed_to_wc_customer_constructor ); + $this->assertNull( $customer_passed_to_get_rates ); + $this->assertFalse( $get_base_rates_invoked ); } else { $this->assertFalse( $customer_id_passed_to_wc_customer_constructor ); $this->assertFalse( $customer_passed_to_get_rates ); @@ -114,8 +118,8 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case { wc_get_price_excluding_tax( $product ); $this->assertFalse( $customer_id_passed_to_wc_customer_constructor ); - $this->assertFalse( $customer_passed_to_get_rates ); - $this->assertTrue( $get_base_rates_invoked ); + $this->assertEquals( $set_filter ? null : false, $customer_passed_to_get_rates ); + $this->assertEquals( ! $set_filter, $get_base_rates_invoked ); } // phpcs:enable Squiz.Commenting