Changeset 51419
- Timestamp:
- 07/13/2021 04:13:01 PM (4 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/abstract-testcase.php
r51335 r51419 158 158 } 159 159 160 // Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars are added when the next test runs. 160 /* 161 * Reset globals related to current screen to provide a consistent global starting state 162 * for tests that interact with admin screens. Replaces the need for individual tests 163 * to invoke `set_current_screen( 'front' )` (or an alternative implementation) as a reset. 164 * 165 * The globals are from `WP_Screen::set_current_screen()`. 166 * 167 * Why not invoke `set_current_screen( 'front' )`? 168 * Performance (faster test runs with less memory usage). How so? For each test, 169 * it saves creating an instance of WP_Screen, making two method calls, 170 * and firing of the `current_screen` action. 171 */ 172 $current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' ); 173 foreach ( $current_screen_globals as $global ) { 174 $GLOBALS[ $global ] = null; 175 } 176 177 /* 178 * Reset $wp_sitemap global so that sitemap-related dynamic $wp->public_query_vars 179 * are added when the next test runs. 180 */ 161 181 $GLOBALS['wp_sitemaps'] = null; 162 182 -
trunk/tests/phpunit/tests/admin/includesPlugin.php
r51397 r51419 98 98 // Clean up the temporary user. 99 99 wp_delete_user( $admin_user ); 100 // Reset current screen.101 set_current_screen( 'front' );102 100 103 101 // Verify the menu was inserted at the expected position. … … 208 206 // Clean up the temporary user. 209 207 wp_delete_user( $admin_user ); 210 // Reset current screen.211 set_current_screen( 'front' );212 208 213 209 foreach ( $actual_positions as $test => $actual_position ) { … … 293 289 wp_set_current_user( $current_user ); 294 290 wp_delete_user( $admin_user ); 295 // Reset current screen.296 set_current_screen( 'front' );297 291 298 292 // Verify the menu was inserted at the expected position. … … 326 320 wp_set_current_user( $current_user ); 327 321 wp_delete_user( $admin_user ); 328 // Reset current screen.329 set_current_screen( 'front' );330 322 331 323 // Verify the menu was inserted at the expected position. -
trunk/tests/phpunit/tests/admin/includesScreen.php
r51367 r51419 156 156 ); 157 157 158 function setUp() {159 parent::setUp();160 set_current_screen( 'front' );161 }162 163 158 function tearDown() { 164 159 unset( $GLOBALS['wp_taxonomies']['old-or-new'] ); 165 unset( $GLOBALS['screen'] );166 unset( $GLOBALS['current_screen'] );167 160 parent::tearDown(); 168 161 } … … 312 305 ); 313 306 307 set_current_screen( 'edit.php' ); 314 308 $screen = get_current_screen(); 315 309 $screen->add_help_tab( $tab_args ); … … 373 367 ); 374 368 369 set_current_screen( 'edit.php' ); 375 370 $screen = get_current_screen(); 376 371 … … 441 436 ); 442 437 438 set_current_screen( 'edit.php' ); 443 439 $screen = get_current_screen(); 444 440 … … 457 453 458 454 function test_in_admin() { 459 $screen = get_current_screen();460 461 455 set_current_screen( 'edit.php' ); 462 456 $this->assertTrue( get_current_screen()->in_admin() ); … … 482 476 $this->assertFalse( get_current_screen()->in_admin( 'network' ) ); 483 477 $this->assertFalse( get_current_screen()->in_admin( 'user' ) ); 484 485 $GLOBALS['current_screen'] = $screen;486 478 } 487 479 -
trunk/tests/phpunit/tests/admin/includesTemplate.php
r49124 r51419 235 235 // This doesn't actually get removed due to the invalid priority. 236 236 remove_meta_box( 'dashboard2', 'dashboard', 'normal' ); 237 238 set_current_screen( 'front' );239 237 } 240 238 -
trunk/tests/phpunit/tests/adminbar.php
r51397 r51419 401 401 $node = $wp_admin_bar->get_node( 'archive' ); 402 402 403 set_current_screen( 'front' );404 405 403 $this->assertNull( $node ); 406 404 } … … 416 414 $node = $wp_admin_bar->get_node( 'archive' ); 417 415 418 set_current_screen( 'front' );419 420 416 $this->assertNotNull( $node ); 421 417 } … … 429 425 $wp_admin_bar = $this->get_standard_admin_bar(); 430 426 $node = $wp_admin_bar->get_node( 'archive' ); 431 432 set_current_screen( 'front' );433 427 434 428 $this->assertNull( $node ); … … 509 503 $node = $wp_admin_bar->get_node( 'archive' ); 510 504 511 set_current_screen( 'front' );512 505 unregister_post_type( 'foo-non-public' ); 513 506 … … 533 526 $node = $wp_admin_bar->get_node( 'archive' ); 534 527 535 set_current_screen( 'front' );536 528 unregister_post_type( 'foo-non-public' ); 537 529 … … 557 549 $node = $wp_admin_bar->get_node( 'archive' ); 558 550 559 set_current_screen( 'front' );560 551 unregister_post_type( 'foo-non-public' ); 561 552 … … 680 671 $wp_customize->start_previewing_theme(); 681 672 682 set_current_screen( 'front' );683 673 $wp_admin_bar = $this->get_standard_admin_bar(); 684 674 $node = $wp_admin_bar->get_node( 'customize' ); -
trunk/tests/phpunit/tests/dependencies/jquery.php
r51397 r51419 83 83 $this->assertTrue( wp_script_is( $library, 'registered' ) ); 84 84 } 85 86 set_current_screen( 'front' );87 85 } 88 86 -
trunk/tests/phpunit/tests/l10n/getUserLocale.php
r51415 r51419 19 19 20 20 wp_set_current_user( $this->user_id ); 21 }22 23 public function tearDown() {24 set_current_screen( 'front' );25 26 parent::tearDown();27 21 } 28 22 -
trunk/tests/phpunit/tests/l10n/loadTextdomain.php
r50463 r51419 196 196 load_muplugin_textdomain( 'wp-tests-domain' ); 197 197 198 set_current_screen( 'front' );199 200 198 $this->assertSame( get_user_locale(), $this->locale ); 201 199 } … … 216 214 load_plugin_textdomain( 'wp-tests-domain' ); 217 215 218 set_current_screen( 'front' );219 220 216 $this->assertSame( get_user_locale(), $this->locale ); 221 217 } … … 236 232 load_theme_textdomain( 'wp-tests-domain' ); 237 233 238 set_current_screen( 'front' );239 240 234 $this->assertSame( get_user_locale(), $this->locale ); 241 235 } -
trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
r50926 r51419 212 212 $expected = i18n_plugin_test(); 213 213 214 set_current_screen( 'front' );215 216 214 $this->assertSame( 'Das ist ein Dummy Plugin', $expected ); 217 215 } … … 229 227 $expected = i18n_theme_test(); 230 228 231 set_current_screen( 'front' );232 229 switch_theme( WP_DEFAULT_THEME ); 233 230 -
trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php
r50456 r51419 285 285 $wp_locale_switcher = $locale_switcher; 286 286 287 set_current_screen( 'front' );288 289 287 $this->assertFalse( $locale_switched_user_locale ); 290 288 $this->assertTrue( $locale_switched_site_locale ); … … 336 334 $wp_locale_switcher = $locale_switcher; 337 335 338 set_current_screen( 'front' );339 340 336 remove_filter( 'locale', array( $this, 'filter_locale' ) ); 341 337 … … 383 379 $wp_locale_switcher = $locale_switcher; 384 380 385 set_current_screen( 'front' );386 387 381 $this->assertSame( 'en_US', get_locale() ); 388 382 $this->assertSame( 'This is a dummy plugin', $expected ); -
trunk/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
r50450 r51419 5 5 */ 6 6 class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase { 7 8 /**9 * Current screen.10 *11 * @var mixed12 */13 protected $current_screen;14 15 /**16 * Set up. Workaround set_current_screen( null ) not working due to $hook_suffix not being set.17 */18 function setUp() {19 parent::setUp();20 21 global $current_screen;22 $this->current_screen = $current_screen;23 }24 25 /**26 * Tear down. Workaround set_current_screen( null ) not working due to $hook_suffix not being set.27 */28 function tearDown() {29 global $current_screen;30 $current_screen = $this->current_screen;31 parent::tearDown();32 }33 7 34 8 /** -
trunk/tests/phpunit/tests/post/attachments.php
r51403 r51419 411 411 $url = wp_get_attachment_url( $attachment_id ); 412 412 413 // Cleanup.414 set_current_screen( 'front' );415 416 413 $this->assertSame( set_url_scheme( $url, 'http' ), $url ); 417 414 } … … 439 436 440 437 // Cleanup. 441 set_current_screen( 'front' );442 438 remove_filter( 'upload_dir', '_upload_dir_https' ); 443 439 -
trunk/tests/phpunit/tests/query/conditionals.php
r48937 r51419 17 17 function setUp() { 18 18 parent::setUp(); 19 20 set_current_screen( 'front' );21 19 22 20 update_option( 'comments_per_page', 5 ); -
trunk/tests/phpunit/tests/query/isTerm.php
r50463 r51419 26 26 parent::setUp(); 27 27 28 set_current_screen( 'front' );29 30 28 $GLOBALS['wp_the_query'] = new WP_Query(); 31 29 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; -
trunk/tests/phpunit/tests/query/postStatus.php
r51276 r51419 275 275 276 276 $this->assertContains( "post_status = 'foo", $q->request ); 277 set_current_screen( 'front' );278 277 } 279 278 -
trunk/tests/phpunit/tests/rest-api.php
r51404 r51419 794 794 // Reset. 795 795 update_option( 'siteurl', $_siteurl ); 796 set_current_screen( 'front' );797 798 796 } 799 797 -
trunk/tests/phpunit/tests/url.php
r51415 r51419 200 200 201 201 function test_home_url_from_admin() { 202 $screen = get_current_screen();203 204 202 // Pretend to be in the site admin. 205 203 set_current_screen( 'dashboard' ); … … 244 242 245 243 update_option( 'home', set_url_scheme( $home, 'http' ) ); 246 247 $GLOBALS['current_screen'] = $screen;248 244 } 249 245 250 246 function test_network_home_url_from_admin() { 251 $screen = get_current_screen();252 253 247 // Pretend to be in the site admin. 254 248 set_current_screen( 'dashboard' ); … … 269 263 $_SERVER['HTTPS'] = 'on'; 270 264 $this->assertSame( $home_https, network_home_url() ); 271 272 $GLOBALS['current_screen'] = $screen;273 265 } 274 266 -
trunk/tests/phpunit/tests/user/wpSendUserRequest.php
r50463 r51419 80 80 81 81 unset( $GLOBALS['locale'] ); 82 unset( $GLOBALS['current_screen'] );83 unset( $GLOBALS['taxnow'] );84 unset( $GLOBALS['typenow'] );85 82 86 83 restore_previous_locale();
Note: See TracChangeset
for help on using the changeset viewer.