Commit Graph

175 Commits

Author SHA1 Message Date
Nestor Soriano 52eed70f04 Add a 'NumberUtil' class with a 'round' method.
There's a number of places in the WooCommerce codebase where the
built-in function 'round' is executed passing a non-numeric value
(not a number and not a string that can be parsed as a number),
for example round(''). In PHP 7 this yields a value of 0, but in
PHP 8 this throws an error.

This commit adds a 'NumberUtil' class with a static 'round' method,
this method checks if the passed value is numeric and if so it just
executes the built-in function, otherwise it returns 0. And all the
calls to 'round' in the codebase are replaced with 'NumberUtil::round'.
2020-10-01 11:08:51 +02:00
vedanshujain d51dd26816 Add unit tests. 2020-09-25 19:41:20 +05:30
Rodrigo Primo 197e8d274c
Merge pull request #27616 from woocommerce/fix/26960
Paypal gateway: protect code against a fatal error if WooCommerce is unable to communicate with PayPal
2020-09-18 09:34:57 -03:00
vedanshujain 140dafb704 Add unit tests for when PayPal API will return error 2020-09-18 17:12:33 +05:30
Claudio Sanches ed1a59b39b
Merge pull request #27416 from woocommerce/fix/27415
Fixed country list sorting
2020-09-17 10:35:43 -03:00
Claudio Sanches b5d8d94bc8 Use reference in wc_asort_by_locale 2020-09-10 16:02:39 -03:00
vedanshujain 6a2ea0e27a Add unit test for show_shipping for different countries. 2020-09-09 19:53:21 +05:30
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
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
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
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 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
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
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
Christopher Allford 154c812fc0 Renamed the `StringUtility` to `StringUtil` to make it easier to work with 2020-08-06 12:35:51 -07:00
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
Christopher Allford 8e8698a3f6 Fixed test that used PHPUnit function from newer version 2020-08-05 15:43:08 -07: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
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
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
Claudio Sanches 1cd84d6446 Merge branch 'master' into fix/23790 2020-07-30 16:46:01 -03: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
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
Claudio Sanches 4048d19a39 Added unit tests for coupon code sanitization 2020-07-27 17:44:04 -03:00
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 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
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 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 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
Claudio Sanches 64f4fb85e2 Move variation validation logic to add to cart 2020-07-23 19:10:42 -03: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
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
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
vedanshujain af401a7d80 Add unit test 2020-07-14 23:32:12 +05:30
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
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
Claudio Sanches 6afbed0c14 Fixed coding standards 2020-06-01 23:55:17 -03:00
vedanshujain bbb7600f87 Add unit test for calculation based on rounding pref 2020-05-27 23:55:46 +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 418741a0b2 Add unit test for verify_base_tables function 2020-05-22 18:32:04 +05:30
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
vedanshujain 27ad4a552e Rename file and class to resemble PSR4 like convention for consistency. 2020-05-05 19:19:37 +05:30
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
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