WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/02/2017 03:36:18 AM (22 months ago)
Author:
westonruter
Message:

Customize: Add infrastructure for trashing/reverting of unpublished changes; introduce full-screen OverlayNotification for trashing and theme install/preview.

  • Introduce a new wp.customize.previewer.trash() JS API to trash the current changeset, along with logic to WP_Customize_Manager to handle deleting changeset drafts.
  • Add trashing to wp.customize.state which is then used to update the UI.
  • UI for trashing is pending design feedback. One possibility is to add a new trash button to Publish Settings section that invokes wp.customize.previewer.trash().
  • Improve logic for managing the visibility and disabled states for publish buttons.
  • Prevent attempting requestChangesetUpdate while processing and bump processing while doing save.
  • Update changeset_date state only if sent in save response.
  • Merge ThemesSection#loadThemePreview() into ThemesPanel#loadThemePreview().
  • Remove unused autosaved state.
  • Start autosaving and prompting at beforeunload after a change first happens. This is key for theme previews since even if a user did not make any changes, there were still dirty settings which would get stored in an auto-draft unexpectedly.
  • Allow Notification to accept additional classes to be added to container.
  • Introduce OverlayNotification and use for theme installing, previewing, and trashing. Such overlay notifications take over the entire window.

Props westonruter, celloexpressions.
See #37661, #39896, #21666, #35210.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/CustomizeManager.php

    r41626 r41667  
    444444
    445445    /**
    446      * Test request for dismissing autosave changesets.
     446     * Test request for trashing a changeset.
    447447     *
    448448     * @ticket 39896
    449      * @covers WP_Customize_Manager::handle_dismiss_changeset_autosave_request()
    450      * @covers WP_Customize_Manager::dismiss_user_auto_draft_changesets()
    451      */
    452     public function test_handle_dismiss_changeset_autosave_request() {
     449     * @covers WP_Customize_Manager::handle_changeset_trash_request()
     450     */
     451    public function test_handle_changeset_trash_request() {
    453452        $uuid = wp_generate_uuid4();
    454453        $wp_customize = $this->set_up_valid_state( $uuid );
    455454
    456         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     455        $this->make_ajax_call( 'customize_trash' );
     456        $this->assertFalse( $this->_last_response_parsed['success'] );
     457        $this->assertEquals( 'invalid_nonce', $this->_last_response_parsed['data']['code'] );
     458
     459        $nonce = wp_create_nonce( 'trash_customize_changeset' );
     460        $_POST['nonce'] = $_GET['nonce'] = $_REQUEST['nonce'] = $nonce;
     461        $this->make_ajax_call( 'customize_trash' );
     462        $this->assertFalse( $this->_last_response_parsed['success'] );
     463        $this->assertEquals( 'non_existent_changeset', $this->_last_response_parsed['data']['code'] );
     464
     465        $wp_customize->register_controls(); // And settings too.
     466        $wp_customize->set_post_value( 'blogname', 'HELLO' );
     467        $wp_customize->save_changeset_post( array(
     468            'status' => 'save',
     469        ) );
     470
     471        add_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) );
     472        $this->make_ajax_call( 'customize_trash' );
     473        $this->assertFalse( $this->_last_response_parsed['success'] );
     474        $this->assertEquals( 'changeset_trash_unauthorized', $this->_last_response_parsed['data']['code'] );
     475        remove_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) );
     476
     477        wp_update_post( array(
     478            'ID' => $wp_customize->changeset_post_id(),
     479            'post_status' => 'trash',
     480        ) );
     481        $this->make_ajax_call( 'customize_trash' );
     482        $this->assertFalse( $this->_last_response_parsed['success'] );
     483        $this->assertEquals( 'changeset_already_trashed', $this->_last_response_parsed['data']['code'] );
     484
     485        wp_update_post( array(
     486            'ID' => $wp_customize->changeset_post_id(),
     487            'post_status' => 'draft',
     488        ) );
     489
     490        $wp_trash_post_count = did_action( 'wp_trash_post' );
     491        add_filter( 'pre_trash_post', '__return_false' );
     492        $this->make_ajax_call( 'customize_trash' );
     493        $this->assertFalse( $this->_last_response_parsed['success'] );
     494        $this->assertEquals( 'changeset_trash_failure', $this->_last_response_parsed['data']['code'] );
     495        remove_filter( 'pre_trash_post', '__return_false' );
     496        $this->assertEquals( $wp_trash_post_count, did_action( 'wp_trash_post' ) );
     497
     498        $wp_trash_post_count = did_action( 'wp_trash_post' );
     499        $this->assertEquals( 'draft', get_post_status( $wp_customize->changeset_post_id() ) );
     500        $this->make_ajax_call( 'customize_trash' );
     501        $this->assertTrue( $this->_last_response_parsed['success'] );
     502        $this->assertEquals( 'trash', get_post_status( $wp_customize->changeset_post_id() ) );
     503        $this->assertEquals( $wp_trash_post_count + 1, did_action( 'wp_trash_post' ) );
     504    }
     505
     506    /**
     507     * Return caps array containing 'do_not_allow'.
     508     *
     509     * @return array Caps.
     510     */
     511    public function return_do_not_allow() {
     512        return array( 'do_not_allow' );
     513    }
     514
     515    /**
     516     * Test request for dismissing autosave changesets.
     517     *
     518     * @ticket 39896
     519     * @covers WP_Customize_Manager::handle_dismiss_autosave_request()
     520     * @covers WP_Customize_Manager::dismiss_user_auto_draft_changesets()
     521     */
     522    public function test_handle_dismiss_autosave_request() {
     523        $uuid = wp_generate_uuid4();
     524        $wp_customize = $this->set_up_valid_state( $uuid );
     525
     526        $this->make_ajax_call( 'customize_dismiss_autosave' );
    457527        $this->assertFalse( $this->_last_response_parsed['success'] );
    458528        $this->assertEquals( 'invalid_nonce', $this->_last_response_parsed['data'] );
    459529
    460         $nonce = wp_create_nonce( 'dismiss_customize_changeset_autosave' );
     530        $nonce = wp_create_nonce( 'customize_dismiss_autosave' );
    461531        $_POST['nonce'] = $_GET['nonce'] = $_REQUEST['nonce'] = $nonce;
    462         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     532        $this->make_ajax_call( 'customize_dismiss_autosave' );
    463533        $this->assertFalse( $this->_last_response_parsed['success'] );
    464534        $this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] );
     
    490560            $this->assertFalse( (bool) get_post_meta( $post_id, '_customize_restore_dismissed', true ) );
    491561        }
    492         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     562        $this->make_ajax_call( 'customize_dismiss_autosave' );
    493563        $this->assertTrue( $this->_last_response_parsed['success'] );
    494564        $this->assertEquals( 'auto_draft_dismissed', $this->_last_response_parsed['data'] );
     
    503573
    504574        // Subsequent test results in none dismissed.
    505         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     575        $this->make_ajax_call( 'customize_dismiss_autosave' );
    506576        $this->assertFalse( $this->_last_response_parsed['success'] );
    507577        $this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] );
     
    521591
    522592        // Since no autosave yet, confirm no action.
    523         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     593        $this->make_ajax_call( 'customize_dismiss_autosave' );
    524594        $this->assertFalse( $this->_last_response_parsed['success'] );
    525595        $this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
     
    541611
    542612        // Confirm autosave gets deleted.
    543         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     613        $this->make_ajax_call( 'customize_dismiss_autosave' );
    544614        $this->assertTrue( $this->_last_response_parsed['success'] );
    545615        $this->assertEquals( 'autosave_revision_deleted', $this->_last_response_parsed['data'] );
     
    547617
    548618        // Since no autosave yet, confirm no action.
    549         $this->make_ajax_call( 'dismiss_customize_changeset_autosave' );
     619        $this->make_ajax_call( 'customize_dismiss_autosave' );
    550620        $this->assertFalse( $this->_last_response_parsed['success'] );
    551621        $this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
Note: See TracChangeset for help on using the changeset viewer.