Skip to content

Commit

Permalink
MDL-42627 behat: Moving the deprecated method to behat_deprecate and …
Browse files Browse the repository at this point in the history
…updating scenarios
  • Loading branch information
David Monllao committed Dec 2, 2013
1 parent c3a40de commit e7c71c4
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cohort/tests/behat/behat_cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function i_add_user_to_cohort($username, $cohortidnumber) {
$userid = $DB->get_field('user', 'id', array('username' => $username));

$steps = array(
new Given('I click on "' . get_string('assign', 'cohort') . '" "link" in the "' . $this->escape($cohortidnumber) . '" table row'),
new Given('I click on "' . get_string('assign', 'cohort') . '" "link" in the "' . $this->escape($cohortidnumber) . '" "table_row"'),
new Given('I select "' . $userid . '" from "' . get_string('potusers', 'cohort') . '"'),
new Given('I press "' . get_string('add') . '"'),
new Given('I press "' . get_string('backtocohorts', 'cohort') . '"')
Expand Down
4 changes: 2 additions & 2 deletions cohort/tests/behat/upload_cohort_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Feature: Upload users to a cohort
And I press "Upload users"
And I press "Continue"
And I follow "Cohorts"
And I click on "Assign" "link" in the "Cohort 1" table row
And I click on "Assign" "link" in the "Cohort 1" "table_row"
Then the "Current users" select box should contain "Tom Jones ([email protected])"
And the "Current users" select box should contain "Bob Jones ([email protected])"
And I press "Back to cohorts"
And I click on "Assign" "link" in the "Cohort 2" table row
And I click on "Assign" "link" in the "Cohort 2" "table_row"
And the "Current users" select box should contain "Mary Smith ([email protected])"
And the "Current users" select box should contain "Alice Smith ([email protected])"
And I am on homepage
Expand Down
2 changes: 1 addition & 1 deletion group/tests/behat/id_uniqueness.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Feature: Uniqueness of Group ID number
And I fill the moodle form with:
| Grouping ID number | GG2 |
And I press "Save changes"
And I click on "Edit" "link" in the "Grouping 1" table row
And I click on "Edit" "link" in the "Grouping 1" "table_row"
And I fill the moodle form with:
| Grouping ID number | GG2 |
And I press "Save changes"
Expand Down
33 changes: 33 additions & 0 deletions lib/tests/behat/behat_deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;

/**
* Deprecated behat step definitions.
*
Expand All @@ -37,6 +39,37 @@
*/
class behat_deprecated extends behat_base {

/**
* Click on the specified element inside a table row containing the specified text.
*
* @deprecated since Moodle 2.7 MDL-42627
* @todo MDL-42862 This will be deleted in Moodle 2.9
* @see behat_general::i_click_on_in_the()
*
* @Given /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" in the "(?P<row_text_string>(?:[^"]|\\")*)" table row$/
* @throws ElementNotFoundException
* @param string $element Element we look for
* @param string $selectortype The type of what we look for
* @param string $tablerowtext The table row text
*/
public function i_click_on_in_the_table_row($element, $selectortype, $tablerowtext) {

// Throw an exception if deprecated methods are not allowed otherwise allow it's execution.
$alternative = 'I click on "' . $this->escape($element) . '" "' . $this->escape($selectortype) .
'" in the "' . $this->escape($tablerowtext) . '" "table_row"';
$this->deprecated_message($alternative);

// The table row container.
$nocontainerexception = new ElementNotFoundException($this->getSession(), '"' . $tablerowtext . '" row text ');
$tablerowtext = $this->getSession()->getSelectorsHandler()->xpathLiteral($tablerowtext);
$rownode = $this->find('xpath', "//tr[contains(., $tablerowtext)]", $nocontainerexception);

// Looking for the element DOM node inside the specified row.
list($selector, $locator) = $this->transform_selector($selectortype, $element);
$elementnode = $this->find($selector, $locator, false, $rownode);
$elementnode->click();
}

/**
* Throws an exception if $CFG->behat_usedeprecated is not allowed.
*
Expand Down
22 changes: 0 additions & 22 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,6 @@ public function i_click_on_in_the($element, $selectortype, $nodeelement, $nodese
$node->click();
}

/**
* Click on the specified element inside a table row containing the specified text.
*
* @Given /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" in the "(?P<row_text_string>(?:[^"]|\\")*)" table row$/
* @throws ElementNotFoundException
* @param string $element Element we look for
* @param string $selectortype The type of what we look for
* @param string $tablerowtext The table row text
*/
public function i_click_on_in_the_table_row($element, $selectortype, $tablerowtext) {

// The table row container.
$nocontainerexception = new ElementNotFoundException($this->getSession(), '"' . $tablerowtext . '" row text ');
$tablerowtext = $this->getSession()->getSelectorsHandler()->xpathLiteral($tablerowtext);
$rownode = $this->find('xpath', "//tr[contains(., $tablerowtext)]", $nocontainerexception);

// Looking for the element DOM node inside the specified row.
list($selector, $locator) = $this->transform_selector($selectortype, $element);
$elementnode = $this->find($selector, $locator, false, $rownode);
$elementnode->click();
}

/**
* Drags and drops the specified element to the specified container. This step does not work in all the browsers, consider it experimental.
*
Expand Down
2 changes: 1 addition & 1 deletion message/tests/behat/block_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Block users from contacting me
And I follow "Messages"
And I fill in "Search people and messages" with "User Two"
And I press "Search people and messages"
When I click on "Block contact" "link" in the "User Two" table row
When I click on "Block contact" "link" in the "User Two" "table_row"
Then the "Message navigation:" select box should contain "Blocked users (1)"
And I select "Blocked users (1)" from "Message navigation:"
And I should see "User Two"
Expand Down
2 changes: 1 addition & 1 deletion message/tests/behat/display_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feature: Message history displays correctly
And I click on "Messages" "link" in the "Navigation" "block"
And I fill in "Search people and messages" with "User Two"
And I press "Search people and messages"
And I click on "Message history" "link" in the "User Two" table row
And I click on "Message history" "link" in the "User Two" "table_row"
# The message history link shows all messages.
Then I should see "Message 1 from user1 to user2"
And I should see "Message 10 from user1 to user2"
Expand Down
2 changes: 1 addition & 1 deletion message/tests/behat/manage_contacts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Manage contacts
And I click on "Messages" "link" in the "Navigation" "block"
And I fill in "Search people and messages" with "User Two"
And I press "Search people and messages"
When I click on "Add contact" "link" in the "User Two" table row
When I click on "Add contact" "link" in the "User Two" "table_row"
Then I should see "Message 1 from user1 to user2"
And I should see "Message 2 from user1 to user2"
And I should see "User Two" in the "#message_contacts" "css_element"
Expand Down
2 changes: 1 addition & 1 deletion message/tests/behat/search_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Users can search their message history
And I fill in "Search people and messages" with "your biscuits"
And I press "Search people and messages"
Then I should see "User Two"
And I click on "context" "link" in the "User Two" table row
And I click on "context" "link" in the "User Two" "table_row"
And I should see "Give me your biscuits"

@javascript
Expand Down
10 changes: 5 additions & 5 deletions mod/wiki/tests/behat/page_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ Feature: A history of each wiki page is available
And I follow "History"
# Checking that there are 3 history items (the first one is are th)
And "//*[@id='region-main']/descendant::table/descendant::tr[4]" "xpath_element" should exists
And I click on "1" "link" in the "Teacher 1" table row
And I click on "1" "link" in the "Teacher 1" "table_row"
And I should see "First edition"
And I should see "Teacher 1"
And I follow "History"
And I click on "2" "link" in the "Student 1" table row
And I click on "2" "link" in the "Student 1" "table_row"
And I should see "Second edition"
And I should see "Student 1"
And I follow "History"
And I click on "3" "link" in the "Student 2" table row
And I click on "3" "link" in the "Student 2" "table_row"
And I should see "Third edition"
And I should see "Student 2" in the "#region-main" "css_element"
And I follow "History"
And I click on "comparewith" "radio" in the "Student 1" table row
And I click on "compare" "radio" in the "Teacher 1" table row
And I click on "comparewith" "radio" in the "Student 1" "table_row"
And I click on "compare" "radio" in the "Teacher 1" "table_row"
And I press "Compare selected"
And I should see "Comparing version 1 with version 3"
And I follow "Next"
Expand Down
6 changes: 3 additions & 3 deletions question/tests/behat/edit_questions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: A teacher can edit questions in the question bank
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Question bank"
When I click on "Edit" "link" in the "Test question name" table row
When I click on "Edit" "link" in the "Test question name" "table_row"
And I fill the moodle form with:
| Question name | Edited question name |
| Question text | Write a lot about what you want |
Expand All @@ -33,10 +33,10 @@ Feature: A teacher can edit questions in the question bank
And I should not see "Test question name"
And I should see "Admin User" in the ".categoryquestionscontainer tbody .creatorname" "css_element"
And I should see "Teacher 1" in the ".categoryquestionscontainer tbody .modifiername" "css_element"
And I click on "Edit" "link" in the "Edited question name" table row
And I click on "Edit" "link" in the "Edited question name" "table_row"
And the "Question name" field should match "Edited question name" value
And I press "Cancel"
And I click on "Preview" "link" in the "Edited question name" table row
And I click on "Preview" "link" in the "Edited question name" "table_row"
And I switch to "questionpreview" window
And I should see "Edited question name"
And I should see "Write a lot about what you want"
Expand Down
2 changes: 1 addition & 1 deletion question/tests/behat/preview_question.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: A teacher can preview questions in the question bank
| fraction[0] | 100% |
| answer[1] | * |
| fraction[1] | None |
When I click on "Preview" "link" in the "Test question name" table row
When I click on "Preview" "link" in the "Test question name" "table_row"
And I switch to "questionpreview" window
And I fill the moodle form with:
| Whether correct | Shown |
Expand Down

0 comments on commit e7c71c4

Please sign in to comment.