Skip to content

Commit

Permalink
Merge branch 'MDL-42627_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Dec 3, 2013
2 parents a5ec4f7 + e7c71c4 commit 23a05a1
Show file tree
Hide file tree
Showing 14 changed files with 127 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
5 changes: 5 additions & 0 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@
// Example:
// $CFG->behat_extraallowedsettings = array('logsql', 'dblogerror');
//
// You should explicitly allow the usage of the deprecated behat steps, otherwise an exception will
// be thrown when using them. The setting is disabled by default.
// Example:
// $CFG->behat_usedeprecated = true;
//
//=========================================================================
// 12. DEVELOPER DATA GENERATOR
//=========================================================================
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
5 changes: 5 additions & 0 deletions lib/behat/classes/behat_config_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public static function update_config_file($component = '', $testsrunner = true)
}
}

// We don't want the deprecated steps definitions here.
if (!$testsrunner) {
unset($stepsdefinitions['behat_deprecated']);
}

// Behat config file specifing the main context class,
// the required Behat extensions and Moodle test wwwroot.
$contents = self::get_config_file_contents($features, $stepsdefinitions);
Expand Down
100 changes: 100 additions & 0 deletions lib/tests/behat/behat_deprecated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Steps definitions that will be deprecated in the next releases.
*
* @package core
* @category test
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

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

use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;

/**
* Deprecated behat step definitions.
*
* @package core
* @category test
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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.
*
* @throws Exception
* @param string|array $alternatives Alternative/s to the requested step
* @return void
*/
protected function deprecated_message($alternatives) {
global $CFG;

// We do nothing if it is enabled.
if (!empty($CFG->behat_usedeprecated)) {
return;
}

if (is_scalar($alternatives)) {
$alternatives = array($alternatives);
}

$message = 'Deprecated step, rather than using this step you can:';
foreach ($alternatives as $alternative) {
$message .= PHP_EOL . '- ' . $alternative;
}
$message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps if you don\'t have any other option';
throw new Exception($message);
}

}
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 23a05a1

Please sign in to comment.