Commit Graph

2819 Commits

Author SHA1 Message Date
Shiki ecb2936f9e Use different terms to avoid clash with the similar V2 test
I suppose I could have deleted the attribute and term first but I think
this is better and shorter. Maybe.
2020-08-26 23:51:36 +05:30
Shiki face3fe27e OrdersV2: Add test for line items meta_data
This currently fails because it's not implemented yet.
2020-08-26 23:51:36 +05:30
Shiki ad00eb3a98 Add line items meta_data schema test for Orders V2 and V3
This currently fails because the expected meta_data properties are only
available in V3.
2020-08-26 23:51:36 +05:30
Shiki 2a01aa968f WC_Tests_API_Orders: Add test data for site-level attributes 2020-08-26 23:51:36 +05:30
Shiki dc2a4d1ccc WC_Tests_API_Orders: Rearrange order variable for clarity 2020-08-26 23:51:36 +05:30
Shiki 00a5c3101e WC_Tests_API_Orders: Rename first_meta_data to size_* 2020-08-26 23:51:36 +05:30
Shiki d681a8c7a4 Add unit test for an Order's line item meta data. 2020-08-26 23:51:36 +05:30
Claudio Sanches 5240682f38 Improve choice of words 2020-08-25 18:03:03 -03:00
Claudio Sanches a133e56ebd Fixed unit tests 2020-08-25 16:13:49 -03:00
Ron Rennick 81dae70033 phpcs fixes 2020-08-25 15:41:31 -03:00
Ron Rennick de79f1a3cd update unit tests for included Paypal gate name change 2020-08-25 15:36:50 -03:00
Ron Rennick 074b2b86c6 update package-lock.json 2020-08-21 13:39:33 -03:00
Ron Rennick 7a14368982 add small tweaks/checks for edge cases 2020-08-21 13:25:30 -03:00
Tam Mullen b41bd5139d Updating e2e test for OBW changes 2020-08-21 16:03:02 +01:00
Ron Rennick 51afe3207a
Merge pull request #27023 from HikeMike/add/hidden-form-field
"Hidden" field type added to woocommerce_form_field() #26468
2020-08-20 11:48:26 -03:00
Claudio Sanches 47aaac8600 Introduced wc_asort_by_locale() function 2020-08-19 20:22:18 -03:00
Claudio Sanches b5221ab479 Added unit tests for changes in wc_ascii_uasort_comparison 2020-08-19 19:00:18 -03:00
Claudio Sanches 98d5f52de2 Merge branch 'master' into add/woorelease-support 2020-08-19 12:10:15 -03:00
Ron Rennick dfdf4e9d18 update e2e config parsing to support no port 2020-08-19 09:57:14 -03:00
Christopher Allford 358db5dc3e Removed the internals of the Container pending package conflict resolution
Since reverting the PR at this point would be a mess I've gone ahead and removed the internals of the container. We should aim to keep the class since it's now part of our public API but it won't work as expected anymore. This is fine for now since we don't actually have anything in it!
2020-08-18 20:39:48 -07:00
Claudio Sanches 9773675b8d Merge branch 'master' into add/woorelease-support 2020-08-18 17:59:47 -03:00
Claudio Sanches e102ec3d83 Merge branch 'master' into fix/25133 2020-08-17 14:59:49 -03:00
Néstor Soriano f1ed7005f9
Merge pull request #26232 from woocommerce/update/e2e-test-utils
Update/e2e test utils
2020-08-17 15:26:13 +02:00
Claudio Sanches bb0c4406de
Merge pull request #27314 from woocommerce/add/unit-tests-27108
Added unit tests for #27244
2020-08-14 15:32:02 -03:00
Ron Rennick 45391c4b18 update unit test for account page being automatically created 2020-08-14 10:36:16 -03:00
Ron Rennick f0ad8a01be merge current master 2020-08-13 14:33:07 -03:00
Vedanshu Jain a887cd7369
Merge pull request #27318 from woocommerce/fix/27282
Change data-type from mixed to composite and date-time to string on the fly for REST API
2020-08-13 21:25:11 +05:30
vedanshujain 7fa6510c1a Add a explicit test for null as well 2020-08-13 16:52:16 +05:30
vedanshujain dd9b9cfae2 Add test for update in date-time field 2020-08-13 16:32:00 +05:30
vedanshujain 4294e06f7a Add test for variation v2 controller for complex meta object 2020-08-13 15:46:31 +05:30
vedanshujain 9f680aa120 Add test for null meta value as well 2020-08-13 14:17:28 +05:30
vedanshujain 826fdde721 Add unit tests for checking that updating complex meta is possible 2020-08-13 13:27:00 +05:30
Néstor Soriano 4c636b1d5c
Merge pull request #27303 from woocommerce/fix/travis-coding-standards-test
Fix coding standards test on Travis
2020-08-13 09:19:13 +02:00
Claudio Sanches 1839feae91 Added unit tests for #27244 2020-08-12 18:50:25 -03:00
Christopher Allford 7340c9af44
Merge pull request #27171 from woocommerce/fix/25543
Added the parent's SKU to product searches for variations
2020-08-12 12:58:00 -07:00
Claudio Sanches 1699b34295 Use npm run build:core 2020-08-12 16:53:06 -03:00
Christopher Allford 7071c6dc0c
Merge pull request #27228 from woocommerce/feature/container-injection-change
Dependency Injection should use method injection instead of constructor injection
2020-08-12 12:41:48 -07:00
Claudio Sanches 521ad8c3ff Update all dependencies of woocommerce-sniffs 2020-08-11 20:42:42 -03:00
Claudio Sanches 7fdf209713 Check if PHPCS is installed before trying to install a new copy 2020-08-11 20:08:28 -03:00
Claudio Sanches 29bc98816e
Merge pull request #27143 from woocommerce/fix/26876
Fix "Hide shipping costs until an address is entered"
2020-08-11 20:06:17 -03:00
Ron Rennick 4ba2e0267f remove unused local test-e2e.json 2020-08-11 09:53:34 -03:00
Tam Mullen 9ad9ff2df8 Fixing import path 2020-08-11 12:26:53 +01:00
Tam Mullen c8365213c3 Fixing import path. 2020-08-11 00:34:57 +01:00
Tam Mullen ed525087ac Addressing comments. 2020-08-10 21:27:20 +01:00
Tam Mullen b2262f1cf7 Updating exports for completeOnboardingWizard function. 2020-08-10 21:26:11 +01:00
Tam Mullen 2bc918d353 Updating e2e-utils formatting. 2020-08-10 21:26:10 +01:00
Tam Mullen cdaefa332e Updating e2e-utils formatting. 2020-08-10 21:26:10 +01:00
Tam Mullen 4544190462 Updating e2e-utils dependencies. 2020-08-10 21:26:10 +01:00
Tam Mullen ead4b93a7d Adding e2e-utils README 2020-08-10 21:26:10 +01:00
Tam Mullen da1916c663 Updating product test dependencies 2020-08-10 21:26:10 +01:00
Tam Mullen 43c55e2c6a Converting e2e-utils to package. 2020-08-10 21:26:10 +01:00
Ron Rennick 0b0595ab4c
Merge pull request #27048 from vallter2/postcode-bih
Add postcode validation for Bosnia and Herzegovina
2020-08-10 16:24:06 -03:00
Ron Rennick c14ce54752 fix e2e docker:ssh command to work in any repo 2020-08-10 14:54:10 -03:00
Christopher Allford 116e11565a
Merge pull request #27262 from woocommerce/fix/unit-tests-coding-standards
Fixed packages required to run code sniffer on unit tests
2020-08-10 06:57:05 -07:00
Christopher Allford 12397aec0e Added `_with` suffix to `StringUtil` methods for clarity 2020-08-07 16:45:35 -07:00
Christopher Allford 13a3b80cb6 Removed classes accidentally added back by merge from master 2020-08-07 16:45:09 -07:00
Christopher Allford eb65252ba8 Merge branch 'master' into feature/container-injection-change 2020-08-07 14:35:44 -07:00
Christopher Allford 081f0d9133 Settled on an injection method of `init`
1. Since our code style dictates that these be `final` methods, we shouldn't be concerned about overlap.
2. There is precedent for `init` methods as requirements before using class instances.
2020-08-07 14:28:29 -07:00
Claudio Sanches 02cf0dfaed
Merge pull request #27239 from woocommerce/fix/package-tag
Fix usage of "package" tag in file headers
2020-08-07 13:37:24 -03:00
Claudio Sanches 17f9883f00 Changed | to \ 2020-08-07 13:36:41 -03:00
Claudio Sanches 48732ee0dd Fixed package tag 2020-08-07 13:35:15 -03:00
Claudio Sanches 3fd42a0fd5 Fixed packages required to run code sniffer on unit tests 2020-08-07 13:28:41 -03:00
Ron Rennick 6aa52c8499 remove duplicate readme text 2020-08-07 13:04:36 -03:00
Ron Rennick db76c8ac2d merge package config with factories changes 2020-08-07 10:53:51 -03:00
Néstor Soriano 76cf1e4e93
Merge pull request #27140 from woocommerce/fix/23790
Always sanitize coupon code to prevent inconsistent between admins and shop owners
2020-08-07 12:42:02 +02:00
Néstor Soriano a13a0d2187
Merge pull request #27179 from woocommerce/fix/26741
Release coupon holds when status it updated to cancelled regardless of recorded coupons
2020-08-07 11:27:45 +02:00
Christopher Allford 154c812fc0 Renamed the `StringUtility` to `StringUtil` to make it easier to work with 2020-08-06 12:35:51 -07:00
Claudio Sanches 9eae43c0d4
Merge pull request #27240 from woocommerce/dependabot/npm_and_yarn/tests/e2e/factories/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19 in /tests/e2e/factories
2020-08-06 15:50:26 -03:00
vedanshujain 2f76e52fa7 Skip test for < 5.3 as feature is not supported. 2020-08-06 14:34:02 +05:30
vedanshujain 55a9687e6d Make api included structure more linear. 2020-08-06 14:34:02 +05:30
vedanshujain cfe357cfb2 Fix UT to add predefined values to run tests in isolation. 2020-08-06 14:34:02 +05:30
vedanshujain 222852dea6 Merge branch 'master' of https://github.com/woocommerce/woocommerce 2020-08-06 14:06:29 +05:30
Christopher Allford 39376abfd2 Added a requirement that `container_init` methods be marked `final` when registering using reflection 2020-08-05 22:34:00 -07:00
Christopher Allford ff6e30f1c1 Renamed `set_internal_dependencies` to `container_init` 2020-08-05 22:20:13 -07:00
Christopher Allford cbbfed4989 Replaced the rest of the constructor injection references 2020-08-05 21:28:06 -07:00
dependabot[bot] 089df498d3
Bump lodash from 4.17.15 to 4.17.19 in /tests/e2e/factories
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-08-05 23:04:18 +00:00
Christopher Allford 8e8698a3f6 Fixed test that used PHPUnit function from newer version 2020-08-05 15:43:08 -07:00
Christopher Allford 678705cdd4 Merge branch 'master' into package/e2e-factories/product 2020-08-05 14:00:05 -07:00
Ron Rennick 0ca4ce27c5 update e2e readmes 2020-08-05 16:58:38 -03:00
Ron Rennick 7f04d800e9 keep browser reset at end of setup 2020-08-05 15:01:43 -03:00
Claudio Sanches 3632714885 Removed package tag from src 2020-08-05 14:23:50 -03:00
Claudio Sanches a50552af75 Use only WooCommerce as package name 2020-08-05 14:11:20 -03:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
Ron Rennick 7799c1bcf0 merge master 2020-08-05 10:33:16 -03:00
Tam Mullen 5a410c02a6 Fix e2e OBW test to not untick physical products in product type list 2020-08-05 12:49:42 +01:00
Christopher Allford d178c7ff01 Replaced constructor injection with method injection
Since we need to maintain backwards compatibility for class constructors we should settle on using method injection instead of constructor injection. I've replaced the `Definition` class we're using with one that doesn't support constructor arguments and added a check for auto_arg addition. Note that we don't check for method existence in the extended container. This is because reflection is unnecessarily expensive and we should avoid it if at all possible.
2020-08-04 20:37:28 -07:00
Ron Rennick 52d67cead1 move trash posts/products from sequencer to local config 2020-08-04 19:55:13 -03:00
Ron Rennick 14c9154fcb use consistent MySQL configuration values 2020-08-04 16:17:00 -03:00
vedanshujain 1ada7d8b26 Merge branch 'master' of https://github.com/woocommerce/woocommerce 2020-08-04 18:22:41 +05:30
Nestor Soriano 200599f8e0 Add unit tests for the type of the value returned by 'get_available_variations' 2020-08-03 16:30:54 +02:00
Nestor Soriano 71fccd6a07 Fix: pagination controls not displaying in products list.
This bug was introduced in #26260. The sequence is:

