Make behat command compatible with Moodle 2.7-dev
authorFrederic Massart <fmcell@gmail.com>
Tue, 7 Jan 2014 14:19:38 +0000 (15:19 +0100)
committerFrederic Massart <fmcell@gmail.com>
Tue, 7 Jan 2014 14:19:38 +0000 (15:19 +0100)
config-dist.json
lib/commands/behat.py
lib/moodle.py

index 417aa94..1eee99f 100644 (file)
     // What to call the upstream remote, the one pointing to the official repositoriy (stable or integration)
     "upstreamRemote": "origin",
 
+    // Behat related settings
+    "behat": {
+
+        // From 2.7 Behat requires a different wwwroot than the one set in config.php.
+        // MDK assumes that the only thing that will differ between the wwwroot and
+        // behat wwwroot is the host, nothing else. Use a ServerAlias or /etc/hosts entries.
+        "host": "127.0.0.1"
+    },
+
     // The name of the data directory
     "dataDir": "moodledata",
     // The name of the www directory
index 877c179..21a0227 100644 (file)
@@ -46,7 +46,7 @@ class BehatCommand(Command):
             ['-d', '--disable'],
             {
                 'action': 'store_true',
-                'help': 'disable Behat, runs the tests first if --run has been set.'
+                'help': 'disable Behat, runs the tests first if --run has been set. Ignored from 2.7.'
             }
         ),
         (
@@ -84,7 +84,7 @@ class BehatCommand(Command):
             {
                 'action': 'store_true',
                 'dest': 'switchcompletely',
-                'help': 'force the switch completely setting. This will be automatically enabled for PHP < 5.4'
+                'help': 'force the switch completely setting. This will be automatically enabled for PHP < 5.4. Ignored from 2.7.'
             }
         ),
         (
@@ -266,7 +266,8 @@ class BehatCommand(Command):
                     self.disable(M)
 
             else:
-                logging.info('Launch PHP Server (or set $CFG->behat_switchcompletely to True):\n %s' % (phpCommand))
+                if M.branch_compare(27, '<'):
+                    logging.info('Launch PHP Server (or set $CFG->behat_switchcompletely to True):\n %s' % (phpCommand))
                 if seleniumCommand:
                     logging.info('Launch Selenium (optional):\n %s' % (seleniumCommand))
                 logging.info('Launch Behat:\n %s' % (cmd))
index 30a6bf0..db005d1 100644 (file)
@@ -333,12 +333,20 @@ class Moodle(object):
         self.updateConfig('behat_prefix', behat_prefix)
 
         # Switch completely?
-        if switchcompletely:
-            self.updateConfig('behat_switchcompletely', switchcompletely)
-            self.updateConfig('behat_wwwroot', self.get('wwwroot'))
+        if self.branch_compare(27, '<'):
+            if switchcompletely:
+                self.updateConfig('behat_switchcompletely', switchcompletely)
+                self.updateConfig('behat_wwwroot', self.get('wwwroot'))
+            else:
+                self.removeConfig('behat_switchcompletely')
+                self.removeConfig('behat_wwwroot')
         else:
-            self.removeConfig('behat_switchcompletely')
-            self.removeConfig('behat_wwwroot')
+            # Defining wwwroot.
+            wwwroot = '%s://%s/' % (C.get('scheme'), C.get('behat.host'))
+            if C.get('path') != '' and C.get('path') != None:
+                wwwroot = wwwroot + C.get('path') + '/'
+            wwwroot = wwwroot + self.identifier
+            self.updateConfig('behat_wwwroot', wwwroot)
 
         # Force a cache purge
         self.purge()