From a283d4856a0bfc4c8af1cc7aa1948e8a781544af Mon Sep 17 00:00:00 2001 From: Miguel Torres Date: Tue, 3 May 2022 15:54:23 +0200 Subject: [PATCH] Admin menu: Avoid usage of pseudorandom numbers in tests (#24224) * Admin menu: Avoid usage of pseudorandom numbers in tests --- .../jetpack/changelog/fix-admin-menu-tests-wp6 | 5 +++++ .../modules/masterbar/test-class-admin-menu.php | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/fix-admin-menu-tests-wp6 diff --git a/projects/plugins/jetpack/changelog/fix-admin-menu-tests-wp6 b/projects/plugins/jetpack/changelog/fix-admin-menu-tests-wp6 new file mode 100644 index 0000000000000..41eec00d2b1a6 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-admin-menu-tests-wp6 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Makes the Admin_Menu tests compatible with WordPress 6.0 + + diff --git a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-admin-menu.php b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-admin-menu.php index 8ca4704f3bef1..42b3ee648043c 100644 --- a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-admin-menu.php +++ b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-admin-menu.php @@ -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.' ); } @@ -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] ); } /**