1. WC_Query::adjust_posts_count runs, to handle found_posts filter,
   this indirectly executes wc_setup_loop.
2. At this point $GLOBALS['wp_query']->max_num_pages hasn't been set
   yet, and has a value of 0. Thus the loop variable total_pages
   is set to 0.
3. Later wc_setup_loop runs again and this time
   $GLOBALS['wp_query']->max_num_pages is already set, but since
   the loop variable total_pages already exists, it keeps its
   value of 0.
4. The pagination controls never show if total_pages is less than 2.

The fix consists of hooking into the_posts to set the value of
total_pages again, at that point $GLOBALS['wp_query']->max_num_pages
is already set.
2020-07-31 16:40:25 +02:00
Claudio Sanches 825d57dd41 Merge branch 'master' into fix/23790 2020-07-30 17:33:50 -03:00
Claudio Sanches 48974f29f1 Fixed unit tests for WC_Notes_Run_Db_Update 2020-07-30 17:00:11 -03:00
Claudio Sanches 1cd84d6446 Merge branch 'master' into fix/23790 2020-07-30 16:46:01 -03:00
Claudio Sanches 608fc8620d
Merge pull request #27172 from woocommerce/fix/27168
Let user stay in the same page after clicking to update WooCommerce
2020-07-30 15:48:27 -03:00
Jonathan Sadowski 163e10253a Release coupon holds when status it updated to cancelled regardless of recorded coupons 2020-07-30 10:35:23 -05:00
Néstor Soriano e44154bf6e
Update tests/legacy/unit-tests/util/class-wc-tests-wc-query.php
Fix small coding standards issue.

Co-authored-by: Claudio Sanches <contato@claudiosanches.com>
2020-07-30 16:17:05 +02:00
vedanshujain 3a63d75e0f Merge branch 'master' of https://github.com/woocommerce/woocommerce 2020-07-30 17:55:11 +05:30
Nestor Soriano 86c88f1750 Fix: incorrect adjustment of post count in WC_Query.
PR #26260 introduced a handler for 'found_posts' filter in WC_Query
class in order to adjust the count depending on the visibility
of variation products. However the handler incorrectly assumed
that the filter was triggered only when listing products, when
actually it's also triggered for any post type e.g. pages.
In these cases the post count was set to zero, which caused bugs.

