Make WordPress Core

Changeset 63604


Ignore:
Timestamp:
09/11/2026 08:59:28 PM (5 weeks ago)
Author:
lancewillett
Message:

Tests: Use assertSame() in WP_Customize_Nav_Menu_Item_Setting tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Where a loose comparison is intentional, inline comments now explain why: post meta returns IDs as strings, and some objects are compared by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13451

Props r1k0, mukesh27.
See #64895.

Location:
trunk/tests/phpunit/tests/customize
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php

    r62717 r63604  
    191191                $this->assertSame( $menu_item->title, $value['title'] );
    192192                $this->assertSame( $menu_item->type, $value['type'] );
    193                 $this->assertEquals( $menu_item->object_id, $value['object_id'] );
     193                $this->assertSame( (int) $menu_item->object_id, $value['object_id'] );
    194194                $this->assertSame( $menu_id, $value['nav_menu_term_id'] );
    195195                $this->assertSame( 'Hello World', $value['original_title'] );
    … …  
    274274                $this->assertSame( $menu_item->title, $value['title'] );
    275275                $this->assertSame( $menu_item->type, $value['type'] );
    276                 $this->assertEquals( $menu_item->object_id, $value['object_id'] );
     276                $this->assertSame( (int) $menu_item->object_id, $value['object_id'] );
    277277                $this->assertSame( $menu_id, $value['nav_menu_term_id'] );
    278278                $this->assertSame( 'Salutations', $value['original_title'] );
    … …  
    633633                $nav_menu_item = wp_setup_nav_menu_item( clone $post );
    634634
     635                /*
     636                 * Keep assertEquals() because sanitize() returns object_id as an integer
     637                 * while wp_setup_nav_menu_item() retrieves it as a string from post meta.
     638                 */
    635639                $this->assertEquals( $expected_sanitized['object_id'], $nav_menu_item->object_id );
    636640                $this->assertSame( $expected_sanitized['object'], $nav_menu_item->object );
     641
     642                /*
     643                 * Keep assertEquals() because sanitize() returns menu_item_parent as an integer,
     644                 * while wp_setup_nav_menu_item() retrieves it as a string from post meta.
     645                 */
    637646                $this->assertEquals( $expected_sanitized['menu_item_parent'], $nav_menu_item->menu_item_parent );
    638647                $this->assertSame( $expected_sanitized['position'], $post->menu_order );
    … …  
    698707                $post_value['post_status'] = $post_value['status'];
    699708                unset( $post_value['status'] );
     709
     710                /*
     711                 * Keep assertEquals() because object_id is an integer in $post_value
     712                 * but is returned as a string from post meta by wp_setup_nav_menu_item().
     713                 */
    700714                foreach ( $post_value as $key => $value ) {
    701715                        $this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" );
    … …  
    771785                $post_value['menu_order'] = $post_value['position'];
    772786                unset( $post_value['position'] );
     787
     788                /*
     789                 * Keep assertEquals() because object_id is an integer in $post_value
     790                 * but is returned as a string from post meta by wp_setup_nav_menu_item().
     791                 */
    773792                foreach ( $post_value as $key => $value ) {
    774793                        $this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." );
  • trunk/tests/phpunit/tests/customize/nav-menu-setting.php

    r60253 r63604  
    233233
    234234                $menu_object = wp_get_nav_menu_object( $menu_id );
     235
     236                // Keep assertEquals() because the objects are intentionally compared by value.
    235237                $this->assertEquals( (object) $term, $menu_object );
    236238                $this->assertSame( $post_value['name'], $menu_object->name );
    … …  
    278280
    279281                $menu_object = wp_get_nav_menu_object( $menu_id );
     282
     283                // Keep assertEquals() because the objects are intentionally compared by value.
    280284                $this->assertEquals( (object) $term, $menu_object );
    281285                $this->assertSame( $post_value['name'], $menu_object->name );
  • trunk/tests/phpunit/tests/customize/widgets.php

    r63311 r63604  
    516516                $this->assertTrue( $sanitized_for_js['is_widget_customizer_js_value'] );
    517517                $this->assertArrayHasKey( 'instance_hash_key', $sanitized_for_js );
     518
     519                // Keep assertEquals() because the objects are intentionally compared by value.
    518520                $this->assertEquals( (object) $block_instance, $sanitized_for_js['raw_instance'] );
    519521
Note: See TracChangeset for help on using the changeset viewer.