Make WordPress Core


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

    r57008 r60253  
    1010    protected $user_id;
    1111
    12     public function set_up() {
    13         parent::set_up();
     12    /**
     13     * ID of the administrator user with de_DE local.
     14     *
     15     * @var int
     16     */
     17    public static $administrator_de_de;
    1418
    15         $this->user_id = self::factory()->user->create(
     19    /**
     20     * ID of the user with es_ES local.
     21     *
     22     * @var int
     23     */
     24    public static $user_es_es;
     25
     26    /**
     27     * Set up the shared fixtures.
     28     *
     29     * @param WP_UnitTest_Factory $factory Factory instance.
     30     */
     31    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     32        self::$administrator_de_de = $factory->user->create(
    1633            array(
    1734                'role'   => 'administrator',
     
    2037        );
    2138
    22         wp_set_current_user( $this->user_id );
     39        self::$user_es_es = self::factory()->user->create(
     40            array(
     41                'locale' => 'es_ES',
     42            )
     43        );
     44    }
     45
     46    public function set_up() {
     47        parent::set_up();
     48
     49        wp_set_current_user( self::$administrator_de_de );
    2350    }
    2451
     
    2653        set_current_screen( 'dashboard' );
    2754        $this->assertSame( 'de_DE', get_user_locale() );
    28         $this->assertSame( get_user_by( 'id', $this->user_id )->locale, get_user_locale() );
     55        $this->assertSame( get_user_by( 'id', self::$administrator_de_de )->locale, get_user_locale() );
    2956    }
    3057
    3158    public function test_update_user_locale() {
    3259        set_current_screen( 'dashboard' );
    33         update_user_meta( $this->user_id, 'locale', 'fr_FR' );
     60        update_user_meta( self::$administrator_de_de, 'locale', 'fr_FR' );
    3461        $this->assertSame( 'fr_FR', get_user_locale() );
    3562    }
     
    3764    public function test_returns_site_locale_if_empty() {
    3865        set_current_screen( 'dashboard' );
    39         update_user_meta( $this->user_id, 'locale', '' );
     66        update_user_meta( self::$administrator_de_de, 'locale', '' );
    4067        $this->assertSame( get_locale(), get_user_locale() );
    4168    }
     
    79106
    80107    public function test_user_id_argument_with_id() {
    81         $user_id = self::factory()->user->create(
    82             array(
    83                 'locale' => 'es_ES',
    84             )
    85         );
     108        $user_id = self::$user_es_es;
    86109
    87110        $user_locale1 = get_user_locale( $user_id );
     
    96119
    97120    public function test_user_id_argument_with_wp_user_object() {
    98         $user_id = self::factory()->user->create(
    99             array(
    100                 'locale' => 'es_ES',
    101             )
    102         );
     121        $user_id = self::$user_es_es;
    103122
    104123        $user = get_user_by( 'id', $user_id );
Note: See TracChangeset for help on using the changeset viewer.