This commit is contained in:
David Monllao 2016-08-24 09:26:29 +08:00
commit 30daa61475
15 changed files with 1851 additions and 357 deletions

View file

@ -47,11 +47,13 @@ list($options, $unrecognized) = cli_get_params(
'help' => false,
'fromrun' => 1,
'torun' => 0,
'themesuitewithallfeatures' => false,
),
array(
'j' => 'parallel',
'm' => 'maxruns',
'h' => 'help',
'a' => 'themesuitewithallfeatures',
)
);
@ -68,6 +70,8 @@ Options:
--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:
@ -95,6 +99,11 @@ if ($options['parallel'] && $options['parallel'] > 1) {
}
}
$themesuitewithallfeatures = '';
if ($options['themesuitewithallfeatures']) {
$themesuitewithallfeatures = '--themesuitewithallfeatures="true"';
}
// Changing the cwd to admin/tool/behat/cli.
$cwd = getcwd();
$output = null;
@ -104,7 +113,7 @@ testing_update_composer_dependencies();
// 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";
@ -112,7 +121,7 @@ if ($code == 0) {
} 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);
@ -121,14 +130,14 @@ if ($code == 0) {
} 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);
@ -143,7 +152,7 @@ if ($code == 0) {
// 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);

View file

@ -51,15 +51,18 @@ list($options, $unrecognised) = cli_get_params(
'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',
)
);
@ -73,10 +76,13 @@ Usage:
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:
@ -101,9 +107,6 @@ if (empty($options['torun'])) {
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");
}
@ -144,6 +147,11 @@ if ($options['tags']) {
$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'];
@ -170,6 +178,8 @@ if (empty($parallelrun)) {
// 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;
@ -186,7 +196,7 @@ if ($tags) {
} 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;

View file

@ -56,11 +56,13 @@ list($options, $unrecognized) = cli_get_params(
'updatesteps' => false,
'fromrun' => 1,
'torun' => 0,
'themesuitewithallfeatures' => false,
),
array(
'h' => 'help',
'j' => 'parallel',
'm' => 'maxruns'
'm' => 'maxruns',
'a' => 'themesuitewithallfeatures',
)
);
@ -78,9 +80,11 @@ Options:
--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:
@ -175,12 +179,15 @@ if ($options['diag'] || $options['enable'] || $options['disable']) {
} 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);
}

View file

@ -40,16 +40,18 @@ list($options, $unrecognized) = cli_get_params(
'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',
)
);
@ -72,6 +74,8 @@ Options:
--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:
@ -130,15 +134,22 @@ require_once($CFG->libdir . '/behat/classes/behat_command.php');
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).
@ -146,7 +157,7 @@ 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");
}
@ -155,30 +166,30 @@ if ($options['install']) {
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 .
@ -188,7 +199,7 @@ if ($options['install']) {
} 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");
}

View file

@ -45,7 +45,8 @@ $steps = tool_behat::stepsdefinitions($type, $component, $filter);
$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.

View file

@ -70,6 +70,7 @@ class tool_behat_manager_testcase extends advanced_testcase {
);
$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']);
@ -95,6 +96,7 @@ class tool_behat_manager_testcase extends advanced_testcase {
);
$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']);
@ -138,6 +140,7 @@ class tool_behat_manager_testcase extends advanced_testcase {
);
$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

View file

