mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Customize: Update server-sent setting validation notifications as changes are entered.
Send back setting validities with full refreshes and selective refreshes so that invalid settings can have notifications displayed immediately before attempting save, and so that these notifications can be cleared as soon as the input is corrected. * Splits out JS logic for listing controls into separate methods `wp.customize.Setting.prototype.findControls()` and `wp.customize.findControlsForSettings()`. * Adds a `setting` property to the `data` on notifications added to controls that are synced from their settings. * Adds `selective-refresh-setting-validities` message sent from preview to pane. * Changes `WP_Customize_Manager::validate_setting_values()` to return when settings are valid as well as invalid. * Adds `WP_Customize_Manager::prepare_setting_validity_for_js()`. * Add setting validities to data exported to JS in Customizer Preview and in selective refresh responses. Fixes #36944. git-svn-id: https://develop.svn.wordpress.org/trunk@37700 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -196,7 +196,6 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
* @see WP_Customize_Manager::validate_setting_values()
|
||||
*/
|
||||
function test_validate_setting_values() {
|
||||
$default_value = 'foo_default';
|
||||
$setting = $this->manager->add_setting( 'foo', array(
|
||||
'validate_callback' => array( $this, 'filter_customize_validate_foo' ),
|
||||
'sanitize_callback' => array( $this, 'filter_customize_sanitize_foo' ),
|
||||
@@ -204,7 +203,9 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
|
||||
$post_value = 'bar';
|
||||
$this->manager->set_post_value( 'foo', $post_value );
|
||||
$this->assertEmpty( $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() ) );
|
||||
$validities = $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() );
|
||||
$this->assertCount( 1, $validities );
|
||||
$this->assertEquals( array( 'foo' => true ), $validities );
|
||||
|
||||
$this->manager->set_post_value( 'foo', 'return_wp_error_in_sanitize' );
|
||||
$invalid_settings = $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() );
|
||||
@@ -233,6 +234,30 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( 'source' => 'filter_customize_validate_foo' ), $error->get_error_data() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WP_Customize_Manager::prepare_setting_validity_for_js().
|
||||
*
|
||||
* @see WP_Customize_Manager::prepare_setting_validity_for_js()
|
||||
*/
|
||||
function test_prepare_setting_validity_for_js() {
|
||||
$this->assertTrue( $this->manager->prepare_setting_validity_for_js( true ) );
|
||||
$error = new WP_Error();
|
||||
$error->add( 'bad_letter', 'Bad letter' );
|
||||
$error->add( 'bad_letter', 'Bad letra' );
|
||||
$error->add( 'bad_number', 'Bad number', array( 'number' => 123 ) );
|
||||
$validity = $this->manager->prepare_setting_validity_for_js( $error );
|
||||
$this->assertInternalType( 'array', $validity );
|
||||
foreach ( $error->errors as $code => $messages ) {
|
||||
$this->assertArrayHasKey( $code, $validity );
|
||||
$this->assertInternalType( 'array', $validity[ $code ] );
|
||||
$this->assertEquals( join( ' ', $messages ), $validity[ $code ]['message'] );
|
||||
$this->assertArrayHasKey( 'data', $validity[ $code ] );
|
||||
$this->assertArrayHasKey( 'from_server', $validity[ $code ]['data'] );
|
||||
}
|
||||
$this->assertArrayHasKey( 'number', $validity['bad_number']['data'] );
|
||||
$this->assertEquals( 123, $validity['bad_number']['data']['number'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WP_Customize_Manager::set_post_value().
|
||||
*
|
||||
@@ -565,6 +590,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertArrayHasKey( 'activePanels', $settings );
|
||||
$this->assertArrayHasKey( 'activeSections', $settings );
|
||||
$this->assertArrayHasKey( 'activeControls', $settings );
|
||||
$this->assertArrayHasKey( 'settingValidities', $settings );
|
||||
$this->assertArrayHasKey( 'nonce', $settings );
|
||||
$this->assertArrayHasKey( '_dirty', $settings );
|
||||
|
||||
|
||||
@@ -344,6 +344,7 @@ class Test_WP_Customize_Selective_Refresh_Ajax extends WP_UnitTestCase {
|
||||
$this->assertEquals( $count_customize_render_partials_after + 1, has_action( 'customize_render_partials_after' ) );
|
||||
$output = json_decode( ob_get_clean(), true );
|
||||
$this->assertEquals( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_blogname'] );
|
||||
$this->assertArrayHasKey( 'setting_validities', $output['data'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user