Now the handler starts with the originally supplied posts count,
and only decrements it when a post is a product AND is not visible.
2020-07-30 09:32:28 +02:00
Claudio Sanches 3c1132e274 Added unit tests for wc_get_current_admin_url() 2020-07-29 21:02:52 -03:00
Christopher Allford 78bff3b2da Added the parent's SKU to product searches for variations
Since the parent's SKU is used when the variation does not have one, we should fall back when searching for consistency.
2020-07-29 16:53:36 -07:00
Ron Rennick ba942aa32f expose getAppRoot, getTestConfig in package 2020-07-29 20:03:29 -03:00
Ron Rennick 09a594443d restore non-dev puppeteer config, move test config to sequencer 2020-07-29 18:57:59 -03:00
Ron Rennick d4620b5351 merge master 2020-07-29 15:25:11 -03:00
Ron Rennick 1e365733b4 add local puppeteer config support 2020-07-29 15:13:22 -03:00
Néstor Soriano 0f134ca6a2
Merge pull request #27054 from woocommerce/fix/27036
add/update correct deprecated notices on existing deprecations
2020-07-29 15:20:24 +02:00
Ron Rennick d9e9faaa44 use @automattic/puppeteer-utils 2020-07-28 16:29:19 -03:00
Claudio Sanches 119b5d6568
Merge branch 'master' into fix/23790 2020-07-28 13:07:17 -03:00
Ron Rennick e78beaf569 move jest/puppeteer related packages to environment package 2020-07-28 12:00:46 -03:00
Nestor Soriano 681401850a Adjustments in the items count calculation on the nav filtering widget.
The calculations are now consistent with the change made to the
visibility of the variable products when using one or multiple filters.
2020-07-28 09:01:55 +02:00
Nestor Soriano 29843b9396 Change in the logic of is_visible_core for variable products
Now, if there are filters present the logic is as follows:

- For multiple filtering values of the same attribute:
  the product is visible if there's at least one variation
  that has one of the filtering values associated to the attribute,
  or if there's at least one variation having the attribute
  with a value of "Any".

- For filtering by more than one attribute:
  the product is visible if there's at least one variation that
  is visible for ALL the attributes according to the above rule.

Note that this is irrespective of the type of logic configured for
the filter (OR or AND).
2020-07-28 09:01:52 +02:00
Nestor Soriano 3fefe84a51 Fix: WC_Query()::adjust_posts_count failing when posts list is null. 2020-07-28 08:55:55 +02:00
Nestor Soriano 9142e27a19 Adjustments in WC_Query::adjust_posts_count
Two adjustments were needed:

- Adjust the count even when there's no nav filtering in the query.
  This is necessary to present the proper products count.
  even when the woocommerce_product_is_visible filter is used.
- Account for the case where $GLOBALS['wp_query']->posts
  returns objects instead of ids (for example when viewing
  a product page).
2020-07-28 08:55:55 +02:00
Nestor Soriano 9de1306c21 Fix counters in nav filtering widgets for variable products.
After the change that registers variation attributes as terms
(in addition to reigstering them as post meta) it is now time
to modify the get_filtered_term_product_counts methods in
WC_Widget_Layered_Nav so that it works consistently for both
variable and non-variable products. The logic for the counters
is now as follows:

with OR operator:
- Simple products: count the attributes of all visible products
  (unchanged behavior).
- Variable products: count attributes corresponding to
  visible variations.

with AND operator:
- Simple products: count the attributes of visible products but only
  for products that have all the selected (unchanged behavior).
- Variable products: find all the products for which all the variations
  corresponding to the selected attributes exist and are visible,
  then count the attributes corresponding to the visible variations
  of those products.

A product is "visible" if it's published, not excluded for catalog,
and has stock. Additionally, a variable product will not be considered
visible if the parent product is not.
2020-07-28 08:55:55 +02:00
Nestor Soriano 9c6c0d73d8 Record attribute terms for product variations in wp_term_relationships.
Product attributes are currently recorded as terms in
wp_term_relationships (product attributes are actually taxonomies).
In the case of variable products this is true for the main product,
but not for the variations. The attributes used to define variations
are stored as post meta, but nothing is recorded in the term
relationships table.

This is a problem when using the layered nav filtering plugin,
since the attribute counters displayed are calculated based solely
on the contents of the term relationships table. Adding meta queries
would be really messy (especially when the widget is configured
with AND operator) and would probably also hurt performance.

This commit adds a change to store the attributes for variations
as term relationships, additionally to storing them as post meta.
Terms are stored on variation creation, and updated/deleted together
with the variation as appropriate. "Any" variations (stored in meta
as empty values) are not stored as terms.

Additionally, a database upgrade is included in order to backfill
terms for already existing products.
2020-07-28 08:55:55 +02:00
Nestor Soriano e1265bfa25 Refactor WC_Helper_Product by extracting duplicated code to methods.
The new methods are create_product_variation_object and
create_product_attribute_object, they are public.
2020-07-28 08:55:55 +02:00
Nestor Soriano 50e8f27bc7 Fix visibility of variable products with layered nav filtering.
The layered nav filtering doesn't work well with variable products
when some variations have stock and other don't. When a term is
selected in the widget, a variable product having no stock for
the variation corresponding to that term but having stock for
other variations will be displayed, but it shouldn't.

This commit fixes that by introducing two changes:

- A new override of "is_visible" for WC_Product_Variable that
  looks at the supplied filters, compares them against the corresponding
  available variations and calculates the visibility based on
  the query type (OR or AND).

- A hook on the "found_posts" filter in WC_Query, that adjusts
  the posts count based on the found products visibility
  when there are filters available; this is needed to sync the
  "displaying X posts" messages and the paging when variable
  products are hidden due to stock status.

Additionally, the visibility calculated in "found_posts" is cached
as loop variables so that it isn't calculated again when actually
displaying the products.
2020-07-28 08:55:52 +02:00
Nestor Soriano c27283dffe Fix code sniffer errors in some files.
Fixed files:

includes/abstracts/abstract-wc-product.php
includes/class-wc-query.php
includes/wc-template-functions.php
includes/widgets/class-wc-widget-layered-nav.php
templates/loop/result-count.php
tests/unit-tests/util/class-wc-tests-wc-query.php
2020-07-28 08:47:29 +02:00
Christopher Allford 578b205b4e
Merge pull request #27123 from woocommerce/feature/jetpack-autoloader-upgrade
Upgraded Jetpack Autoloader to 2.0
2020-07-27 23:35:53 -07:00
Claudio Sanches de383971eb Reset all after test 2020-07-27 22:07:46 -03:00
Claudio Sanches 2043954ceb
Fixed class name 2020-07-27 21:53:28 -03:00
Claudio Sanches 0f091406df Test WC_Cart::show_shipping() 2020-07-27 21:52:33 -03:00
Christopher Allford 1868cd8aaa Adjusting the shipping task order in the E2E test for setup tasks 2020-07-27 15:18:27 -07:00
Christopher Allford edf1932ee9 Adjusted the OBW test for changes in WC-Admin 1.4.0 2020-07-27 14:38:43 -07:00
Claudio Sanches 4048d19a39 Added unit tests for coupon code sanitization 2020-07-27 17:44:04 -03:00
Christopher Allford ddc1f87f8d
Update README.md
Changed `npm install` suggestion to better suggest saving the dependencies as devDependencies
2020-07-27 13:30:39 -07:00
Matt Harrison e696ac7824
Queue all webhooks on shutdown.
It is possible for a later duplicate webhook to be fired too early if
the same webhook triggers in one request more than once with the updated
changes from the second one missing if it happens too quickly.
This queues all webhook to be register on shutdown instead of just
syncronous ones to make sure all data from the request is updated first
before the webhook gets queued.
2020-07-27 12:11:40 -04:00
Nestor Soriano cc118c0c10 Fixed the number of product types in the onboarding E2E test 2020-07-27 16:49:32 +02:00
Christopher Allford 4123d048e0 Fixed the number of industries in the onboarding E2E test 2020-07-27 07:08:54 -07:00
Claudio Sanches 7bd34e3545
Merge branch 'master' into fix/25843 2020-07-24 17:04:28 -03:00
Ron Rennick aca91f587d update version script to work in both desktop and Travis, add fallback versions 2020-07-24 17:02:33 -03:00
Claudio Sanches 419e5c239a
Fixed docblocks 2020-07-24 17:01:42 -03:00
Ron Rennick 96d73d2300
Merge pull request #27090 from woocommerce/update/wp-jest-preset-version
Update E2E env jest preset default version.
2020-07-24 14:39:55 -03:00
Ron Rennick 06e3ae9939 fix software version checks in Travis 2020-07-24 10:57:16 -03:00
vedanshujain f90699ddb9 Add more assertions in tests for order totals. 2020-07-24 19:12:25 +05:30
vedanshujain 0e7b064c02 Add more assertions in tests for round at subtotal. 2020-07-24 19:12:25 +05:30
vedanshujain 3aed8f1c85 Remove incorrect comments. 2020-07-24 19:09:59 +05:30
vedanshujain 7735eed314 Add unit tests and helpers for #26654 2020-07-24 19:09:59 +05:30
Néstor Soriano 8c2412ea7d
Merge pull request #26731 from woocommerce/feature/introduce-dependency-injection
Introduce a dependency injection framework
2020-07-24 15:12:16 +02:00
Ron Rennick eaafc88d33 add port configuration support 2020-07-24 10:12:07 -03:00
Nestor Soriano c2e28b2b05 Replace array_merge_recursive in MockableLegacyProxy with custom code
test_static_mocks_can_be_used_via_injected_legacy_proxy_and_woocommerce_object
was failing in PHP 7.0, this replacement fixes it.
Suspected cause: https://bugs.php.net/bug.php?id=76505
2020-07-24 14:51:37 +02:00
Peter Fabian 03230ecf01
Merge pull request #26642 from woocommerce/fix/26607
Limit stock changes for order items to status methods for consistency.
2020-07-24 13:23:53 +02:00
Nestor Soriano e55ef052a2 Add documentation about the container and good coding practices.
- src/README.md largely expanded
- tests/README.md expanded
- includes/README.md added
- src/Internal/REAMDE.md added

