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

Admin menu: Avoid usage of pseudorandom numbers in tests #24224

Merged
merged 4 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions projects/plugins/jetpack/changelog/fix-admin-menu-tests-wp6
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Makes the Admin_Menu tests compatible with WordPress 6.0


Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ public function test_admin_menu_output() {

static::$admin_menu->reregister_menu_items();

$this->assertSame(
array_keys( $menu ),
array( 2, '3.86682', 4, 5, 10, 15, 20, 25, 30, 50, 51, 58, 59, 60, 65, 70, 75, 80 ),
'Admin menu should not have unexpected top menu items.'
);
$this->assertCount( 18, $menu, 'Admin menu should not have unexpected top menu items.' );

$this->assertEquals( static::$submenu_data[''], $submenu[''], 'Submenu items without parent should stay the same.' );
}
Expand Down Expand Up @@ -208,7 +204,14 @@ public function test_add_stats_menu() {

static::$admin_menu->add_stats_menu();

$this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu['3.86682'][2] );
// Ignore position keys, since the key used for the Stats menu contains a pseudorandom number
// that we shouldn't hardcode. The only thing that matters is that the menu should be in the
// 3rd position regardless of the key.
// @see https://core.trac.wordpress.org/ticket/40927
ksort( $menu );
$menu_items = array_values( $menu );

$this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu_items[2][2] );
}

/**
Expand Down