Commit Graph

1664 Commits

Author SHA1 Message Date
Rodrigo Primo 27915dd696 Exception when WC_Product_Variation is instantiated with the wrong type
This commits changes WC_Product_Variation to raise an exception when the
class is instantiated with an ID that belongs to a post object that is
not a product variation.

This is necessary to avoid problems like the one described in #24956
where passing a variable product ID to WC_Product_Variation would result
in transparently modifying the variable product title and excerpt.
2019-12-05 15:45:48 -03:00
Claudio Sanches d7e2a98aaf
Merge pull request #24828 from woocommerce/fix/24695
Adds shared code between Orders and Cart calculation logic.
2019-12-05 12:39:50 -03:00
Peter Fabian 4dfa68b62d More PHPCS fixes. 2019-12-05 15:46:13 +01:00
Peter Fabian 9b398947dd Fixed the test by sleeping longer. 2019-12-05 15:17:34 +01:00
Peter Fabian 3ba3d5cf1b Made the fail messages unique. 2019-12-05 15:07:03 +01:00
Peter Fabian 7bfbe7a5f1 Removed incorrect comment. 2019-12-05 15:05:38 +01:00
Peter Fabian 0d3074a554 Added rate limiting to Add payment method. 2019-12-05 12:03:02 +01:00
Rodrigo Primo 3af024fc5c
Merge pull request #25031 from woocommerce/feature/24956
Introduced wc_get_product_object() helper
2019-12-04 16:53:04 -03:00
Claudio Sanches e3b2d9f10c Merge branch 'master' into feature/inline-notices 2019-12-04 16:26:10 -03:00
Claudio Sanches 5fdb880831
Merge branch 'master' into feature/24956 2019-12-04 16:18:39 -03:00
Claudio Sanches 8033d5751e Changed wc_get_product_classname function name to wc_get_product_object 2019-12-04 16:15:16 -03:00
Claudio Sanches a12c25862b
Revert "Add support for '_held_for_checkout` records to prevent race conditions." 2019-12-04 16:03:05 -03:00
Claudio Sanches 0686e6f1cd
Merge pull request #25000 from woocommerce/feature/pay-button-support
Initial support for "pay button"
2019-12-04 16:02:02 -03:00
Rodrigo Primo 4af9a94129 PHPCS fixes 2019-12-04 15:52:20 -03:00
Claudio Sanches adbb4fd2d3
Merge pull request #24937 from jenkoian/wc-placeholder-attrs
Add support for custom attributes to wc_placeholder_img().
2019-12-04 15:42:41 -03:00
James Collins 7187db66e1 Add unit test 2019-12-04 12:29:40 +08:00
Claudio Sanches 0c486785ad
Merge pull request #25089 from woocommerce/fix/24009
Add support for '_held_for_checkout` records to prevent race conditions.
2019-12-03 17:47:22 -03:00
Claudio Sanches df4eb9c817 Use wc_get_order() in unit tests, and fixed coding standards 2019-12-03 16:44:37 -03:00
Claudio Sanches 988b72e461 Updated filter name to woocommerce_hold_stock_for_checkout
Also fixed coding standards
2019-12-03 16:38:17 -03:00
Rodrigo Primo 567b667acf Improve wc_print_notices() test coverage 2019-12-03 15:29:10 -03:00
Claudio Sanches 6a395e2485
Merge pull request #25064 from woocommerce/fix/24315
Optimize variable product duplication slug generation
2019-12-03 15:28:55 -03:00
vedanshujain 8c2c83d488 Use `wc_round_tax_total` to make it consistent with how we round taxes.
When price includes taxes, we round down. This patch uses the correct method to round taxes depending on the mode instead of plain rounding.
2019-11-27 03:13:39 +05:30
vedanshujain 5ef41f1ecc Empty cart before test to make sure everything in cart exists 2019-11-26 18:21:24 +05:30
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
Rodrigo Primo 6cd08dc7bd Use the spread operator instead of call_user_func_array() in WC_Data_Store
This commit replaces a call to call_user_func_array() in WC_Data_Store::__call() with argument unpacking using the spread operator which was introduced in PHP 5.6. This change should improve WooCommerce performance a tiny bit since WC_Data_Store::__call() is called somewhat frequently and call_user_func_array() has a bad performance reputation. I added one unit test to make sure this change doesn't break the functionality of the altered method.
2019-11-21 11:52:47 -03:00
Rodrigo Primo ed1c4b11b8 Fix PHPCS errors in WC_Tests_Data_Store class file 2019-11-21 10:41:27 -03:00
Rodrigo Primo 44b09cb15a Remove unused test method 2019-11-21 10:40:38 -03:00
vedanshujain 70a54d0639 Added Unit Tests for `held_for_checkout` records. 2019-11-21 18:11:37 +05:30
Christopher Allford 753f39ff27 Added unique slug generation for variable product duplication
The standard wp_unique_post_slug() function will run one query per name collision, leading to a large number of queries being made when a product template is duplicated repeatedly. We can avoid this by doing the unique generation ourselves.
2019-11-18 13:49:41 -08:00
Maxime Jobin 61256ad208
Use the $username variable
This test could fail if time() does not return the same value twice.
2019-11-16 11:09:59 -05:00
Christopher Allford 4120fe1cd8 Added tests to product duplication 2019-11-15 21:12:22 -08:00
Claudio Sanches e95dcfb68a Added unit tests for wc_get_product_classname() 2019-11-13 15:30:03 -03:00
Claudio Sanches d8fed95403 Convert all notice data into HTML data 2019-11-07 20:34:49 -03:00
Claudio Sanches 830e612420 Updated notice tests 2019-11-07 20:25:32 -03:00
Claudio Sanches fdd391e10e Introduced wc_get_pay_buttons() function 2019-11-07 17:23:38 -03:00
Claudio Sanches ced207633c Added unit tests for pay button support 2019-11-07 17:23:19 -03:00
Ian Jenkins 2340f269cf Add support for custom attributes to wc_placeholder_img().
When displaying a list of images you often want a specific class to be
attached to each image, therefore you pass through a custom class using
the attr parameter. Unfortunately this doesn't get passed through to a
placeholder image should one be needed. This means that, for example, if
you're custom class center an image or something, it won't be honoured
for placeholders, which can lead to some wonky image listings.

