MDL-37046 behat: CLI option to add/remove javascript tests
authorDavid Monllao <davidm@moodle.com>
Sat, 17 Nov 2012 03:34:23 +0000 (11:34 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 29 Jan 2013 00:40:36 +0000 (08:40 +0800)
admin/tool/behat/cli/util.php
admin/tool/behat/locallib.php

index fe6dfc8..93c5914 100644 (file)
@@ -37,6 +37,7 @@ list($options, $unrecognized) = cli_get_params(
         'filter'             => false,
         'tags'               => false,
         'extra'              => false,
+        'with-javascript'    => false,
         'testenvironment'    => false
     ),
     array(
@@ -51,13 +52,15 @@ Ensure the user who executes the action has permissions over behat installation
 
 Options:
 --stepsdefinitions   Displays the available steps definitions (accepts --filter=\"\" option to restrict the list to the matching definitions)
---runtests           Runs the tests (accepts --tags=\"\" option to execute only the matching tests and --extra=\"\" to specify extra behat options)
+--runtests           Runs the tests (accepts --with-javascript option, --tags=\"\" option to execute only the matching tests and --extra=\"\" to specify extra behat options)
 --testenvironment    Allows the test environment to be accesses through the built-in server (accepts value 'enable' or 'disable')
 
 -h, --help     Print out this help
 
 Example from Moodle root directory:
 \$ php admin/tool/behat/cli/util.php --runtests --tags=\"tool_behat\"
+
+More info in http://docs.moodle.org/dev/Acceptance_testing#Usage
 ";
 
 if (!empty($options['help'])) {
@@ -90,7 +93,7 @@ switch ($action) {
         break;
 
     case 'runtests':
-        tool_behat::runtests($options['tags'], $options['extra']);
+        tool_behat::runtests($options['with-javascript'], $options['tags'], $options['extra']);
         break;
 
     case 'testenvironment':
index 1037dc7..2b5cc76 100644 (file)
@@ -146,7 +146,7 @@ class tool_behat {
      * @param string $tags Restricts the executed tests to the ones that matches the tags
      * @param string $extra Extra CLI behat options
      */
-    public static function runtests($tags = false, $extra = false) {
+    public static function runtests($withjavascript = false, $tags = false, $extra = false) {
         global $CFG;
 
         // Checks that the behat reference is properly set up
@@ -159,14 +159,22 @@ class tool_behat {
 
         @set_time_limit(0);
 
-        // Priority to the one specified as argument.
-        if (!$tags) {
-            $tags = optional_param('tags', false, PARAM_ALPHANUMEXT);
+        // No javascript by default
+        if (!$withjavascript && strstr($tags, 'javascript') == false) {
+            $jsstr = '~javascript';
         }
 
+        // Adding javascript option to --tags.
         $tagsoption = '';
         if ($tags) {
+            if (!empty($jsstr)) {
+                $tags .= ',' . $jsstr;
+            }
             $tagsoption = ' --tags ' . $tags;
+
+        // No javascript by default.
+        } else if (!empty($jsstr)) {
+            $tagsoption = ' --tags ' . $jsstr;
         }
 
         if (!$extra) {