From 10619e8759fb91c13d8f1bd028de23c2d85accce Mon Sep 17 00:00:00 2001 From: mmtr Date: Tue, 3 May 2022 13:55:03 +0200 Subject: [PATCH 1/4] Admin menu: Avoid usage of pseudorandom numbers in tests --- .../php/modules/masterbar/test-class-admin-menu.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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..e4d74cd206b1f 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,9 @@ 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] ); + $menu_items = array_values( $menu ); + + $this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu_items[1][2] ); } /** From 9cfc0410f50570eea72438f311b0b396ebaa857a Mon Sep 17 00:00:00 2001 From: mmtr Date: Tue, 3 May 2022 13:56:27 +0200 Subject: [PATCH 2/4] Add changelog --- projects/plugins/jetpack/changelog/fix-admin-menu-tests-wp6 | 5 +++++ 1 file changed, 5 insertions(+) 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 + + From 9fa9133f7ed2704a3f17ea9031744b5e3a23e159 Mon Sep 17 00:00:00 2001 From: mmtr Date: Tue, 3 May 2022 14:08:10 +0200 Subject: [PATCH 3/4] Fix test_add_stats_menu test --- .../tests/php/modules/masterbar/test-class-admin-menu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e4d74cd206b1f..74f1bc0ea511d 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 @@ -206,7 +206,7 @@ public function test_add_stats_menu() { $menu_items = array_values( $menu ); - $this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu_items[1][2] ); + $this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu_items[4][2] ); } /** From aad712b88891cc8b4c2d08001e33439db72ff438 Mon Sep 17 00:00:00 2001 From: mmtr Date: Tue, 3 May 2022 14:11:53 +0200 Subject: [PATCH 4/4] Add comment --- .../tests/php/modules/masterbar/test-class-admin-menu.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 74f1bc0ea511d..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 @@ -204,9 +204,14 @@ public function test_add_stats_menu() { static::$admin_menu->add_stats_menu(); + // 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[4][2] ); + $this->assertSame( 'https://wordpress.com/stats/day/' . static::$domain, $menu_items[2][2] ); } /**