Changeset 61466 for trunk/tests/phpunit/tests/widgets.php
- Timestamp:
- 01/10/2026 06:28:18 PM (9 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/widgets.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets.php
r60732 r61466 1413 1413 $this->assertSame( array(), $new_sidebars['primary'], 'Primary sidebar should be an empty array after normalization.' ); 1414 1414 } 1415 1416 /** 1417 * Tests that is_active_widget() does not generate a PHP warning when 1418 * a widget ID exists in sidebars_widgets but is not in $wp_registered_widgets, 1419 * and the function is called with id_base and widget_id parameters. 1420 * 1421 * This can happen when a widget is saved to a sidebar but the widget class 1422 * has not yet been registered (e.g., during early plugin/theme loading). 1423 * 1424 * @ticket 57518 1425 * @covers ::is_active_widget 1426 */ 1427 public function test_is_active_widget_with_unregistered_widget_and_id_base_match() { 1428 global $wp_registered_widgets; 1429 1430 // Set up a sidebar with a widget that is NOT registered in $wp_registered_widgets. 1431 update_option( 1432 'sidebars_widgets', 1433 array( 1434 'wp_inactive_widgets' => array(), 1435 'sidebar-1' => array( 'search-2' ), 1436 'array_version' => 3, 1437 ) 1438 ); 1439 1440 // Ensure the widget is NOT in $wp_registered_widgets. 1441 unset( $wp_registered_widgets['search-2'] ); 1442 1443 /* 1444 * Call is_active_widget() with id_base and widget_id parameters. 1445 * This should NOT generate a PHP warning about accessing array offset on null. 1446 * 1447 * The bug occurs because when matching by id_base, the code checks 1448 * _get_widget_id_base( $widget ) === $id_base without verifying 1449 * $wp_registered_widgets[ $widget ] exists, then tries to access 1450 * $wp_registered_widgets[ $widget ]['id'] on the next line. 1451 */ 1452 $result = is_active_widget( false, 'search-2', 'search', true ); 1453 1454 $this->assertFalse( $result, 'The widget is not registered, so the function should return false.' ); 1455 } 1415 1456 }
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)