Make WordPress Core

Changeset 63781


Ignore:
Timestamp:
09/21/2026 06:49:19 PM (7 weeks ago)
Author:
lancewillett
Message:

Tests: Reuse the editor fixture in REST term meta tests.

Create one editor user for the REST term meta test class and reuse it when granting write permission. Delete the shared user during class teardown, avoiding repeated user creation while preserving the existing assertions.

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

Props sainathpoojary.
See #66074.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-term-meta-fields.php

    r61424 r63781  
    1212        protected static $category_id;
    1313        protected static $customtax_term_id;
     14        protected static $editor_id;
    1415
    1516        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    … …  
    2526                self::$category_id        = $factory->category->create();
    2627                self::$customtax_term_id  = $factory->term->create( array( 'taxonomy' => 'customtax' ) );
     28                self::$editor_id          = $factory->user->create( array( 'role' => 'editor' ) );
    2729        }
    2830
    … …  
    3133                wp_delete_term( self::$category_id, 'category' );
    3234                wp_delete_term( self::$customtax_term_id, 'customtax' );
     35                self::delete_user( self::$editor_id );
    3336
    3437                unregister_taxonomy( 'customtax' );
    … …  
    199202        protected function grant_write_permission() {
    200203                // Ensure we have write permission.
    201                 $user = self::factory()->user->create(
    202                         array(
    203                                 'role' => 'editor',
    204                         )
    205                 );
    206                 wp_set_current_user( $user );
     204                wp_set_current_user( self::$editor_id );
    207205        }
    208206
Note: See TracChangeset for help on using the changeset viewer.