Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'wip-mdl-55072' of https://github.com/rajeshtaneja/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Aug 24, 2016
2 parents bae868b + b4bc428 commit 30daa61
Show file tree
Hide file tree
Showing 15 changed files with 1,851 additions and 357 deletions.
19 changes: 14 additions & 5 deletions admin/tool/behat/cli/init.php
Expand Up @@ -47,11 +47,13 @@
'help' => false,
'fromrun' => 1,
'torun' => 0,
'themesuitewithallfeatures' => false,
),
array(
'j' => 'parallel',
'm' => 'maxruns',
'h' => 'help',
'a' => 'themesuitewithallfeatures',
)
);

Expand All @@ -68,6 +70,8 @@
--fromrun Execute run starting from (Used for parallel runs on different vms)
--torun Execute run till (Used for parallel runs on different vms)
-a, --themesuitewithallfeatures Theme suite do not include core features by default. If you want to run core features
with theme, then use this option.
-h, --help Print out this help
Example from Moodle root directory:
Expand Down Expand Up @@ -95,6 +99,11 @@
}
}

$themesuitewithallfeatures = '';
if ($options['themesuitewithallfeatures']) {
$themesuitewithallfeatures = '--themesuitewithallfeatures="true"';
}

// Changing the cwd to admin/tool/behat/cli.
$cwd = getcwd();
$output = null;
Expand All @@ -104,15 +113,15 @@

// Check whether the behat test environment needs to be updated.
chdir(__DIR__);
exec("php $utilfile --diag $paralleloption", $output, $code);
exec("php $utilfile --diag $paralleloption $themesuitewithallfeatures", $output, $code);

if ($code == 0) {
echo "Behat test environment already installed\n";

} else if ($code == BEHAT_EXITCODE_INSTALL) {
// Behat and dependencies are installed and we need to install the test site.
chdir(__DIR__);
passthru("php $utilfile --install $paralleloption", $code);
passthru("php $utilfile --install $paralleloption $themesuitewithallfeatures", $code);
if ($code != 0) {
chdir($cwd);
exit($code);
Expand All @@ -121,14 +130,14 @@
} else if ($code == BEHAT_EXITCODE_REINSTALL) {
// Test site data is outdated.
chdir(__DIR__);
passthru("php $utilfile --drop $paralleloption", $code);
passthru("php $utilfile --drop $paralleloption $themesuitewithallfeatures", $code);
if ($code != 0) {
chdir($cwd);
exit($code);
}

chdir(__DIR__);
passthru("php $utilfile --install $paralleloption", $code);
passthru("php $utilfile --install $paralleloption $themesuitewithallfeatures", $code);
if ($code != 0) {
chdir($cwd);
exit($code);
Expand All @@ -143,7 +152,7 @@

// Enable editing mode according to config.php vars.
chdir(__DIR__);
passthru("php $utilfile --enable $paralleloption", $code);
passthru("php $utilfile --enable $paralleloption $themesuitewithallfeatures", $code);
if ($code != 0) {
echo "Error enabling site" . PHP_EOL;
chdir($cwd);
Expand Down
18 changes: 14 additions & 4 deletions admin/tool/behat/cli/run.php
Expand Up @@ -51,15 +51,18 @@
'tags' => '',
'profile' => '',
'feature' => '',
'suite' => '',
'fromrun' => 1,
'torun' => 0,
'single-run' => false,
'themesuitewithallfeatures' => false,
),
array(
'h' => 'help',
't' => 'tags',
'p' => 'profile',
's' => 'single-run',
'a' => 'themesuitewithallfeatures',
)
);

Expand All @@ -73,10 +76,13 @@
Options:
--BEHAT_OPTION Any combination of behat option specified in http://behat.readthedocs.org/en/v2.5/guides/6.cli.html
--feature Only execute specified feature file (Absolute path of feature file).
--suite Specified theme scenarios will be executed.
--replace Replace args string with run process number, useful for output.
--fromrun Execute run starting from (Used for parallel runs on different vms)
--torun Execute run till (Used for parallel runs on different vms)
-a, --themesuitewithallfeatures Theme suite do not include core features by default. If you want to run core features
with theme, then use this option.
-h, --help Print out this help
Example from Moodle root directory:
Expand All @@ -101,9 +107,6 @@
if (extension_loaded('pcntl')) {
$disabled = explode(',', ini_get('disable_functions'));
if (!in_array('pcntl_signal', $disabled)) {
// Handle interrupts on PHP7.
declare(ticks = 1);

pcntl_signal(SIGTERM, "signal_handler");
pcntl_signal(SIGINT, "signal_handler");
}
Expand Down Expand Up @@ -144,6 +147,11 @@
$extraopts[] = '--tags="' . $tags . '"';
}

// Add suite option if specified.
if ($options['suite']) {
$extraopts[] = '--suite="' . $options['suite'] . '"';
}

// Feature should be added to last, for behat command.
if ($options['feature']) {
$extraopts[] = $options['feature'];
Expand All @@ -170,6 +178,8 @@

// Update config file if tags defined.
if ($tags) {
define('ABORT_AFTER_CONFIG_CANCEL', true);
require("$CFG->dirroot/lib/setup.php");
// Hack to set proper dataroot and wwwroot.
$behatdataroot = $CFG->behat_dataroot;
$behatwwwroot = $CFG->behat_wwwroot;
Expand All @@ -186,7 +196,7 @@
} else {
$CFG->behat_dataroot = $behatdataroot . $i;
}
behat_config_manager::update_config_file('', true, $tags);
behat_config_manager::update_config_file('', true, $tags, $options['themesuitewithallfeatures'], $parallelrun);
}
$CFG->behat_dataroot = $behatdataroot;
$CFG->behat_wwwroot = $behatwwwroot;
Expand Down
15 changes: 11 additions & 4 deletions admin/tool/behat/cli/util.php
Expand Up @@ -56,11 +56,13 @@
'updatesteps' => false,
'fromrun' => 1,
'torun' => 0,
'themesuitewithallfeatures' => false,
),
array(
'h' => 'help',
'j' => 'parallel',
'm' => 'maxruns'
'm' => 'maxruns',
'a' => 'themesuitewithallfeatures',
)
);

Expand All @@ -78,9 +80,11 @@
--disable Disables test environment
--diag Get behat test environment status code
--updatesteps Update feature step file.
-j, --parallel Number of parallel behat run operation
-m, --maxruns Max parallel processes to be executed at one time.
-a, --themesuitewithallfeatures Theme suite do not include core features by default. If you want to run core features
with theme, then use this option.
-h, --help Print out this help
Example from Moodle root directory:
Expand Down Expand Up @@ -175,12 +179,15 @@
} else if ($options['updatesteps']) {
// Rewrite config file to ensure we have all the features covered.
if (empty($options['parallel'])) {
behat_config_manager::update_config_file();
behat_config_manager::update_config_file('', true, '', $options['themesuitewithallfeatures'], false, false);
} else {
// Update config file, ensuring we have up-to-date behat.yml.
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
$CFG->behatrunprocess = $i;
behat_config_manager::update_config_file();

// Update config file for each run.
behat_config_manager::update_config_file('', true, '', $options['themesuitewithallfeatures'],
$options['parallel'], $i);
}
unset($CFG->behatrunprocess);
}
Expand Down
39 changes: 25 additions & 14 deletions admin/tool/behat/cli/util_single_run.php
Expand Up @@ -40,16 +40,18 @@
'help' => false,
'install' => false,
'parallel' => 0,
'run' => '',
'run' => 0,
'drop' => false,
'enable' => false,
'disable' => false,
'diag' => false,
'tags' => '',
'updatesteps' => false,
'themesuitewithallfeatures' => false,
),
array(
'h' => 'help'
'h' => 'help',
'a' => 'themesuitewithallfeatures',
)
);

Expand All @@ -72,6 +74,8 @@
--diag Get behat test environment status code
--updatesteps Update feature step file.
-a, --themesuitewithallfeatures Theme suite do not include core features by default. If you want to run core features
with theme, then use this option.
-h, --help Print out this help
Example from Moodle root directory:
Expand Down Expand Up @@ -130,23 +134,30 @@
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');

