Skip to content

Commit 62b286f

Browse files
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
1 parent e635540 commit 62b286f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/wp-admin/includes/class-wp-automatic-updater.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function is_vcs_checkout( $context ) {
148148
}
149149

150150
$check_dirs = array_unique( $check_dirs );
151+
$checkout = false;
151152

152153
// Search all directories we've found for evidence of version control.
153154
foreach ( $vcs_dirs as $vcs_dir ) {

tests/phpunit/tests/admin/wpAutomaticUpdater.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,4 +706,28 @@ public function data_is_allowed_dir_should_throw_doing_it_wrong_with_invalid_dir
706706
'string with only carriage returns' => array( 'dir' => "\r\r" ),
707707
);
708708
}
709+
710+
/**
711+
* Tests that `WP_Automatic_Updater::is_vcs_checkout()` returns `false`
712+
* when none of the checked directories are allowed.
713+
*
714+
* @ticket 58563
715+
*
716+
* @covers WP_Automatic_Updater::is_vcs_checkout
717+
*/
718+
public function test_is_vcs_checkout_should_return_false_when_no_directories_are_allowed() {
719+
$updater_mock = $this->getMockBuilder( 'WP_Automatic_Updater' )
720+
// Note: setMethods() is deprecated in PHPUnit 9, but still supported.
721+
->setMethods( array( 'is_allowed_dir' ) )
722+
->getMock();
723+
724+
/*
725+
* As none of the directories should be allowed, simply mocking `WP_Automatic_Updater`
726+
* and forcing `::is_allowed_dir()` to return `false` removes the need to run the test
727+
* in a separate process due to setting the `open_basedir` PHP directive.
728+
*/
729+
$updater_mock->expects( $this->any() )->method( 'is_allowed_dir' )->willReturn( false );
730+
731+
$this->assertFalse( $updater_mock->is_vcs_checkout( get_temp_dir() ) );
732+
}
709733
}

0 commit comments

Comments
 (0)