Make WordPress Core

Changeset 60253


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

Location:
trunk/tests/phpunit/tests
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPlugin.php

    r58876 r60253  
    55 */
    66class Tests_Admin_IncludesPlugin extends WP_UnitTestCase {
     7
     8    /**
     9     * Admin user ID.
     10     *
     11     * @var int $admin_id
     12     */
     13    public static $admin_id;
     14
    715    public static function wpSetUpBeforeClass( $factory ) {
     16        self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
    817        self::_back_up_mu_plugins();
    918    }
     
    3847    public function test_menu_page_url() {
    3948        $current_user = get_current_user_id();
    40         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     49        wp_set_current_user( self::$admin_id );
    4150        update_option( 'siteurl', 'http://example.com' );
    4251
     
    8291        global $menu;
    8392        $current_user = get_current_user_id();
    84         $admin_user   = self::factory()->user->create( array( 'role' => 'administrator' ) );
     93        $admin_user   = self::$admin_id;
    8594        wp_set_current_user( $admin_user );
    8695        set_current_screen( 'dashboard' );
     
    135144
    136145        $current_user = get_current_user_id();
    137         $admin_user   = self::factory()->user->create( array( 'role' => 'administrator' ) );
     146        $admin_user   = self::$admin_id;
    138147        wp_set_current_user( $admin_user );
    139148        set_current_screen( 'dashboard' );
     
    284293        $menu         = array();
    285294        $current_user = get_current_user_id();
    286         $admin_user   = self::factory()->user->create( array( 'role' => 'administrator' ) );
     295        $admin_user   = self::$admin_id;
    287296        wp_set_current_user( $admin_user );
    288297        set_current_screen( 'dashboard' );
     
    317326        $menu         = array();
    318327        $current_user = get_current_user_id();
    319         $admin_user   = self::factory()->user->create( array( 'role' => 'administrator' ) );
     328        $admin_user   = self::$admin_id;
    320329        wp_set_current_user( $admin_user );
    321330        set_current_screen( 'dashboard' );
     
    345354        $menu         = array();
    346355        $current_user = get_current_user_id();
    347         $admin_user   = self::factory()->user->create( array( 'role' => 'administrator' ) );
     356        $admin_user   = self::$admin_id;
    348357        wp_set_current_user( $admin_user );
    349358        set_current_screen( 'dashboard' );
  • trunk/tests/phpunit/tests/admin/includesTemplate.php

    r59564 r60253  
    44 */
    55class Tests_Admin_IncludesTemplate extends WP_UnitTestCase {
     6    /**
     7     * Editor user ID.
     8     *
     9     * @var int $editor_id
     10     */
     11    public static $editor_id;
     12
     13    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     14        self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
     15    }
    616
    717    /**
     
    6575
    6676        // Test that get_inline_data() has `post_category` div containing the assigned term.
    67         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     77        wp_set_current_user( self::$editor_id );
    6878        get_inline_data( $post );
    6979        $this->expectOutputRegex( '/<div class="post_category" id="wptests_tax_1_' . $post->ID . '">' . $term['term_id'] . '<\/div>/' );
     
    91101
    92102        // Test that get_inline_data() has `tags_input` div containing the assigned term.
    93         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     103        wp_set_current_user( self::$editor_id );
    94104        get_inline_data( $post );
    95105        $this->expectOutputRegex( '/<div class="tags_input" id="wptests_tax_1_' . $post->ID . '">Test<\/div>/' );
  • trunk/tests/phpunit/tests/ajax/wpAjaxSendAttachmentToEditor.php

    r55764 r60253  
    1313 */
    1414class Tests_Ajax_wpAjaxSendAttachmentToEditor extends WP_Ajax_UnitTestCase {
     15
     16    /**
     17     * Shared user ID for the tests.
     18     *
     19     * @var int
     20     */
     21    public static $user_id = 0;
     22
     23    /**
     24     * Set up shared fixtures.
     25     *
     26     * @param WP_UnitTest_Factory $factory
     27     */
     28    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     29        self::$user_id = $factory->user->create(
     30            array(
     31                'role'       => 'administrator',
     32                'user_login' => 'user_36578_administrator',
     33                'user_email' => 'user_36578_administrator@example.com',
     34            )
     35        );
     36    }
    1537
    1638    /**
     
    106128        // Become an administrator.
    107129        $post    = $_POST;
    108         $user_id = self::factory()->user->create(
    109             array(
    110                 'role'       => 'administrator',
    111                 'user_login' => 'user_36578_administrator',
    112                 'user_email' => 'user_36578_administrator@example.com',
    113             )
    114         );
     130        $user_id = self::$user_id;
    115131        wp_set_current_user( $user_id );
    116132        $_POST = array_merge( $_POST, $post );
     
    152168        // Become an administrator.
    153169        $post    = $_POST;
    154         $user_id = self::factory()->user->create(
    155             array(
    156                 'role'       => 'administrator',
    157                 'user_login' => 'user_36578_administrator',
    158                 'user_email' => 'user_36578_administrator@example.com',
    159             )
    160         );
     170        $user_id = self::$user_id;
    161171        wp_set_current_user( $user_id );
    162172        $_POST = array_merge( $_POST, $post );
  • 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(
  • trunk/tests/phpunit/tests/auth.php

    r60124 r60253  
    15801580     */
    15811581    public function test_application_password_authentication() {
    1582         $user_id = self::factory()->user->create(
    1583             array(
    1584                 'user_login' => 'http_auth_login',
    1585                 'user_pass'  => 'http_auth_pass', // Shouldn't be allowed for API login.
    1586             )
    1587         );
     1582        $user_id = self::$_user->ID;
    15881583
    15891584        // Create a new app-only password.
     
    15951590
    15961591        // Fake an HTTP Auth request with the regular account password first.
    1597         $_SERVER['PHP_AUTH_USER'] = 'http_auth_login';
    1598         $_SERVER['PHP_AUTH_PW']   = 'http_auth_pass';
     1592        $_SERVER['PHP_AUTH_USER'] = self::USER_LOGIN;
     1593        $_SERVER['PHP_AUTH_PW']   = self::USER_PASS;
    15991594
    16001595        $this->assertNull(
  • trunk/tests/phpunit/tests/comment/wpHandleCommentSubmission.php

    r59319 r60253  
    1010    protected static $post;
    1111    protected static $author_id;
     12    protected static $author_id2;
    1213    protected static $editor_id;
    1314
     
    2021            array(
    2122                'role' => 'author',
     23            )
     24        );
     25
     26        self::$author_id2 = $factory->user->create(
     27            array(
     28                'role'     => 'author',
     29                'user_url' => 'http://user.example.org',
    2230            )
    2331        );
     
    224232    public function test_submitting_valid_comment_as_logged_in_user_succeeds() {
    225233
    226         $user = self::factory()->user->create_and_get(
    227             array(
    228                 'user_url' => 'http://user.example.org',
    229             )
    230         );
     234        $user = get_user_by( 'id', self::$author_id2 );
    231235
    232236        wp_set_current_user( $user->ID );
     
    315319        $error = 'comment_id_not_found';
    316320
    317         $user = self::factory()->user->create_and_get(
    318             array(
    319                 'role' => 'author',
    320             )
    321         );
     321        $user = get_user_by( 'id', self::$author_id2 );
    322322
    323323        wp_set_current_user( $user->ID );
     
    344344        $error = 'comment_id_not_found';
    345345
    346         $user = self::factory()->user->create_and_get(
    347             array(
    348                 'role' => 'author',
    349             )
    350         );
     346        $user = get_user_by( 'id', self::$author_id2 );
    351347
    352348        wp_set_current_user( $user->ID );
     
    835831     * @ticket 36901
    836832     */
    837     public function test_comments_flood_user_is_admin() {
    838         $user = self::factory()->user->create_and_get(
    839             array(
    840                 'role' => 'administrator',
    841             )
    842         );
     833    public function test_comments_flood_user_can_moderate_comments() {
     834        $user = get_user_by( 'id', self::$editor_id );
    843835        wp_set_current_user( $user->ID );
    844836
     
    854846        $second_comment  = wp_handle_comment_submission( $data );
    855847
    856         $this->assertNotWPError( $second_comment );
    857         $this->assertSame( (string) self::$post->ID, $second_comment->comment_post_ID );
     848        $this->assertTrue( current_user_can( 'moderate_comments' ), 'Test user should have the moderate_comments capability' );
     849        $this->assertNotWPError( $second_comment, 'Second comment should not trigger comment flooding error.' );
     850        $this->assertSame( (string) self::$post->ID, $second_comment->comment_post_ID, 'Second comment should be made against initial post.' );
    858851    }
    859852
  • trunk/tests/phpunit/tests/customize/control.php

    r55457 r60253  
    1919
    2020    /**
     21     * Shared user ID for the tests.
     22
     23     * @var int
     24     */
     25    public static $user_id = 0;
     26
     27    /**
     28     * Set up shared fixtures.
     29     *
     30     * @param WP_UnitTest_Factory $factory Factory.
     31     */
     32    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     33        self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
     34    }
     35
     36    /**
    2137     * Set up.
    2238     */
    2339    public function set_up() {
    2440        parent::set_up();
    25         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     41        wp_set_current_user( self::$user_id );
    2642        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    2743        $GLOBALS['wp_customize'] = new WP_Customize_Manager();
  • trunk/tests/phpunit/tests/customize/custom-css-setting.php

    r54865 r60253  
    2424
    2525    /**
     26     * The user ID to use for the tests.
     27     *
     28     * @var int
     29     */
     30    public static $user_id = 0;
     31
     32    /**
     33     * Set up the test case.
     34     *
     35     * @see WP_UnitTestCase::set_up()
     36     */
     37    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     38        // Create a user to use for the tests.
     39        self::$user_id = $factory->user->create(
     40            array(
     41                'role' => 'administrator',
     42            )
     43        );
     44
     45        if ( is_multisite() ) {
     46            grant_super_admin( self::$user_id );
     47        }
     48    }
     49
     50    /**
    2651     * Set up the test case.
    2752     *
     
    3257        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    3358
    34         $user_id = self::factory()->user->create(
    35             array(
    36                 'role' => 'administrator',
    37             )
    38         );
    39         if ( is_multisite() ) {
    40             grant_super_admin( $user_id );
    41         }
    42 
    43         wp_set_current_user( $user_id );
     59        wp_set_current_user( self::$user_id );
    4460
    4561        global $wp_customize;
  • trunk/tests/phpunit/tests/customize/manager.php

    r57242 r60253  
    2828
    2929    /**
     30     * Second admin user ID.
     31     *
     32     * @var int
     33     */
     34    protected static $other_admin_user_id;
     35
     36    /**
    3037     * Subscriber user ID.
    3138     *
     
    4754     */
    4855    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    49         self::$subscriber_user_id = $factory->user->create( array( 'role' => 'subscriber' ) );
    50         self::$admin_user_id      = $factory->user->create( array( 'role' => 'administrator' ) );
     56        self::$subscriber_user_id  = $factory->user->create( array( 'role' => 'subscriber' ) );
     57        self::$admin_user_id       = $factory->user->create( array( 'role' => 'administrator' ) );
     58        self::$other_admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );
    5159    }
    5260
     
    154162    public function test_constructor_deferred_changeset_uuid() {
    155163        wp_set_current_user( self::$admin_user_id );
    156         $other_admin_user_id = self::factory()->user->create( array( 'role' => 'admin' ) );
     164        $other_admin_user_id = self::$other_admin_user_id;
    157165
    158166        $data = array(
     
    12551263    public function test_save_changeset_post_without_kses_corrupting_json() {
    12561264        global $wp_customize;
    1257         $lesser_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     1265        $lesser_admin_user_id = self::$other_admin_user_id;
    12581266
    12591267        $uuid         = wp_generate_uuid4();
     
    15001508        add_theme_support( 'custom-background' );
    15011509        wp_set_current_user( self::$admin_user_id );
    1502         $other_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     1510        $other_admin_user_id = self::$other_admin_user_id;
    15031511
    15041512        $uuid         = wp_generate_uuid4();
     
    17151723        add_theme_support( 'custom-background' );
    17161724        wp_set_current_user( self::$admin_user_id );
    1717         $other_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     1725        $other_admin_user_id = self::$other_admin_user_id;
    17181726
    17191727        $uuid         = wp_generate_uuid4();
     
    18781886            array(
    18791887                'autosave' => true,
    1880                 'user_id'  => self::factory()->user->create( array( 'role' => 'administrator' ) ),
     1888                'user_id'  => self::$other_admin_user_id,
    18811889            )
    18821890        );
     
    30103018     */
    30113019    public function test_return_url() {
    3012         wp_set_current_user( self::factory()->user->create( array( 'role' => 'author' ) ) );
     3020        wp_set_current_user( self::$subscriber_user_id );
    30133021        $this->assertSame( home_url( '/' ), $this->manager->get_return_url() );
    30143022
  • trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php

    r56421 r60253  
    1515
    1616    /**
     17     * ID of the administrator user.
     18     *
     19     * @var int
     20     */
     21    public static $administrator_id;
     22
     23    /**
     24     * Set up the shared fixture.
     25     *
     26     * @param WP_UnitTest_Factory $factory Factory instance.
     27     */
     28    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     29        self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
     30    }
     31
     32    /**
    1733     * Set up a test case.
    1834     *
     
    2238        parent::set_up();
    2339        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    24         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     40        wp_set_current_user( self::$administrator_id );
    2541
    2642        global $wp_customize;
  • trunk/tests/phpunit/tests/customize/nav-menu-setting.php

    r54865 r60253  
    1616
    1717    /**
     18     * ID of the administrator user.
     19     *
     20     * @var int
     21     */
     22    public static $administrator_id;
     23
     24    /**
     25     * Set up the shared fixture.
     26     *
     27     * @param WP_UnitTest_Factory $factory Factory instance.
     28     */
     29    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     30        self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
     31    }
     32
     33    /**
    1834     * Set up a test case.
    1935     *
     
    2339        parent::set_up();
    2440        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    25         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     41        wp_set_current_user( self::$administrator_id );
    2642
    2743        global $wp_customize;
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r60251 r60253  
    1616
    1717    /**
     18     * ID of the administrator user.
     19     *
     20     * @var int
     21     */
     22    public static $administrator_id;
     23
     24    /**
     25     * Set up the shared fixture.
     26     *
     27     * @param WP_UnitTest_Factory $factory Factory instance.
     28     */
     29    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     30        self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
     31    }
     32
     33    /**
    1834     * Set up a test case.
    1935     *
     
    2339        parent::set_up();
    2440        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    25         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     41        wp_set_current_user( self::$administrator_id );
    2642        global $wp_customize;
    2743        $this->wp_customize = new WP_Customize_Manager();
     
    855871        $contributor_user_id   = self::factory()->user->create( array( 'role' => 'contributor' ) );
    856872        $author_user_id        = self::factory()->user->create( array( 'role' => 'author' ) );
    857         $administrator_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     873        $administrator_user_id = self::$administrator_id;
    858874
    859875        $contributor_post_id   = self::factory()->post->create(
  • trunk/tests/phpunit/tests/customize/panel.php

    r56547 r60253  
    77 */
    88class Tests_WP_Customize_Panel extends WP_UnitTestCase {
     9
     10    /**
     11     * ID of the administrator user.
     12     *
     13     * @var int
     14     */
     15    public static $administrator_id;
     16
     17    /**
     18     * Set up the shared fixture.
     19     *
     20     * @param WP_UnitTest_Factory $factory Factory instance.
     21     */
     22    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     23        self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
     24    }
    925
    1026    /**
     
    132148     */
    133149    public function test_check_capabilities() {
    134         $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    135         wp_set_current_user( $user_id );
     150        wp_set_current_user( self::$administrator_id );
    136151
    137152        $panel = new WP_Customize_Panel( $this->manager, 'foo' );
     
    158173     */
    159174    public function test_maybe_render() {
    160         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     175        wp_set_current_user( self::$administrator_id );
    161176        $panel                        = new WP_Customize_Panel( $this->manager, 'bar' );
    162177        $customize_render_panel_count = did_action( 'customize_render_panel' );
     
    183198     */
    184199    public function test_print_templates_standard() {
    185         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     200        wp_set_current_user( self::$administrator_id );
    186201
    187202        $panel = new WP_Customize_Panel( $this->manager, 'baz' );
     
    201216     */
    202217    public function test_print_templates_custom() {
    203         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     218        wp_set_current_user( self::$administrator_id );
    204219
    205220        $panel = new Custom_Panel_Test( $this->manager, 'baz' );
  • 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
  • trunk/tests/phpunit/tests/customize/setting.php

    r57920 r60253  
    1717     */
    1818    public $undefined;
     19
     20    /**
     21     * Shared admin user ID for the tests.
     22     *
     23     * @var int
     24     */
     25    public static $admin_id = 0;
     26
     27    /**
     28     * Set up shared fixtures.
     29     *
     30     * @param WP_UnitTest_Factory $factory Factory.
     31     */
     32    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     33        self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
     34    }
    1935
    2036    public function set_up() {
     
    138154     */
    139155    public function test_preview_standard_types_non_multidimensional() {
    140         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     156        wp_set_current_user( self::$admin_id );
    141157        $_POST['customized'] = wp_slash( wp_json_encode( $this->post_data_overrides ) );
    142158
     
    217233     */
    218234    public function test_preview_standard_types_multidimensional() {
    219         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     235        wp_set_current_user( self::$admin_id );
    220236        $_POST['customized'] = wp_slash( wp_json_encode( $this->post_data_overrides ) );
    221237
     
    363379     */
    364380    public function test_preview_custom_type() {
    365         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     381        wp_set_current_user( self::$admin_id );
    366382        $type                = 'custom_type';
    367383        $post_data_overrides = array(
     
    514530
    515531        // Satisfy all requirements for save to happen.
    516         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     532        wp_set_current_user( self::$admin_id );
    517533        $this->assertNotFalse( $setting->save() );
    518534        $this->assertTrue( 1 === did_action( 'customize_update_custom' ) );
     
    552568     */
    553569    public function test_is_current_blog_previewed() {
    554         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     570        wp_set_current_user( self::$admin_id );
    555571        $type       = 'option';
    556572        $name       = 'blogname';
     
    574590     */
    575591    public function test_previewing_with_switch_to_blog() {
    576         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     592        wp_set_current_user( self::$admin_id );
    577593        $type       = 'option';
    578594        $name       = 'blogdescription';
     
    597613    public function test_option_autoloading() {
    598614        global $wpdb;
    599         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     615        wp_set_current_user( self::$admin_id );
    600616
    601617        $name    = 'autoloaded1';
     
    744760     */
    745761    public function test_multidimensional_value_when_previewed() {
    746         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     762        wp_set_current_user( self::$admin_id );
    747763        WP_Customize_Setting::reset_aggregated_multidimensionals();
    748764
  • trunk/tests/phpunit/tests/customize/widgets.php

    r56746 r60253  
    2121    protected $backup_registered_sidebars;
    2222
     23    /**
     24     * ID of the administrator user.
     25     *
     26     * @var int
     27     */
     28    public static $administrator_id;
     29
     30    /**
     31     * Set up the shared fixture.
     32     *
     33     * @param WP_UnitTest_Factory $factory Factory instance.
     34     */
     35    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     36        self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
     37    }
     38
    2339    public function set_up() {
    2440        parent::set_up();
     
    2844        add_action( 'widgets_init', array( $this, 'remove_widgets_block_editor' ) );
    2945
    30         $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    31         wp_set_current_user( $user_id );
     46        wp_set_current_user( self::$administrator_id );
    3247
    3348        update_option(
  • 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(
  • trunk/tests/phpunit/tests/l10n.php

    r58062 r60253  
    1515     */
    1616    private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
     17
     18    /**
     19     * Editor user ID.
     20     *
     21     * @var int $editor_id
     22     */
     23    public static $editor_id;
     24
     25    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     26        self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
     27    }
    1728
    1829    /**
     
    465476         * "passing null to non-nullable" deprecation notice.
    466477         */
    467         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     478        wp_set_current_user( self::$editor_id );
    468479
    469480        $args = array(
     
    504515         * "passing null to non-nullable" deprecation notice.
    505516         */
    506         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     517        wp_set_current_user( self::$editor_id );
    507518
    508519        $args = array(
     
    543554         * "passing null to non-nullable" deprecation notice.
    544555         */
    545         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     556        wp_set_current_user( self::$editor_id );
    546557
    547558        $args = array(
  • 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 );
  • trunk/tests/phpunit/tests/meta.php

    r60251 r60253  
    1010     * @var \WP_User
    1111     */
    12     private $author;
    13 
    14     private $meta_id;
    15     private $delete_meta_id;
    16 
    17     public function set_up() {
    18         parent::set_up();
    19         $this->author         = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
    20         $this->meta_id        = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value' );
    21         $this->delete_meta_id = add_metadata( 'user', $this->author->ID, 'delete_meta_key', 'delete_meta_value' );
     12    private static $author;
     13
     14    private static $meta_id;
     15    private static $delete_meta_id;
     16
     17    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     18        self::$author         = new WP_User( $factory->user->create( array( 'role' => 'author' ) ) );
     19        self::$meta_id        = add_metadata( 'user', self::$author->ID, 'meta_key', 'meta_value' );
     20        self::$delete_meta_id = add_metadata( 'user', self::$author->ID, 'delete_meta_key', 'delete_meta_value' );
    2221    }
    2322
     
    3837        // Let's try and delete a non-existing ID, non existing meta.
    3938        $this->assertFalse( delete_metadata_by_mid( 'user', 0 ) );
    40         $this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', $this->delete_meta_id ) );
     39        $this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', self::$delete_meta_id ) );
    4140
    4241        // Now let's delete the real meta data.
    43         $this->assertTrue( delete_metadata_by_mid( 'user', $this->delete_meta_id ) );
     42        $this->assertTrue( delete_metadata_by_mid( 'user', self::$delete_meta_id ) );
    4443
    4544        // And make sure it's been deleted.
    46         $this->assertFalse( get_metadata_by_mid( 'user', $this->delete_meta_id ) );
     45        $this->assertFalse( get_metadata_by_mid( 'user', self::$delete_meta_id ) );
    4746
    4847        // Make sure the caches are cleared.
    49         $this->assertFalse( (bool) get_user_meta( $this->author->ID, 'delete_meta_key' ) );
     48        $this->assertFalse( (bool) get_user_meta( self::$author->ID, 'delete_meta_key' ) );
    5049    }
    5150
    5251    public function test_update_metadata_by_mid() {
    5352        // Setup.
    54         $meta = get_metadata_by_mid( 'user', $this->meta_id );
     53        $meta = get_metadata_by_mid( 'user', self::$meta_id );
    5554
    5655        // Update the meta value.
    57         $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value' ) );
    58         $meta = get_metadata_by_mid( 'user', $this->meta_id );
     56        $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'meta_new_value' ) );
     57        $meta = get_metadata_by_mid( 'user', self::$meta_id );
    5958        $this->assertSame( 'meta_new_value', $meta->meta_value );
    6059
    6160        // Update the meta value.
    62         $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value', 'meta_new_key' ) );
    63         $meta = get_metadata_by_mid( 'user', $this->meta_id );
     61        $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'meta_new_value', 'meta_new_key' ) );
     62        $meta = get_metadata_by_mid( 'user', self::$meta_id );
    6463        $this->assertSame( 'meta_new_key', $meta->meta_key );
    6564
    6665        // Update the key and value.
    67         $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_value', 'meta_key' ) );
    68         $meta = get_metadata_by_mid( 'user', $this->meta_id );
     66        $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'meta_value', 'meta_key' ) );
     67        $meta = get_metadata_by_mid( 'user', self::$meta_id );
    6968        $this->assertSame( 'meta_key', $meta->meta_key );
    7069        $this->assertSame( 'meta_value', $meta->meta_value );
    7170
    7271        // Update the value that has to be serialized.
    73         $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, array( 'first', 'second' ) ) );
    74         $meta = get_metadata_by_mid( 'user', $this->meta_id );
     72        $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, array( 'first', 'second' ) ) );
     73        $meta = get_metadata_by_mid( 'user', self::$meta_id );
    7574        $this->assertSame( array( 'first', 'second' ), $meta->meta_value );
    7675
    7776        // Let's try some invalid meta data.
    7877        $this->assertFalse( update_metadata_by_mid( 'user', 0, 'meta_value' ) );
    79         $this->assertFalse( update_metadata_by_mid( 'user', $this->meta_id, 'meta_value', array( 'invalid', 'key' ) ) );
     78        $this->assertFalse( update_metadata_by_mid( 'user', self::$meta_id, 'meta_value', array( 'invalid', 'key' ) ) );
    8079
    8180        // Let's see if caches get cleared after updates.
    82         $meta  = get_metadata_by_mid( 'user', $this->meta_id );
     81        $meta  = get_metadata_by_mid( 'user', self::$meta_id );
    8382        $first = get_user_meta( $meta->user_id, $meta->meta_key );
    84         $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'other_meta_value' ) );
     83        $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'other_meta_value' ) );
    8584        $second = get_user_meta( $meta->user_id, $meta->meta_key );
    8685        $this->assertFalse( $first === $second );
     
    116115
    117116    public function test_metadata_exists() {
    118         $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'foobarbaz' ) );
    119         $this->assertTrue( metadata_exists( 'user', $this->author->ID, 'meta_key' ) );
     117        $this->assertFalse( metadata_exists( 'user', self::$author->ID, 'foobarbaz' ) );
     118        $this->assertTrue( metadata_exists( 'user', self::$author->ID, 'meta_key' ) );
    120119        $this->assertFalse( metadata_exists( 'user', 1234567890, 'foobarbaz' ) );
    121120        $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) );
     
    128127        // Let's see if it returns the correct value when adding a filter.
    129128        add_filter( 'get_user_metadata', '__return_zero' );
    130         $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // Existing meta key.
     129        $this->assertFalse( metadata_exists( 'user', self::$author->ID, 'meta_key' ) ); // Existing meta key.
    131130        $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) );
    132131        remove_filter( 'get_user_metadata', '__return_zero' );
     
    151150
    152151        // User found is not locally defined author (it's the admin).
    153         $this->assertNotEquals( $this->author->user_login, $u[0]->user_login );
     152        $this->assertNotEquals( self::$author->user_login, $u[0]->user_login );
    154153
    155154        // Test EXISTS and NOT EXISTS together, no users should be found.
     
    186185        );
    187186
    188         delete_metadata( 'user', $this->author->ID, 'meta_key' );
     187        delete_metadata( 'user', self::$author->ID, 'meta_key' );
    189188
    190189        $this->assertCount(
     
    209208        $value2    = 'Test\\\\doubleslash';
    210209        $expected2 = 'Test\\doubleslash';
    211         $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) );
    212         $this->assertFalse( delete_metadata( 'user', $this->author->ID, $key ) );
    213         $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
    214         $this->assertIsInt( add_metadata( 'user', $this->author->ID, $key, $value ) );
    215         $this->assertSame( $expected, get_metadata( 'user', $this->author->ID, $key, true ) );
    216         $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );
    217         $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
    218         $this->assertIsInt( update_metadata( 'user', $this->author->ID, $key, $value ) );
    219         $this->assertSame( $expected, get_metadata( 'user', $this->author->ID, $key, true ) );
    220         $this->assertTrue( update_metadata( 'user', $this->author->ID, $key, 'blah' ) );
    221         $this->assertSame( 'blah', get_metadata( 'user', $this->author->ID, $key, true ) );
    222         $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );
    223         $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
    224         $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) );
     210        $this->assertFalse( metadata_exists( 'user', self::$author->ID, $key ) );
     211        $this->assertFalse( delete_metadata( 'user', self::$author->ID, $key ) );
     212        $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) );
     213        $this->assertIsInt( add_metadata( 'user', self::$author->ID, $key, $value ) );
     214        $this->assertSame( $expected, get_metadata( 'user', self::$author->ID, $key, true ) );
     215        $this->assertTrue( delete_metadata( 'user', self::$author->ID, $key ) );
     216        $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) );
     217        $this->assertIsInt( update_metadata( 'user', self::$author->ID, $key, $value ) );
     218        $this->assertSame( $expected, get_metadata( 'user', self::$author->ID, $key, true ) );
     219        $this->assertTrue( update_metadata( 'user', self::$author->ID, $key, 'blah' ) );
     220        $this->assertSame( 'blah', get_metadata( 'user', self::$author->ID, $key, true ) );
     221        $this->assertTrue( delete_metadata( 'user', self::$author->ID, $key ) );
     222        $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) );
     223        $this->assertFalse( metadata_exists( 'user', self::$author->ID, $key ) );
    225224
    226225        // Test overslashing.
    227         $this->assertIsInt( add_metadata( 'user', $this->author->ID, $key, $value2 ) );
    228         $this->assertSame( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );
    229         $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );
    230         $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
    231         $this->assertIsInt( update_metadata( 'user', $this->author->ID, $key, $value2 ) );
    232         $this->assertSame( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );
     226        $this->assertIsInt( add_metadata( 'user', self::$author->ID, $key, $value2 ) );
     227        $this->assertSame( $expected2, get_metadata( 'user', self::$author->ID, $key, true ) );
     228        $this->assertTrue( delete_metadata( 'user', self::$author->ID, $key ) );
     229        $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) );
     230        $this->assertIsInt( update_metadata( 'user', self::$author->ID, $key, $value2 ) );
     231        $this->assertSame( $expected2, get_metadata( 'user', self::$author->ID, $key, true ) );
    233232    }
    234233
     
    347346     */
    348347    public function test_negative_meta_id() {
    349         $negative_mid = $this->meta_id * -1;
     348        $negative_mid = self::$meta_id * -1;
    350349
    351350        $this->assertLessThan( 0, $negative_mid );
     
    359358     */
    360359    public function test_floating_meta_id() {
    361         $floating_mid = $this->meta_id + 0.1337;
     360        $floating_mid = self::$meta_id + 0.1337;
    362361
    363362        $this->assertTrue( floor( $floating_mid ) !== $floating_mid );
     
    371370     */
    372371    public function test_string_point_zero_meta_id() {
    373         $meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value_2' );
     372        $meta_id = add_metadata( 'user', self::$author->ID, 'meta_key', 'meta_value_2' );
    374373
    375374        $string_mid = "{$meta_id}.0";
     
    388387        $data  = array( 1, 2 );
    389388        $value = serialize( $data );
    390         add_metadata( 'user', $this->author->ID, 'foo', $data );
    391         $found = get_metadata( 'user', $this->author->ID );
     389        add_metadata( 'user', self::$author->ID, 'foo', $data );
     390        $found = get_metadata( 'user', self::$author->ID );
    392391
    393392        $this->assertSame( array( $value ), $found['foo'] );
     
    401400        $data->foo = 'bar';
    402401        $value     = serialize( $data );
    403         add_metadata( 'user', $this->author->ID, 'foo', $data );
    404         $found = get_metadata( 'user', $this->author->ID );
     402        add_metadata( 'user', self::$author->ID, 'foo', $data );
     403        $found = get_metadata( 'user', self::$author->ID );
    405404
    406405        $this->assertSame( array( $value ), $found['foo'] );
     
    416415        );
    417416        $value = serialize( $data );
    418         add_metadata( 'user', $this->author->ID, 'foo', $data );
    419         $found = get_metadata( 'user', $this->author->ID );
     417        add_metadata( 'user', self::$author->ID, 'foo', $data );
     418        $found = get_metadata( 'user', self::$author->ID );
    420419
    421420        $this->assertSame( array( $value ), $found['foo'] );
  • trunk/tests/phpunit/tests/oembed/controller.php

    r58286 r60253  
    305305
    306306    public function test_request_json() {
    307         $user = self::factory()->user->create_and_get(
    308             array(
    309                 'display_name' => 'John Doe',
    310             )
    311         );
     307        $user = get_user_by( 'id', self::$subscriber );
    312308        $post = self::factory()->post->create_and_get(
    313309            array(
     
    392388
    393389    public function test_request_xml() {
    394         $user = self::factory()->user->create_and_get(
    395             array(
    396                 'display_name' => 'John Doe',
    397             )
    398         );
     390        $user = get_user_by( 'id', self::$subscriber );
    399391        $post = self::factory()->post->create_and_get(
    400392            array(
     
    462454
    463455    public function test_rest_pre_serve_request() {
    464         $user = self::factory()->user->create_and_get(
    465             array(
    466                 'display_name' => 'John Doe',
    467             )
    468         );
     456        $user = get_user_by( 'id', self::$subscriber );
    469457        $post = self::factory()->post->create_and_get(
    470458            array(
     
    678666        wp_set_current_user( self::$editor );
    679667
    680         $user = self::factory()->user->create_and_get(
    681             array(
    682                 'display_name' => 'John Doe',
    683             )
    684         );
     668        $user = get_user_by( 'id', self::$subscriber );
    685669        $post = self::factory()->post->create_and_get(
    686670            array(
  • trunk/tests/phpunit/tests/oembed/wpOembed.php

    r51568 r60253  
    1212    public $pre_oembed_result_filtered = false;
    1313
     14    /**
     15     * ID of the user.
     16     *
     17     * @var int
     18     */
     19    public static $user_id;
     20
     21    /**
     22     * Set up the shared fixture.
     23     *
     24     * @param WP_UnitTest_Factory $factory Factory instance.
     25     */
     26    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     27        self::$user_id = $factory->user->create();
     28    }
     29
    1430    public function set_up() {
    1531        parent::set_up();
     
    97113     */
    98114    public function test_wp_filter_pre_oembed_result_multisite_sub_samesub() {
    99         $user_id = self::factory()->user->create();
     115        $user_id = self::$user_id;
    100116
    101117        $blog_id = self::factory()->blog->create(
     
    126142     */
    127143    public function test_wp_filter_pre_oembed_result_multisite_sub_othersub() {
    128         $user_id = self::factory()->user->create();
     144        $user_id = self::$user_id;
    129145
    130146        $blog_id = self::factory()->blog->create(
     
    165181        $post_id   = self::factory()->post->create();
    166182        $permalink = get_permalink( $post_id );
    167         $user_id   = self::factory()->user->create();
     183        $user_id   = self::$user_id;
    168184        $blog_id   = self::factory()->blog->create(
    169185            array(
     
    190206     */
    191207    public function test_wp_filter_pre_oembed_result_multisite_preserves_switched_state() {
    192         $user_id = self::factory()->user->create();
     208        $user_id = self::$user_id;
    193209
    194210        $blog_id = self::factory()->blog->create( array( 'user_id' => $user_id ) );
     
    221237        $current_blog_id = get_current_blog_id();
    222238
    223         $user_id = self::factory()->user->create();
     239        $user_id = self::$user_id;
    224240        $blog_id = self::factory()->blog->create(
    225241            array(
  • trunk/tests/phpunit/tests/post/getPages.php

    r56746 r60253  
    77 */
    88class Tests_Post_GetPages extends WP_UnitTestCase {
     9
     10    /**
     11     * ID of the first author.
     12     *
     13     * @var int
     14     */
     15    public static $author_id_1;
     16
     17    /**
     18     * ID of the second author.
     19     *
     20     * @var int
     21     */
     22    public static $author_id_2;
     23
     24    /**
     25     * Set up the shared fixture.
     26     *
     27     * @param WP_UnitTest_Factory $factory Factory instance.
     28     */
     29    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     30        self::$author_id_1 = $factory->user->create(
     31            array(
     32                'user_login' => 'author1',
     33                'role'       => 'author',
     34            )
     35        );
     36
     37        self::$author_id_2 = $factory->user->create(
     38            array(
     39                'user_login' => 'author2',
     40                'role'       => 'author',
     41            )
     42        );
     43    }
     44
    945    /**
    1046     * @ticket 23167
     
    9641000     */
    9651001    public function test_get_pages_author() {
    966         $author_1 = self::factory()->user->create(
    967             array(
    968                 'user_login' => 'author1',
    969                 'role'       => 'author',
    970             )
    971         );
     1002        $author_1 = self::$author_id_1;
    9721003        $posts    = self::factory()->post->create_many(
    9731004            2,
     
    9901021     */
    9911022    public function test_get_pages_multiple_authors() {
    992         $author_1 = self::factory()->user->create(
    993             array(
    994                 'user_login' => 'author1',
    995                 'role'       => 'author',
    996             )
    997         );
     1023        $author_1 = self::$author_id_1;
    9981024        $post_1   = self::factory()->post->create(
    9991025            array(
     
    10051031        );
    10061032
    1007         $author_2 = self::factory()->user->create(
    1008             array(
    1009                 'user_login' => 'author2',
    1010                 'role'       => 'author',
    1011             )
    1012         );
     1033        $author_2 = self::$author_id_2;
    10131034        $post_2   = self::factory()->post->create(
    10141035            array(
     
    10321053     */
    10331054    public function test_get_pages_multiple_authors_by_user_login() {
    1034         $author_1 = self::factory()->user->create(
    1035             array(
    1036                 'user_login' => 'author1',
    1037                 'role'       => 'author',
    1038             )
    1039         );
     1055        $author_1 = self::$author_id_1;
    10401056        $post_1   = self::factory()->post->create(
    10411057            array(
     
    10471063        );
    10481064
    1049         $author_2 = self::factory()->user->create(
    1050             array(
    1051                 'user_login' => 'author2',
    1052                 'role'       => 'author',
    1053             )
    1054         );
     1065        $author_2 = self::$author_id_2;
    10551066        $post_2   = self::factory()->post->create(
    10561067            array(
  • trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php

    r51566 r60253  
    55 */
    66class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase {
     7
     8    /**
     9     * ID of the first user.
     10     *
     11     * @var int
     12     */
     13    public static $user_id_1;
     14
     15    /**
     16     * ID of the second user.
     17     *
     18     * @var int
     19     */
     20    public static $user_id_2;
     21
     22    /**
     23     * Set up the shared fixture.
     24     *
     25     * @param WP_UnitTest_Factory $factory Factory instance.
     26     */
     27    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     28        self::$user_id_1 = $factory->user->create();
     29        self::$user_id_2 = $factory->user->create();
     30    }
    731
    832    public function test_post_type_post() {
     
    6084    public function test_public_only_true_should_not_allow_any_private_posts_for_loggedin_user() {
    6185        $current_user = get_current_user_id();
    62         $u            = self::factory()->user->create();
     86        $u            = self::$user_id_1;
    6387        wp_set_current_user( $u );
    6488
     
    7195    public function test_public_only_should_default_to_false() {
    7296        $current_user = get_current_user_id();
    73         $u            = self::factory()->user->create();
     97        $u            = self::$user_id_1;
    7498        wp_set_current_user( $u );
    7599
     
    81105    public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_current_user_matches_post_author() {
    82106        $current_user = get_current_user_id();
    83         $u            = self::factory()->user->create();
     107        $u            = self::$user_id_1;
    84108        wp_set_current_user( $u );
    85109
     
    92116    public function test_public_only_false_should_not_allow_access_to_private_posts_if_current_user_is_not_post_author() {
    93117        $current_user = get_current_user_id();
    94         $u1           = self::factory()->user->create();
    95         $u2           = self::factory()->user->create();
     118        $u1           = self::$user_id_1;
     119        $u2           = self::$user_id_2;
    96120        wp_set_current_user( $u1 );
    97121
     
    104128    public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_post_author_is_not_provided() {
    105129        $current_user = get_current_user_id();
    106         $u            = self::factory()->user->create();
     130        $u            = self::$user_id_1;
    107131        wp_set_current_user( $u );
    108132
  • trunk/tests/phpunit/tests/query/conditionals.php

    r56559 r60253  
    1515    protected $post_ids;
    1616
     17    /**
     18     * ID of the user-a.
     19     *
     20     * @var int
     21     */
     22    public static $user_a_id;
     23
     24    /**
     25     * Set up the shared fixture.
     26     *
     27     * @param WP_UnitTest_Factory $factory Factory instance.
     28     */
     29    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     30        self::$user_a_id = $factory->user->create( array( 'user_login' => 'user-a' ) );
     31    }
     32
    1733    public function set_up() {
    1834        parent::set_up();
     
    589605    // 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
    590606    public function test_author_feed() {
    591         self::factory()->user->create( array( 'user_login' => 'user-a' ) );
    592607        // Check the long form.
    593608        $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
     
    608623    public function test_author_paged() {
    609624        update_option( 'posts_per_page', 2 );
    610         $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
     625        $user_id = self::$user_a_id;
    611626        self::factory()->post->create_many( 3, array( 'post_author' => $user_id ) );
    612627        $this->go_to( '/author/user-a/page/2/' );
     
    616631    // 'author/([^/]+)/?$' => 'index.php?author_name=$matches[1]',
    617632    public function test_author() {
    618         $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
     633        $user_id = self::$user_a_id;
    619634        self::factory()->post->create( array( 'post_author' => $user_id ) );
    620635        $this->go_to( '/author/user-a/' );
     
    623638
    624639    public function test_author_with_no_posts() {
    625         $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
    626640        $this->go_to( '/author/user-a/' );
    627641        $this->assertQueryTrue( 'is_archive', 'is_author' );
     
    11231137     */
    11241138    public function test_is_author_with_nicename_that_begins_with_a_number_that_clashes_with_another_author_id() {
    1125         $u1 = self::factory()->user->create();
     1139        $u1 = self::$user_a_id;
    11261140
    11271141        $u2_name = $u1 . '_user';
     
    12801294
    12811295        // We need a non-post that shares an ID with a post assigned a template.
    1282         $user_id = self::factory()->user->create();
     1296        $user_id = self::$user_a_id;
    12831297        if ( ! get_post( $user_id ) ) {
    12841298            $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
     
    13531367     */
    13541368    public function test_is_author_should_not_match_numeric_id_to_nickname_beginning_with_id() {
    1355         $u1 = self::factory()->user->create(
    1356             array(
    1357                 'nickname'      => 'Foo',
    1358                 'user_nicename' => 'foo',
    1359             )
    1360         );
     1369        $u1 = self::$user_a_id;
    13611370        $u2 = self::factory()->user->create(
    13621371            array(
     
    13761385     */
    13771386    public function test_is_author_should_not_match_numeric_id_to_user_nicename_beginning_with_id() {
    1378         $u1 = self::factory()->user->create(
    1379             array(
    1380                 'nickname'      => 'Foo',
    1381                 'user_nicename' => 'foo',
    1382             )
    1383         );
     1387        $u1 = self::$user_a_id;
    13841388        $u2 = self::factory()->user->create(
    13851389            array(
  • trunk/tests/phpunit/tests/taxonomy.php

    r60251 r60253  
    55 */
    66class Tests_Taxonomy extends WP_UnitTestCase {
     7
     8    /**
     9     * Editor user ID.
     10     *
     11     * @var int $editor_id
     12     */
     13    public static $editor_id;
     14
     15    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     16        self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
     17    }
     18
    719    public function test_get_post_taxonomies() {
    820        $this->assertSame( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) );
     
    10111023        );
    10121024
    1013         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     1025        wp_set_current_user( self::$editor_id );
    10141026        $updated_post_id = edit_post(
    10151027            array(
     
    10371049    public function test_default_term_for_custom_taxonomy() {
    10381050
    1039         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     1051        wp_set_current_user( self::$editor_id );
    10401052
    10411053        $tax = 'custom-tax';
  • trunk/tests/phpunit/tests/url.php

    r56549 r60253  
    88class Tests_URL extends WP_UnitTestCase {
    99
     10    /**
     11     * Author user ID.
     12     *
     13     * @var int $author_id
     14     */
     15    public static $author_id;
     16
     17    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     18        self::$author_id = $factory->user->create( array( 'role' => 'author' ) );
     19    }
     20
    1021    public function set_up() {
    1122        parent::set_up();
     
    387398     */
    388399    public function test_get_adjacent_post_should_return_private_posts_belonging_to_the_current_user() {
    389         $u       = self::factory()->user->create( array( 'role' => 'author' ) );
     400        $u       = self::$author_id;
    390401        $old_uid = get_current_user_id();
    391402        wp_set_current_user( $u );
     
    426437     */
    427438    public function test_get_adjacent_post_should_return_private_posts_belonging_to_other_users_if_the_current_user_can_read_private_posts() {
    428         $u1      = self::factory()->user->create( array( 'role' => 'author' ) );
     439        $u1      = self::$author_id;
    429440        $u2      = self::factory()->user->create( array( 'role' => 'administrator' ) );
    430441        $old_uid = get_current_user_id();
     
    466477     */
    467478    public function test_get_adjacent_post_should_not_return_private_posts_belonging_to_other_users_if_the_current_user_cannot_read_private_posts() {
    468         $u1      = self::factory()->user->create( array( 'role' => 'author' ) );
     479        $u1      = self::$author_id;
    469480        $u2      = self::factory()->user->create( array( 'role' => 'author' ) );
    470481        $old_uid = get_current_user_id();
  • trunk/tests/phpunit/tests/user.php

    r60250 r60253  
    10841084     */
    10851085    public function test_wp_update_user_should_delete_userslugs_cache() {
    1086         $u    = self::factory()->user->create();
     1086        $u    = self::$sub_id;
    10871087        $user = get_userdata( $u );
    10881088
     
    19401940        $_REQUEST = array();
    19411941
    1942         $administrator = self::factory()->user->create(
    1943             array(
    1944                 'role' => 'administrator',
    1945             )
    1946         );
     1942        $administrator = self::$admin_id;
    19471943
    19481944        wp_set_current_user( $administrator );
     
    19581954
    19591955        // Promote an editor to an administrator.
    1960         $editor = self::factory()->user->create(
    1961             array(
    1962                 'role' => 'editor',
    1963             )
    1964         );
     1956        $editor = self::$editor_id;
    19651957
    19661958        $_POST['role']     = 'administrator';
Note: See TracChangeset for help on using the changeset viewer.