Tests: Add a unit test for post trash hooks executed when trashing a changeset.

The test ensures that the correct number of arguments is passed to post trash hooks in `WP_Customize_Manager::trash_changeset_post()`, which bypasses `wp_trash_post()`.

Follow-up to [56043], [57238].

See #60183.

git-svn-id: https://develop.svn.wordpress.org/trunk@57241 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2024-01-04 11:45:31 +00:00
parent 43d2455dc6
commit e43275b61c

View File

@ -2150,6 +2150,44 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertSame( $args['post_content'], $post->post_content );
}
/**
* Test that trash_changeset_post() passes the correct number of arguments to post trash hooks.
*
* @covers WP_Customize_Manager::trash_changeset_post
*/
public function test_trash_changeset_post_passes_all_arguments_to_trash_hooks() {
$args = array(
'post_type' => 'customize_changeset',
'post_content' => wp_json_encode(
array(
'blogname' => array(
'value' => 'Test',
),
)
),
'post_name' => wp_generate_uuid4(),
'post_status' => 'draft',
);
$post_id = wp_insert_post( $args );
$manager = $this->create_test_manager( $args['post_name'] );
$pre_trash_post = new MockAction();
$wp_trash_post = new MockAction();
$trashed_post = new MockAction();
add_action( 'pre_trash_post', array( $pre_trash_post, 'action' ), 10, 3 );
add_action( 'wp_trash_post', array( $wp_trash_post, 'action' ), 10, 2 );
add_action( 'trashed_post', array( $trashed_post, 'action' ), 10, 2 );
$manager->trash_changeset_post( $post_id );
$this->assertCount( 3, $pre_trash_post->get_args()[0] );
$this->assertCount( 2, $wp_trash_post->get_args()[0] );
$this->assertCount( 2, $trashed_post->get_args()[0] );
}
/**
* Register scratchpad setting.
*