Changeset 63334 for trunk/tests/phpunit/tests/widgets.php
- Timestamp:
- 08/21/2026 04:15:34 PM (3 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/widgets.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets.php
r61466 r63334 44 44 unregister_widget( $widget_class ); 45 45 $this->assertArrayNotHasKey( $widget_class, $wp_widget_factory->widgets ); 46 } 47 48 /** 49 * Tests that a widget registered as an instance is keyed by a string. 50 * 51 * WP_Widget_Factory::$widgets is public, and its keys were strings in every release before the 52 * object ID was introduced. PHP casts an array key from string to int whenever the string is the 53 * canonical decimal representation of an integer, so a bare spl_object_id() value would change 54 * the type of the keys that consumers of that property read back. 55 * 56 * @see register_widget() 57 * @ticket 65919 58 * 59 * @global WP_Widget_Factory $wp_widget_factory 60 */ 61 public function test_register_widget_instance_is_keyed_by_string() { 62 global $wp_widget_factory; 63 64 register_widget( new WP_Widget_Search() ); 65 66 $this->assertCount( 1, $wp_widget_factory->widgets ); 67 $this->assertIsString( array_key_first( $wp_widget_factory->widgets ) ); 68 } 69 70 /** 71 * Tests that the key returned for a widget registered as an instance is a string. 72 * 73 * WP_Widget_Factory::get_widget_key() is documented as returning a string, and core passes what 74 * it returns to the_widget(), which in turn passes it to the 'the_widget' action, both of which 75 * document the value as a string. 76 * 77 * @see WP_Widget_Factory::get_widget_key() 78 * @ticket 65919 79 * 80 * @global WP_Widget_Factory $wp_widget_factory 81 */ 82 public function test_get_widget_key_for_instance_returns_string() { 83 global $wp_widget_factory; 84 85 $widget = new WP_Widget_Search(); 86 $widget->id_base = 'better_search'; 87 $widget->name = 'Better Search'; 88 $widget->option_name = 'widget_' . $widget->id_base; 89 $widget->widget_options['classname'] = 'widget_' . $widget->id_base; 90 $widget->control_options['id_base'] = $widget->id_base; 91 92 register_widget( $widget ); 93 94 $this->assertIsString( $wp_widget_factory->get_widget_key( 'better_search' ) ); 95 $this->assertSame( $widget, $wp_widget_factory->get_widget_object( 'better_search' ) ); 46 96 } 47 97
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)