Upgrade/Install: Initialize the local $checkout variable in WP_Automatic_Updater::is_vcs_checkout().

This avoids an `Undefined variable $checkout` PHP warning if all of the directories checked for access are disallowed due to the PHP `open_basedir` restrictions.

Follow-up to [55425].

Props jqz, costdev, audrasjb.
Fixes #58563.

git-svn-id: https://develop.svn.wordpress.org/trunk@56124 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2023-07-02 10:33:18 +00:00
parent e635540d1c
commit 62b286f9b2
2 changed files with 25 additions and 0 deletions

View File

@ -148,6 +148,7 @@ class WP_Automatic_Updater {
}
$check_dirs = array_unique( $check_dirs );
$checkout = false;
// Search all directories we've found for evidence of version control.
foreach ( $vcs_dirs as $vcs_dir ) {

View File

@ -706,4 +706,28 @@ class Tests_Admin_WpAutomaticUpdater extends WP_UnitTestCase {
'string with only carriage returns' => array( 'dir' => "\r\r" ),
);
}
/**
* Tests that `WP_Automatic_Updater::is_vcs_checkout()` returns `false`
* when none of the checked directories are allowed.
*
* @ticket 58563
*
* @covers WP_Automatic_Updater::is_vcs_checkout
*/
public function test_is_vcs_checkout_should_return_false_when_no_directories_are_allowed() {
$updater_mock = $this->getMockBuilder( 'WP_Automatic_Updater' )
// Note: setMethods() is deprecated in PHPUnit 9, but still supported.
->setMethods( array( 'is_allowed_dir' ) )
->getMock();
/*
* As none of the directories should be allowed, simply mocking `WP_Automatic_Updater`
* and forcing `::is_allowed_dir()` to return `false` removes the need to run the test
* in a separate process due to setting the `open_basedir` PHP directive.
*/
$updater_mock->expects( $this->any() )->method( 'is_allowed_dir' )->willReturn( false );
$this->assertFalse( $updater_mock->is_vcs_checkout( get_temp_dir() ) );
}
}