Skip to content

Commit

Permalink
Admin menu: Avoid usage of pseudorandom numbers in tests (#24224)
Browse files Browse the repository at this point in the history
* Admin menu: Avoid usage of pseudorandom numbers in tests
  • Loading branch information
mmtr authored and jeherve committed May 19, 2022
1 parent 5823923 commit a283d48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit a283d48

Please sign in to comment.