Commit Graph

140 Commits

Author SHA1 Message Date
Nestor Soriano 0eed82b3b7 Fix code standards violations introduced in #25092 2020-04-07 12:28:30 +02:00
Vedanshu Jain 3bf473517d
Merge pull request #25708 from woocommerce/update/reserve-stock-for-checkout
Introduce a `reserved stock` class and database table to prevent race conditions during checkout
2020-04-07 02:16:22 +05:30
Vedanshu Jain 237463c39b
Merge pull request #25800 from woocommerce/fix/25748
Fixes tax rounding issues
2020-04-07 00:24:34 +05:30
vedanshujain ef17b148be Removed unused tax class prop 2020-04-06 12:49:46 +00:00
Néstor Soriano 13765d9e91
Merge pull request #25092 from leanzafrancesco/fix/25091
Fix/25091 - Wrong totals in orders with taxable and non-taxable products and percentage coupons
2020-04-06 12:31:07 +02:00
Mike Jolley 9b5189dc7a Remove tests for order methods which were removed 2020-04-03 15:55:15 +01:00
vedanshujain facfb16131 Changed class name to match file name 2020-04-03 15:55:14 +01:00
Claudio Sanches 2ebd86f2dc Revert "Revert "Add support for '_held_for_checkout` records to prevent race conditions."" 2020-04-03 15:55:13 +01:00
vedanshujain 1314fdc0e7 Clear existing shippin rates before adding rate for test 2020-03-03 16:15:25 +05:30
vedanshujain 2c2d96ec95 Added tests for rounding issues 2020-03-02 15:30:10 +05:30
Peter Fabian ee865fe0b4
Merge pull request #25504 from woocommerce/update/order-detail-summary
Enhance order details and payment summary
2020-02-06 11:40:45 +01:00
Rodrigo Primo fb3b977a16 Add test to make sure that negative fees never make order total negative
For some reason unknown to me, the following commit added logic to make
sure that negative fees never make the order total negative: 804feb9333

Probably by accident, commit 4326e39250 changed this logic when `$fees_total += $item->get_total()` was replaced by `$fees_total += $fee_total`:

4326e39250 (diff-9b4164165828b26c4b7aec01c7b17884R1594)

This commit adds a failing test that ensures that the old behavior is
tested. This test needs to be fixed before we merge the changes proposed
in PR #25504.
2020-02-04 15:33:21 -03:00
Rodrigo Primo 08e0936aa6 Improve coverage of WC_Abstract_Order::calculate_totals() test
This commits improves the coverage of the
WC_Abstract_Order::calculate_totals() test by including a fee to the
order used to test the method.
2020-02-04 15:26:52 -03:00
Rodrigo Primo b87d0e26fe Add basic unit test for WC_Abstract_Order::get_total_fees() 2020-02-04 15:13:27 -03:00
Christopher Allford 1d1413b4ee Replaced direct access of many constants with the Constants library 2020-01-31 22:18:47 -08:00
Claudio Sanches 85a077b939 Coupon race condition prevention 2020-01-06 19:44:24 -03:00
Rodrigo Primo 62d6b05b58 Fix Generic.Formatting.MultipleStatementAlignment violations
This commit fixes all violations of the Generic.Formatting.MultipleStatementAlignment sniff automatically using phpcbf.
2019-12-20 14:21:08 -03:00
vedanshujain 53bfcea110 Use same filter for stocks and coupon for consistency. 2019-12-17 19:13:19 +05:30
vedanshujain 72545c44b7 Add support for `_held_for_checkout` records to improve performance.
This will also improve transactional stability and avoid race conditions by providing a way to lock usage counts.
2019-12-17 19:13:19 +05:30
Francesco Leanza 59af851069
Merge branch 'master' into fix/25091 2019-12-09 16:46:02 +01:00
vedanshujain 60cd7b3651 Refactor Order Class to use shared calculation logic.
We added a trait to move shared logic betweem Orders and Cart. This commit refactors Order class to use that shared logic.
Also adds a test for a failing case.
2019-11-25 17:53:14 +05:30
Francesco Leanza dd3427958b Fixed order totals calculation if it contains taxable and non-taxable products and percentage coupons
Added PHPUnit tests
2019-11-21 11:28:22 +01:00
vedanshujain 6f2d64dcb4 Check for max discount to be -ve to prevent overwriting fee.
When we refund fee and some other line item whose value is more than fee in a single requst, value of line item will overwrite refund fee.

This is because where we check to make sure that we do not discount more than total possible value (to prevent negative total), we do not account for the fact that sometimes the cart could contain refund items. In those cases max_discount * -1 will always be larges then fees total.