src/README.md and includes/README.md have TODO placeholders to add
guidelines regarding to actions and filters.
2020-07-24 09:25:12 +02:00
Christopher Allford 811ac747e6 Added callable reflection to `add_with_auto_arguments`
This allows the dependencies of the callable function to be automatically resolved out of the container too!
2020-07-24 09:25:12 +02:00
Nestor Soriano 408295720c Fix LegacyProxy::get_instance_of for classesd having an `instance` method.
Pass the arguments as `...$args` instead of `$args`.
Also fix related unit test, and remove unnecessary `is_function`.
2020-07-24 09:25:12 +02:00
Nestor Soriano bd1e6a5db0 Add the ContainerException class, use it for dependency injection related errors. 2020-07-24 09:25:12 +02:00
Nestor Soriano 65b5cbe692 Improve AbstractServiceProvider::add_with_auto_arguments
If a class name is passed as a concrete, check that the class
constructor is public if it exists. If another type of concrete is
passed, check that it's valid (a callback or an object).

Also update the autoloader to check if the class file exists,
otherwise class_exists fails if a namespaced class doesn't exist.
2020-07-24 09:25:11 +02:00
Nestor Soriano 6fd84a0401 Add shortcut methods for the LegacyProxy in the WooCommerce class.
The following methods are added and can be invoked using `WC()`,
they just redirect to the same methods in LegacyProxy:

call_function
call_static
get_instance_of
2020-07-24 09:25:11 +02:00
Nestor Soriano abf53086ca Remove @throws annotation from some unit tests. 2020-07-24 09:25:11 +02:00
Christopher Allford 53e1f23af5 Moved autoloading of `Automattic\WooCommerce\Testing\Tools` namespace into test bootstrap
Since we need to load all of these files before WooCommerce has initialized we can't rely on Composer to handle the autoloading. We should take this namespace out of Composer altogether and just have our test autoloader take care of it.
2020-07-24 09:25:09 +02:00
Nestor Soriano 29cf161415 Small changes after review feedback:
- Method and class renames.
- Removed unnecessary autoloader registration.
- Add a unit test for classes with non-object type hints
  in constructor arguments.
2020-07-24 09:24:06 +02:00
Nestor Soriano 1684ce08b3 Removed annotations as we're not going to use them. 2020-07-24 09:24:06 +02:00
Nestor Soriano 4ec143532c Adjustments in the LegacyProxy class.
- `get_instance_of` accepts now arguments to be passed to the
  class constructor if necessary.
- `get_special_instance_of` method removed, instead, now if a method
  named `get_instance_of_<lowercased class name>` exists in the class,
  it is used to get the instance of the class.
- A couple more unit tests added.
2020-07-24 09:24:06 +02:00
Nestor Soriano 282d1dab86 DependencyManagement code folder moved inside an Internal folder. 2020-07-24 09:24:06 +02:00
Nestor Soriano c1ed403dd0 Add `@public` to `FunctionsMockerHack`.
Also to a couple of methods related to the code hacker.
2020-07-24 09:24:06 +02:00
Nestor Soriano 044a79d941 Added unit tests for `LegacyProxy` and `MockableLegacyProxy`.
Also:

- Added sutoloader for the `tests/tools` directory.
2020-07-24 09:24:04 +02:00
Nestor Soriano c9154d071c Add tests for `AbstractServiceProvider` and `ExtendedContainer`.
Also:

- Make the methods in `AbstractServiceProvider` protected.
- Add an autoloader for files in the `tests/php/src` directory.
- Fix a bug in the provisional (?) autoloader.
2020-07-24 09:23:05 +02:00
Nestor Soriano d55f7d10f8 Some small imrpovements in the dependency injection framework:
- camelCase methods changed to snake_case for consistency with WP.
- Added a check in `ExtendedContainer::get` that throws an informative
  exception if a non-namespaced class name is passed.
- `container->reset_resolved()` is called during unit testing bootstrap.
- Added some utility methods in `WC_Unit_Test_Case`.
2020-07-24 09:23:05 +02:00
Nestor Soriano ca9ed93b9a Added dependency injection infrastructure for unit tests:
- Added a new class `ExtendedContainer` that extends League's container.
  - `add` modified to reject classes not in the root Woo namespace.
  - Has two new methods, `replace` and `reset_resolved`.
  - It's used as the underlying container instead of League's one
    in `Container`, but the new methods are not exposed.
- At unit test bootstrap time the globally registered container is
  replaced with the extended one that `Container` stores
  (grabbed from private property using reflection).
- A new `MockableLegacyProxy` is added. It inherits from `LegacyProxy`
  and allows to mock functions, static methods and legacy classes.
  - The registeed `LegacyProxy` is replaced with the mockable version
    during unit test bootstrap.
- A PHPUnit hook is added to reset the mockable proxy to its initial
  state (so that nothing is mocked) before each test.
- `WC_Unit_Test_Case` gets helper methods to mock functions, static
  methods and classes without having to retrieve the proxy class.
