Changeset 56068
- Timestamp:
- 06/27/2023 04:00:00 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-plugins-list-table.php
r55954 r56068 296 296 $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) ); 297 297 } 298 299 /** 300 * Filters the array of plugins for the list table. 301 * 302 * @since 6.3.0 303 * 304 * @param array[] $plugins An array of arrays of plugin data, keyed by context. 305 */ 306 $plugins = apply_filters( 'plugins_list', $plugins ); 298 307 299 308 $totals = array(); -
trunk/tests/phpunit/tests/admin/wpPluginsListTable.php
r55903 r56068 20 20 21 21 /** 22 * Creates an admin user before any tests run. 22 * The original value of the `$s` global. 23 * 24 * @var string|null 25 */ 26 private static $original_s; 27 28 /** 29 * @var array 30 */ 31 public $fake_plugin = array( 32 'fake-plugin.php' => array( 33 'Name' => 'Fake Plugin', 34 'PluginURI' => 'https://wordpress.org/', 35 'Version' => '1.0.0', 36 'Description' => 'A fake plugin for testing.', 37 'Author' => 'WordPress', 38 'AuthorURI' => 'https://wordpress.org/', 39 'TextDomain' => 'fake-plugin', 40 'DomainPath' => '/languages', 41 'Network' => false, 42 'Title' => 'Fake Plugin', 43 'AuthorName' => 'WordPress', 44 ), 45 ); 46 47 /** 48 * Creates an admin user before any tests run and backs up the `$s` global. 23 49 */ 24 50 public static function set_up_before_class() { 51 global $s; 52 25 53 parent::set_up_before_class(); 26 54 … … 33 61 ) 34 62 ); 63 self::$original_s = $s; 35 64 } 36 65 … … 38 67 parent::set_up(); 39 68 $this->table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => 'plugins' ) ); 69 } 70 71 /** 72 * Restores the `$s` global after each test. 73 */ 74 public function tear_down() { 75 global $s; 76 77 $s = self::$original_s; 78 79 parent::tear_down(); 40 80 } 41 81 … … 254 294 ); 255 295 } 296 297 /** 298 * Tests that WP_Plugins_List_Table::prepare_items() 299 * applies 'plugins_list' filters. 300 * 301 * @ticket 57278 302 * 303 * @covers WP_Plugins_List_Table::prepare_items 304 */ 305 public function test_plugins_list_filter() { 306 global $status, $s; 307 308 $old_status = $status; 309 $status = 'mustuse'; 310 $s = ''; 311 312 add_filter( 'plugins_list', array( $this, 'plugins_list_filter' ), 10, 1 ); 313 $this->table->prepare_items(); 314 $plugins = $this->table->items; 315 remove_filter( 'plugins_list', array( $this, 'plugins_list_filter' ), 10 ); 316 317 // Restore to default. 318 $status = $old_status; 319 $this->table->prepare_items(); 320 321 $this->assertSame( $plugins, $this->fake_plugin ); 322 } 323 324 /** 325 * Adds a fake plugin to an array of plugins. 326 * 327 * Used as a callback for the 'plugins_list' hook. 328 * 329 * @return array 330 */ 331 public function plugins_list_filter( $plugins_list ) { 332 $plugins_list['mustuse'] = $this->fake_plugin; 333 334 return $plugins_list; 335 } 256 336 }
Note: See TracChangeset
for help on using the changeset viewer.