Make WordPress Core

Changeset 64484


Ignore:
Timestamp:
10/18/2026 12:24:57 AM (7 hours ago)
Author:
lancewillett
Message:

Tests: Reuse existing fixtures in REST user tests.

Reuse the author and subscriber fixtures in read-only and rejected-request tests in WP_Test_REST_Users_Controller, avoiding 13 user creations per class run.

Preserve the requests, assertions, and include-query ordering checks. Keep fresh users for successful updates, deletions, and identity-specific scenarios, and retain per-test post and page fixtures.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14339

Props abcd95.
See #66074.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r64233 r64484  
    657657                wp_set_current_user( self::$user );
    658658
    659                 $id1 = self::factory()->user->create();
    660                 $id2 = self::factory()->user->create();
     659                $id1 = self::$author;
     660                $id2 = self::$subscriber;
    661661
    662662                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    … …  
    692692                wp_set_current_user( self::$user );
    693693
    694                 $id1 = self::factory()->user->create();
    695                 $id2 = self::factory()->user->create();
     694                $id1 = self::$subscriber;
     695                $id2 = self::$author;
    696696
    697697                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    … …  
    10901090
    10911091        public function test_get_item() {
    1092                 $user_id = self::factory()->user->create();
     1092                $user_id = self::$subscriber;
    10931093
    10941094                wp_set_current_user( self::$user );
    … …  
    12431243
    12441244        public function test_get_item_published_author_post() {
    1245                 $author_id = self::factory()->user->create(
    1246                         array(
    1247                                 'role' => 'author',
    1248                         )
    1249                 );
     1245                $author_id = self::$author;
    12501246
    12511247                $post_id = self::factory()->post->create(
    … …  
    12631259
    12641260        public function test_get_item_published_author_pages() {
    1265                 $author_id = self::factory()->user->create(
    1266                         array(
    1267                                 'role' => 'author',
    1268                         )
    1269                 );
     1261                $author_id = self::$author;
    12701262
    12711263                wp_set_current_user( 0 );
    … …  
    12871279
    12881280        public function test_get_user_with_edit_context() {
    1289                 $user_id = self::factory()->user->create();
     1281                $user_id = self::$subscriber;
    12901282
    12911283                $this->allow_user_to_manage_multisite();
    … …  
    12981290
    12991291        public function test_get_item_published_author_wrong_context() {
    1300                 $author_id = self::factory()->user->create(
    1301                         array(
    1302                                 'role' => 'author',
    1303                         )
    1304                 );
     1292                $author_id = self::$author;
    13051293
    13061294                $post_id = self::factory()->post->create(
    … …  
    21842172         */
    21852173        public function test_update_item_only_roles_as_editor() {
    2186                 $user_id = self::factory()->user->create(
    2187                         array(
    2188                                 'role' => 'author',
    2189                         )
    2190                 );
     2174                $user_id = self::$author;
    21912175
    21922176                wp_set_current_user( self::$editor );
    … …  
    25962580
    25972581        public function test_delete_user_without_permission() {
    2598                 $user_id = self::factory()->user->create();
     2582                $user_id = self::$subscriber;
    25992583
    26002584                $this->allow_user_to_manage_multisite();
    … …  
    33173301         */
    33183302        public function test_head_request_with_specified_fields_returns_success_response( $path ) {
    3319                 $user_id = self::factory()->user->create();
     3303                $user_id = self::$subscriber;
    33203304                wp_set_current_user( self::$user );
    33213305
Note: See TracChangeset for help on using the changeset viewer.