Make WordPress Core

Changeset 64367


Ignore:
Timestamp:
10/15/2026 08:59:04 PM (11 hours ago)
Author:
lancewillett
Message:

Tests: Reduce setup overhead in REST comments tests.

Remove the unused controller instance and two unused post creations from WP_Test_REST_Comments_Controller. Reuse existing class fixtures in four permission and validation tests that reject requests before creating database records.

Preserve the existing assertions while avoiding unnecessary fixture setup.

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

Props sainathpoojary.
See #66074.

File:
1 edited

Legend:

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

    r64358 r64367  
    3131        protected static $num_notes      = 10;
    3232
    33         protected $endpoint;
    34 
    3533        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    3634                add_role(
    … …  
    170168        public function set_up() {
    171169                parent::set_up();
    172                 $this->endpoint = new WP_REST_Comments_Controller();
    173170                wp_create_initial_comment_meta();
    174171
    … …  
    648645                wp_set_current_user( 0 );
    649646
    650                 $post_id = self::factory()->post->create( array( 'post_status' => 'private' ) );
    651 
    652647                $request = new WP_REST_Request( $method, '/wp/v2/comments' );
    653                 $request->set_param( 'post', $post_id );
     648                $request->set_param( 'post', self::$private_id );
    654649                $response = rest_get_server()->dispatch( $request );
    655650                $this->assertErrorResponse( 'rest_cannot_read_post', $response, 401 );
    … …  
    16821677         */
    16831678        public function test_create_comment_with_invalid_type() {
    1684                 $post_id = self::factory()->post->create();
    1685 
    1686                 wp_set_current_user( self::$admin_id );
    1687 
    1688                 $params = array(
    1689                         'post'         => $post_id,
     1679                wp_set_current_user( self::$admin_id );
     1680
     1681                $params = array(
     1682                        'post'         => self::$post_id,
    16901683                        'author'       => self::$admin_id,
    16911684                        'author_name'  => 'Comic Book Guy',
    … …  
    17061699
    17071700        public function test_create_comment_invalid_email() {
    1708                 $post_id = self::factory()->post->create();
    1709 
    1710                 wp_set_current_user( self::$admin_id );
    1711 
    1712                 $params = array(
    1713                         'post'         => $post_id,
     1701                wp_set_current_user( self::$admin_id );
     1702
     1703                $params = array(
     1704                        'post'         => self::$post_id,
    17141705                        'author'       => self::$admin_id,
    17151706                        'author_name'  => 'Comic Book Guy',
    … …  
    25222513
    25232514        public function test_update_item_no_content() {
    2524                 $post_id = self::factory()->post->create();
    2525 
    25262515                wp_set_current_user( self::$admin_id );
    25272516
    … …  
    25442533         */
    25452534        public function test_update_item_no_content_allow_empty_comment_filter() {
    2546                 $post_id = self::factory()->post->create();
    2547 
    25482535                wp_set_current_user( self::$admin_id );
    25492536
    … …  
    38783865        public function test_cannot_create_with_non_valid_comment_type() {
    38793866                wp_set_current_user( self::$admin_id );
    3880                 $post_id = self::factory()->post->create();
    3881 
    3882                 $params = array(
    3883                         'post'         => $post_id,
     3867
     3868                $params = array(
     3869                        'post'         => self::$post_id,
    38843870                        'author_name'  => 'Ishmael',
    38853871                        'author_email' => 'herman-melville@earthlink.net',
Note: See TracChangeset for help on using the changeset viewer.