Skip to content

Commit

Permalink
Tests: Add a unit test for post trash hooks executed when trashing a …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
SergeyBiryukov committed Jan 4, 2024
1 parent 43d2455 commit e43275b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/phpunit/tests/customize/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,44 @@ public function test_trash_changeset_post_preserves_properties() {
$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.
*
Expand Down

0 comments on commit e43275b

Please sign in to comment.