Changeset 63608
- Timestamp:
- 09/13/2026 04:21:34 PM (7 hours ago)
- Location:
- trunk/tests/phpunit/tests/admin
- Files:
-
- 4 edited
-
includesPlugin.php (modified) (2 diffs)
-
plugin-dependencies/base.php (modified) (1 diff)
-
wpAutomaticUpdater.php (modified) (3 diffs)
-
wpListTable.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/admin/includesPlugin.php
r61006 r63608 12 12 */ 13 13 public static $admin_id; 14 15 public function set_up() { 16 parent::set_up(); 17 $this->reset_menu_globals(); 18 } 19 20 public function tear_down() { 21 $this->reset_menu_globals(); 22 parent::tear_down(); 23 } 24 25 /** 26 * Resets the global menu registries modified by the menu API tests. 27 */ 28 private function reset_menu_globals() { 29 global $menu, $submenu, $admin_page_hooks, $_registered_pages, $_parent_pages; 30 31 $menu = array(); 32 $submenu = array(); 33 $admin_page_hooks = array(); 34 $_registered_pages = array(); 35 $_parent_pages = array(); 36 } 14 37 15 38 public static function wpSetUpBeforeClass( $factory ) { … … 502 525 unlink( WPMU_PLUGIN_DIR . '/foo.php' ); 503 526 unlink( WPMU_PLUGIN_DIR . '/bar.txt' ); 527 rmdir( WPMU_PLUGIN_DIR ); 504 528 505 529 $this->assertSame( array( 'foo.php' ), array_keys( $found ) ); -
trunk/tests/phpunit/tests/admin/plugin-dependencies/base.php
r60729 r63608 62 62 63 63 /** 64 * Resets all static properties to a default value before each test. 65 */ 66 public function set_up() { 67 parent::set_up(); 68 $this->reset_static_properties(); 69 } 70 71 /** 64 72 * Resets all static properties to a default value after each test. 65 73 */ 66 74 public function tear_down() { 75 $this->reset_static_properties(); 76 parent::tear_down(); 77 } 78 79 /** 80 * Resets all static properties to their default values. 81 */ 82 private function reset_static_properties() { 67 83 foreach ( self::$static_properties as $name => $default_value ) { 68 84 $this->set_property_value( $name, $default_value ); 69 85 } 70 71 parent::tear_down();72 86 } 73 87 -
trunk/tests/phpunit/tests/admin/wpAutomaticUpdater.php
r60729 r63608 39 39 parent::set_up(); 40 40 add_filter( 'pre_wp_mail', '__return_false' ); 41 } 42 43 /** 44 * Builds an open_basedir value that allows PHPUnit to load Composer dependencies. 45 * 46 * Composer dependencies may live outside a secondary worktree, and PHPUnit can 47 * load assertion-related classes after the restriction is set. 48 * 49 * @param string $abspath_grandparent Directory containing the repository. 50 * @return string The open_basedir value. 51 */ 52 private function get_open_basedir_for_tests( $abspath_grandparent ) { 53 $composer_vendor_dir = dirname( 54 ( new ReflectionClass( Composer\Autoload\ClassLoader::class ) )->getFileName(), 55 2 56 ); 57 58 return implode( 59 PATH_SEPARATOR, 60 array( 61 sys_get_temp_dir(), 62 wp_normalize_path( $abspath_grandparent ), 63 wp_normalize_path( $composer_vendor_dir ), 64 ) 65 ); 41 66 } 42 67 … … 613 638 614 639 $open_basedir_backup = ini_get( 'open_basedir' ); 615 // Allow access to the directory one level above the repository. 616 ini_set( 'open_basedir', sys_get_temp_dir() . PATH_SEPARATOR . wp_normalize_path( $abspath_grandparent ) ); 640 ini_set( 'open_basedir', $this->get_open_basedir_for_tests( $abspath_grandparent ) ); 617 641 618 642 // Checking an allowed directory should succeed. … … 648 672 649 673 $open_basedir_backup = ini_get( 'open_basedir' ); 650 // Allow access to the directory one level above the repository. 651 ini_set( 'open_basedir', sys_get_temp_dir() . PATH_SEPARATOR . wp_normalize_path( $abspath_grandparent ) ); 674 ini_set( 'open_basedir', $this->get_open_basedir_for_tests( $abspath_grandparent ) ); 652 675 653 676 // Checking a directory not within the allowed path should trigger an `open_basedir` warning. -
trunk/tests/phpunit/tests/admin/wpListTable.php
r60729 r63608 18 18 * Original value of $GLOBALS['hook_suffix']. 19 19 * 20 * @var string 20 * @var string|null 21 21 */ 22 22 private static $original_hook_suffix; 23 24 /** 25 * Whether $GLOBALS['hook_suffix'] existed before the test class ran. 26 * 27 * @var bool 28 */ 29 private static $hook_suffix_was_set; 23 30 24 31 public static function set_up_before_class() { 25 32 parent::set_up_before_class(); 26 33 27 static::$original_hook_suffix = $GLOBALS['hook_suffix']; 34 static::$hook_suffix_was_set = array_key_exists( 'hook_suffix', $GLOBALS ); 35 static::$original_hook_suffix = $GLOBALS['hook_suffix'] ?? null; 28 36 29 37 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; … … 38 46 39 47 public function clean_up_global_scope() { 40 global $hook_suffix; 41 $hook_suffix = static::$original_hook_suffix; 48 if ( static::$hook_suffix_was_set ) { 49 $GLOBALS['hook_suffix'] = static::$original_hook_suffix; 50 } else { 51 unset( $GLOBALS['hook_suffix'] ); 52 } 53 42 54 parent::clean_up_global_scope(); 43 55 } … … 62 74 add_filter( 'list_table_primary_column', array( $hook, 'filter' ) ); 63 75 64 /* 65 * Set a dummy value for the current screen in the admin to prevent 66 * `_get_list_table()` throwing. 67 */ 68 $GLOBALS['hook_suffix'] = 'my-hook'; 69 70 $list_table = _get_list_table( $list_class ); 76 $list_table = _get_list_table( 77 $list_class, 78 array( 'screen' => 'wp-list-table-test-' . sanitize_key( $list_class ) ) 79 ); 71 80 72 81 $column_headers = new ReflectionProperty( $list_table, '_column_headers' ); … … 98 107 $list_primary_columns = array( 99 108 'WP_Application_Passwords_List_Table' => 'name', 100 'WP_Comments_List_Table' => ' author',109 'WP_Comments_List_Table' => 'comment', 101 110 'WP_Links_List_Table' => 'name', 102 111 'WP_Media_List_Table' => 'title',
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)