Make WordPress Core


Ignore:
Timestamp:
05/26/2025 02:34:12 PM (15 months ago)
Author:
johnbillion
Message:

Build/Test Tools: Increase shared user fixtures following switch to bcrypt hashing.

User creation is somewhat more expensive since switching the default password hashing algorithm to bcrypt in 6.8. This speeds up the tests by making more use of shared user fixtures, thus reducing the number of users that are created during tests.

Props peterwilsoncc.

See #63026

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/selective-refresh-ajax.php

    r56971 r60253  
    3030
    3131        /**
     32         * Shared user ID for the tests.
     33         *
     34         * @var int
     35         */
     36        public static $user_id = 0;
     37
     38        /**
     39         * Set up shared fixtures.
     40         *
     41         * @param WP_UnitTest_Factory $factory Factory.
     42         */
     43        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     44                self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
     45        }
     46
     47        /**
    3248         * Set up the test fixture.
    3349         */
     
    8096
    8197                // Check expected_customize_preview.
    82                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     98                wp_set_current_user( self::$user_id );
    8399                $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->wp_customize->theme()->get_stylesheet() );
    84100                ob_start();
     
    122138         */
    123139        private function setup_valid_render_partials_request_environment() {
    124                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     140                wp_set_current_user( self::$user_id );
    125141                $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->wp_customize->theme()->get_stylesheet() );
    126142                $_POST[ WP_Customize_Selective_Refresh::RENDER_QUERY_VAR ] = '1';
     
    172188        public function test_handle_render_partials_request_for_non_rendering_partial() {
    173189                $this->setup_valid_render_partials_request_environment();
    174                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     190                wp_set_current_user( self::$user_id );
    175191                $this->wp_customize->add_setting( 'home' );
    176192                $this->wp_customize->selective_refresh->add_partial( 'foo', array( 'settings' => array( 'home' ) ) );
     
    209225        public function test_handle_rendering_disallowed_partial() {
    210226                $this->setup_valid_render_partials_request_environment();
    211                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     227                wp_set_current_user( self::$user_id );
    212228                $this->wp_customize->add_setting(
    213229                        'secret_message',
     
    245261        public function test_handle_rendering_partial_with_missing_settings() {
    246262                $this->setup_valid_render_partials_request_environment();
    247                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     263                wp_set_current_user( self::$user_id );
    248264                $this->wp_customize->selective_refresh->add_partial( 'bar', array( 'settings' => 'bar' ) );
    249265
Note: See TracChangeset for help on using the changeset viewer.