MDL-38788 behat: Add a block and add an activity steps definitions compatible with JS disabled

This commit is contained in:
David Monllao
2013-04-01 11:18:33 +08:00
parent cd7ea8f0cc
commit 1c00d6f636
2 changed files with 38 additions and 9 deletions
+10 -1
View 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;
}
}
+28 -8
View 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();
$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();
}
// Clicks the selected activity if it exists.
$activityxpath = ".//label[contains(.,'" . $activity . "')]/input";
$activitynode = $this->find('xpath', $activityxpath);
$activitynode->doubleClick();
}
}