diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index 622089d3b5a..790406fa146 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -101,24 +101,6 @@ require("$CFG->dirroot/lib/setup.php"); raise_memory_limit(MEMORY_HUGE); -// Check that the directory does not contains other things. -if (!file_exists("$CFG->behat_dataroot/behattestdir.txt")) { - if ($dh = opendir($CFG->behat_dataroot)) { - while (($file = readdir($dh)) !== false) { - if ($file === 'behat' or $file === '.' or $file === '..' or $file === '.DS_Store') { - continue; - } - behat_error(BEHAT_EXITCODE_CONFIG, '$CFG->behat_dataroot directory is not empty, ensure this is the directory where you want to install behat test dataroot'); - } - closedir($dh); - unset($dh); - unset($file); - } - - // Now we create dataroot directory structure for behat tests. - testing_initdataroot($CFG->behat_dataroot, 'behat'); -} - require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/upgradelib.php'); require_once($CFG->libdir.'/clilib.php'); diff --git a/lib/behat/classes/behat_command.php b/lib/behat/classes/behat_command.php index b41772ccd14..619dcd65888 100644 --- a/lib/behat/classes/behat_command.php +++ b/lib/behat/classes/behat_command.php @@ -100,10 +100,9 @@ class behat_command { * It checks behat dependencies have been installed and runs * the behat help command to ensure it works as expected * - * @param bool $checkphp Extra check for the PHP version * @return int Error code or 0 if all ok */ - public static function behat_setup_problem($checkphp = false) { + public static function behat_setup_problem() { global $CFG; $clibehaterrorstr = "Behat dependencies not installed. Ensure you ran the composer installer. " . self::DOCS_URL . "#Installation\n"; diff --git a/lib/behat/classes/util.php b/lib/behat/classes/util.php index 7ae4b900b4e..ca16c26bb99 100644 --- a/lib/behat/classes/util.php +++ b/lib/behat/classes/util.php @@ -196,7 +196,7 @@ class behat_util extends testing_util { } // Checks the behat set up and the PHP version. - if ($errorcode = behat_command::behat_setup_problem(true)) { + if ($errorcode = behat_command::behat_setup_problem()) { exit($errorcode); } @@ -230,7 +230,7 @@ class behat_util extends testing_util { } // Checks the behat set up and the PHP version, returning an error code if something went wrong. - if ($errorcode = behat_command::behat_setup_problem(true)) { + if ($errorcode = behat_command::behat_setup_problem()) { return $errorcode; } diff --git a/lib/behat/lib.php b/lib/behat/lib.php index b5f61fe4362..b3d1052efd1 100644 --- a/lib/behat/lib.php +++ b/lib/behat/lib.php @@ -211,6 +211,7 @@ function behat_check_config_vars() { } if (!file_exists($CFG->behat_dataroot)) { $permissions = isset($CFG->directorypermissions) ? $CFG->directorypermissions : 02777; + umask(0); if (!mkdir($CFG->behat_dataroot, $permissions, true)) { behat_error(BEHAT_EXITCODE_PERMISSIONS, '$CFG->behat_dataroot directory can not be created'); } diff --git a/lib/setup.php b/lib/setup.php index 0a42c50ee4e..44274e31ffb 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -71,6 +71,28 @@ if (defined('BEHAT_SITE_RUNNING')) { // selected wwwroot to prevent conflicts with production and phpunit environments. behat_check_config_vars(); + // Check that the directory does not contains other things. + if (!file_exists("$CFG->behat_dataroot/behattestdir.txt")) { + if ($dh = opendir($CFG->behat_dataroot)) { + while (($file = readdir($dh)) !== false) { + if ($file === 'behat' or $file === '.' or $file === '..' or $file === '.DS_Store') { + continue; + } + behat_error(BEHAT_EXITCODE_CONFIG, '$CFG->behat_dataroot directory is not empty, ensure this is the directory where you want to install behat test dataroot'); + } + closedir($dh); + unset($dh); + unset($file); + } + + if (defined('BEHAT_UTIL')) { + // Now we create dataroot directory structure for behat tests. + testing_initdataroot($CFG->behat_dataroot, 'behat'); + } else { + behat_error(BEHAT_EXITCODE_INSTALL); + } + } + if (!defined('BEHAT_UTIL') and !defined('BEHAT_TEST')) { // Somebody tries to access test site directly, tell them if not enabled. if (!file_exists($CFG->behat_dataroot . '/behat/test_environment_enabled.txt')) { diff --git a/lib/testing/lib.php b/lib/testing/lib.php index 4cee9b1b61c..c67a1a9c207 100644 --- a/lib/testing/lib.php +++ b/lib/testing/lib.php @@ -38,7 +38,13 @@ function testing_cli_argument_path($moodlepath) { $moodlepath = preg_replace('|^/admin/|', "/$CFG->admin/", $moodlepath); } - $cwd = getcwd(); + if (isset($_SERVER['REMOTE_ADDR'])) { + // Web access, this should not happen often. + $cwd = dirname(dirname(__DIR__)); + } else { + // This is the real CLI script, work with relative paths. + $cwd = getcwd(); + } if (substr($cwd, -1) !== DIRECTORY_SEPARATOR) { $cwd .= DIRECTORY_SEPARATOR; }