Skip to content

Build/Test Tools: Ensure strict assertion - #13451

Open
3kori wants to merge 5 commits into
WordPress:trunkfrom
3kori:test/64895-change-assertions
Open

Build/Test Tools: Ensure strict assertion#13451
3kori wants to merge 5 commits into
WordPress:trunkfrom
3kori:test/64895-change-assertions

Conversation

@3kori

@3kori 3kori commented Sep 9, 2026

Copy link
Copy Markdown

Replace assertEquals with assertSame in Test_WP_Customize_Nav_Menu_Item_Setting::test_value_type_post_type and Test_WP_Customize_Nav_Menu_Item_Setting::test_value_type_taxanomy.

Converted the $expected value to an integer to account for the integer normalization performed by populate_value() when it is called in WP_Customize_Nav_Menu_Item_Setting::value().

For the rest of the assertEquals, I kept them as is for the reasons below:

  1. In
$this->assertEquals( $expected_sanitized['object_id'], $nav_menu_item->object_id );

The $expected_sanitized['object_id'] is an integer while $nav_menu_item->object_id is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
$this->assertEquals( $expected_sanitized['menu_item_parent'], $nav_menu_item->menu_item_parent );

The $expected_sanitized['menu_item_parent'] is an integer while $nav_menu_item->menu_item_parent is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
foreach ( $post_value as $key => $value ) {
	$this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" );
}

The $post_value[object_id'] is an integer while $updated_item->object_id is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
foreach ( $post_value as $key => $value ) {
	$this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." );
}

The $post_value[object_id'] is an integer while $last_item->object_id is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
$this->assertEquals( (object) $term, $menu_object );

The (object) $term and $menu_object are objects being compared by value, so this assertion should remain assertEquals() rather than requiring identical object instances with assertSame().

  1. In
$this->assertEquals( (object) $block_instance, $sanitized_for_js['raw_instance'] );

Kept assertEquals because raw_instance is a newly created cast from the input array, so the test intentionally compares the objects by value rather than requiring the same object instance.

Trac ticket: #64895

Use of AI Tools

AI assistance: Yes
Tool(s): ChatGPT
Model(s): GPT-5.6
Used for: To track down how values are transformed through sanitize, wp_set_up_nav_menu_item and populate_value to determine which assertions should be converted or retained. The final code changes and decisions were reviewed and made by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props r1k0, lancewillett, mukesh27.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@lancewillett
lancewillett self-requested a review September 9, 2026 13:31

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @3kori for the PR!

Use multiline comment.

Comment thread tests/phpunit/tests/customize/nav-menu-item-setting.php Outdated
Comment thread tests/phpunit/tests/customize/nav-menu-item-setting.php Outdated
Comment thread tests/phpunit/tests/customize/nav-menu-item-setting.php Outdated
Comment thread tests/phpunit/tests/customize/nav-menu-item-setting.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants