wordpress-develop/tests/phpunit/tests/customize
Weston Ruter c7ff79df64 Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.

PHP changes:

* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.

JS changes:

* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.

Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.


git-svn-id: https://develop.svn.wordpress.org/trunk@37476 602fd350-edb4-49c9-b593-d223f7449a82
2016-05-20 21:09:40 +00:00
..
control.php Customize: Allow controls to be registered without any associated settings. 2016-02-24 18:27:45 +00:00
manager.php Customize: Add setting validation model and control notifications to augment setting sanitization. 2016-05-20 21:09:40 +00:00
nav-menu-item-setting.php Customize: Ensure that wp_setup_nav_menu_item filter applies consistently on nav_menu_item setting values. 2016-05-10 06:40:48 +00:00
nav-menu-setting.php Customize: Prevent dropping backslashes from input on general settings and settings for nav menus and some widgets. 2016-02-23 01:01:43 +00:00
nav-menus.php Customize: Fix regressions and harden implementation of selective refresh for nav menus. 2016-03-09 00:08:51 +00:00
panel.php Unit Tests: after [35225], make factory a method/getter on WP_UnitTestCase and add magic methods for BC for every plugin that is extending WP_UnitTestCase and accessing the $factory instance prop. 2015-10-17 18:02:16 +00:00
partial.php Customize: Define params on WP_Customize_Partial::render_callback() for the sake of subclasses overriding this method. 2016-03-02 06:08:38 +00:00
section.php Unit Tests: better fixtures for Tests_Meta_Slashes and Tests_WP_Customize_Section. 2015-10-17 21:28:43 +00:00
selective-refresh-ajax.php Customize: Fix and extend broken ajax unit tests to account for partials being skipped from rendering. 2016-02-23 21:45:51 +00:00
selective-refresh.php Customize: Skip exporting partials to client and handling rendering requests if user can't modify associated settings. 2016-02-23 18:13:30 +00:00
setting.php Customize: Add setting validation model and control notifications to augment setting sanitization. 2016-05-20 21:09:40 +00:00
widgets.php Customize: Handle filtering sidebars_widgets when the underlying option is non-existent. 2016-05-02 23:41:18 +00:00