Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2f5cad3
Adds reset of current screen goals to base tearDown.
hellofromtonya Jun 16, 2021
ac6222b
Removes current screen reset from Tests_Admin_includesPlugin.
hellofromtonya Jun 16, 2021
379a405
Adds inline documentation for the base reset circuit to explain the r…
hellofromtonya Jun 16, 2021
0848ffe
Removes current screen reset from Tests_Adminbar.
hellofromtonya Jun 16, 2021
b0d5be6
Removes current screen reset from Tests_REST_API.
hellofromtonya Jun 16, 2021
763b50b
Removes global reset from Tests_URL.
hellofromtonya Jun 16, 2021
f76c195
Removes reset from Tests_Admin_includesScreen.
hellofromtonya Jun 16, 2021
48f2137
Removes reset from Tests_Admin_includesTemplate.
hellofromtonya Jun 16, 2021
058dab5
Removes reset from Tests_Dependencies_jQuery.
hellofromtonya Jun 16, 2021
972f0f4
Removes reset from Tests_L10n_GetUserLocale.
hellofromtonya Jun 16, 2021
ba8ad86
Removes reset from Tests_L10n_LoadTextdomain.
hellofromtonya Jun 16, 2021
d49809b
Removes reset from Tests_L10n_LoadTextdomainJustInTime.
hellofromtonya Jun 16, 2021
8b0480d
Removes reset from Tests_L10n_wpLocalSwitcher.
hellofromtonya Jun 16, 2021
9f515df
Removes reset from Tests_Post_Attachments.
hellofromtonya Jun 16, 2021
426aba7
Removes reset from Tests_Query_Conditionals.
hellofromtonya Jun 16, 2021
c770535
Removes reset from Tests_Query_IsTerm.
hellofromtonya Jun 16, 2021
61af822
Removes reset from Tests_Query_PostStatus.
hellofromtonya Jun 16, 2021
9fc057f
Removes alternative reset implementations.
hellofromtonya Jun 16, 2021
a538457
Improves inline doc.
hellofromtonya Jun 16, 2021
3580894
Replaces "front" with "edit.php" as front would not have tabs or opti…
hellofromtonya Jun 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ public function tearDown() {
// Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars are added when the next test runs.
$GLOBALS['wp_sitemaps'] = null;

/*
* Reset globals related to current screen to provide a consistent global starting state for tests that interact
* with admin screens. Replaces the need for individual tests to invoke `set_current_screen( 'front' )` (or an
* alternative implementation) as a reset.
*
* The globals are from `WP_Screen::set_current_screen`.
*
* Why not invoke `set_current_screen( 'front' )`?
* Performance (faster test runs with less memory usage). How so? For each test, it saves instantiating an instance
* of WP_Screen, making 2 method calls, and firing of the `current_screen` action.
*/
$current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' );
foreach ( $current_screen_globals as $global ) {
$GLOBALS[ $global ] = null;
}

$this->unregister_all_meta_keys();
remove_theme_support( 'html5' );
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
Expand Down
8 changes: 0 additions & 8 deletions tests/phpunit/tests/admin/includesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ function test_submenu_position( $position, $expected_position ) {

// Clean up the temporary user.
wp_delete_user( $admin_user );
// Reset current screen.
set_current_screen( 'front' );

// Verify the menu was inserted at the expected position.
$this->assertSame( 'custom-position', $submenu[ $parent ][ $expected_position ][2] );
Expand Down Expand Up @@ -207,8 +205,6 @@ function test_submenu_helpers_position( $position, $expected_position ) {

// Clean up the temporary user.
wp_delete_user( $admin_user );
// Reset current screen.
set_current_screen( 'front' );

foreach ( $actual_positions as $test => $actual_position ) {
// Verify the menu was inserted at the expected position.
Expand Down Expand Up @@ -292,8 +288,6 @@ function test_position_when_parent_slug_child_slug_are_the_same() {
// Clean up the temporary user.
wp_set_current_user( $current_user );
wp_delete_user( $admin_user );
// Reset current screen.
set_current_screen( 'front' );

// Verify the menu was inserted at the expected position.
$this->assertSame( 'main_slug', $submenu['main_slug'][0][2] );
Expand Down Expand Up @@ -325,8 +319,6 @@ function test_passing_string_as_position_fires_doing_it_wrong() {
// Clean up the temporary user.
wp_set_current_user( $current_user );
wp_delete_user( $admin_user );
// Reset current screen.
set_current_screen( 'front' );

// Verify the menu was inserted at the expected position.
$this->assertSame( 'submenu_page_1', $submenu['main_slug'][1][2] );
Expand Down
14 changes: 3 additions & 11 deletions tests/phpunit/tests/admin/includesScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,8 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
),
);

function setUp() {
parent::setUp();
set_current_screen( 'front' );
}

function tearDown() {
unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
unset( $GLOBALS['screen'] );
unset( $GLOBALS['current_screen'] );
parent::tearDown();
}

Expand Down Expand Up @@ -311,6 +304,7 @@ function test_help_tabs() {
'callback' => false,
);

set_current_screen( 'edit.php' );
$screen = get_current_screen();
$screen->add_help_tab( $tab_args );
$this->assertSame(
Expand Down Expand Up @@ -372,6 +366,7 @@ function test_help_tabs_priority() {
// Don't include a priority.
);

set_current_screen( 'edit.php' );
$screen = get_current_screen();

// Add help tabs.
Expand Down Expand Up @@ -440,6 +435,7 @@ function test_options() {
'option' => $option,
);

set_current_screen( 'edit.php' );
$screen = get_current_screen();

$screen->add_option( $option, $option_args );
Expand All @@ -456,8 +452,6 @@ function test_options() {
}

function test_in_admin() {
$screen = get_current_screen();

set_current_screen( 'edit.php' );
$this->assertTrue( get_current_screen()->in_admin() );
$this->assertTrue( get_current_screen()->in_admin( 'site' ) );
Expand All @@ -481,8 +475,6 @@ function test_in_admin() {
$this->assertFalse( get_current_screen()->in_admin( 'site' ) );
$this->assertFalse( get_current_screen()->in_admin( 'network' ) );
$this->assertFalse( get_current_screen()->in_admin( 'user' ) );

$GLOBALS['current_screen'] = $screen;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/tests/admin/includesTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ public function test_wp_add_dashboard_widget() {

// This doesn't actually get removed due to the invalid priority.
remove_meta_box( 'dashboard2', 'dashboard', 'normal' );

set_current_screen( 'front' );
}

}
10 changes: 0 additions & 10 deletions tests/phpunit/tests/adminbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ public function test_admin_bar_has_no_archives_link_if_no_static_front_page() {
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );

set_current_screen( 'front' );

$this->assertNull( $node );
}

Expand All @@ -415,8 +413,6 @@ public function test_admin_bar_contains_view_archive_link_if_static_front_page()
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );

set_current_screen( 'front' );

$this->assertNotNull( $node );
}

Expand All @@ -429,8 +425,6 @@ public function test_admin_bar_has_no_archives_link_for_pages() {
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );

set_current_screen( 'front' );

$this->assertNull( $node );
}

Expand Down Expand Up @@ -508,7 +502,6 @@ public function test_admin_bar_has_no_archives_link_for_non_public_cpt() {
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );

set_current_screen( 'front' );
unregister_post_type( 'foo-non-public' );

$this->assertNull( $node );
Expand All @@ -532,7 +525,6 @@ public function test_admin_bar_has_no_archives_link_for_cpt_without_archive() {
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );

set_current_screen( 'front' );
unregister_post_type( 'foo-non-public' );

$this->assertNull( $node );
Expand All @@ -556,7 +548,6 @@ public function test_admin_bar_has_no_archives_link_for_cpt_not_shown_in_admin_b
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );

set_current_screen( 'front' );
unregister_post_type( 'foo-non-public' );

$this->assertNull( $node );
Expand Down Expand Up @@ -679,7 +670,6 @@ public function test_customize_link() {
);
$wp_customize->start_previewing_theme();

set_current_screen( 'front' );
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'customize' );
$this->assertNotEmpty( $node );
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/tests/dependencies/jquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ function test_dont_allow_deregister_core_scripts_in_admin() {
wp_deregister_script( $library );
$this->assertTrue( wp_script_is( $library, 'registered' ) );
}

