You appear to be a bot. Output may be restricted
Description
Test request for trashing a changeset.
Usage
Tests_Ajax_CustomizeManager::test_handle_changeset_trash_request();
Parameters
Returns
void
Source
File name: wordpress-develop-tests/phpunit/tests/ajax/CustomizeManager.php
Lines:
1 to 74 of 74
public function test_handle_changeset_trash_request() { $uuid = wp_generate_uuid4(); $wp_customize = $this->set_up_valid_state( $uuid ); $this->make_ajax_call( 'customize_trash' ); $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'invalid_nonce', $this->_last_response_parsed['data']['code'] ); $nonce = wp_create_nonce( 'trash_customize_changeset' ); $_POST['nonce'] = $nonce; $_GET['nonce'] = $nonce; $_REQUEST['nonce'] = $nonce; $this->make_ajax_call( 'customize_trash' ); $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'non_existent_changeset', $this->_last_response_parsed['data']['code'] ); $wp_customize->register_controls(); // And settings too. $wp_customize->set_post_value( 'blogname', 'HELLO' ); $wp_customize->save_changeset_post( array( 'status' => 'save', ) ); add_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) ); $this->make_ajax_call( 'customize_trash' ); $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'changeset_trash_unauthorized', $this->_last_response_parsed['data']['code'] ); remove_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) ); $lock_user_id = static::factory()->user->create( array( 'role' => 'administrator' ) ); $previous_user = get_current_user_id(); wp_set_current_user( $lock_user_id ); $wp_customize->set_changeset_lock( $wp_customize->changeset_post_id() ); wp_set_current_user( $previous_user ); $this->make_ajax_call( 'customize_trash' ); $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'changeset_locked', $this->_last_response_parsed['data']['code'] ); delete_post_meta( $wp_customize->changeset_post_id(), '_edit_lock' ); wp_update_post( array( 'ID' => $wp_customize->changeset_post_id(), 'post_status' => 'trash', ) ); $this->make_ajax_call( 'customize_trash' ); $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'changeset_already_trashed', $this->_last_response_parsed['data']['code'] ); wp_update_post( array( 'ID' => $wp_customize->changeset_post_id(), 'post_status' => 'draft', ) ); $wp_trash_post_count = did_action( 'wp_trash_post' ); add_filter( 'pre_trash_post', '__return_false' ) <; $this->make_ajax_call( 'customize_trash' ); $this->assertFalse( $this->_last_response_parsed['success'] ); $this->assertSame( 'changeset_trash_failure', $this->_last_response_parsed['data']['code'] ); remove_filter( 'pre_trash_post', '__return_false' ); $this->assertSame( $wp_trash_post_count, did_action( 'wp_trash_post' ) ); $wp_trash_post_count = did_action( 'wp_trash_post' ); $this->assertSame( 'draft', get_post_status( $wp_customize->changeset_post_id() ) ); $this->make_ajax_call( 'customize_trash' ); $this->assertTrue( $this->_last_response_parsed['success'] ); $this->assertSame( 'trash', get_post_status( $wp_customize->changeset_post_id() ) ); $this->assertSame( $wp_trash_post_count + 1, did_action( 'wp_trash_post' ) ); }