mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-39752 behat: Added support for behat_wwwroot and behat_dataroot
This commit is contained in:
parent
b1c36d966e
commit
5b9e6b5526
@ -147,13 +147,17 @@ if ($options['profile']) {
|
||||
|
||||
// Update config file if tags defined.
|
||||
if ($tags) {
|
||||
// Hack to set proper dataroot and wwroot.
|
||||
// Hack to set proper dataroot and wwwroot.
|
||||
$behatdataroot = $CFG->behat_dataroot;
|
||||
$behatwwwroot = $CFG->behat_wwwroot;
|
||||
for ($i = 1; $i <= $parallelrun; $i++) {
|
||||
$CFG->behatrunprocess = $i;
|
||||
$CFG->behat_dataroot = $behatdataroot . $i;
|
||||
$CFG->behat_wwwroot = $behatwwwroot . "/" . BEHAT_PARALLEL_SITE_NAME . $i;
|
||||
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
|
||||
$CFG->behat_wwwroot = $CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'];
|
||||
} else {
|
||||
$CFG->behat_wwwroot = $behatwwwroot . "/" . BEHAT_PARALLEL_SITE_NAME . $i;
|
||||
}
|
||||
behat_config_manager::update_config_file('', true, $tags);
|
||||
}
|
||||
$CFG->behat_dataroot = $behatdataroot;
|
||||
|
@ -187,7 +187,12 @@ if ($options['install']) {
|
||||
|
||||
// Display all sites which are installed/drop/diabled.
|
||||
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
|
||||
echo $CFG->behat_wwwroot . "/" . BEHAT_PARALLEL_SITE_NAME . $i . PHP_EOL;
|
||||
if (empty($CFG->behat_parallel_run[$i - 1]['behat_wwwroot'])) {
|
||||
echo $CFG->behat_wwwroot . "/" . BEHAT_PARALLEL_SITE_NAME . $i . PHP_EOL;
|
||||
} else {
|
||||
echo $CFG->behat_parallel_run[$i - 1]['behat_wwwroot'] . PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
||||
} else if ($options['drop']) {
|
||||
echo "Acceptance tests site dropped for " . $options['parallel'] . " parallel sites" . PHP_EOL;
|
||||
|
@ -735,7 +735,9 @@ $CFG->admin = 'admin';
|
||||
// 'dbuser' => 'moodle',
|
||||
// 'dbpass' => 'moodle',
|
||||
// 'behat_prefix' => 'mdl_',
|
||||
// 'wd_host' => 'http://127.0.0.1:4444/wd/hub'
|
||||
// 'wd_host' => 'http://127.0.0.1:4444/wd/hub',
|
||||
// 'behat_wwwroot' => 'http://127.0.0.1/moodle',
|
||||
// 'behat_dataroot' => '/home/example/bht_moodledata'
|
||||
// ),
|
||||
// );
|
||||
//
|
||||
|
@ -50,9 +50,13 @@ class behat_command {
|
||||
public static function get_behat_dir($runprocess = 0) {
|
||||
global $CFG;
|
||||
|
||||
$runprocess = empty($runprocess) ? "" : $runprocess;
|
||||
|
||||
$behatdir = $CFG->behat_dataroot . $runprocess . '/behat';
|
||||
if (empty($runprocess)) {
|
||||
$behatdir = $CFG->behat_dataroot . '/behat';
|
||||
} else if (isset($CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'])) {
|
||||
$behatdir = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'] . '/behat';;
|
||||
} else {
|
||||
$behatdir = $CFG->behat_dataroot . $runprocess . '/behat';
|
||||
}
|
||||
|
||||
if (!is_dir($behatdir)) {
|
||||
if (!mkdir($behatdir, $CFG->directorypermissions, true)) {
|
||||
|
@ -214,7 +214,11 @@ class behat_config_manager {
|
||||
global $CFG;
|
||||
|
||||
if ($runprocess) {
|
||||
$command = $CFG->behat_dataroot . $runprocess;
|
||||
if (isset($CFG->behat_parallel_run[$runprocess - 1 ]['behat_dataroot'])) {
|
||||
$command = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'];
|
||||
} else {
|
||||
$command = $CFG->behat_dataroot . $runprocess;
|
||||
}
|
||||
} else {
|
||||
$command = $CFG->behat_dataroot;
|
||||
}
|
||||
@ -276,6 +280,10 @@ class behat_config_manager {
|
||||
// If parallel run then remove links and original file.
|
||||
clearstatcache();
|
||||
for ($i = 1; $i <= $parallelrun; $i++) {
|
||||
// Don't delete links for specified sites, as they should be accessible.
|
||||
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
|
||||
continue;
|
||||
}
|
||||
$link = $CFG->dirroot . '/' . BEHAT_PARALLEL_SITE_NAME . $i;
|
||||
if (file_exists($link) && is_link($link)) {
|
||||
@unlink($link);
|
||||
@ -297,6 +305,10 @@ class behat_config_manager {
|
||||
// Create site symlink if necessary.
|
||||
clearstatcache();
|
||||
for ($i = $fromrun; $i <= $torun; $i++) {
|
||||
// Don't create links for specified sites, as they should be accessible.
|
||||
if (!empty($CFG->behat_parallel_run['behat_wwwroot'][$i - 1]['behat_wwwroot'])) {
|
||||
continue;
|
||||
}
|
||||
$link = $CFG->dirroot.'/'.BEHAT_PARALLEL_SITE_NAME.$i;
|
||||
clearstatcache();
|
||||
if (file_exists($link)) {
|
||||
|
@ -287,20 +287,25 @@ function behat_is_test_site() {
|
||||
function behat_update_vars_for_process() {
|
||||
global $CFG;
|
||||
|
||||
$allowedconfigoverride = array('dbtype', 'dblibrary', 'dbhost', 'dbname', 'dbuser', 'dbpass', 'behat_prefix');
|
||||
$allowedconfigoverride = array('dbtype', 'dblibrary', 'dbhost', 'dbname', 'dbuser', 'dbpass', 'behat_prefix',
|
||||
'behat_wwwroot', 'behat_dataroot');
|
||||
$behatrunprocess = behat_get_run_process();
|
||||
$CFG->behatrunprocess = $behatrunprocess;
|
||||
|
||||
if ($behatrunprocess) {
|
||||
// Set www root for run process.
|
||||
if (isset($CFG->behat_wwwroot) && !preg_match("#/" . BEHAT_PARALLEL_SITE_NAME . $behatrunprocess . "\$#",
|
||||
$CFG->behat_wwwroot)) {
|
||||
$CFG->behat_wwwroot .= "/" . BEHAT_PARALLEL_SITE_NAME . $behatrunprocess;
|
||||
if (empty($CFG->behat_parallel_run[$behatrunprocess - 1]['behat_wwwroot'])) {
|
||||
// Set www root for run process.
|
||||
if (isset($CFG->behat_wwwroot) &&
|
||||
!preg_match("#/" . BEHAT_PARALLEL_SITE_NAME . $behatrunprocess . "\$#", $CFG->behat_wwwroot)) {
|
||||
$CFG->behat_wwwroot .= "/" . BEHAT_PARALLEL_SITE_NAME . $behatrunprocess;
|
||||
}
|
||||
}
|
||||
|
||||
// Set behat_dataroot.
|
||||
if (!preg_match("#" . $behatrunprocess . "\$#", $CFG->behat_dataroot)) {
|
||||
$CFG->behat_dataroot .= $behatrunprocess;
|
||||
if (empty($CFG->behat_parallel_run[$behatrunprocess - 1]['behat_dataroot'])) {
|
||||
// Set behat_dataroot.
|
||||
if (!preg_match("#" . $behatrunprocess . "\$#", $CFG->behat_dataroot)) {
|
||||
$CFG->behat_dataroot .= $behatrunprocess;
|
||||
}
|
||||
}
|
||||
|
||||
// Set behat_prefix for db, just suffix run process number, to avoid max length exceed.
|
||||
@ -372,7 +377,17 @@ function behat_get_run_process() {
|
||||
if (defined('BEHAT_CURRENT_RUN') && BEHAT_CURRENT_RUN) {
|
||||
$behatrunprocess = BEHAT_CURRENT_RUN;
|
||||
} else if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
if (preg_match('#/' . BEHAT_PARALLEL_SITE_NAME . '(.+?)/#', $_SERVER['REQUEST_URI'])) {
|
||||
// Try get it from config if present.
|
||||
if (!empty($CFG->behat_parallel_run)) {
|
||||
foreach ($CFG->behat_parallel_run as $run => $behatconfig) {
|
||||
if (isset($behatconfig['behat_wwwroot']) && behat_is_requested_url($behatconfig['behat_wwwroot'])) {
|
||||
$behatrunprocess = $run + 1; // We start process from 1.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if parallel site prefix is used.
|
||||
if (empty($behatrunprocess) && preg_match('#/' . BEHAT_PARALLEL_SITE_NAME . '(.+?)/#', $_SERVER['REQUEST_URI'])) {
|
||||
$dirrootrealpath = str_replace("\\", "/", realpath($CFG->dirroot));
|
||||
$serverrealpath = str_replace("\\", "/", realpath($_SERVER['SCRIPT_FILENAME']));
|
||||
$afterpath = str_replace($dirrootrealpath.'/', '', $serverrealpath);
|
||||
@ -385,13 +400,25 @@ function behat_get_run_process() {
|
||||
} else if (defined('BEHAT_TEST') || defined('BEHAT_UTIL')) {
|
||||
if ($match = preg_filter('#--run=(.+)#', '$1', $argv)) {
|
||||
$behatrunprocess = reset($match);
|
||||
}
|
||||
|
||||
if ($k = array_search('--config', $argv)) {
|
||||
} else if ($k = array_search('--config', $argv)) {
|
||||
$behatconfig = str_replace("\\", "/", $argv[$k + 1]);
|
||||
$behatdataroot = str_replace("\\", "/", $CFG->behat_dataroot);
|
||||
$behatrunprocess = preg_filter("#^{$behatdataroot}" .
|
||||
"(.+?)[/|\\\]behat[/|\\\]behat\.yml#", '$1', $behatconfig);
|
||||
// Try get it from config if present.
|
||||
if (!empty($CFG->behat_parallel_run)) {
|
||||
foreach ($CFG->behat_parallel_run as $run => $parallelconfig) {
|
||||
if (!empty($parallelconfig['behat_dataroot']) &&
|
||||
$parallelconfig['behat_dataroot'] . '/behat/behat.yml' == $behatconfig) {
|
||||
|
||||
$behatrunprocess = $run + 1; // We start process from 1.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if default behat datroot increment was done.
|
||||
if (empty($behatrunprocess)) {
|
||||
$behatdataroot = str_replace("\\", "/", $CFG->behat_dataroot);
|
||||
$behatrunprocess = preg_filter("#^{$behatdataroot}" . "(.+?)[/|\\\]behat[/|\\\]behat\.yml#", '$1',
|
||||
$behatconfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user