Make WordPress Core


Ignore:
Timestamp:
07/13/2021 04:13:01 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Reset $current_screen global between tests to avoid cross-test interdependencies.

This provides a consistent global starting state for tests that interact with admin screens.

Individual tests no longer need to invoke set_current_screen( 'front' ) (or an alternative implementation) as a reset.

Follow-up to [29251], [29860], [31046], [36721], [38678], [48908], [50433].

Props hellofromTonya, johnbillion.
Fixes #53431.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesScreen.php

    r51367 r51419  
    156156    );
    157157
    158     function setUp() {
    159         parent::setUp();
    160         set_current_screen( 'front' );
    161     }
    162 
    163158    function tearDown() {
    164159        unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
    165         unset( $GLOBALS['screen'] );
    166         unset( $GLOBALS['current_screen'] );
    167160        parent::tearDown();
    168161    }
     
    312305        );
    313306
     307        set_current_screen( 'edit.php' );
    314308        $screen = get_current_screen();
    315309        $screen->add_help_tab( $tab_args );
     
    373367        );
    374368
     369        set_current_screen( 'edit.php' );
    375370        $screen = get_current_screen();
    376371
     
    441436        );
    442437
     438        set_current_screen( 'edit.php' );
    443439        $screen = get_current_screen();
    444440
     
    457453
    458454    function test_in_admin() {
    459         $screen = get_current_screen();
    460 
    461455        set_current_screen( 'edit.php' );
    462456        $this->assertTrue( get_current_screen()->in_admin() );
     
    482476        $this->assertFalse( get_current_screen()->in_admin( 'network' ) );
    483477        $this->assertFalse( get_current_screen()->in_admin( 'user' ) );
    484 
    485         $GLOBALS['current_screen'] = $screen;
    486478    }
    487479
Note: See TracChangeset for help on using the changeset viewer.