MDL-37046 behat: Added to standard plugins list

This commit is contained in:
David Monllao
2013-01-29 08:40:38 +08:00
parent 0922ef8789
commit ff2ec29bb1
7 changed files with 116 additions and 104 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ $help = "
Behat tool
Options:
--enable Enables test environment
--enable Enables test environment and updates tests list
--disable Disables test environment
-h, --help Print out this help
+5 -6
View File
@@ -22,14 +22,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['allavailablesteps'] = 'All the available steps';
$string['allavailablesteps'] = 'All the available steps definitions';
$string['giveninfo'] = 'Given. Processes to set up the environment';
$string['installinfo'] = 'for installation and tests execution info';
$string['moreinfoin'] = 'More info in';
$string['newstepsinfo'] = 'for info about adding new steps definitions';
$string['newtestsinfo'] = 'for info about writting new tests';
$string['noaction'] = 'No action selected';
$string['nostepsdefinitions'] = 'There aren\'t steps definitions matching this filter';
$string['newstepsinfo'] = 'for info about how to add new steps definitions';
$string['newtestsinfo'] = 'for info about how to write new tests';
$string['nostepsdefinitions'] = 'There aren\'t steps definitions matching this filters';
$string['pluginname'] = 'Acceptance testing';
$string['phpunitenvproblem'] = 'PHPUnit environment problem';
$string['stepsdefinitionscomponent'] = 'Area';
@@ -41,5 +40,5 @@ $string['testenvironmentdisable'] = 'Test environment disabled';
$string['theninfo'] = 'Then. Checkings to ensure the outcomes are the expected ones';
$string['viewsteps'] = 'Filter';
$string['wheninfo'] = 'When. Actions that provokes an event';
$string['wrongphpversion'] = 'PHP 5.4.0 or higher is required to run acceptance tests';
$string['wrongphpversion'] = 'PHP 5.4 or higher is required to run acceptance tests. See config-dist.php for alternatives.';
$string['wrongbehatsetup'] = 'Something is wrong with the setup, ensure you ran the composer installer and vendor/bin/behat file has execution permissions';
+5 -7
View File
@@ -73,7 +73,7 @@ class tool_behat {
$currentcwd = getcwd();
chdir($CFG->dirroot);
exec(self::get_behat_command() . ' --config="' . self::get_steps_list_config_filepath() . '" ' . $filteroption, $steps, $code);
exec(self::get_behat_command() . ' --config="'.self::get_steps_list_config_filepath(). '" '.$filteroption, $steps, $code);
chdir($currentcwd);
if ($steps) {
@@ -123,7 +123,7 @@ class tool_behat {
$prefix = '';
$configfilepath = $CFG->dirroot . '/behat.yml';
// Alternative for steps definitions filtering
// Alternative for steps definitions filtering.
} else {
$configfilepath = self::get_steps_list_config_filepath();
$prefix = $CFG->dirroot .'/';
@@ -238,11 +238,9 @@ class tool_behat {
unset($config);
}
// Add the param if it doesn't exists.
// Add the param if it doesn't exists or merge branches.
if (empty($config[$key])) {
$config[$key] = $value;
// Merge branches if the key exists in both branches.
} else {
$config[$key] = self::merge_config($config[$key], $localconfig[$key]);
}
@@ -350,12 +348,12 @@ class tool_behat {
}
// Moodle setting.
if (!tool_behat::are_behat_dependencies_installed()) {
if (!self::are_behat_dependencies_installed()) {
$msg = get_string('wrongbehatsetup', 'tool_behat');
// With HTML.
$docslink = tool_behat::$docsurl . '#Installation';
$docslink = self::$docsurl . '#Installation';
if (!CLI_SCRIPT) {
$docslink = html_writer::tag('a', $docslink, array('href' => $docslink, 'target' => '_blank'));
}
+7 -2
View File
@@ -38,7 +38,7 @@ class steps_definitions_form extends moodleform {
/**
* Form definition
*/
function definition() {
public function definition() {
$mform = $this->_form;
@@ -52,7 +52,12 @@ class steps_definitions_form extends moodleform {
);
$mform->addElement('select', 'type', get_string('stepsdefinitionstype', 'tool_behat'), $types);
$mform->addElement('select', 'component', get_string('stepsdefinitionscomponent', 'tool_behat'), $this->_customdata['components']);
$mform->addElement(
'select',
'component',
get_string('stepsdefinitionscomponent', 'tool_behat'),
$this->_customdata['components']
);
$mform->addElement('text', 'filter', get_string('stepsdefinitionscontains', 'tool_behat'));
+93 -83
View File
@@ -33,6 +33,7 @@ require_once($CFG->dirroot.'/' . $CFG->admin .'/tool/behat/locallib.php');
class testable_tool_behat extends tool_behat {
/**
* Allow access to protected method
* @see parent::merge_config()
* @param mixed $config
* @param mixed $localconfig
@@ -43,6 +44,7 @@ class testable_tool_behat extends tool_behat {
}
/**
* Allow access to protected method
* @see parent::get_config_file_contents()
* @param string $prefix
* @param array $features
@@ -59,12 +61,14 @@ class testable_tool_behat extends tool_behat {
*/
class tool_behat_testcase extends advanced_testcase {
/**
* test_switch_environment
*/
public function test_switch_environment() {
public function test_switch_environment() {
// Only run the tests if behat dependencies are installed.
// We don't need to pre-check PHPUnit initialisation because we are running on it.
if (version_compare(PHP_VERSION, '5.4.0', '>=') && tool_behat::are_behat_dependencies_installed()) {
// Only run the tests if behat dependencies are installed.
// We don't need to pre-check PHPUnit initialisation because we are running on it.
if (version_compare(PHP_VERSION, '5.4.0', '>=') && tool_behat::are_behat_dependencies_installed()) {
tool_behat::switchenvironment('enable');
$this->assertTrue(tool_behat::is_test_mode_enabled());
$this->assertFalse(tool_behat::is_test_environment_running());
@@ -84,101 +88,107 @@ class tool_behat_testcase extends advanced_testcase {
// Ensure all continues disabled.
$this->assertFalse(tool_behat::is_test_mode_enabled());
$this->assertFalse(tool_behat::is_test_environment_running());
}
}
}
}
public function test_merge_configs() {
/**
* test_merge_configs
*/
public function test_merge_configs() {
// Simple default config.
$array1 = array(
'the' => 'same',
'simple' => 'value',
'array' => array(
'one' => 'arrayvalue1',
'two' => 'arrayvalue2'
)
);
// Simple default config.
$array1 = array(
'the' => 'same',
'simple' => 'value',
'array' => array(
'one' => 'arrayvalue1',
'two' => 'arrayvalue2'
)
);
// Simple override.
$array2 = array(
'simple' => 'OVERRIDDEN1',
'array' => array(
'one' => 'OVERRIDDEN2'
),
'newprofile' => array(
'anotherlevel' => array(
'andanotherone' => array(
'list1',
'list2'
)
)
)
);
// Simple override.
$array2 = array(
'simple' => 'OVERRIDDEN1',
'array' => array(
'one' => 'OVERRIDDEN2'
),
'newprofile' => array(
'anotherlevel' => array(
'andanotherone' => array(
'list1',
'list2'
)
)
)
);
$array = testable_tool_behat::merge_config($array1, $array2);
$array = testable_tool_behat::merge_config($array1, $array2);
// Overriddes are applied.
$this->assertEquals('OVERRIDDEN1', $array['simple']);
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);
// Overriddes are applied.
$this->assertEquals('OVERRIDDEN1', $array['simple']);
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);
// Other values are respected.
$this->assertNotEmpty($array['array']['two']);
// Other values are respected.
$this->assertNotEmpty($array['array']['two']);
// Completely new nodes are added.
$this->assertNotEmpty($array['newprofile']);
$this->assertNotEmpty($array['newprofile']['anotherlevel']['andanotherone']);
$this->assertEquals('list1', $array['newprofile']['anotherlevel']['andanotherone'][0]);
$this->assertEquals('list2', $array['newprofile']['anotherlevel']['andanotherone'][1]);
// Completely new nodes are added.
$this->assertNotEmpty($array['newprofile']);
$this->assertNotEmpty($array['newprofile']['anotherlevel']['andanotherone']);
$this->assertEquals('list1', $array['newprofile']['anotherlevel']['andanotherone'][0]);
$this->assertEquals('list2', $array['newprofile']['anotherlevel']['andanotherone'][1]);
// Complex override changing vectors to scalars and scalars to vectors.
$array2 = array(
'simple' => array(
'simple' => 'should',
'be' => 'overridden',
'by' => 'this-array'
),
'array' => 'one'
);
// Complex override changing vectors to scalars and scalars to vectors.
$array2 = array(
'simple' => array(
'simple' => 'should',
'be' => 'overridden',
'by' => 'this-array'
),
'array' => 'one'
);
$array = testable_tool_behat::merge_config($array1, $array2);
$array = testable_tool_behat::merge_config($array1, $array2);
// Overrides applied.
$this->assertNotEmpty($array['simple']);
$this->assertNotEmpty($array['array']);
$this->assertTrue(is_array($array['simple']));
$this->assertFalse(is_array($array['array']));
// Overrides applied.
$this->assertNotEmpty($array['simple']);
$this->assertNotEmpty($array['array']);
$this->assertTrue(is_array($array['simple']));
$this->assertFalse(is_array($array['array']));
// Other values are maintained.
$this->assertEquals('same', $array['the']);
}
// Other values are maintained.
$this->assertEquals('same', $array['the']);
}
public function test_config_file_contents() {
global $CFG;
/**
* test_config_file_contents
*/
public function test_config_file_contents() {
global $CFG;
unset($CFG->behat_config);
unset($CFG->behat_config);
// List.
$features = array(
'feature1',
'feature2',
'feature3'
);
// List.
$features = array(
'feature1',
'feature2',
'feature3'
);
// Associative array.
$stepsdefinitions = array(
'micarro' => '/me/lo/robaron',
'anoche' => '/cuando/yo/dormia'
);
// Associative array.
$stepsdefinitions = array(
'micarro' => '/me/lo/robaron',
'anoche' => '/cuando/yo/dormia'
);
$contents = testable_tool_behat::get_config_file_contents('/i/am/a/prefix/', $features, $stepsdefinitions);
$contents = testable_tool_behat::get_config_file_contents('/i/am/a/prefix/', $features, $stepsdefinitions);
$this->assertContains('features: /i/am/a/prefix/lib/behat/features', $contents);
$this->assertContains('micarro: /me/lo/robaron', $contents);
$this->assertContains('base_url: \'' . $CFG->behat_wwwroot . '\'', $contents);
$this->assertContains('class: behat_init_context', $contents);
$this->assertContains('- feature1', $contents);
$this->assertContains('- feature3', $contents);
$this->assertContains('features: /i/am/a/prefix/lib/behat/features', $contents);
$this->assertContains('micarro: /me/lo/robaron', $contents);
$this->assertContains('base_url: \'' . $CFG->behat_wwwroot . '\'', $contents);
$this->assertContains('class: behat_init_context', $contents);
$this->assertContains('- feature1', $contents);
$this->assertContains('- feature3', $contents);
}
}
}
+1 -1
View File
@@ -25,5 +25,5 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012120700;
$plugin->requires = 2012120300; // Requires Moodle 2.5
$plugin->requires = 2012120300; // Requires Moodle 2.5.
$plugin->component = 'tool_behat';
+4 -4
View File
@@ -560,10 +560,10 @@ class plugin_manager {
),
'tool' => array(
'assignmentupgrade', 'capability', 'customlang', 'dbtransfer', 'generator',
'health', 'innodb', 'langimport', 'multilangupgrade', 'phpunit', 'profiling',
'qeupgradehelper', 'replace', 'spamcleaner', 'timezoneimport', 'unittest',
'uploaduser', 'unsuproles', 'xmldb'
'assignmentupgrade', 'behat', 'capability', 'customlang', 'dbtransfer',
'generator', 'health', 'innodb', 'langimport', 'multilangupgrade', 'phpunit',
'profiling', 'qeupgradehelper', 'replace', 'spamcleaner', 'timezoneimport',
'unittest', 'uploaduser', 'unsuproles', 'xmldb'
),
'webservice' => array(