From 1c00d6f636f9128c8c667d71d584925366edb2ec Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 28 Mar 2013 18:05:05 +0800 Subject: [PATCH] MDL-38788 behat: Add a block and add an activity steps definitions compatible with JS disabled --- blocks/tests/behat/behat_blocks.php | 11 ++++++++- course/tests/behat/behat_course.php | 36 ++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/blocks/tests/behat/behat_blocks.php b/blocks/tests/behat/behat_blocks.php index c90f1df87b3..1c8f70d9aa1 100644 --- a/blocks/tests/behat/behat_blocks.php +++ b/blocks/tests/behat/behat_blocks.php @@ -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; } } diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index 0f1e0ca0e0b..51dae371df0 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -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(); } }