Browse files

Merge branch 'MDL-40246_25' of git://github.com/dmonllao/moodle into …

…MOODLE_25_STABLE
  • Loading branch information...
2 parents 4d52fbb + ff46f98 commit a9155c2875adeada1bc4680bcb89f8d1d00facf1 @stronk7 stronk7 committed Jul 2, 2013
View
55 lib/tests/behat/behat_general.php
@@ -28,7 +28,8 @@
require_once(__DIR__ . '/../../behat/behat_base.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException,
- Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
+ Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
+ Behat\Mink\Exception\DriverException as DriverException;
/**
* Cross component steps definitions.
@@ -64,6 +65,48 @@ public function reload() {
}
/**
+ * Follows the page redirection. Use this step after any action that shows a message and waits for a redirection
+ *
+ * @Given /^I wait to be redirected$/
+ */
+ public function i_wait_to_be_redirected() {
+
+ // Xpath and processes based on core_renderer::redirect_message(), core_renderer::$metarefreshtag and
+ // moodle_page::$periodicrefreshdelay possible values.
+ if (!$metarefresh = $this->getSession()->getPage()->find('xpath', "//head/descendant::meta[@http-equiv='refresh']")) {
+ // We don't fail the scenario if no redirection with message is found to avoid race condition false failures.
+ return false;
+ }
+
+ $content = $metarefresh->getAttribute('content');
+ if (strstr($content, 'url') != false) {
+
+ list($waittime, $url) = explode(';', $metarefresh->getAttribute('content'));
+
+ // Cleaning the URL value.
+ $url = trim(substr($url, strpos($url, 'http')));
+
+ } else {
+ // Just wait then.
+ $waittime = $content;
+ }
+
+
+ // Wait until the URL change is executed.
+ if ($this->running_javascript()) {
+ $this->getSession()->wait($waittime * 1000, false);
+
+ } else if (!empty($url)) {
+ // We redirect directly as we can not wait for an automatic redirection.
+ $this->getSession()->getDriver()->getClient()->request('get', $url);
+
+ } else {
+ // Reload the page if no URL was provided.
+ $this->getSession()->getDriver()->reload();
+ }
+ }
+
+ /**
* Switches to the specified window. Useful when interacting with popup windows.
*
* @Given /^I switch to "(?P<window_name_string>(?:[^"]|\\")*)" window$/
@@ -110,6 +153,11 @@ public function click_link($link) {
* @param int $seconds
*/
public function i_wait_seconds($seconds) {
+
+ if (!$this->running_javascript()) {
+ throw new DriverException('Waits are disabled in scenarios without Javascript support');
+ }
+
$this->getSession()->wait($seconds * 1000, false);
}
@@ -119,6 +167,11 @@ public function i_wait_seconds($seconds) {
* @Given /^I wait until the page is ready$/
*/
public function wait_until_the_page_is_ready() {
+
+ if (!$this->running_javascript()) {
+ throw new DriverException('Waits are disabled in scenarios without Javascript support');
+ }
+
$this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")');
}
View
17 mod/forum/tests/behat/behat_mod_forum.php
@@ -51,30 +51,31 @@ public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $ta
// Escaping $forumname as it has been stripped automatically by the transformer.
return array(
new Given('I follow "' . $this->escape($forumname) . '"'),
- new Given('I press "Add a new discussion topic"'),
+ new Given('I press "' . get_string('addanewdiscussion', 'mod_forum') . '"'),
new Given('I fill the moodle form with:', $table),
- new Given('I press "Post to forum"'),
- new Given('I wait "5" seconds')
+ new Given('I press "' . get_string('posttoforum', 'mod_forum') . '"'),
+ new Given('I wait to be redirected')
);
}
/**
* Adds a reply to the specified post of the specified forum. The step begins from the forum's page or from the forum's course page.
*
* @Given /^I reply "(?P<post_subject_string>(?:[^"]|\\")*)" post from "(?P<forum_name_string>(?:[^"]|\\")*)" forum with:$/
- * @param mixed $postname The subject of the post
- * @param mixed $forumname The forum name
+ * @param string $postname The subject of the post
+ * @param string $forumname The forum name
* @param TableNode $table
*/
public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode $table) {
return array(
new Given('I follow "' . $this->escape($forumname) . '"'),
new Given('I follow "' . $this->escape($postsubject) . '"'),
- new Given('I follow "Reply"'),
+ new Given('I follow "' . get_string('reply', 'mod_forum') . '"'),
new Given('I fill the moodle form with:', $table),
- new Given('I press "Post to forum"'),
- new Given('I wait "5" seconds')
+ new Given('I press "' . get_string('posttoforum', 'mod_forum') . '"'),
+ new Given('I wait to be redirected')
);
+
}
}
View
4 mod/forum/tests/behat/edit_post_student.feature
@@ -33,17 +33,15 @@ Feature: Students can edit or delete their forum posts within a set time limit
And I add a new discussion to "Test forum name" forum with:
| Subject | Forum post subject |
| Message | This is the body |
- And I wait "6" seconds
- @javascript
Scenario: Edit forum post
When I follow "Forum post subject"
And I follow "Edit"
And I fill the moodle form with:
| Subject | Edited post subject |
| Message | Edited post body |
And I press "Save changes"
- And I wait "6" seconds
+ And I wait to be redirected
Then I should see "Edited post subject"
And I should see "Edited post body"

0 comments on commit a9155c2

Please sign in to comment.