Merge branch 'w23_MDL-33557_m23_initpath' of git://github.com/skodak/moodle
This commit is contained in:
@@ -63,10 +63,12 @@ function phpunit_bootstrap_error($errorcode, $text = '') {
|
||||
$text = "Moodle PHPUnit environment configuration warning:\n".$text;
|
||||
break;
|
||||
case PHPUNIT_EXITCODE_INSTALL:
|
||||
$text = "Moodle PHPUnit environment is not initialised, please use:\n php admin/tool/phpunit/cli/init.php";
|
||||
$path = phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/init.php');
|
||||
$text = "Moodle PHPUnit environment is not initialised, please use:\n php $path";
|
||||
break;
|
||||
case PHPUNIT_EXITCODE_REINSTALL:
|
||||
$text = "Moodle PHPUnit environment was initialised for different version, please use:\n php admin/tool/phpunit/cli/init.php";
|
||||
$path = phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/init.php');
|
||||
$text = "Moodle PHPUnit environment was initialised for different version, please use:\n php $path";
|
||||
break;
|
||||
default:
|
||||
$text = empty($text) ? '' : ': '.$text;
|
||||
@@ -79,6 +81,32 @@ function phpunit_bootstrap_error($errorcode, $text = '') {
|
||||
exit($errorcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relative path against current working directory,
|
||||
* to be used for shell execution hints.
|
||||
* @param string $moodlepath starting with "/", ex: "/admin/tool/cli/init.php"
|
||||
* @return string path relative to current directory or absolute path
|
||||
*/
|
||||
function phpunit_bootstrap_cli_argument_path($moodlepath) {
|
||||
global $CFG;
|
||||
|
||||
if (isset($CFG->admin) and $CFG->admin !== 'admin') {
|
||||
$moodlepath = preg_replace('|^/admin/|', "/$CFG->admin/", $moodlepath);
|
||||
}
|
||||
|
||||
$cwd = getcwd();
|
||||
if (substr($cwd, -1) !== DIRECTORY_SEPARATOR) {
|
||||
$cwd .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$path = realpath($CFG->dirroot.$moodlepath);
|
||||
|
||||
if (strpos($path, $cwd) === 0) {
|
||||
return substr($path, strlen($cwd));
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark empty dataroot to be used for testing.
|
||||
* @param string $dataroot The dataroot directory
|
||||
|
||||
Reference in New Issue
Block a user