From 6891dd73a3a247ca4f1e742dbf5315a2f82acc72 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:40:23 -0500 Subject: [PATCH] Tests: Demonstrate the version check test never reporting on multisite. `WP_Site_Health_Auto_Updates::test_wp_version_check_attached()` reports a plugin removing `wp_version_check()` from its hook. On multisite, [50035] limited it to the main site, because wp-includes/update.php only adds the hook there. The condition also requires `is_network_admin()`, but Site Health has no network admin screen, and the background updates test runs through the REST API, so the test never reports a problem on multisite. The single site baseline and the test for other sites pass. The main site test fails. See #52135. Co-Authored-By: Claude Opus 5.5 --- .../tests/admin/wpSiteHealthAutoUpdates.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/phpunit/tests/admin/wpSiteHealthAutoUpdates.php b/tests/phpunit/tests/admin/wpSiteHealthAutoUpdates.php index 4366a6ef1fc5e..6561b6a99e08d 100644 --- a/tests/phpunit/tests/admin/wpSiteHealthAutoUpdates.php +++ b/tests/phpunit/tests/admin/wpSiteHealthAutoUpdates.php @@ -52,4 +52,82 @@ public function test_vcs_abspath_should_report_git_file() { $this->assertStringContainsString( '' . ABSPATH . '', $result['description'] ); $this->assertStringContainsString( '.git', $result['description'] ); } + + /** + * Tests that the test reports a plugin removing wp_version_check() from + * its hook on a single site install. + * + * This is the baseline for + * test_wp_version_check_attached_should_report_removed_check_on_main_site(). + * + * @group ms-excluded + * + * @covers WP_Site_Health_Auto_Updates::test_wp_version_check_attached + */ + public function test_wp_version_check_attached_should_report_removed_check() { + remove_action( 'wp_version_check', 'wp_version_check' ); + + $health_check = new WP_Site_Health_Auto_Updates(); + $result = $health_check->test_wp_version_check_attached(); + + $this->assertIsArray( $result, 'The test should report the removed version check.' ); + $this->assertSame( 'fail', $result['severity'] ); + } + + /** + * Tests that the test reports a plugin removing wp_version_check() from + * its hook on the main site of a network. + * + * wp-includes/update.php only hooks wp_version_check() on the main site, + * so the test is limited to the main site on multisite (see #52135). It + * also requires the network admin, where Site Health has no screen, and + * the background updates test runs through the REST API, where + * is_network_admin() is false. The test never reports a problem on + * multisite as a result. + * + * @ticket 52135 + * @group multisite + * @group ms-required + * + * @covers WP_Site_Health_Auto_Updates::test_wp_version_check_attached + */ + public function test_wp_version_check_attached_should_report_removed_check_on_main_site() { + $this->assertTrue( is_main_site(), 'The test should run on the main site.' ); + $this->assertFalse( is_network_admin(), 'Site Health does not run in the network admin.' ); + + remove_action( 'wp_version_check', 'wp_version_check' ); + + $health_check = new WP_Site_Health_Auto_Updates(); + $result = $health_check->test_wp_version_check_attached(); + + $this->assertIsArray( $result, 'The test should report the removed version check on the main site.' ); + $this->assertSame( 'fail', $result['severity'] ); + } + + /** + * Tests that the test does not report a missing wp_version_check() hook + * on a site other than the main site of a network. + * + * wp-includes/update.php only hooks wp_version_check() on the main site, + * so the hook is always missing on other sites. + * + * @ticket 52135 + * @group multisite + * @group ms-required + * + * @covers WP_Site_Health_Auto_Updates::test_wp_version_check_attached + */ + public function test_wp_version_check_attached_should_not_report_on_other_sites() { + $site_id = self::factory()->blog->create(); + switch_to_blog( $site_id ); + + remove_action( 'wp_version_check', 'wp_version_check' ); + + $health_check = new WP_Site_Health_Auto_Updates(); + $result = $health_check->test_wp_version_check_attached(); + + restore_current_blog(); + + $this->assertNull( $result ); + } }