Make WordPress Core


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

    r60062 r60253  
    3333    public static $home_page_id;
    3434
     35    /**
     36     * ID of the administrator user.
     37     *
     38     * @var int
     39     */
     40    public static $administrator_id;
     41
     42    /**
     43     * ID of the author user.
     44     *
     45     * @var int
     46     */
     47    public static $author_id;
     48
     49    /**
     50     * Set up the shared fixtures.
     51     *
     52     * @param WP_UnitTest_Factory $factory Factory instance.
     53     */
    3554    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     55        self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
     56        self::$author_id        = $factory->user->create( array( 'role' => 'author' ) );
     57
    3658        /*
    3759         * Declare theme support for custom logo.
     
    213235    public function test_customize_preview_wp_site_icon_empty() {
    214236        global $wp_customize;
    215         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     237        wp_set_current_user( self::$administrator_id );
    216238
    217239        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
     
    231253    public function test_customize_preview_wp_site_icon_dirty() {
    232254        global $wp_customize;
    233         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     255        wp_set_current_user( self::$administrator_id );
    234256
    235257        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
     
    764786     */
    765787    public function test_get_the_archive_title_is_correct_for_author_queries() {
    766         $user_with_posts    = self::factory()->user->create_and_get(
    767             array(
    768                 'role' => 'author',
    769             )
    770         );
    771         $user_with_no_posts = self::factory()->user->create_and_get(
    772             array(
    773                 'role' => 'author',
    774             )
    775         );
     788        $user_with_posts    = get_user_by( 'id', self::$administrator_id );
     789        $user_with_no_posts = get_user_by( 'id', self::$author_id );
    776790
    777791        self::factory()->post->create(
Note: See TracChangeset for help on using the changeset viewer.