This commit adds a check to make sure that max discount * -1 is indeed negative before overwriting fee total.
2019-09-03 20:45:33 +05:30
Rodrigo Primo 16442956e8 Fix PHPCS errors 2019-07-19 10:19:23 -03:00
Claudio Sanches 16041d9247 Fixed failing tests 2019-07-18 22:42:31 -03:00
Gerhard Potgieter b2ed079520 Manual orders coupon usage limits by email (#23775)
* Add functionality to wp-admin order to check for coupon usage based on email addresses, similar to how WC_Cart handles this seperately, included unit tests.

* Only do the coupon by email usage check if order is from a guest. Fix issue with unit test.
2019-05-27 11:45:29 -03:00
Gerhard Potgieter 30ce9ff6a3
Merge pull request #23689 from woocommerce/add/get_used_coupon_codes
Deprecate get_used_coupons in favor of get_coupon_codes
2019-05-15 15:34:40 +02:00
Gerhard 486321161c Update usage of get_used_coupon_codes to get_coupon_codes 2019-05-14 11:21:27 +02:00
Daniel Bitzer 3024043bb4 Add unit test for WC_Abstract_Order::get_coupons() 2019-05-14 15:46:49 +09:30
Gerhard 31acfbcb4a Deprecate WC_Abstract_Order::get_used_coupons in favor of WC_Abstract_Order::get_used_coupon_codes, this reflects the actual data being returned better. 2019-05-13 14:40:54 +02:00
Rodrigo Primo 18ee70918b Fix PHPCS violations in tests/ using PHPCBF
This commit fixes all 1533 PHPCS errors that PHPCBF can fix automatically in the tests/ directory. Before this change there was a total of 3106 PHPCS errors in the WooCommerce repository and now there is 1573 errors.
2019-05-01 19:05:00 -03:00
unknown 883ecc3ca4 removed variable that was not being used 2019-01-11 19:19:15 -05:00
Steve Grunwell 550b309901 Merge branch 'master' into feature/sanitize-order-id-tests 2018-10-17 02:21:04 +00:00
Steve Grunwell 6f77040eb4 Since PHP 5.2 runs a *really* old version of PHPUnit (that doesn't support the @testWith annotation), run the scenarios in a single test case 2018-10-17 02:05:10 +00:00
Steve Grunwell c3b76a38f7 Add a test for handling errors during order status transitions 2018-10-06 18:09:44 +00:00
Steve Grunwell 65cda44fe6 Add tests for wc_sanitize_order_id()
This commit adds four test cases (via a PHPUnit data provider) for the `wc_sanitize_order_id()` function.

While writing the tests, it was also discovered that the function was returning a *string*, not an integer as indicated by the DocBlock, so explicit type-casting was added.
2018-10-04 13:53:55 +00:00
Rodrigo Primo 5f6c729107 Remove unnecessary clean up code from unit tests
This commit removes unnecessary clean up code form some unit tests. All database changes done during a test are automatically reverted after the test finishes, so it is not necessary to write code to manually remove them. This change simplifies the test code and make it run a bit faster.
2018-08-23 15:15:17 -03:00
Mike Jolley 31058ac215 Tests -> CRUD 2018-06-13 16:30:42 +01:00
Steve Grunwell 4bbf9c364d Ensure tests use ISO 3166-1 alpha-2 country codes
[According to the WooCommerce wiki](https://github.com/woocommerce/woocommerce/wiki/Order-and-Order-Line-Item-Data) and `WC_REST_Orders_Controller`, WooCommerce stores country codes using the ISO 3166-1 alpha-2 (2 character) standard. However, the `WC_Tests_Order_Functions::test_wc_get_order_address_params()` test method was using 'USA' instead of 'US'.
2018-05-24 20:50:01 +00:00
Rodrigo Primo 42e801db0c Add test to check WC_Order_Query when using the 'customer' parameter 2018-05-08 17:24:16 -03:00
Rodrigo Primo b43f828a7b Fix PHPCS violations automatically using phpcbf 2018-05-08 11:55:32 -03:00
Rodrigo Primo 5d9dadca87 Remove unnecessary cleanup code from orders unit tests
It is not necessary to manually remove data added to the database after each test. WP unit tests framework does this automatically.
2018-05-08 11:52:58 -03:00
Mike Jolley 21d7dbc612 Merge branch 'master' into update/17252 2018-03-01 15:58:17 +00:00
Mike Jolley 6b722e1120 Update tests to use subtotal as a basis for the discounts. 2018-02-27 18:57:28 +00:00
Mike Jolley dbdc3af9e5 Tests 2018-01-12 14:20:39 +00:00
claudiulodro 1e0dbbf544 Better whitespace 2018-01-04 10:31:28 -08:00
claudiulodro 431c9b5766 Unit tests for order error handling 2018-01-04 10:28:52 -08:00
Rodrigo Primo 2329e4f526 Add exception message to fix failing test
This commit adds the exception message thrown when WC_Order::set_billing_email() is called with an invalid message to a test to fix it.

I couldn't find what change in WC codebase broke the test and I'm not sure why it is failing only when running using PHP 5.6:

https://travis-ci.org/woocommerce/woocommerce/jobs/315750242#L600
2017-12-13 12:28:48 -02:00
Rodrigo Primo ddc2d926fc PHPCS: fix violations manually 2017-12-13 12:19:51 -02:00
Rodrigo Primo c4665bff46 Automatic PHPCS fixes using phpcbf 2017-12-13 12:11:47 -02:00