Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_nav_menu() throws undefined offset if a menu item's parent has a higher ID. #3635

Conversation

peterwilsoncc
Copy link
Contributor

@peterwilsoncc peterwilsoncc force-pushed the fix/57122-menu-undefined-offset branch 2 times, most recently from 1471695 to 5e8f2e7 Compare November 16, 2022 03:53
*
* @ticket 57122
*/
public function test_parent_with_higher_id_should_not_error() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, the parent of self::$lvl1_menu_item does not need to be reset to self::$lvl0_menu_item as the parent set_up()/tear_down() methods handle resetting this. Is that correct?

All other tests pass if you move this new test to the top of the file, and this drop-in test method also passes:

public function test_that_peter_did_not_break_the_test_suite() {
	$menu_items = wp_get_nav_menu_items( self::$menu_id );
	$this->assertSame( (int) $menu_items[1]->menu_item_parent, self::$lvl0_menu_item );
}

But just asking to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to confirm, the parent of self::$lvl1_menu_item does not need to be reset to self::$lvl0_menu_item as the parent set_up()/tear_down() methods handle resetting this. Is that correct?

Yes, that is correct.

Changes to the post and post meta table are stored in a transaction that is started in the test suite's setup and rolled back during the tear-down.

$this->start_transaction();
$this->expectDeprecated();
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
}
/**
* After a test method runs, resets any state in WordPress the test method might have changed.
*/
public function tear_down() {
global $wpdb, $wp_query, $wp;
$wpdb->query( 'ROLLBACK' );

@peterwilsoncc
Copy link
Contributor Author

Committed in c98ca19 / r55328

@peterwilsoncc peterwilsoncc deleted the fix/57122-menu-undefined-offset branch February 14, 2023 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants