Merge branch 'MDL-46778-master' of git://github.com/odeialba/moodle

This commit is contained in:
Sara Arjona 2021-09-06 10:03:07 +02:00
commit c467ce725e
7 changed files with 51 additions and 12 deletions

View file

@ -19,6 +19,9 @@
*
* All CLI utilities uses $CFG->behat_dataroot and $CFG->prefix_dataroot as
* $CFG->dataroot and $CFG->prefix
* Same applies for $CFG->behat_dbname, $CFG->behat_dbuser, $CFG->behat_dbpass
* and $CFG->behat_dbhost. But if any of those is not defined $CFG->dbname,
* $CFG->dbuser, $CFG->dbpass and/or $CFG->dbhost will be used.
*
* @package tool_behat
* @copyright 2012 David Monllaó

View file

@ -19,6 +19,9 @@
*
* All CLI utilities uses $CFG->behat_dataroot and $CFG->prefix_dataroot as
* $CFG->dataroot and $CFG->prefix
* Same applies for $CFG->behat_dbname, $CFG->behat_dbuser, $CFG->behat_dbpass
* and $CFG->behat_dbhost. But if any of those is not defined $CFG->dbname,
* $CFG->dbuser, $CFG->dbpass and/or $CFG->dbhost will be used.
*
* @package tool_behat
* @copyright 2012 David Monllaó

View file

@ -29,7 +29,7 @@ $string['errorbehatcommand'] = 'Error running behat CLI command. Try running "{$
$string['errorcomposer'] = 'Composer dependencies are not installed.';
$string['errordataroot'] = '$CFG->behat_dataroot is not set or is invalid.';
$string['errorsetconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot need to be set in config.php.';
$string['erroruniqueconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot values need to be different than $CFG->dataroot, $CFG->prefix, $CFG->wwwroot, $CFG->phpunit_dataroot and $CFG->phpunit_prefix values.';
$string['erroruniqueconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot values need to be different than $CFG->dataroot, $CFG->prefix, $CFG->wwwroot, $CFG->phpunit_dataroot and $CFG->phpunit_prefix values.<br/>Or, if $CFG->behat_prefix is the same, $CFG->behat_dbname or $CFG->behat_dbhost need to be different from $CFG->phpunit_dbname and $CFG->phpunit_dbhost and from $CFG->dbname and $CFG->dbhost.';
$string['fieldvalueargument'] = 'Field value arguments';
$string['fieldvalueargument_help'] = 'This argument should be completed by a field value. There are many field types, including simple ones like checkboxes, selects or textareas, or complex ones like date selectors. See the dev documentation <a href="https://docs.moodle.org/dev/Acceptance_testing" target="_blank">Acceptance_testing</a> for details of expected field values.';
$string['giveninfo'] = 'Given. Processes to set up the environment';

View file

@ -880,6 +880,10 @@ $CFG->admin = 'admin';
// $CFG->behat_wwwroot = 'http://127.0.0.1/moodle';
// $CFG->behat_prefix = 'bht_';
// $CFG->behat_dataroot = '/home/example/bht_moodledata';
// $CFG->behat_dbname = 'behat'; // optional
// $CFG->behat_dbuser = 'username'; // optional
// $CFG->behat_dbpass = 'password'; // optional
// $CFG->behat_dbhost = 'localhost'; // optional
//
// You can override default Moodle configuration for Behat and add your own
// params; here you can add more profiles, use different Mink drivers than Selenium...

View file

@ -203,13 +203,19 @@ class behat_command {
// We only need to check this when the behat site is not running as
// at this point, when it is running, all $CFG->behat_* vars have
// already been copied to $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
if (!defined('BEHAT_SITE_RUNNING') &&
($CFG->behat_prefix == $CFG->prefix ||
$CFG->behat_dataroot == $CFG->dataroot ||
$CFG->behat_wwwroot == $CFG->wwwroot ||
(!empty($CFG->phpunit_prefix) && $CFG->phpunit_prefix == $CFG->behat_prefix) ||
(!empty($CFG->phpunit_dataroot) && $CFG->phpunit_dataroot == $CFG->behat_dataroot)
)) {
$phpunitprefix = empty($CFG->phpunit_prefix) ? '' : $CFG->phpunit_prefix;
$behatdbname = empty($CFG->behat_dbname) ? $CFG->dbname : $CFG->behat_dbname;
$phpunitdbname = empty($CFG->phpunit_dbname) ? $CFG->dbname : $CFG->phpunit_dbname;
$behatdbhost = empty($CFG->behat_dbhost) ? $CFG->dbhost : $CFG->behat_dbhost;
$phpunitdbhost = empty($CFG->phpunit_dbhost) ? $CFG->dbhost : $CFG->phpunit_dbhost;
$samedataroot = $CFG->behat_dataroot == $CFG->dataroot;
$samedataroot = $samedataroot || (!empty($CFG->phpunit_dataroot) && $CFG->phpunit_dataroot == $CFG->behat_dataroot);
$samewwwroot = $CFG->behat_wwwroot == $CFG->wwwroot;
$sameprefix = ($CFG->behat_prefix == $CFG->prefix && $behatdbname == $CFG->dbname && $behatdbhost == $CFG->dbhost);
$sameprefix = $sameprefix || ($CFG->behat_prefix == $phpunitprefix && $behatdbname == $phpunitdbname &&
$behatdbhost == $phpunitdbhost);
if (!defined('BEHAT_SITE_RUNNING') && ($samedataroot || $samewwwroot || $sameprefix)) {
self::output_msg(get_string('erroruniqueconfig', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}

View file

@ -243,18 +243,31 @@ function behat_clean_init_config() {
function behat_check_config_vars() {
global $CFG;
$moodleprefix = empty($CFG->prefix) ? '' : $CFG->prefix;
$behatprefix = empty($CFG->behat_prefix) ? '' : $CFG->behat_prefix;
$phpunitprefix = empty($CFG->phpunit_prefix) ? '' : $CFG->phpunit_prefix;
$behatdbname = empty($CFG->behat_dbname) ? $CFG->dbname : $CFG->behat_dbname;
$phpunitdbname = empty($CFG->phpunit_dbname) ? $CFG->dbname : $CFG->phpunit_dbname;
$behatdbhost = empty($CFG->behat_dbhost) ? $CFG->dbhost : $CFG->behat_dbhost;
$phpunitdbhost = empty($CFG->phpunit_dbhost) ? $CFG->dbhost : $CFG->phpunit_dbhost;
// Verify prefix value.
if (empty($CFG->behat_prefix)) {
behat_error(BEHAT_EXITCODE_CONFIG,
'Define $CFG->behat_prefix in config.php');
}
if (!empty($CFG->prefix) and $CFG->behat_prefix == $CFG->prefix) {
if ($behatprefix == $moodleprefix && $behatdbname == $CFG->dbname && $behatdbhost == $CFG->dbhost) {
behat_error(BEHAT_EXITCODE_CONFIG,
'$CFG->behat_prefix in config.php must be different from $CFG->prefix');
'$CFG->behat_prefix in config.php must be different from $CFG->prefix' .
' when $CFG->behat_dbname and $CFG->behat_host are not set or when $CFG->behat_dbname equals $CFG->dbname' .
' and $CFG->behat_dbhost equals $CFG->dbhost');
}
if (!empty($CFG->phpunit_prefix) and $CFG->behat_prefix == $CFG->phpunit_prefix) {
if ($phpunitprefix !== '' && $behatprefix == $phpunitprefix && $behatdbname == $phpunitdbname &&
$behatdbhost == $phpunitdbhost) {
behat_error(BEHAT_EXITCODE_CONFIG,
'$CFG->behat_prefix in config.php must be different from $CFG->phpunit_prefix');
'$CFG->behat_prefix in config.php must be different from $CFG->phpunit_prefix' .
' when $CFG->behat_dbname equals $CFG->phpunit_dbname' .
' and $CFG->behat_dbhost equals $CFG->phpunit_dbhost');
}
// Verify behat wwwroot value.

View file

@ -141,6 +141,16 @@ if (defined('BEHAT_SITE_RUNNING')) {
$CFG->wwwroot = $CFG->behat_wwwroot;
$CFG->prefix = $CFG->behat_prefix;
$CFG->dataroot = $CFG->behat_dataroot;
// And we do the same with the optional ones.
$allowedconfigoverride = ['dbname', 'dbuser', 'dbpass', 'dbhost'];
foreach ($allowedconfigoverride as $config) {
$behatconfig = 'behat_' . $config;
if (!isset($CFG->$behatconfig)) {
continue;
}
$CFG->$config = $CFG->$behatconfig;
}
}
}