@ -0,0 +1,394 @@
<?php
// @codingStandardsIgnoreFile
// @codeCoverageIgnoreStart
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for behat manager.
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/' . $CFG->admin .'/tool/behat/locallib.php');
require_once($CFG->libdir . '/behat/classes/util.php');
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
/**
* Behat manager tests.
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_behat_manager_util_testcase extends advanced_testcase {
/**
* @var array core features.
*/
private $corefeatures = array(
'feedback_editpdf_behat_test1' => '/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature',
'feedback_file_behat_test2' => "C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature",
'moodle_login_behat_test3' => "C:\\test\\moodle/login/tests/behat/behat_test3.feature",
);
/**
* @var array theme features.
*/
private $themefeatures = array(
'behat_themetest1_core_behat_tests_testtheme_theme' => '/test/moodle/theme/testtheme/tests/behat/core/behat_themetest1.feature',
'behat_themetest2_mod_assign_behat_tests_testtheme_theme' => "C:\\test\\moodle\\theme\\testtheme\\tests\\behat\\mod_assign\\behat_themetest2.feature",
'behat_themetest3_behat_tests_testtheme_theme_moodle' => "C:\\test\\moodle/theme/testtheme/tests/behat/behat_themetest3.feature",
);
/**
* @var array core contexts.
*/
private $corecontexts = array(
'behat_context1' => '/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_context1.php',
'behat_context2' => "C:\\test\\moodle\\blocks\\comments\\tests\\behat\\behat_context2.php",
'behat_context3' => "C:\\test\\moodle/lib/editor/atto/tests/behat/behat_context3.php",
);
/**
* @var array Theme contexts for test.
*/
private $themecontexts = array(
'behat_theme_testtheme_behat_context1' =>
'/test/moodle/theme/testtheme/tests/behat/mod_assign/behat_theme_testtheme_behat_context1.php',
'behat_theme_testtheme_behat_context2' =>
"C:\\test\\moodle\\theme\\testtheme\\tests\\behat\\block_comments\\behat_theme_testtheme_behat_context2.php",
'behat_theme_testtheme_behat_context3' =>
"C:\\test\\moodle/theme/testtheme/tests/behat/editor_atto/behat_theme_testtheme_behat_context3.php"
);
/**
* Keep instance of behat_config_util mock object.
*
* @var null
*/
private $behatconfigutil = null;
/**
* Test setup.
*/
public function setUp() {
$this->resetAfterTest(true);
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_behat_features_for_theme', 'get_behat_contexts_for_theme',
'get_list_of_themes', 'get_overridden_theme_contexts'));
$this->behatconfigutil = $mockbuilder->getMock();
// List of themes is const for test.
$this->behatconfigutil->expects($this->any())
->method('get_list_of_themes')
->will($this->returnValue(array('testtheme')));
$this->behatconfigutil->expects($this->any())
->method('get_behat_contexts_for_theme')
->with($this->equalTo('testtheme'))
->will($this->returnValue(array_keys($this->themecontexts)));
}
/**
* Behat config for single run.
*
*/
public function test_get_config_file_contents_with_single_run() {
global $CFG;
$CFG->behat_wwwroot = 'http://example.com/behat';
$behatconfigutil = $this->behatconfigutil;
// No theme feature exists.
$behatconfigutil->expects($this->once())
->method('get_behat_features_for_theme')
->with($this->anything())
->will($this->returnValue(array(array(), array())));
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$expectedconfigwithfeatures = "default:
formatters:
moodle_progress:
output_styles:
comment:
- magenta
suites:
default:
paths:
- /test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature
- 'C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature'
- 'C:\\test\\moodle/login/tests/behat/behat_test3.feature'
contexts:
- behat_context1
- behat_context2
- behat_context3
testtheme:
paths: { }
contexts:
- behat_theme_testtheme_behat_context1
- behat_theme_testtheme_behat_context2
- behat_theme_testtheme_behat_context3
extensions:
Behat\\MinkExtension:
base_url: 'http://example.com/behat'
goutte: null
selenium2:
wd_host: 'http://localhost:4444/wd/hub'
";
$this->assertContains($expectedconfigwithfeatures, $config);
$expectedstepdefinitions = "steps_definitions:
behat_context1: /test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_context1.php
behat_context2: 'C:\\test\\moodle\\blocks\\comments\\tests\\behat\\behat_context2.php'
behat_context3: 'C:\\test\\moodle/lib/editor/atto/tests/behat/behat_context3.php'
";
$this->assertContains($expectedstepdefinitions, $config);
}
/**
* Behat config for parallel run.
*/
public function test_get_config_file_contents_with_parallel_run() {
global $CFG;
$CFG->behat_wwwroot = 'http://example.com/behat';
$behatconfigutil = $this->behatconfigutil;
// No theme feature exists.
$behatconfigutil->expects($this->any())
->method('get_behat_features_for_theme')
->with($this->anything())
->will($this->returnValue(array(array(), array())));
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '', 3, 1);
// First run.
$this->assertContains('/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature',
$config);
$this->assertNotContains('C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature',
$config);
$this->assertNotContains('C:\\test\\moodle/login/tests/behat/behat_test3.feature',
$config);
// Second run.
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '', 3, 2);
$this->assertNotContains('/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature',
$config);
$this->assertContains('C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature',
$config);
$this->assertNotContains('C:\\test\\moodle/login/tests/behat/behat_test3.feature',
$config);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '', 3, 3);
$this->assertNotContains('/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature',
$config);
$this->assertNotContains('C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature',
$config);
$this->assertContains('C:\\test\\moodle/login/tests/behat/behat_test3.feature',
$config);
}
/**
* Behat config with theme features.
*/
public function test_get_config_file_contents_with_theme_features() {
global $CFG;
$behatconfigutil = $this->behatconfigutil;
$suitefeatures = array_merge($this->corefeatures, $this->themefeatures);
$themefeatures = $this->themefeatures;
$behatconfigutil->expects($this->once())
->method('get_behat_features_for_theme')
->with($this->equalTo('testtheme'))
->will($this->returnValue(array(array(), $themefeatures)));
$behatconfigutil->expects($this->once())
->method('get_behat_contexts_for_theme')
->with($this->equalTo('testtheme'))
->will($this->returnValue(array_keys($this->themecontexts)));
$behatconfigutil->expects($this->once())
->method('get_overridden_theme_contexts')
->will($this->returnValue($this->themecontexts));
$behatconfigutil->set_theme_suite_to_include_core_features(true);
$CFG->behat_wwwroot = 'http://example.com/behat';
$config = $behatconfigutil->get_config_file_contents($suitefeatures, $this->corecontexts);
$expectedconfigwithfeatures = "default:
formatters:
moodle_progress:
output_styles:
comment:
- magenta
suites:
default:
paths:
- /test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature
- 'C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature'
- 'C:\\test\\moodle/login/tests/behat/behat_test3.feature'
contexts:
- behat_context1
- behat_context2
- behat_context3
testtheme:
paths:
- /test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature
- 'C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature'
- 'C:\\test\\moodle/login/tests/behat/behat_test3.feature'
- /test/moodle/theme/testtheme/tests/behat/core/behat_themetest1.feature
- 'C:\\test\\moodle\\theme\\testtheme\\tests\\behat\\mod_assign\\behat_themetest2.feature'
- 'C:\\test\\moodle/theme/testtheme/tests/behat/behat_themetest3.feature'
contexts:
- behat_theme_testtheme_behat_context1
- behat_theme_testtheme_behat_context2
- behat_theme_testtheme_behat_context3
extensions:
Behat\\MinkExtension:
base_url: 'http://example.com/behat'
goutte: null
selenium2:
wd_host: 'http://localhost:4444/wd/hub'
";
$this->assertContains($expectedconfigwithfeatures, $config);
$expectedstepdefinitions = "steps_definitions:
behat_context1: /test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_context1.php
behat_context2: 'C:\\test\\moodle\\blocks\\comments\\tests\\behat\\behat_context2.php'
behat_context3: 'C:\\test\\moodle/lib/editor/atto/tests/behat/behat_context3.php'
behat_theme_testtheme_behat_context1: /test/moodle/theme/testtheme/tests/behat/mod_assign/behat_theme_testtheme_behat_context1.php
behat_theme_testtheme_behat_context2: 'C:\\test\\moodle\\theme\\testtheme\\tests\\behat\\block_comments\\behat_theme_testtheme_behat_context2.php'
behat_theme_testtheme_behat_context3: 'C:\\test\\moodle/theme/testtheme/tests/behat/editor_atto/behat_theme_testtheme_behat_context3.php'";
$this->assertContains($expectedstepdefinitions, $config);
}
/**
* Behat config for parallel run.
*/
public function test_get_config_file_contents_with_theme_and_parallel_run() {
global $CFG;
$CFG->behat_wwwroot = 'http://example.com/behat';
$behatconfigutil = $this->behatconfigutil;
$features = array_merge($this->corefeatures, $this->themefeatures);
$themefeatures = $this->themefeatures;
$behatconfigutil->expects($this->atLeastOnce())
->method('get_behat_features_for_theme')
->with($this->equalTo('testtheme'))
->will($this->returnValue(array(array(), $themefeatures)));
$behatconfigutil->expects($this->atLeastOnce())
->method('get_behat_contexts_for_theme')
->with($this->equalTo('testtheme'))
->will($this->returnValue(array_keys($this->themecontexts)));
$CFG->behat_wwwroot = 'http://example.com/behat';
$behatconfigutil->set_theme_suite_to_include_core_features(false);
$config = $behatconfigutil->get_config_file_contents($features, $this->themecontexts, '', 3, 1);
// First run.
$this->assertContains('/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature',
$config);
$this->assertNotContains('C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature',
$config);
$this->assertNotContains('C:\\test\\moodle/login/tests/behat/behat_test3.feature',
$config);
// Theme suite features.
$this->assertContains('/test/moodle/theme/testtheme/tests/behat/core/behat_themetest1.feature',
$config);
$this->assertNotContains('C:\\test\\moodle\\theme\\testtheme\\tests\\behat\\mod_assign\\behat_themetest2.feature',
$config);
$this->assertNotContains('C:\\test\\moodle/theme/testtheme/tests/behat/behat_themetest3.feature',
$config);
// Second run.
$config = $behatconfigutil->get_config_file_contents($features, $this->themecontexts, '', 3, 2);
$this->assertNotContains('/test/moodle/mod/assign/feedback/editpdf/tests/behat/behat_test1.feature',
$config);
$this->assertContains('C:\\test\\moodle\\mod\\assign\\feedback\\file\\tests\\behat\\behat_test2.feature',
$config);
$this->assertNotContains('C:\\test\\moodle/login/tests/behat/behat_test3.feature',
$config);
// Theme suite features.
$this->assertNotContains('/test/moodle/theme/testtheme/tests/behat/core/behat_themetest1.feature',
$config);
$this->assertContains('C:\\test\\moodle\\theme\\testtheme\\tests\\behat\\mod_assign\\behat_themetest2.feature',
$config);
$this->assertNotContains('C:\\test\\moodle/theme/testtheme/tests/behat/behat_themetest3.feature',
$config);
}
/**
* Test if clean features key and path is returned.
* @dataProvider clean_features_path_list
*/
public function test_get_clean_feature_key_and_path($featurepath, $key, $cleanfeaturepath) {
global $CFG;
// This is a hack so directory name is correctly detected in tests.
$CFG->dirroot = 'C:';
$behatconfigutil = $this->behatconfigutil;
// Fix expected directory path for OS.
$cleanfeaturepath = str_replace('\\', DIRECTORY_SEPARATOR, $cleanfeaturepath);
$cleanfeaturepath = str_replace('/', DIRECTORY_SEPARATOR, $cleanfeaturepath);
if (testing_is_cygwin()) {
$featurepath = str_replace('\\', '/', $cleanfeaturepath);
}
list($retkey, $retcleanfeaturepath) = $behatconfigutil->get_clean_feature_key_and_path($featurepath);
$this->assertEquals($key, $retkey);
$this->assertEquals($cleanfeaturepath, $retcleanfeaturepath);
}
public function clean_features_path_list() {
return array(
['/home/test/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_test', '/home/test/this/that/test/behat/mod_assign.feature'],
['/home/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_home', '/home/this/that/test/behat/mod_assign.feature'],
['/home/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_home', '/home/that/test/behat/mod_assign.feature'],
['/home/test/behat/mod_assign.feature', 'mod_assign_behat_test_home', '/home/test/behat/mod_assign.feature'],
['mod_assign.feature', 'mod_assign', 'mod_assign.feature'],
['C:\test\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this_test', 'C:\test\this\that\test\behat\mod_assign.feature'],
['C:\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this', 'C:\this\that\test\behat\mod_assign.feature'],
['C:\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that', 'C:\that\test\behat\mod_assign.feature'],
['C:\test\behat\mod_assign.feature', 'mod_assign_behat_test', 'C:\test\behat\mod_assign.feature'],
['C:\mod_assign.feature', 'mod_assign', 'C:\mod_assign.feature'],
);
}
}
// @codeCoverageIgnoreEnd