woocommerce/tests/php/includes
Nestor Soriano 5a11d9e064
Refactor the settings pages, and add unit tests for them.
This commit fixes some inconsistencies in the settings pages, and
makes all the existing pages extensible by adding new sections
(that was possible in some pages, but not in others). Main changes:

1. Modify the 'get_sections' method so that it invokes a new protected
   'get_own_sections' method and then triggers the
   'woocommerce_get_sections_' . id filter.

This way the filter is triggered only in the base class
and not in each of the derived classes too.

2. Change the get_settings() method so that it has its signature
   changed to get_settings( $current_section = '' )
   in the base class and in all the derived class.

Some derived classes were already using this signature, but others
(those not having multiple sections natively) weren't, making then
effectively impossible to define multiple sections for these pages
via filters.

With this change all the section pages act consistently and allow
both adding new settings to the default "General" section
and creating new sections via filters.

3. Change the implementation of 'get_settings' in the base class
   so that it searches for a 'get_settings_for_{section_id}_section'
   method in the class and executes it, otherwise it executes the new
   protected method get_settings_for_section( $current_section ); then
   it triggers the 'woocommerce_get_settings_' . id filter.

This makes it easier to separate the code that returns the list
of filters in multiple methods, one per section, instead of using
one big if-else-else... block.

So now instead of overriding get_settings($current_section='') derived
classes need to implement get_settings_for_{$current_section}_section
for each section, or override get_settings_for_section($current_section)
or both. 'get_settings_for_section' returns an empty array by default.

Also, 'woocommerce_get_settings_' . id is triggered in one single
place too.

Other improvements:

* Remove duplicated code from 'output' in 'WC_Settings_Page' children.

Some classes inherited from 'WC_Settings_Page' override the 'output'
method with custom code, which in all cases ended up repeating the code
of the original method as a fallback. These repetitions have been
replaced with 'parent::output()'.

* Fix inconsistencies for 'save' and 'output' in WC_Settings_Tax/Emails

The 'WC_Settings_Tax' and 'WC_Settings_Emails' classes had some
inconsistencies in their 'save' and 'output' methods that prevented the
proper creation new sections and the addition of new settings via the
'woocommerce_get_sections_' and 'woocommerce_get_settings_' filters.
Now they work as expected.

* Deduplicate parts of 'save' in 'WC_Settings_Page' and children.

Two methods have been added to 'WC_Settings_Page' class:
'save_settings_for_current_section' and 'do_update_options_action'.
These are intended to be invoked by derived classes in their 'save'
methods, in order to remove code repetition.

* Add some helper methods to WC_Unit_Test_Case.

Methods added:
- assertOutputsHTML
- assertEqualsHTML
- normalize_html
- capture_output_from
2021-04-12 12:42:26 +02:00
..
abstracts Add unit test 2020-11-12 22:58:05 +05:30
admin Adjust tests for WC_Admin_Dashboard_Setup (consider 'payments' task) 2021-03-29 17:39:58 +02:00
data-stores Do not copy fields from the billing address to the shipping address. | #28759 2021-03-26 17:08:37 -07:00
exporter Added unit tests for importer and exporter 2020-07-15 21:49:26 -03:00
gateways/paypal Add unit tests for when PayPal API will return error 2020-09-18 17:12:33 +05:30
importer Added unit tests for importer and exporter 2020-07-15 21:49:26 -03:00
rest-api/Controllers Update REST API v3 taxes endpoint descriptions with deprecation/introduction information. 2021-03-31 12:41:53 +02:00
settings Refactor the settings pages, and add unit tests for them. 2021-04-12 12:42:26 +02:00
class-wc-ajax-test.php Add unit tests. 2020-09-25 19:41:20 +05:30
class-wc-cart-test.php Fixed copy and paste 2021-02-23 19:55:54 -03:00
class-wc-checkout-test.php Don't verify empty country codes on checkout 2021-04-07 09:59:56 +02:00
class-wc-comments-test.php Add unit tests for review count methods. 2021-01-14 18:31:02 +05:30
class-wc-customer-test.php Add tests for #28692 2020-12-30 19:29:22 +05:30
class-wc-discounts-tests.php Add unit tests for #28592 2020-12-16 19:37:01 +05:30
class-wc-emails-tests.php Fix typos. 2021-01-18 19:52:20 +05:30
class-wc-install-test.php Added some exceptions to the PHPCS standards for unit tests 2020-07-15 14:29:13 -07:00
class-wc-post-data-test.php Added unit tests for coupon code sanitization 2020-07-27 17:44:04 -03:00
class-wc-product-variable-test.php Fixed test that used PHPUnit function from newer version 2020-08-05 15:43:08 -07:00
class-wc-query-test.php Fix price filtering when there are variations. 2021-02-05 16:34:42 +01:00
class-wc-tracker-test.php Remove debug code in tests. 2021-02-25 15:19:27 -08:00
wc-core-functions-test.php Use reference in wc_asort_by_locale 2020-09-10 16:02:39 -03:00
wc-formatting-functions-test.php Added unit tests for coupon code sanitization 2020-07-27 17:44:04 -03:00
wc-stock-functions-tests.php Improved tests, added save points, fixed comments. 2021-03-16 13:08:29 +01:00