MDL-38788 behat: Add a block and add an activity steps definitions compatible with...
authorDavid Monllao <davidm@moodle.com>
Thu, 28 Mar 2013 10:05:05 +0000 (18:05 +0800)
committerDavid Monllao <davidm@moodle.com>
Mon, 1 Apr 2013 03:18:33 +0000 (11:18 +0800)
blocks/tests/behat/behat_blocks.php
course/tests/behat/behat_course.php

index c90f1df..1c8f70d 100644 (file)
@@ -46,7 +46,16 @@ class behat_blocks extends behat_base {
      * @param string $blockname
      */
     public function i_add_the_block($blockname) {
-        return new Given('I select "' . $blockname . '" from "bui_addblock"');
+        $steps = new Given('I select "' . $blockname . '" from "bui_addblock"');
+
+        // If we are running without javascript we need to submit the form.
+        if (!$this->running_javascript()) {
+            $steps = array(
+                $steps,
+                new Given('I click on "Go" "button" in the "#add_block" "css_element"')
+            );
+        }
+        return $steps;
     }
 
 }
index 0f1e0ca..51dae37 100644 (file)
@@ -83,15 +83,35 @@ class behat_course extends behat_base {
      */
     public function i_add_to_section($activity, $section) {
 
-        // Clicks add activity or resource section link.
-        $sectionxpath = "//*[@id='section-" . $section . "']/*/*/*/div[@class='section-modchooser']/span/a";
-        $sectionnode = $this->find('xpath', $sectionxpath);
-        $sectionnode->click();
-
-        // Clicks the selected activity if it exists.
-        $activityxpath = ".//label[contains(.,'" . $activity . "')]/input";
-        $activitynode = $this->find('xpath', $activityxpath);
-        $activitynode->doubleClick();
+        $sectionxpath = "//*[@id='section-" . $section . "']";
+
+        if ($this->running_javascript()) {
+
+            // Clicks add activity or resource section link.
+            $sectionxpath = $sectionxpath . "/descendant::div[@class='section-modchooser']/span/a";
+            $sectionnode = $this->find('xpath', $sectionxpath);
+            $sectionnode->click();
+
+            // Clicks the selected activity if it exists.
+            $activityxpath = ".//label[contains(.,'" . $activity . "')]/input";
+            $activitynode = $this->find('xpath', $activityxpath);
+            $activitynode->doubleClick();
+
+        } else {
+            // Without Javascript.
+
+            // Selecting the option from the select box which contains the option.
+            $selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', @class, ' '), ' section_add_menus ')]
+/descendant::select[contains(., '" . $activity . "')]";
+            $selectnode = $this->find('xpath', $selectxpath);
+            $selectnode->selectOption($activity);
+
+            // Go button.
+            $gobuttonxpath = $selectxpath . "/ancestor::form/descendant::input[@type='submit']";
+            $gobutton = $this->find('xpath', $gobuttonxpath);
+            $gobutton->click();
+        }
+
     }
 
 }