Commit Graph

23 Commits

Author SHA1 Message Date
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 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
Nestor Soriano 8a7d955253 Improvements on the code hacker.
- Add methods to temporarily disable and reenable the code hacker.

The code hacker is causing issues in some tests that perform
write operations to the local filesystem. Since this happens only
in a few cases, the easiest fix is to temporarily disable the
code hacker when that happens. This commit adds two new methods
for that in `WC_Unit_Test_Case`: `disable_code_hacker` and
`reenable_code_hacker`.

These methods use a disabling requests count so that the hacker
isn't enabled before it should. E.g. you call `disable`, then
a helper method that does `disable` and `enable`, then `enable` -
then only the last `enable` will have effect.

- `CodeHacker::add_hack` has now a boolean `persistent` parameter.
Persistent hacks won't be cleared by `clear_hacks`.

- `CodeHackerTestHook::executeAfterTest` will now disable the hacker
only if no persistent hacks are registered.

- The existing `file_copy` method is made static for consistency.

- `CodeHacker::restore` method renamed to `disable` for clarity.
2020-05-20 09:56:26 +02:00
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
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
Peter Fabian 2f141eca77 PHPCS 2020-05-15 09:40:23 +02: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
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
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
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 b5bd8225e8 Moved PHPUnit suite into tests/legacy 2020-04-24 13:53:40 -07:00