Make WordPress Core


Ignore:
Timestamp:
06/14/2016 07:16:54 PM (8 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r37476 r37700  
    197197     */
    198198    function test_validate_setting_values() {
    199         $default_value = 'foo_default';
    200199        $setting = $this->manager->add_setting( 'foo', array(
    201200            'validate_callback' => array( $this, 'filter_customize_validate_foo' ),
     
    205204        $post_value = 'bar';
    206205        $this->manager->set_post_value( 'foo', $post_value );
    207         $this->assertEmpty( $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() ) );
     206        $validities = $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() );
     207        $this->assertCount( 1, $validities );
     208        $this->assertEquals( array( 'foo' => true ), $validities );
    208209
    209210        $this->manager->set_post_value( 'foo', 'return_wp_error_in_sanitize' );
     
    235236
    236237    /**
     238     * Test WP_Customize_Manager::prepare_setting_validity_for_js().
     239     *
     240     * @see WP_Customize_Manager::prepare_setting_validity_for_js()
     241     */
     242    function test_prepare_setting_validity_for_js() {
     243        $this->assertTrue( $this->manager->prepare_setting_validity_for_js( true ) );
     244        $error = new WP_Error();
     245        $error->add( 'bad_letter', 'Bad letter' );
     246        $error->add( 'bad_letter', 'Bad letra' );
     247        $error->add( 'bad_number', 'Bad number', array( 'number' => 123 ) );
     248        $validity = $this->manager->prepare_setting_validity_for_js( $error );
     249        $this->assertInternalType( 'array', $validity );
     250        foreach ( $error->errors as $code => $messages ) {
     251            $this->assertArrayHasKey( $code, $validity );
     252            $this->assertInternalType( 'array', $validity[ $code ] );
     253            $this->assertEquals( join( ' ', $messages ), $validity[ $code ]['message'] );
     254            $this->assertArrayHasKey( 'data', $validity[ $code ] );
     255            $this->assertArrayHasKey( 'from_server', $validity[ $code ]['data'] );
     256        }
     257        $this->assertArrayHasKey( 'number', $validity['bad_number']['data'] );
     258        $this->assertEquals( 123, $validity['bad_number']['data']['number'] );
     259    }
     260
     261    /**
    237262     * Test WP_Customize_Manager::set_post_value().
    238263     *
     
    566591        $this->assertArrayHasKey( 'activeSections', $settings );
    567592        $this->assertArrayHasKey( 'activeControls', $settings );
     593        $this->assertArrayHasKey( 'settingValidities', $settings );
    568594        $this->assertArrayHasKey( 'nonce', $settings );
    569595        $this->assertArrayHasKey( '_dirty', $settings );
Note: See TracChangeset for help on using the changeset viewer.