From ff2ec29bb1b8635ab59121c7dc30ab2831520f44 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 19 Dec 2012 16:32:12 +0800 Subject: [PATCH] MDL-37046 behat: Added to standard plugins list --- admin/tool/behat/cli/util.php | 2 +- admin/tool/behat/lang/en/tool_behat.php | 11 +- admin/tool/behat/locallib.php | 12 +- admin/tool/behat/steps_definitions_form.php | 9 +- admin/tool/behat/tests/tool_behat_test.php | 212 ++++++++++---------- admin/tool/behat/version.php | 2 +- lib/pluginlib.php | 8 +- 7 files changed, 134 insertions(+), 122 deletions(-) diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index bb97667b816a5..3f39442a8523b 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -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 diff --git a/admin/tool/behat/lang/en/tool_behat.php b/admin/tool/behat/lang/en/tool_behat.php index 1c723f3a39e7f..353d1b5b8d8e9 100644 --- a/admin/tool/behat/lang/en/tool_behat.php +++ b/admin/tool/behat/lang/en/tool_behat.php @@ -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['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'; diff --git a/admin/tool/behat/locallib.php b/admin/tool/behat/locallib.php index 7c93619bff9eb..96ea9e4a47668 100644 --- a/admin/tool/behat/locallib.php +++ b/admin/tool/behat/locallib.php @@ -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) { @@ -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 .'/'; @@ -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]); } @@ -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')); } diff --git a/admin/tool/behat/steps_definitions_form.php b/admin/tool/behat/steps_definitions_form.php index 8a993e72c9a48..788a3fb164b94 100644 --- a/admin/tool/behat/steps_definitions_form.php +++ b/admin/tool/behat/steps_definitions_form.php @@ -38,7 +38,7 @@ class steps_definitions_form extends moodleform { /** * Form definition */ - function definition() { + public function definition() { $mform = $this->_form; @@ -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')); diff --git a/admin/tool/behat/tests/tool_behat_test.php b/admin/tool/behat/tests/tool_behat_test.php index bdc406e61b02d..2e6324bd843a6 100644 --- a/admin/tool/behat/tests/tool_behat_test.php +++ b/admin/tool/behat/tests/tool_behat_test.php @@ -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 @@ -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 @@ -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()); @@ -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); + } + } diff --git a/admin/tool/behat/version.php b/admin/tool/behat/version.php index 7d7e0368efb1d..a5ddb157cb9e0 100644 --- a/admin/tool/behat/version.php +++ b/admin/tool/behat/version.php @@ -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'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index e1971d17dc415..57e15fb5f77f1 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -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(