WordPress.org

Make WordPress Core

Changeset 36650


Ignore:
Timestamp:
02/23/2016 09:45:51 PM (2 years ago)
Author:
westonruter
Message:

Customize: Fix and extend broken ajax unit tests to account for partials being skipped from rendering.

Fixes regression introduced in [36643].

See #35914.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/selective-refresh-ajax.php

    r36586 r36650  
    199199    function test_handle_render_partials_request_for_non_rendering_partial() {
    200200        $this->setup_valid_render_partials_request_environment();
     201        wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     202        $this->wp_customize->add_setting( 'home' );
    201203        $this->wp_customize->selective_refresh->add_partial( 'foo', array( 'settings' => array( 'home' ) ) );
    202204        $context_data = array();
     
    223225        $output = json_decode( ob_get_clean(), true );
    224226        $this->assertEquals( array( false ), $output['data']['contents']['foo'] );
     227    }
     228
     229    /**
     230     * Test WP_Customize_Selective_Refresh::handle_render_partials_request() for a partial the user doesn't have the capability to edit.
     231     *
     232     * @see WP_Customize_Selective_Refresh::handle_render_partials_request()
     233     */
     234    function test_handle_rendering_disallowed_partial() {
     235        $this->setup_valid_render_partials_request_environment();
     236        wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     237        $this->wp_customize->add_setting( 'secret_message', array(
     238            'capability' => 'top_secret_clearance',
     239        ) );
     240        $this->wp_customize->selective_refresh->add_partial( 'secret_message', array( 'settings' => 'secret_message' ) );
     241
     242        $context_data = array();
     243        $placements = array( $context_data );
     244        $_POST['partials'] = wp_slash( wp_json_encode( array(
     245            'secret_message' => $placements,
     246        ) ) );
     247
     248        ob_start();
     249        try {
     250            $this->selective_refresh->handle_render_partials_request();
     251        } catch ( WPDieException $e ) {
     252            $this->assertEquals( '', $e->getMessage() );
     253        }
     254        $output = json_decode( ob_get_clean(), true );
     255        $this->assertNull( $output['data']['contents']['secret_message'] );
     256    }
     257
     258    /**
     259     * Test WP_Customize_Selective_Refresh::handle_render_partials_request() for a partial for which an associated setting does not exist.
     260     *
     261     * @see WP_Customize_Selective_Refresh::handle_render_partials_request()
     262     */
     263    function test_handle_rendering_partial_with_missing_settings() {
     264        $this->setup_valid_render_partials_request_environment();
     265        wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     266        $this->wp_customize->selective_refresh->add_partial( 'bar', array( 'settings' => 'bar' ) );
     267
     268        $context_data = array();
     269        $placements = array( $context_data );
     270        $_POST['partials'] = wp_slash( wp_json_encode( array(
     271            'bar' => $placements,
     272        ) ) );
     273
     274        ob_start();
     275        try {
     276            $this->selective_refresh->handle_render_partials_request();
     277        } catch ( WPDieException $e ) {
     278            $this->assertEquals( '', $e->getMessage() );
     279        }
     280        $output = json_decode( ob_get_clean(), true );
     281        $this->assertNull( $output['data']['contents']['bar'] );
    225282    }
    226283
Note: See TracChangeset for help on using the changeset viewer.