Commit Graph

176 Commits

Author SHA1 Message Date
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 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
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 e102ec3d83 Merge branch 'master' into fix/25133 2020-08-17 14:59:49 -03: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
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
Claudio Sanches 1839feae91 Added unit tests for #27244 2020-08-12 18:50:25 -03: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
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
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
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
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
vedanshujain 1ada7d8b26 Merge branch 'master' of https://github.com/woocommerce/woocommerce 2020-08-04 18:22:41 +05:30
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
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
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
Claudio Sanches 119b5d6568
Merge branch 'master' into fix/23790 2020-07-28 13:07:17 -03: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 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
Claudio Sanches 4048d19a39 Added unit tests for coupon code sanitization 2020-07-27 17:44:04 -03: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
Claudio Sanches 7bd34e3545
Merge branch 'master' into fix/25843 2020-07-24 17:04:28 -03:00
Claudio Sanches 419e5c239a
Fixed docblocks 2020-07-24 17:01:42 -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
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
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 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
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
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
Damir Ha 161eb4a320 Add test postcode validation for Bosnia and Herzegovina 2020-07-16 13:57:44 +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 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
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
Claudio Sanches d3d8e74b58 Fixed unit tests for #26462 2020-07-01 18:13:29 -03: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
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
Ron Rennick e1c16ba7ef remove setup unit tests 2020-06-23 16:19:54 -03:00
Ron Rennick 59f2bdbe46 add template cache unit test 2020-06-22 16:05:29 -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
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
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
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 d904db815d Disable flaky test which was causing many calculation tests to fail. 2020-05-27 23:53:20 +05:30
vedanshujain 57d336433a Fix regression caused by merging #25092 conflicting with #24828 2020-05-22 22:08:42 +05:30
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