set_current_screen( 'front' );
}

/**
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/tests/l10n/getUserLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public function setUp() {
wp_set_current_user( $this->user_id );
}

public function tearDown() {
set_current_screen( 'front' );

parent::tearDown();
}

public function test_user_locale_property() {
set_current_screen( 'dashboard' );
$this->assertSame( 'de_DE', get_user_locale() );
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/tests/l10n/loadTextdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public function test_load_muplugin_textdomain_user_locale() {

load_muplugin_textdomain( 'wp-tests-domain' );

set_current_screen( 'front' );

$this->assertSame( get_user_locale(), $this->locale );
}

Expand All @@ -215,8 +213,6 @@ public function test_load_plugin_textdomain_user_locale() {

load_plugin_textdomain( 'wp-tests-domain' );

set_current_screen( 'front' );

$this->assertSame( get_user_locale(), $this->locale );
}

Expand All @@ -235,8 +231,6 @@ public function test_load_theme_textdomain_user_locale() {

load_theme_textdomain( 'wp-tests-domain' );

set_current_screen( 'front' );

$this->assertSame( get_user_locale(), $this->locale );
}
}
3 changes: 0 additions & 3 deletions tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ public function test_plugin_translation_with_user_locale() {

$expected = i18n_plugin_test();

set_current_screen( 'front' );

$this->assertSame( 'Das ist ein Dummy Plugin', $expected );
}

Expand All @@ -228,7 +226,6 @@ public function test_theme_translation_with_user_locale() {

$expected = i18n_theme_test();

set_current_screen( 'front' );
switch_theme( WP_DEFAULT_THEME );

$this->assertSame( 'Das ist ein Dummy Theme', $expected );
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/tests/l10n/wpLocaleSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ public function test_switch_to_site_locale_if_user_locale_is_set() {

$wp_locale_switcher = $locale_switcher;

set_current_screen( 'front' );

$this->assertFalse( $locale_switched_user_locale );
$this->assertTrue( $locale_switched_site_locale );
$this->assertSame( $site_locale, $site_locale_after_switch );
Expand Down Expand Up @@ -335,8 +333,6 @@ public function test_switch_to_different_site_locale_if_user_locale_is_set() {

$wp_locale_switcher = $locale_switcher;

set_current_screen( 'front' );

remove_filter( 'locale', array( $this, 'filter_locale' ) );

$this->assertFalse( $locale_switched_user_locale );
Expand Down Expand Up @@ -382,8 +378,6 @@ public function test_multiple_switches_to_site_locale_and_user_locale() {

$wp_locale_switcher = $locale_switcher;

set_current_screen( 'front' );

$this->assertSame( 'en_US', get_locale() );
$this->assertSame( 'This is a dummy plugin', $expected );
}
Expand Down
26 changes: 0 additions & 26 deletions tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,6 @@
*/
class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase {

/**
* Current screen.
*
* @var mixed
*/
protected $current_screen;

/**
* Set up. Workaround set_current_screen( null ) not working due to $hook_suffix not being set.
*/
function setUp() {
parent::setUp();

global $current_screen;
$this->current_screen = $current_screen;
}

/**
* Tear down. Workaround set_current_screen( null ) not working due to $hook_suffix not being set.
*/
function tearDown() {
global $current_screen;
$current_screen = $this->current_screen;
parent::tearDown();
}

/**
* Test search returns results for pages.
*
Expand Down
4 changes: 0 additions & 4 deletions tests/phpunit/tests/post/attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ public function test_wp_get_attachment_url_should_not_force_https_when_administe

$url = wp_get_attachment_url( $attachment_id );

// Cleanup.
set_current_screen( 'front' );

$this->assertSame( set_url_scheme( $url, 'http' ), $url );
}

Expand All @@ -438,7 +435,6 @@ public function test_wp_get_attachment_url_should_force_https_when_administering
$url = wp_get_attachment_url( $attachment_id );

// Cleanup.
set_current_screen( 'front' );
remove_filter( 'upload_dir', '_upload_dir_https' );

$this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) );
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/tests/query/conditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
function setUp() {
parent::setUp();

set_current_screen( 'front' );

update_option( 'comments_per_page', 5 );
update_option( 'posts_per_page', 5 );

Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/tests/query/isTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Tests_Query_IsTerm extends WP_UnitTestCase {
function setUp() {
parent::setUp();

set_current_screen( 'front' );

$GLOBALS['wp_the_query'] = new WP_Query();
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];

Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/tests/query/postStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public function test_protected_should_be_included_when_in_the_admin() {
);

$this->assertContains( "post_status = 'foo", $q->request );
set_current_screen( 'front' );
}

public function test_private_statuses_should_be_included_when_current_user_can_read_private_posts() {
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/tests/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,6 @@ public function test_rest_url_scheme() {

// Reset.
update_option( 'siteurl', $_siteurl );
set_current_screen( 'front' );

}

/**
Expand Down
8 changes: 0 additions & 8 deletions tests/phpunit/tests/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ function data_home_urls() {
}

function test_home_url_from_admin() {
$screen = get_current_screen();

// Pretend to be in the site admin.
set_current_screen( 'dashboard' );
$home = get_option( 'home' );
Expand Down Expand Up @@ -243,13 +241,9 @@ function test_home_url_from_admin() {
$this->assertSame( $home, home_url() );

update_option( 'home', set_url_scheme( $home, 'http' ) );

$GLOBALS['current_screen'] = $screen;
}

function test_network_home_url_from_admin() {
$screen = get_current_screen();

// Pretend to be in the site admin.
set_current_screen( 'dashboard' );
$home = network_home_url();
Expand All @@ -268,8 +262,6 @@ function test_network_home_url_from_admin() {
$this->assertSame( $home, network_home_url() );
$_SERVER['HTTPS'] = 'on';
$this->assertSame( $home_https, network_home_url() );

$GLOBALS['current_screen'] = $screen;
}

function test_set_url_scheme() {
Expand Down
Loading