You can work around this currently by leverging the
`woocommerce_product_get_image` filter, but it's a bit gnarly as you
need to do some regexing or string splitting or something and checking
class names and what not. This provides a much easier way, by
supporting custom attrs on placeholder images as is the case for non
placehodler images.
2019-10-30 15:08:19 +00:00
Vedanshu Jain cb12010627
Merge pull request #24295 from woocommerce/fix/24096
Remove %20 from fields in External Products form
2019-10-03 00:15:52 +05:30
Claudio Sanches 8758fbdbdc Fixed unit tests for wc_query_string_form_fields() 2019-10-02 11:23:31 -03:00
Peter Fabian 7ea9fdec62 Added unit test for special case of attribute value 0. 2019-10-02 15:06:22 +02:00
Peter Fabian e45fe949c1 Added unit test & updated other affected tests. 2019-10-02 14:59:42 +02: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
Claudio Sanches 1b2b9d528a Fixed Netherlands postcode formatting (#24284)
* Fixed Netherlands postcode formatting

Trim all spaces, fixes issues when postcode is empty.

* Always trim spaces

* Updated unit test for test_wc_format_postcode()
2019-08-09 15:00:40 -03:00
Gerhard 9c7e1d43b0 Update unit tests for wc_string_to_bool to test for camel case as well as uppercase values. 2019-08-06 14:12:42 +02:00
Claudio Sanches 162c5dd8a2 Updated tests for wc_query_string_form_fields() 2019-08-01 17:30:39 -03:00
Rodrigo Primo 833c5016ea Add unit tests for wc_get_endpoint_url() 2019-08-01 17:23:11 -03:00
Claudio Sanches 83c0e69637 Update wc_format_decimal() tests to check for multiple decimals points 2019-07-31 19:54:58 -03:00
Rodrigo Primo a8f6a94cda Remove methods assertIsWPError() and assertNotWPError() from WC_Unit_Test_Case
Those two methods are already declared in the class WP_UnitTestCase, so there is
no need to declare them again in the class WC_Unit_Test_Case. The only
caveat is that assertIsWPError() is called assertWPError() in
WP_UnitTestCase so it was necessary to update all of its usages.
2019-07-19 10:56:58 -03:00
Rodrigo Primo 16442956e8 Fix PHPCS errors 2019-07-19 10:19:23 -03:00
Claudio Sanches 5eb11ea77a Remove exception for PHP 5.2 2019-07-18 23:02:30 -03:00
Claudio Sanches 16041d9247 Fixed failing tests 2019-07-18 22:42:31 -03:00
Gerhard Potgieter 52f1eb4060
Revert "Prevent negative prices on products" 2019-07-15 08:50:11 +02:00
Claudio Sanches 77191a97f8
Merge pull request #23705 from woocommerce/fix/23696
Prevent negative prices on products
2019-07-12 12:56:34 -03:00
Claudio Sanches 60c18ce544
Merge pull request #23067 from woocommerce/pr/23043
Allow matching of "any" attributes in find_matching_product_variation…
2019-07-12 12:40:53 -03:00
Gerhard aad5b2863a Add more tests to test more expected combinations as well as test the negatives. 2019-07-12 15:10:20 +02:00
Claudio Sanches c63cd802aa
Merge pull request #23957 from woocommerce/feature/feature-plugin-packages
Include external feature plugins as packages
2019-07-10 15:47:48 -03:00
Gerhard Potgieter 49adf8169b
Merge pull request #23672 from woocommerce/fix/23366-2
Auto generate usernames when a username is blacklisted by WP
2019-07-10 15:44:44 +02:00
Mike Jolley c928188831 Update from master 2019-07-10 12:57:02 +01:00
Gerhard 98c24b1090 Merge branch 'master' into pr/23043 2019-07-10 10:34:52 +02:00
Gerhard 22bb52f9be Fix failing unit tests due to changes in #24111 2019-07-10 08:48:33 +02:00
Claudio Sanches 6e6ca196f9
Merge branch 'master' into fix/23340 2019-07-09 16:32:43 -03:00
Rodrigo Primo 34e5018137
Merge pull request #23262 from woocommerce/fix/23257
CSV Import - check if sku or id column exists when updating products from csv
2019-07-09 14:25:03 -03:00
Claudio Sanches 2fa5396cfc Fixed coding standards 2019-07-09 12:43:03 -03:00
Claudio Sanches 32996d2fdd Merge branch 'master' into pr/23043 2019-07-09 12:39:40 -03:00
Gerhard Potgieter a7b6d7bfa4
Merge pull request #24024 from woocommerce/fix/23917/code
Round late when rounding at subtotal to reduce rounding error.
2019-07-09 11:05:40 +02:00
Claudio Sanches a4b8184464
Merge pull request #23950 from parmarhardip/fix-23944
Currency changes applied for 'São Tomé and Príncipe dobra' and 'Mauritanian ouguiya'
2019-07-08 16:12:53 -03:00
Claudio Sanches da99bc8ca0 Merge branch 'master' into feature/feature-plugin-packages 2019-07-08 14:33:21 -03:00
vedanshujain 8ab6cb2b5a Round late when rounding at subtotal to reduce rounding error.
We were earlier rounding different tax rate values while they are merged, even if rounding at subtotal setting is enabled. This increases the rounding error, especially when prices are inclusive of taxes, and thus there is a chance that the total will be slightly different from when add the original values. For egs: https://github.com/woocommerce/woocommerce/issues/23917 .

This commit changes this behavior to round *after* we have summed all the precise unround values. Similar for items prices, we now round as late as possible, if rounding at subtotal is enabled.
2019-07-04 22:34:29 +05:30
Gerhard Potgieter 12fbfa5677
Merge pull request #22927 from woocommerce/update/22895
Allow "Thanks" wording in emails to be reworded by admin
2019-07-04 12:43:00 +02:00
Gerhard 29bb165aca Apply unit tests 2019-07-04 11:50:33 +02:00
Gerhard 88442fea1e Update unit tests to match new placeholder text 2019-07-04 11:36:12 +02:00
Rodrigo Primo 737f6af5e8 Introduce file type check for tax rate importer 2019-07-02 10:44:21 -03:00
Rodrigo Primo 7324e480e7 Fix phpcs violations 2019-07-02 10:43:52 -03:00
Mike Jolley a0a58cfb15 update from master 2019-06-26 15:26:47 +01:00
Mike Jolley 9a8e8dacff Add integration tests 2019-06-25 15:57:44 +01:00
Mike Jolley de06195ae9 Remove API unit tests 2019-06-25 14:25:31 +01:00
Claudio Sanches fe4dfea8eb
Merge pull request #23771 from woocommerce/fix/23756
Fix Top rated shortcode results
2019-06-24 12:18:57 -03:00
Claudio Sanches 606c0417a9
Merge pull request #23837 from woocommerce/fix/23834
Make NL postcode validation more flexible
2019-06-24 12:17:53 -03:00
MD0123-Hardip 9890ab4164 unit testing changes 2019-06-20 11:37:38 +05:30
Claudio Sanches eedc871bea Update unit tests for wc_format_phone_number() 2019-06-19 17:44:01 -03:00
Claudio Sanches 2f7ec9506f New tests for is_postcode with NL postcodes 2019-05-28 20:55:51 -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 f6d9faa062 Introducde wc_load_cart to dynamically load the cart, this allows for functionality outside of frontend to initialise the cart. 2019-05-22 12:24:31 +02:00
Claudio Sanches 8af5117bf4 Fixed unit tests and coding standards 2019-05-20 17:27:25 -03:00
Gerhard Potgieter afd7e72c03
Merge pull request #23690 from woocommerce/update/obw-stripe
Update OWB Payment Gateway structure
2019-05-16 18:26:29 +02:00
Gerhard ddcef3b34c Fix unit test for new scenarios 2019-05-16 16:26:34 +02: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
Rodrigo Primo 47188f05cb Fix unit tests after changes in the default enabled payment gateways 2019-05-14 19:46:38 -03:00
Rodrigo Primo c8b55ff62d Improve WC_Admin_Setup_Wizard::get_wizard_in_cart_payment_gateways() tests
This commit moves two functions declared inside a test method to their
own protected methods inside the same test class to make it easier to
read the tests and it fixes the order of the parameters for the calls to
Assert::assertEquals(). The first parameter passed to this method should
be the expected value and the second parameter should be the actual
value and not the opposite.
2019-05-14 18:38:53 -03:00
Rodrigo Primo ba792a6589 Fix PHPCS errors 2019-05-14 18:34:21 -03:00
Claudio Sanches 33249f3f3d Updated unit tests for wc_format_decimal() 2019-05-14 13:21:42 -03:00
Gerhard Potgieter b7facc0674
Merge pull request #23663 from danielbitzer/add_get_coupons_method
Add WC_Abstract_Order::get_coupons()
2019-05-14 11:35:21 +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
Gerhard Potgieter d2c7d8c86e
Merge pull request #23535 from woocommerce/fix/23518
Fix: parameter values should be converted back as well when building form fields
2019-05-10 10:43:28 +02:00
Claudio Sanches 4c028c13ba Updated unit tests 2019-05-09 17:28:32 -03: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
Rodrigo Primo 45c2c78ea2 Fix: parameter values should be converted back as well when building form fields
PR #23196 added a workaround to `parse_str()` limitation when dealing with full-stops, pluses, and spaces in the parameter key. This workaround involved temporarily replacing those three characters with placeholders before calling `parse_str()` and then replacing back to the original form. This commit fixes a bug in this logic that was replacing back only parameters keys and not parameters values.

For example, if the query string is `?query.parameter=foo.bar`, the resulting <input> field contained `foo{dot}bar`, instead of the expected `foo.bar`.
2019-04-26 13:58:27 -03:00
Rodrigo Primo e21430703c Remove redundant calls to var_export() in test_wc_query_string_form_fields()
It is not necessary to use the $message parameter of assertEquals() to output the value of $actual_html, as PHPUnit already output this variable value in case of error.
2019-04-26 11:49:30 -03:00