Skip to content

Commit

Permalink
MDL-37046 behat: Added to standard plugins list
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Jan 29, 2013
1 parent 0922ef8 commit ff2ec29
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 122 deletions.
2 changes: 1 addition & 1 deletion admin/tool/behat/cli/util.php
Expand Up @@ -44,7 +44,7 @@
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
Expand Down
11 changes: 5 additions & 6 deletions admin/tool/behat/lang/en/tool_behat.php
Expand Up @@ -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';
Expand All @@ -41,5 +40,5 @@
$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';
12 changes: 5 additions & 7 deletions admin/tool/behat/locallib.php
Expand Up @@ -73,7 +73,7 @@ public static function stepsdefinitions($type, $component, $filter) {

$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) {
Expand Down Expand Up @@ -123,7 +123,7 @@ protected static function update_config_file($component = '', $testsrunner = tru
$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 .'/';
Expand Down Expand Up @@ -238,11 +238,9 @@ protected static function merge_config($config, $localconfig) {
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]);
}
Expand Down Expand Up @@ -350,12 +348,12 @@ protected static function check_behat_setup($checkphp = false) {
}

// 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'));
}
Expand Down
9 changes: 7 additions & 2 deletions admin/tool/behat/steps_definitions_form.php
Expand Up @@ -38,7 +38,7 @@ class steps_definitions_form extends moodleform {
/**
* Form definition
*/
function definition() {
public function definition() {

$mform = $this->_form;

Expand All @@ -52,7 +52,12 @@ function definition() {
);
$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'));

Expand Down
212 changes: 111 additions & 101 deletions admin/tool/behat/tests/tool_behat_test.php
Expand Up @@ -33,6 +33,7 @@
class testable_tool_behat extends tool_behat {

/**
* Allow access to protected method
* @see parent::merge_config()
* @param mixed $config
* @param mixed $localconfig
Expand All @@ -43,6 +44,7 @@ public static function merge_config($config, $localconfig) {
}

/**
* Allow access to protected method
* @see parent::get_config_file_contents()
* @param string $prefix
* @param array $features
Expand All @@ -59,12 +61,14 @@ public static function get_config_file_contents($prefix, $features, $stepsdefini
*/
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());
Expand All @@ -84,101 +88,107 @@ public function test_switch_environment() {
// 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() {

// 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'
)
)
)
);

$array = testable_tool_behat::merge_config($array1, $array2);

// Overriddes are applied.
$this->assertEquals('OVERRIDDEN1', $array['simple']);
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);

// 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]);

// 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);

// 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']);
}

public function test_config_file_contents() {
global $CFG;

unset($CFG->behat_config);

// List.
$features = array(
'feature1',
'feature2',
'feature3'
);

// 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);

$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);

}
}
}

/**
* test_merge_configs
*/
public function test_merge_configs() {

// 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'
)
)
)
);

$array = testable_tool_behat::merge_config($array1, $array2);

// Overriddes are applied.
$this->assertEquals('OVERRIDDEN1', $array['simple']);
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);

// 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]);

// 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);

// 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']);
}

/**
* test_config_file_contents
*/
public function test_config_file_contents() {
global $CFG;

unset($CFG->behat_config);

// List.
$features = array(
'feature1',
'feature2',
'feature3'
);

// 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);

$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);
}

}

2 changes: 1 addition & 1 deletion admin/tool/behat/version.php
Expand Up @@ -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';
8 changes: 4 additions & 4 deletions lib/pluginlib.php
Expand Up @@ -560,10 +560,10 @@ public static function standard_plugins_list($type) {
),

'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(
Expand Down

0 comments on commit ff2ec29

Please sign in to comment.