2020-07-24 09:23:05 +02:00
Claudio Sanches 64f4fb85e2 Move variation validation logic to add to cart 2020-07-23 19:10:42 -03:00
Ron Rennick 4cffb9b95c eliminate project root docker-compose.yaml 2020-07-23 15:38:40 -03:00
Ron Rennick 28b537662a add PHP, MariaDB, WP env var version support 2020-07-23 14:30:24 -03:00
Tam Mullen 86da271e6e
Merge pull request #27063 from woocommerce/fix/e2e-obw-4.3
Fix OBW e2e test in WC 4.3: Scroll Home Screen tasks list into view for the `Set up shipping` click to work
2020-07-23 15:48:18 +01:00
vedanshujain 5a784bc1e4 Keep only unit test files for merge into core. 2020-07-23 00:07:29 +05:30
vedanshujain e42b97e7ea Add 'tests/legacy/unit-tests/api/' from commit '5335083922d350e73eaf0e8370d8335e1b076b55'
git-subtree-dir: tests/legacy/unit-tests/api
git-subtree-mainline: 2d39467fb4
git-subtree-split: 5335083922
2020-07-22 23:56:29 +05:30
Jeff Stieler 76e42fec98 Update E2E env jest preset default version.
6.x.x will update the weak ref detection dependencies.
2020-07-21 13:51:16 -04:00
Christopher Allford 840554d788
Merge pull request #27017 from woocommerce/fix/25480
Fixed the `shipping_zone_method` CLI command's instance_id parameter
2020-07-20 11:00:08 -07:00
Christopher Allford 636327c110
Merge pull request #27043 from woocommerce/fix/unit-test-suite
Test Suite & Namespace PHPCS Changes
2020-07-20 08:40:00 -07:00
Mike Dent 541f68363e Test code updated, with thanks to @ObliviousHarmony 2020-07-20 15:45:13 +01:00
Ron Rennick d3ab19b7cf eliminate internal use of deprecated functions
- remove deprecation of offsetGet as it is used throught abstract order
- eliminate use of offsetGet in unit tests, structured data, order functions
-
2020-07-17 17:14:26 -03:00
Julia Amosova 10bfb679eb Scroll home screen tasks list into view for the click to work 2020-07-17 12:44:46 -04:00
Claudio Sanches 86311a9903
Merge pull request #27046 from woocommerce/fix/26860
[Importer/Exporter] Fixed the value display of "Published" for children of draft variable products
2020-07-16 13:15:31 -03:00
Ron Rennick dbf3e99292
Merge pull request #26964 from woocommerce/fix/24604
add rating count to order by rating clause
2020-07-16 10:51:20 -03:00
Damir Ha 161eb4a320 Add test postcode validation for Bosnia and Herzegovina 2020-07-16 13:57:44 +02:00
Néstor Soriano 24bd19c517
Merge pull request #27038 from woocommerce/add/26192
Add existing meta keys to woocommerce_duplicate_product_exclude_meta filter
2020-07-16 11:02:09 +02:00
Claudio Sanches 156b061602 Added unit tests for importer and exporter 2020-07-15 21:49:26 -03:00
Christopher Allford b71ddd35f1 Added sniffs to enforce PSR-4 in the `src` and `tests/php/src` directories 2020-07-15 16:09:00 -07:00
Christopher Allford f72b8db576 Added some exceptions to the PHPCS standards for unit tests
The file comments and @throws tags are unnecessary in unit tests.
2020-07-15 14:29:13 -07:00
Christopher Allford 55385f6cec Moved the orphaned unit test into the correct directory 2020-07-15 14:21:34 -07:00
Christopher Allford 13536bef5b Corrected the WCInstallTest filename
It is in the `includes` test section and should have the same filename as the corresponding class.
2020-07-15 14:20:26 -07:00
Christopher Allford fdee8dceaf Moved test to correct directory 2020-07-15 07:08:09 -07:00
vedanshujain aabf4bfe37 Add unit tests. 2020-07-15 15:27:34 +05:30
Christopher Allford c9f754f5a3 Added the existing meta keys to the `woocommerce_duplicate_product_exclude_meta` filter 2020-07-14 13:57:21 -07:00
vedanshujain af401a7d80 Add unit test 2020-07-14 23:32:12 +05:30
Nestor Soriano fc0be07e0f Add unit test for WC_Admin_Post_Types::bulk_and_quick_edit_save_post.
The test added checks that the new regular or sale price is
appropriately set when bulk saving.
2020-07-14 11:42:21 +02:00
Nestor Soriano 320fa38c51 Improve WC_Helper_Product::create_simple_product.
Add a new optional $props parameter containing the properties
to be set in the newly created product.
2020-07-14 11:42:21 +02:00
Nestor Soriano 4531af3382 Small fix in WC_Tests_Admin_Post_Types::bulk_and_quick_edit_stock_status_for_variable_product.
At some point the 'change_stock' key is assumed to be present
in the request data, but it might not. Fixed to test for existence
before using the value.
2020-07-14 11:42:21 +02:00
Nestor Soriano e05aa8a03a Add unit test for WC_Admin_Post_Types::bulk_and_quick_edit_save_post.
The test added checks that stock status of variations when saving
a variable product is changed or not appropriately depending on
the request data supplied.
2020-07-14 11:42:21 +02:00
Nestor Soriano a3ee904081 Add login_as_role and login_as_administrator to WC_Unit_Test_Case.
Those methods are a convenient replacement for
"this->factory->user->create". Tests that were using that to
simulate user login have been modified to use the new methods.
2020-07-14 11:42:21 +02:00
Nestor Soriano 9c2a43bfd5 Fix code sniffer errors in a few unit test files. 2020-07-14 11:42:21 +02:00
Christopher Allford 6cd4079c8a Added a test to verify the rating ordering for products 2020-07-13 13:35:00 -07:00
Christopher Allford 16c5ac401a Adjusted the publish configuration to respect the @woocommerce scope 2020-07-13 10:05:17 -07:00
Mike Dent 53d9085c16 Fixed indent and incomplete test code. 2020-07-12 19:26:57 +01:00
Mike Dent cf9db99a9f "Hidden" field type added to woocommerce_form_field() #26468 2020-07-12 16:38:36 +01:00
Christopher Allford 933cdd7a7b Removed the default `id` field added to all CLI commands
Some of our endpoints don't have an "<id>" parameter but we're expecting one in the CLI. Since the `id` is already part of the supported IDs we don't actually need this since it will pull it from the route.
2020-07-10 14:16:30 -07:00
Christopher Allford e4d90f10c3 Corrected the tabs in the README.me 2020-07-02 15:28:19 -07:00
Christopher Allford 51467f4683 Added a registry for adapters and factories to be held in globally 2020-07-02 14:43:14 -07:00
Christopher Allford b5e1e1cc8a Added a readme documenting the usage of the model factory package 2020-07-02 14:39:18 -07:00
Christopher Allford 822179e4ac Renamed the e2e-factories package to better reflect its usage-agnostic design 2020-07-02 14:16:01 -07:00
Christopher Allford 5652025d28 Removed unused adapter types 2020-07-02 13:56:48 -07:00
Christopher Allford d8beef56b5 Added support for faker to populate models with dummy data 2020-07-02 13:33:30 -07:00
Christopher Allford 4373c7be1b Moved the factory package init into a common utility 2020-07-02 13:13:23 -07:00
Christopher Allford 9b18a95f93 Adjusted the build:packages command to allow each package to build itself 2020-07-02 11:59:41 -07:00
Christopher Allford f1a616e026 Made the model properties compliant with code style 2020-07-02 10:56:21 -07:00
Christopher Allford 3e69dd3a64 Replaced the `createSimpleProduct` helper with a usage of the factory 2020-07-02 10:50:56 -07:00
Christopher Allford f11a47693b Refactored interceptors to support different authentication styles 2020-07-02 10:03:35 -07:00
Christopher Allford 85833f137c Fixed a bug that would cause APIService failures to throw unhandled exceptions when creating 2020-07-01 22:08:18 -07:00
Christopher Allford c3de8f0d12 Adjusted the structure of the factory package for easier consumption 2020-07-01 22:07:27 -07:00
Claudio Sanches d3d8e74b58 Fixed unit tests for #26462 2020-07-01 18:13:29 -03:00
Christopher Allford 0785e6caa7 Merge branch 'master' into package/e2e-factories/product 2020-07-01 14:11:25 -07:00
Christopher Allford 68daac3a94 Added a utility for initializing all of the APIAdapters with a service 2020-07-01 13:58:12 -07:00
Christopher Allford b4c1f3ca8f Fixed the POST, PUT, and PATCH Axios service actions 2020-07-01 12:31:20 -07:00
Christopher Allford bc3e1b4555 Replaced the exported variables with functions to populate the registry 2020-07-01 12:08:08 -07:00
Christopher Allford e6e764320b Added a registry to hold all of the factories and adapters 2020-07-01 11:07:57 -07:00
Claudio Sanches 54f91a5a59
Merge pull request #26566 from woocommerce/update/26510-generate-order-key
Allow custom values in wc_generate_order_key()
2020-07-01 12:41:24 -03:00
vedanshujain 6a8f9a4abe Disabled flaky test 2020-07-01 19:09:50 +05:30
vedanshujain 836d764c67 Add tests 2020-07-01 19:09:07 +05:30
Christopher Allford 627bd5a99a Simplified the package directory structure 2020-06-30 21:37:17 -07:00
Christopher Allford c23f52aedf Created a base ModelFactory for all factories to extend 2020-06-30 19:00:42 -07:00
Christopher Allford 3e2e03d48a Fixed the URL being passed to the OAuth package 2020-06-30 16:01:47 -07:00
Christopher Allford 603a5e7812 Changed the structure of error responses
In practice having the response class contained within the error feels a little backwards. We can instead have a structured APIError model that is contained in the APIResponse and have a consistent response format to consume.
2020-06-30 16:01:12 -07:00
Christopher Allford 7500cc004d Added a skeleton product factory for testing 2020-06-30 13:05:25 -07:00
Christopher Allford 4aa9360ba7 Added an adapter to support creating models via the API 2020-06-30 12:50:15 -07:00
Claudio Sanches c3608f3b57
Merge pull request #26878 from woocommerce/fix/26787
Moved synchronous webhook execution into a shutdown function
2020-06-30 16:34:12 -03:00
Nestor Soriano 391474c5ef Fix code sniffer errors in class-wc-tests-product.php 2020-06-29 15:20:49 +02:00
Nestor Soriano 9aa3c54bd9 Fix variable product stock status not being properly set on save
When a product is saved its validate_props method is invoked,
and this recalculates the stock_status property based on whether
the product manages stock or not, the stock quantity, and the
value of the woocommerce_notify_no_stock_amount option.

