Make WordPress Core

Changeset 63776


Ignore:
Timestamp:
09/21/2026 05:45:12 PM (7 weeks ago)
Author:
lancewillett
Message:

Tests: Reuse the editor in REST post meta tests.

Create the editor once per class instead of recreating it for each write-permission check. Delete the shared user during class teardown.

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

Props sainathpoojary.
See #66074.

File:
1 edited

Legend:

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

    r62969 r63776  
    1212        protected static $post_id;
    1313        protected static $cpt_post_id;
     14        protected static $editor_id;
    1415
    1516        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    … …  
    2526                self::$post_id            = $factory->post->create();
    2627                self::$cpt_post_id        = $factory->post->create( array( 'post_type' => 'cpt' ) );
     28                self::$editor_id          = $factory->user->create( array( 'role' => 'editor' ) );
    2729        }
    2830
    … …  
    3133                wp_delete_post( self::$post_id, true );
    3234                wp_delete_post( self::$cpt_post_id, true );
     35                self::delete_user( self::$editor_id );
    3336
    3437                unregister_post_type( 'cpt' );
    … …  
    264267        protected function grant_write_permission() {
    265268                // Ensure we have write permission.
    266                 $user = self::factory()->user->create(
    267                         array(
    268                                 'role' => 'editor',
    269                         )
    270                 );
    271                 wp_set_current_user( $user );
     269                wp_set_current_user( self::$editor_id );
    272270        }
    273271
Note: See TracChangeset for help on using the changeset viewer.