MDL-51100 behat: Correct javascript requirement of user menu step
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 13 Aug 2015 00:35:17 +0000 (08:35 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 13 Aug 2015 00:35:17 +0000 (08:35 +0800)
lib/tests/behat/behat_navigation.php

index 9ae6964..3b57e54 100644 (file)
@@ -141,27 +141,24 @@ class behat_navigation extends behat_base {
      * Click on an entry in the user menu.
      * @Given /^I follow "(?P<nodetext_string>(?:[^"]|\\")*)" in the user menu$/
      *
-     * @throws ExpectationException
      * @param string $nodetext
      * @return bool|void
      */
     public function i_follow_in_the_user_menu($nodetext) {
+        $steps = array();
 
-        // The user menu is broken without javascript.
-        if (!$this->running_javascript()) {
-            throw new DriverException('I follow in the user menu step is not available with Javascript disabled');
+        if ($this->running_javascript()) {
+            // The user menu must be expanded when JS is enabled.
+            $xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]";
+            $steps[] = new When('I click on "'.$xpath.'" "xpath_element"');
         }
 
-        $steps = array();
-
-        $xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]";
+        // Now select the link.
+        // The CSS path is always present, with or without JS.
         $csspath = ".usermenu [data-rel='menu-content']";
-
-        $steps[] = new When('I click on "'.$xpath.'" "xpath_element"');
         $steps[] = new When('I click on "'.$nodetext.'" "link" in the "'.$csspath.'" "css_element"');
 
         return $steps;
-
     }
 
     /**