Make WordPress Core

Changeset 57241


Ignore:
Timestamp:
01/04/2024 11:45:31 AM (9 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r56748 r57241  
    21522152
    21532153    /**
     2154     * Test that trash_changeset_post() passes the correct number of arguments to post trash hooks.
     2155     *
     2156     * @covers WP_Customize_Manager::trash_changeset_post
     2157     */
     2158    public function test_trash_changeset_post_passes_all_arguments_to_trash_hooks() {
     2159        $args = array(
     2160            'post_type'    => 'customize_changeset',
     2161            'post_content' => wp_json_encode(
     2162                array(
     2163                    'blogname' => array(
     2164                        'value' => 'Test',
     2165                    ),
     2166                )
     2167            ),
     2168            'post_name'    => wp_generate_uuid4(),
     2169            'post_status'  => 'draft',
     2170        );
     2171
     2172        $post_id = wp_insert_post( $args );
     2173
     2174        $manager = $this->create_test_manager( $args['post_name'] );
     2175
     2176        $pre_trash_post = new MockAction();
     2177        $wp_trash_post  = new MockAction();
     2178        $trashed_post   = new MockAction();
     2179
     2180        add_action( 'pre_trash_post', array( $pre_trash_post, 'action' ), 10, 3 );
     2181        add_action( 'wp_trash_post', array( $wp_trash_post, 'action' ), 10, 2 );
     2182        add_action( 'trashed_post', array( $trashed_post, 'action' ), 10, 2 );
     2183
     2184        $manager->trash_changeset_post( $post_id );
     2185
     2186        $this->assertCount( 3, $pre_trash_post->get_args()[0] );
     2187        $this->assertCount( 2, $wp_trash_post->get_args()[0] );
     2188        $this->assertCount( 2, $trashed_post->get_args()[0] );
     2189    }
     2190
     2191    /**
    21542192     * Register scratchpad setting.
    21552193     *
Note: See TracChangeset for help on using the changeset viewer.