In the case of variable products, and when stock is managed, the stock
was set to "instock" when the current stock was enough, but only
if the "stock_quantity" property was in the list of changed properties
for the object (the method in the base product class doen't check
for changed properties). This is a problem because the
wc_update_product_stock function updates stock_quantity but via direct
database modification, and thus stock_quantity isn't considered
modified. Therefore stock modifications via wc_update_product_stock
don't update stock_status on the product (e.g. when going from 0 to 1
after a refund the stock status will remain as "outofstock").

The fix consists of removing the check for changed properties since
it's not done anyway in the other cases (when stock is below the
woocommerce_notify_no_stock_amount threshold) nor in the base class.

Also, validate_props is refactored for readabiliyy, and an useless
set_stock_status() call placed right before save()
in wc_update_product_stock is removed.
2020-06-29 14:32:17 +02:00
Néstor Soriano 7b3e902952
Merge pull request #26629 from woocommerce/fix/25552
Schedule a deferred product sync for products with parent on delete.
2020-06-29 14:15:10 +02:00
Christopher Allford 7331036d17 Moved synchronous webhook execution into a shutdown function
One of the problems with synchronous webhooks is that they are executed as soon as the related action is. Since we may call an action multiple times in the process of updating something, this causes only the first action to trigger the hook. This differs from asynchronous execution because in that case, the web hook will be executed after the entire request has completed.
2020-06-25 16:54:17 -07:00
Christopher Allford ddbbbbc078 Adjusted the TypeScript configuration to use the --build flag 2020-06-24 16:08:28 -07:00
Christopher Allford 6ad8b57f2e Added formatting requirements to the code style 2020-06-24 14:47:46 -07:00
Christopher Allford 4e02ce7afd Moved the Axios response/error transformations into an interceptor 2020-06-24 11:35:04 -07:00
Christopher Allford 9908a84d0e Added a service for interacting with the WordPress API
We've hid the use of Axios behind a service so that we're able to easily mock it out in factories as well as handle the creation and configuration of the client. This will make it easier on consumers in that they won't have to worry about things like authentication when using the API.
2020-06-23 13:15:26 -07:00
Ron Rennick e1c16ba7ef remove setup unit tests 2020-06-23 16:19:54 -03:00
Christopher Allford 031bb6593f Fixed the usage of baseURL with the APIAuthInterceptor 2020-06-23 11:53:00 -07:00
Christopher Allford 323d06744c Adjusted the APIAuthInterceptor to be more explicitly Axios-specific 2020-06-22 12:10:45 -07:00
Ron Rennick 59f2bdbe46 add template cache unit test 2020-06-22 16:05:29 -03:00
Ron Rennick ee151bbd95 Merge branch 'master' into add/npm-publish 2020-06-22 13:46:54 -03:00
Christopher Allford dd74c3db45 Removed build artifact 2020-06-20 18:46:59 -07:00
Christopher Allford 2a3b1b3780 Adjusted the package to better support NPM distribution 2020-06-20 18:25:19 -07:00
Christopher Allford 9f1decd4c6 Added an interceptor to handle WooCommerce API authentication 2020-06-19 12:08:48 -07:00
Christopher Allford 5e15271f95 Excluded test files from the TypeScript build 2020-06-18 09:43:11 -07:00
Christopher Allford 1418b68910 Initial configuration for e2e-factories package 2020-06-17 15:51:28 -07:00
Julia Amosova 281057eee8 Adjust various conditions of the OBW e2e test to make it pass 2020-06-17 17:20:12 -04:00
Ron Rennick 239476ddc5 create ready page after initialization script 2020-06-16 12:29:43 -03:00
Peter Fabian 418d95298a Merge branch 'master' into update/wc-admin-1.3.0-beta-1
# Conflicts:
#	composer.lock
2020-06-16 14:58:43 +02:00
Peter Fabian bb2cf2e8dc Removed deprecated method call. 2020-06-16 13:18:05 +02:00
Peter Fabian c35c4f1f08
Merge pull request #26395 from woocommerce/revert-26226-revert-25708-update/reserve-stock-for-checkout
Introduce a `reserved stock` class and database table to prevent race conditions during checkout
2020-06-16 11:38:10 +02:00
Vedanshu Jain 60ffc7ab99
Merge pull request #26583 from woocommerce/fix/26582
Fix regression caused by merging #25092 conflicting with #24828
2020-06-12 15:13:21 +05:30
Peter Fabian 296112cbea
Merge pull request #26237 from woocommerce/fix/24000
Fix adding product variant to cart using `add-to-cart` parameter (#24000)
2020-06-11 13:13:12 +02:00
Peter Fabian 439562e854
Merge pull request #23971 from woocommerce/refactor/23783
Better template caching for container environments
2020-06-11 10:13:46 +02:00
Vedanshu Jain b45373fe0c Revert "Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout"" 2020-06-05 15:18:01 +05:30
Vedanshu Jain 6564847802
Merge pull request #26454 from woocommerce/enhancement/verify-db
Add `verify_base_db` method to check if all base tables are present.
2020-06-05 15:15:39 +05:30
Ron Rennick 0265e027ef
Merge pull request #26637 from woocommerce/fix/wc_timezone_string
use wp_timezone_string when available
2020-06-03 15:41:47 -03:00
Claudio Sanches 4922c34180
Merge pull request #26136 from woocommerce/feature/code-hacker-for-unit-tests
Code hacker for unit tests
2020-06-03 08:41:28 -03:00
Nestor Soriano 32dac2486f Update autoload-dev in composer.json to add tests/tools directory
The mapping of the "Automattic\WooCommerce\Testing\Tools\" namespace
to the "tests/tools" directory is moved from manual registration
inside the tests bootstrap constructor to a declaration inside the
autload-dev section in composer.json.
2020-06-03 09:28:54 +02:00
Nestor Soriano bfda3f9938 Code hacker resdesign for single-load of code files.
The code hacker as originally designed, as a mechanism that allowed
to enable hacks at the individual test level, is flawed because it
assumes that code files are loaded before each test, but actually
the PHP engine loads code files only once.

Therefore this commit redesigns it so that the two existing main hacks,
the functions mocker and the static methods hacker, are applied
to all the relevant functions and classes at bootstrap time, and
mocks for each individual function/method can be registered at the
beginning of each test. See README for the full details.
2020-06-02 19:06:53 +02:00
Claudio Sanches 6afbed0c14 Fixed coding standards 2020-06-01 23:55:17 -03:00
Ron Rennick 1215844b05 update timezone unit tests to support WP 5.3/5.4 2020-05-29 08:29:35 -03:00
Ron Rennick 7fbe912e19 use wp_timezone_string when available 2020-05-29 07:54:43 -03:00
Nestor Soriano b43679c181 Schedule a deferred product sync for products with parent on delete.
Right now, when a product having a parent (e.g. a variation having a
parent variable product) is saved, wc_deferred_product_sync is
executed so that product sync is performed at the end of the request.
This commit implements the same when the product is deleted.
2020-05-28 14:07:51 +02:00
Peter Fabian 2394da73b4 Merge branch 'master' into refactor/23783 2020-05-28 11:19:03 +02:00
Peter Fabian 30fe1cde72 Moved unit tests to the new location. 2020-05-28 11:18:47 +02:00
vedanshujain bbb7600f87 Add unit test for calculation based on rounding pref 2020-05-27 23:55:46 +05:30
vedanshujain d904db815d Disable flaky test which was causing many calculation tests to fail. 2020-05-27 23:53:20 +05:30
vedanshujain af942a131a Add test to ensure that verify_base_table also creates table if needed. 2020-05-26 23:46:58 +05:30
vedanshujain 57d336433a Fix regression caused by merging #25092 conflicting with #24828 2020-05-22 22:08:42 +05:30
vedanshujain 418741a0b2 Add unit test for verify_base_tables function 2020-05-22 18:32:04 +05:30
Christopher Allford 2953df2c5d
Merge pull request #26529 from woocommerce/fix/e2e-403-errors
use nonced logout link for store owner logout
2020-05-21 10:44:10 -07:00
Ron Rennick 47aab8c56b
Merge pull request #26522 from woocommerce/tweak/e2e-tests-suite
Tweaks to e2e tests suite README
2020-05-21 13:15:04 -03:00
Claudio Sanches 5d034b83a9 Allow custom values in wc_generate_order_key() 2020-05-20 17:41:22 -03:00
Nestor Soriano 2a68bb018d Move testing tools to the tests/Tools directory
The testing tools (only the code hacker at this time) have been moved
from 'src' to 'tests/Tools', since many opcode cache plugins
load the whole src folder in production.

Also, an extra autoloader is set in the tests bootstrap so that
the 'tests/Tools' directory corresponds, using PSR4, to the
'Automattic\WooCommerce\Testing\Tools' namespace.
2020-05-20 09:57:39 +02:00
Nestor Soriano 8a7d955253 Improvements on the code hacker.
- Add methods to temporarily disable and reenable the code hacker.

The code hacker is causing issues in some tests that perform
write operations to the local filesystem. Since this happens only
in a few cases, the easiest fix is to temporarily disable the
code hacker when that happens. This commit adds two new methods
for that in `WC_Unit_Test_Case`: `disable_code_hacker` and
`reenable_code_hacker`.

These methods use a disabling requests count so that the hacker
isn't enabled before it should. E.g. you call `disable`, then
a helper method that does `disable` and `enable`, then `enable` -
then only the last `enable` will have effect.

- `CodeHacker::add_hack` has now a boolean `persistent` parameter.
Persistent hacks won't be cleared by `clear_hacks`.

- `CodeHackerTestHook::executeAfterTest` will now disable the hacker
only if no persistent hacks are registered.

- The existing `file_copy` method is made static for consistency.

- `CodeHacker::restore` method renamed to `disable` for clarity.
2020-05-20 09:56:26 +02:00
Nestor Soriano 6f2e0bf694 Improve error messaging in WC_Tests_MaxMind_Database::test_download_database_works 2020-05-20 09:56:25 +02:00
Nestor Soriano 884fd08462 Add a workaround for code hacking static methods on already loaded files.
The unit testing bootstrap loads and initializes WooCommerce, this
loads a bunch of code files that can't then be hacked in the test hooks.

A workaround is provided in this commit for the case of hacking
static methods. A new StaticWrapper class is created that allows
defining mock methods after the code file has been loaded.
This is applied to all classes from a fixed list in the bootstrap,
before WooCommerce is initialized. The list should be kept up to date
with the list of classes that require such workaround.
2020-05-20 09:56:25 +02:00
Nestor Soriano 57845ef8b8 All code hacking files moved to src\Testing folder. 2020-05-20 09:56:25 +02:00
Nestor Soriano 1a68abbc28 Miscellaneous code hacking fixes:
- Fix how CodeHackerTestHook::executeBeforeTest parses the test name,
  to account for warnings and tests with data sets.

- CodeHackerTestHook now includes a executeAfterTest hook that
  disables the code hacker (needed to prevent it from inadvertently
  altering further tests). Also, clear_hacks is executed in
  executeBeforeTest for the same reason.

- CodeHacker gets restore, clear_hacks and is_enabled methods
  to support the changes in CodeHackerTestHook.

- FunctionsMockerHack fixed so that it doesn't modify strings
  that are class method definitions.

- Added the WC_Unit_Test_Case::file_copy method, it must be used
  instead of the PHP built-in "copy" in tests, otherwise tests
  that run with the code hacker active will fail.
  This is something to investigate.
2020-05-20 09:56:25 +02:00
Nestor Soriano 9a5b3b353d Add the @hack code annotation for tests.
Now @hack class and method annotations can be used to register
code hacks as an alternative to using before_ methods.
The syntax is /* @hack HackClassName param1 param2 */
where parameters will be passed to the class constructor.
If the class name ends with "Hack", then that suffix can be
omitted (e.g. "Foo" can be specified instead of "FooHack").
2020-05-20 09:56:25 +02:00
Nestor Soriano db58b51de3 Barebones implementation of a code hacker for unit tests.
The "code hacker" is a class that hooks on filesystem events
(using stream_wrapper_unregister) in order to allow for dynamically
modifying the content of PHP code files while they are loaded.
The code hacker class allows registering hacks, which are
functions that take source code as input and return the modified code.
A hack can be a standalone function or a class with a "hack" method.

A few hacks are provided off the shelf. One allows mocking standalone
PHP functions (WP, WOO or not), another one allows mocking static
methods, and there's the one that removes the "final" qualifier
from a class definition. This helps unit testing stuff that would
otherwise be quite hard to test.
2020-05-20 09:56:25 +02:00
Vedanshu Jain 7fb1079137
Merge pull request #26399 from woocommerce/fix/uploads_htaccess
Disable directory listing for redirect download method
2020-05-19 15:56:37 +05:30
Ron Rennick 617a523057 fix merge conflicts 2020-05-18 12:34:03 -03:00
Claudio Sanches eea062f9fa
Merge pull request #26519 from woocommerce/fix/csv-import-special-columns
Fixed the case conversion for meta key column mapping in product CSV imports
2020-05-18 11:33:50 -03:00
Ron Rennick 07c6075dde use nonced logout link for store owner logout 2020-05-15 16:58:50 -03:00
Boro Sitnikovski f34e73d402 Add a comment on @babel/preset-env 2020-05-15 11:28:21 +02:00
Boro Sitnikovski ad3b9fc861 Fix version mismatch error 2020-05-15 11:21:59 +02:00
Boro Sitnikovski b01f3aae93 Add some additional information and be specific about babel file 2020-05-15 11:21:34 +02:00
Peter Fabian 2f141eca77 PHPCS 2020-05-15 09:40:23 +02:00
Christopher Allford 7bf9c31f64 Adjusted the column name normalization to avoid squashing meta key case sensitivity
Since we were converting the field to lowercase we ended up inserting meta in all lowercase, regardless of what it was in the CSV file. We should only be using the normalized field name when looking at the default columns, and should instead rely on a case-insensitive regex for the special columns.

One thing to note is that we're still defaulting the $headers array to the normalized field, as we don't want to change what is being passed to the filter for unmapped columns.
2020-05-14 21:20:55 -07:00
Christopher Allford 63ba6f7ee0 Moved the PSR-4 namespaced test directory to the correct folder
I know this probably doesn't belong in this PR, but it has been thoroughly discussed and I don't think anyone will mind :)
2020-05-14 21:20:47 -07:00
Peter Fabian 777c140611 Skip tests when WC Admin is not active.
Since those Notes were created because of WC Admin and the display is handled by WC Admin, it does not make sense to test them without WC Admin.
In addition, the data store that handles these Notices is not loaded without WC Admin.
2020-05-14 14:35:09 +02:00
Peter Fabian 2c1625d3f9 Added a couple of tests for WC_Notes_Run_Db_Update, a poorly testable class. 2020-05-14 13:31:43 +02:00
Ron Rennick 3053942cf1 chore(release): publish
- @woocommerce/e2e-environment@0.1.5
2020-05-13 15:18:00 -03:00
Ron Rennick a433304757 additional changes
- Update @wordpress/e2e-test-utils to 4.6.0
- ignore all node_modules folders in the install
- remove missed package script
- bump component version
2020-05-13 15:14:18 -03:00
Claudio Sanches 1d99c343e7 Added unit tests 2020-05-12 15:36:25 -03:00
Christopher Allford ef8e7114b7 Merge branch 'privacy-exporter-group-description' of git://github.com/garretthyder/woocommerce into garretthyder-privacy-exporter-group-description 2020-05-12 09:40:17 -07:00
Ron Rennick df6e9e7894 bump e2e-environment to 0.1.4 2020-05-12 13:35:42 -03:00
Job 8fb72c8a1d Decapitalise "Better" in "Build a Better WooCommerce"
All titles and questions in the new onboarding wizards only capitalise names and the first letter of the sentence. This seemed a tiny bit off. (Literally tiny.)

