WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/14/2020 04:33:24 PM (14 months ago)
Author:
SergeyBiryukov
Message:

Tests: Consistently unregister custom settings after performing assertions in WP_Test_REST_Settings_Controller.

This ensures that those settings don't leak to other tests.

Props david.binda, TimothyBlynJacobs, SergeyBiryukov.
Fixes #50986.

File:
1 edited

Legend:

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

    r47325 r48791  
    4242        parent::tearDown();
    4343
    44         if ( isset( get_registered_settings()['mycustomarraysetting'] ) ) {
    45             unregister_setting( 'somegroup', 'mycustomarraysetting' );
     44        $settings_to_unregister = array(
     45            'mycustomsetting',
     46            'mycustomsetting1',
     47            'mycustomsetting2',
     48            'mycustomarraysetting',
     49        );
     50
     51        $registered_settings = get_registered_settings();
     52
     53        foreach ( $settings_to_unregister as $setting ) {
     54            if ( isset( $registered_settings[ $setting ] ) ) {
     55                unregister_setting( 'somegroup', $setting );
     56            }
    4657        }
    4758    }
     
    154165        $data     = $response->get_data();
    155166        $this->assertEquals( 'validvalue2', $data['mycustomsettinginrest'] );
    156 
    157         unregister_setting( 'somegroup', 'mycustomsetting' );
    158167    }
    159168
     
    204213        $data     = $response->get_data();
    205214        $this->assertEquals( null, $data['mycustomsetting'] );
    206 
    207         unregister_setting( 'somegroup', 'mycustomsetting' );
    208215    }
    209216
     
    259266        $data     = $response->get_data();
    260267        $this->assertEquals( null, $data['mycustomsetting'] );
    261 
    262         unregister_setting( 'somegroup', 'mycustomsetting' );
    263268    }
    264269
     
    313318        $this->assertEquals( 'unfiltered2', $data['mycustomsettinginrest2'] );
    314319
    315         unregister_setting( 'somegroup', 'mycustomsetting' );
    316320        remove_all_filters( 'rest_pre_get_setting' );
    317321    }
     
    367371        $data     = $response->get_data();
    368372        $this->assertEquals( null, $data['mycustomsettinginrest'] );
    369         unregister_setting( 'somegroup', 'mycustomsetting' );
    370373    }
    371374
     
    438441
    439442        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    440         unregister_setting( 'somegroup', 'mycustomsetting' );
    441443    }
    442444
     
    541543        $response = rest_get_server()->dispatch( $request );
    542544        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    543         unregister_setting( 'somegroup', 'mycustomsetting' );
    544545    }
    545546
Note: See TracChangeset for help on using the changeset viewer.