Commit Graph

2215 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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 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
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