Changed "Build a Better WooCommerce" to "Build a better WooCommerce"
2020-05-12 07:49:24 -07:00
Ron Rennick 02b649d17c use version of docker supported by trusty and newer 2020-05-11 22:58:45 -03:00
Ron Rennick ed135109e0 add e2e component build
- add build script
- update component for path changes
- bump component version
- move ready post creation to component
- update component readme
2020-05-11 15:54:12 -03:00
Vedanshu Jain 31b648d479
Merge pull request #26358 from woocommerce/fix/26348
Clear only plugin cache if WC header are not present to load with WC headers.
2020-05-11 18:14:39 +05:30
Ron Rennick e2af7e5d10
Merge pull request #26427 from woocommerce/docs/e2e-tests
update tests and e2e readme instructions, file locations
2020-05-11 09:16:38 -03:00
Ron Rennick dea4144be2 docker compose command line arg parsing for local and module 2020-05-08 16:26:30 -03:00
Vedanshu Jain 6d8ca7f4ef
Merge pull request #26056 from woocommerce/fix/fix_cart_unit_test
Fixes broken unit test
2020-05-08 23:52:01 +05:30
Claudio Sanches 73b71023ca Fixed cart get total unit test 2020-05-08 23:17:59 +05:30
yasiendwieb ad3a9e8bf3 fix issue in tax calculation at cart test case 2020-05-08 23:17:59 +05:30
Ron Rennick 72ff998033 remove npm e2e-CI script command 2020-05-08 14:29:02 -03:00
Ron Rennick 209b2edea9 chore(release): publish
- @woocommerce/e2e-environment@0.1.2
2020-05-08 14:09:39 -03:00
Ron Rennick e1c24c9f3e chore(release): publish
- @woocommerce/e2e-environment@0.1.1
2020-05-08 14:00:46 -03:00
Ron Rennick 4f908c452d update tests and e2e readme instructions, file locations 2020-05-08 11:24:43 -03:00
Ron Rennick 0f2fb4f8d5 fix merge conflicts 2020-05-06 14:05:00 -03:00
Ron Rennick 0e2e91371a update for review items 2020-05-06 13:29:13 -03:00
Joshua T Flowers 43ab840e1a
Add a put method to the WC_Helper_API (#26262)
* Merge wc api authorization headers with given headers

* Add put method to WC_Helper_API

* Add unit test coverage around WC_Helper_API request methods

* Add tests for WC_Helper_API url method
2020-05-06 19:25:23 +03:00
Jonathan Sadowski a0a8cf7ab3 Add test to ensure that a notice is displayed when an any attribute is omitted 2020-05-05 14:16:01 -05:00
Jonathan Sadowski 53c905f493 Reset request vars in any attribute test 2020-05-05 13:32:15 -05:00
Jonathan Sadowski c0a72c9185 Reset notices at the start of each test 2020-05-05 13:32:15 -05:00
Jonathan Sadowski 3f47608228 Test adding a variation with 'any' attributes 2020-05-05 13:32:15 -05:00
Jonathan Sadowski 790c8ae8ae Update the test to make sure there are no error notices 2020-05-05 13:32:15 -05:00
Jonathan Sadowski 3f70f70f3a Switch to assertCount for count assertions in test 2020-05-05 13:32:15 -05:00
Jonathan Sadowski 3d0bfd8ee2 Add test to check for notice when invalid attribute is provided for a variant 2020-05-05 13:32:14 -05:00
Jonathan Sadowski 31bdce3725 Fix typo in test_add_variation_with_url test (use British spelling of colour) 2020-05-05 13:32:14 -05:00
Jonathan Sadowski fc683bdb80 Update unit tests to account for issue 24000 2020-05-05 13:32:14 -05:00
vedanshujain 27ad4a552e Rename file and class to resemble PSR4 like convention for consistency. 2020-05-05 19:19:37 +05:30
Ron Rennick 97a6110ae4 combine puppeteer config files 2020-05-04 16:16:21 -03:00
vedanshujain f4e169f21e Moved test specific logic from bootstrap to test file 2020-05-02 00:31:54 +05:30
vedanshujain 13dfb8180f Add unit test and a sample Woo plugin file 2020-05-01 22:47:08 +05:30
Ron Rennick 71fb49dc06 restore latest default.json from master 2020-05-01 13:28:59 -03:00
Ron Rennick 78e777f25f restore travis e2e setup script 2020-05-01 10:18:21 -03:00
Ron Rennick 6726f6423d merge travis config files 2020-04-30 19:58:37 -03:00
Christopher Allford c0ecb79ba2
Merge pull request #26345 from woocommerce/refactor/phpunit-suite
Restructure PHPUnit Suite
2020-04-30 13:51:16 -07:00
Ron Rennick 7fbbbf6608 update travis config 2020-04-30 16:43:36 -03:00
Christopher Allford 98b6b973e8 Updated the tests readme to explain the purpose of our two test directories 2020-04-30 10:09:42 -07:00
Ron Rennick 0de3718770 change component name to e2e-environment 2020-04-30 14:01:42 -03:00
Ron Rennick b4fcfd93c2 rename test:e2e.json, remove redundant files 2020-04-29 11:22:11 -03:00
Christopher Allford 04ec11e90b Added a PSR-4 namespaced tests/php folder for tests written against new code in the src directory 2020-04-28 15:41:04 -07:00
Ron Rennick d41fbc7ff2 update folder structure, use WordPress 5.4 2020-04-28 19:09:39 -03:00
Ron Rennick da494be615 merge master 2020-04-28 16:13:30 -03:00
Vedanshu Jain 15f8eb04c4
Merge pull request #26230 from woocommerce/update/wc-admin-1.1.0
Update wc-admin version to 1.1.0
2020-04-28 19:05:50 +05:30
Julia Amosova b1bb4dfdb9 Add wait for the 'Proceed' button to become active in shipping task 2020-04-27 16:30:50 -04:00
Julia Amosova 46bc16de98 Update the number of fields expected within shipping task 2020-04-27 15:29:09 -04:00
Julia Amosova 3991647c94 Add shipping store location verification step in onboarding e2e test 2020-04-27 14:22:23 -04:00
Christopher Allford b5bd8225e8 Moved PHPUnit suite into tests/legacy 2020-04-24 13:53:40 -07:00
Vedanshu Jain ee119e0a7e
Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout" 2020-04-21 15:37:21 +05:30
Christopher Allford caa1a6d475 Merge remote-tracking branch 'origin/master' into fix/update-minimum-version 2020-04-16 14:46:17 -07:00
Claudio Sanches e43dc9b8a2 Use assertContains 2020-04-16 18:06:18 -03:00
Claudio Sanches 02e3ec7e97 Use assertStringContainsString to compare images 2020-04-16 17:52:22 -03:00
Claudio Sanches a5bc29e26c Fixed unit test on WP 5.5 alpha 2020-04-16 00:25:32 -03:00
Jeff Stieler 17d3771273 Remove defunct E2E test runner script, add docker scripts to package file. 2020-04-15 11:17:48 -06:00
Jeff Stieler 622e47f29f E2E: add app-level node config dir to path. 2020-04-15 11:07:32 -06:00
Ron Rennick e8efb82b9e add install jest 2020-04-14 12:06:26 -06:00
Ron Rennick 9742085f01 move before script to bash 2020-04-14 12:06:26 -06:00
Ron Rennick 049d606b15 use consistent job name 2020-04-14 12:06:26 -06:00