Make WordPress Core


Ignore:
Timestamp:
05/26/2025 02:34:12 PM (6 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/ajax/wpCustomizeNavMenus.php

    r57099 r60253  
    3939    public static $terms;
    4040
     41
     42    /**
     43     * Admin user ID.
     44     *
     45     * @var int
     46     */
     47    public static $admin_user_id = 0;
     48
     49    /**
     50     * User IDs keyed by role.
     51     *
     52     * @var int[]
     53     */
     54    public static $user_ids = array();
     55
     56    /**
     57     * Set up shared fixtures.
     58     *
     59     * @param WP_UnitTest_Factory $factory The factory.
     60     */
    4161    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    4262        // Make some post objects.
     
    4666        // Some terms too.
    4767        self::$terms = $factory->term->create_many( 5 );
     68
     69        // Create an admin user.
     70        self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );
     71
     72        foreach ( array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ) as $role ) {
     73            self::$user_ids[ $role ] = $factory->user->create( array( 'role' => $role ) );
     74        }
    4875    }
    4976
     
    5481        parent::set_up();
    5582        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    56         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     83        wp_set_current_user( self::$admin_user_id );
    5784        global $wp_customize;
    5885        $this->wp_customize = new WP_Customize_Manager();
     
    92119        }
    93120
    94         wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
     121        wp_set_current_user( self::$user_ids[ $role ] );
    95122
    96123        $_POST = array(
     
    486513        }
    487514
    488         wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
     515        wp_set_current_user( self::$user_ids[ $role ] );
    489516
    490517        $_POST = array(
     
    706733
    707734        // Bad nonce.
    708         wp_set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
     735        wp_set_current_user( self::$user_ids['subscriber'] );
    709736        $_POST                = wp_slash(
    710737            array(
     
    719746
    720747        // Missing params.
    721         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     748        wp_set_current_user( self::$user_ids['administrator'] );
    722749        $_POST                = wp_slash(
    723750            array(
Note: See TracChangeset for help on using the changeset viewer.