// Ensure run option is <= parallel run installed.
$run = 0;
$parallel = 0;
if ($options['run']) {
$run = $options['run'];
// If parallel option is not passed, then try get it form config.
if (!$options['parallel']) {
$options['parallel'] = behat_config_manager::get_parallel_test_runs();
$parallel = behat_config_manager::get_parallel_test_runs();
} else {
$parallel = $options['parallel'];
}
if (empty($options['parallel']) || $options['run'] > $options['parallel']) {
echo "Parallel runs can't be more then ".$options['parallel'].PHP_EOL;

if (empty($parallel) || $run > $parallel) {
echo "Parallel runs can't be more then ".$parallel.PHP_EOL;
exit(1);
}
$CFG->behatrunprocess = $options['run'];
$CFG->behatrunprocess = $run;
}

// Run command (only one per time).
if ($options['install']) {
behat_util::install_site();

// This is only displayed once for parallel install.
if (empty($options['run'])) {
if (empty($run)) {
mtrace("Acceptance tests site installed");
}

Expand All @@ -155,30 +166,30 @@
test_lock::acquire('behat');
behat_util::drop_site();
// This is only displayed once for parallel install.
if (empty($options['run'])) {
if (empty($run)) {
mtrace("Acceptance tests site dropped");
}

} else if ($options['enable']) {
if (!empty($options['parallel'])) {
if (!empty($parallel)) {
// Save parallel site info for enable and install options.
$filepath = behat_config_manager::get_parallel_test_file_path();
if (!file_put_contents($filepath, $options['parallel'])) {
if (!file_put_contents($filepath, $parallel)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'File ' . $filepath . ' can not be created');
}
}

// Enable test mode.
behat_util::start_test_mode();
behat_util::start_test_mode($options['themesuitewithallfeatures'], $parallel, $run);

// This is only displayed once for parallel install.
if (empty($options['run'])) {
if (empty($run)) {
// Notify user that 2.5 profile has been converted to 3.5.
if (behat_config_manager::$autoprofileconversion) {
mtrace("2.5 behat profile detected, automatically converted to current 3.x format");
}

$runtestscommand = behat_command::get_behat_command(true, !empty($options['run']));
$runtestscommand = behat_command::get_behat_command(true, !empty($run));

$runtestscommand .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
mtrace("Acceptance tests environment enabled on $CFG->behat_wwwroot, to run the tests use: " . PHP_EOL .
Expand All @@ -188,7 +199,7 @@
} else if ($options['disable']) {
behat_util::stop_test_mode();
// This is only displayed once for parallel install.
if (empty($options['run'])) {
if (empty($run)) {
mtrace("Acceptance tests environment disabled");
}

Expand Down
3 changes: 2 additions & 1 deletion admin/tool/behat/index.php
Expand Up @@ -45,7 +45,8 @@
$componentswithsteps = array('' => get_string('allavailablesteps', 'tool_behat'));

// Complete the components list with the moodle steps definitions.
$components = behat_config_manager::get_components_steps_definitions();
$behatconfig = new behat_config_util();
$components = $behatconfig->get_components_contexts();
if ($components) {
foreach ($components as $component => $filepath) {
// TODO Use a class static attribute instead of the class name.
Expand Down
3 changes: 3 additions & 0 deletions admin/tool/behat/tests/manager_test.php
Expand Up @@ -70,6 +70,7 @@ public function test_merge_configs() {
);

$array = testable_behat_config_manager::merge_config($array1, $array2);
$this->assertDebuggingCalled("Use of merge_config is deprecated, please see behat_config_util");

// Overrides are applied.
$this->assertEquals('OVERRIDDEN1', $array['simple']);
Expand All @@ -95,6 +96,7 @@ public function test_merge_configs() {
);

$array = testable_behat_config_manager::merge_config($array1, $array2);
$this->assertDebuggingCalled("Use of merge_config is deprecated, please see behat_config_util");

// Overrides applied.
$this->assertNotEmpty($array['simple']);
Expand Down Expand Up @@ -138,6 +140,7 @@ public function test_config_file_contents() {
);

$contents = testable_behat_config_manager::get_config_file_contents($features, $stepsdefinitions);
$this->assertDebuggingCalled("Use of get_config_file_contents is deprecated, please see behat_config_util");

// YAML decides when is is necessary to wrap strings between single quotes, so not controlled
// values like paths should not be asserted including the key name as they would depend on the
Expand Down

0 comments on commit 30daa61

Please sign in to comment.