From d02eaee727211584dbc03e3ef1625d1372ef35d5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 22 Jan 2015 12:17:17 +0800 Subject: [PATCH] Revert "Merge branch 'wip-mdl-48624-m27' of https://github.com/rajeshtaneja/moodle into MOODLE_27_STABLE" This reverts commit 85ea64f5ee7812fae1427c3c15f1472bc0114daf, reversing changes made to 1db2e142a29bc61e7ffc5bc5860b9d888fe85619. --- lib/tests/behat/behat_general.php | 31 +--------- .../behat/behat_workshopallocation_manual.php | 58 ++++++++----------- question/export.php | 5 +- .../gift/tests/behat/import_export.feature | 6 +- .../xml/tests/behat/import_export.feature | 5 ++ 5 files changed, 38 insertions(+), 67 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index d8d5264991a..c5e4b3e1dc1 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1220,20 +1220,7 @@ class behat_general extends behat_base { * @param number $expectedsize the expected file size in bytes. */ public function following_should_download_bytes($link, $expectedsize) { - $exception = new ExpectationException('Error while downloading data from ' . $link, $this->getSession()); - - // It will stop spinning once file is downloaded or time out. - $result = $this->spin( - function($context, $args) { - $link = $args['link']; - return $this->download_file_from_link($link); - }, - array('link' => $link), - self::EXTENDED_TIMEOUT, - $exception - ); - - // Check download size. + $result = $this->download_file_from_link($link); $actualsize = (int)strlen($result); if ($actualsize !== (int)$expectedsize) { throw new ExpectationException('Downloaded data was ' . $actualsize . @@ -1262,21 +1249,7 @@ class behat_general extends behat_base { list($minexpectedsize, $maxexpectedsize) = array($maxexpectedsize, $minexpectedsize); } - $exception = new ExpectationException('Error while downloading data from ' . $link, $this->getSession()); - - // It will stop spinning once file is downloaded or time out. - $result = $this->spin( - function($context, $args) { - $link = $args['link']; - - return $this->download_file_from_link($link); - }, - array('link' => $link), - self::EXTENDED_TIMEOUT, - $exception - ); - - // Check download size. + $result = $this->download_file_from_link($link); $actualsize = (int)strlen($result); if ($actualsize < $minexpectedsize || $actualsize > $maxexpectedsize) { throw new ExpectationException('Downloaded data was ' . $actualsize . diff --git a/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php b/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php index 99b861374e4..18579cbf806 100644 --- a/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php +++ b/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php @@ -51,40 +51,32 @@ class behat_workshopallocation_manual extends behat_base { * @param string $participantname */ public function i_add_a_reviewer_for_workshop_participant($reviewername, $participantname) { - // It will stop spinning once all reviewer for workshop participants are added or it time out. - $this->spin( - function($context, $args) { - $participantnameliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($args['participantname']); - $xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/". - "tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]". - "[contains(.,$participantnameliteral)]]/". - "td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]"; - $xpathselect = $xpathtd . "/descendant::select"; - try { - $selectnode = $this->find('xpath', $xpathselect); - } catch (Exception $ex) { - $this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press(); - $selectnode = $this->find('xpath', $xpathselect); - } + $participantnameliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($participantname); + $xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/". + "tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]". + "[contains(.,$participantnameliteral)]]/". + "td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]"; + $xpathselect = $xpathtd . "/descendant::select"; + try { + $selectnode = $this->find('xpath', $xpathselect); + } catch (Exception $ex) { + $this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press(); + $selectnode = $this->find('xpath', $xpathselect); + } + $selectid = $selectnode->getAttribute('id'); + $selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession()); + $selectformfield->set_value($reviewername); - $selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession()); - $selectformfield->set_value($args['reviewername']); - - if (!$this->running_javascript()) { - // Without Javascript we need to press the "Go" button. - $go = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('go')); - $this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click(); - } else { - // With Javascript we just wait for the page to reload and the success string to appear. - $allocatedtext = $this->getSession()->getSelectorsHandler()->xpathLiteral( - get_string('allocationadded', 'workshopallocation_manual')); - $this->find('xpath', "//*[contains(.,$allocatedtext)]"); - } - return true; - }, - array('participantname' => $participantname, 'reviewername' => $reviewername), - self::EXTENDED_TIMEOUT - ); + if (!$this->running_javascript()) { + // Without Javascript we need to press the "Go" button. + $go = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('go')); + $this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click(); + } else { + // With Javascript we just wait for the page to reload and the success string to appear. + $allocatedtext = $this->getSession()->getSelectorsHandler()->xpathLiteral( + get_string('allocationadded', 'workshopallocation_manual')); + $this->find('xpath', "//*[contains(.,$allocatedtext)]"); + } } /** diff --git a/question/export.php b/question/export.php index cea2d2a00b4..8f2396eb011 100644 --- a/question/export.php +++ b/question/export.php @@ -73,10 +73,7 @@ if ($from_form = $export_form->get_data()) { echo get_string('yourfileshoulddownload', 'question', $export_url->out()); echo $OUTPUT->box_end(); - // Don't allow force download for behat site, as pop-up can't be handled by selenium. - if (!defined('BEHAT_SITE_RUNNING')) { - $PAGE->requires->js_function_call('document.location.replace', array($export_url->out(false)), false, 1); - } + $PAGE->requires->js_function_call('document.location.replace', array($export_url->out(false)), false, 1); echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params())); echo $OUTPUT->footer(); diff --git a/question/format/gift/tests/behat/import_export.feature b/question/format/gift/tests/behat/import_export.feature index 075e1ec585b..11ad3bffcb9 100644 --- a/question/format/gift/tests/behat/import_export.feature +++ b/question/format/gift/tests/behat/import_export.feature @@ -34,4 +34,8 @@ Feature: Test importing questions from GIFT format. And I set the field "id_format_gift" to "1" And I press "Export questions to file" And following "click here" should download between "1550" and "1650" bytes - + # If the download step is the last in the scenario then we can sometimes run + # into the situation where the download page causes a http redirect but behat + # has already conducted its reset (generating an error). By putting a logout + # step we avoid behat doing the reset until we are off that page. + And I log out diff --git a/question/format/xml/tests/behat/import_export.feature b/question/format/xml/tests/behat/import_export.feature index 18dcc9bd740..941c722d0a1 100644 --- a/question/format/xml/tests/behat/import_export.feature +++ b/question/format/xml/tests/behat/import_export.feature @@ -36,6 +36,11 @@ Feature: Test importing questions from Moodle XML format. And I set the field "id_format_xml" to "1" And I press "Export questions to file" And following "click here" should download between "57000" and "58000" bytes + # If the download step is the last in the scenario then we can sometimes run + # into the situation where the download page causes a http redirect but behat + # has already conducted its reset (generating an error). By putting a logout + # step we avoid behat doing the reset until we are off that page. + And I log out @javascript @_file_upload Scenario: import some multiple choice questions from Moodle XML format