forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-43584 behat: Removing DB calls from step definitions as much as p…
…ossible Old methods deprecated as the expected arguments have changed.
- Loading branch information
David Monllao
committed
Jan 10, 2014
1 parent
8a0667a
commit 14ebd16
Showing
4 changed files
with
120 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,39 +40,49 @@ | |
class behat_cohort extends behat_base { | ||
|
||
/** | ||
* Adds the user to the specified cohort. | ||
* Adds the user to the specified cohort. The user should be specified like "Firstname Lastname ([email protected])". | ||
* | ||
* @Given /^I add "(?P<user_username_string>(?:[^"]|\\")*)" user to "(?P<cohort_idnumber_string>(?:[^"]|\\")*)" cohort$/ | ||
* @param string $username | ||
* @Given /^I add "(?P<user_fullname_string>(?:[^"]|\\")*)" user to "(?P<cohort_idnumber_string>(?:[^"]|\\")*)" cohort members$/ | ||
* @param string $user | ||
* @param string $cohortidnumber | ||
*/ | ||
public function i_add_user_to_cohort($username, $cohortidnumber) { | ||
global $DB; | ||
|
||
// The user was created by the data generator, executed by the same PHP process that is | ||
// running this step, not by any Selenium action. | ||
$userid = $DB->get_field('user', 'id', array('username' => $username)); | ||
public function i_add_user_to_cohort_members($user, $cohortidnumber) { | ||
|
||
$steps = array( | ||
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 select "' . $this->escape($user) . '" from "' . get_string('potusers', 'cohort') . '"'), | ||
new Given('I press "' . get_string('add') . '"'), | ||
new Given('I press "' . get_string('backtocohorts', 'cohort') . '"') | ||
); | ||
|
||
// If we are not in the cohorts management we should move there before anything else. | ||
if (!$this->getSession()->getPage()->find('css', 'input#cohort_search_q')) { | ||
$steps = array_merge( | ||
array( | ||
new Given('I am on homepage'), | ||
new Given('I collapse "' . get_string('frontpagesettings', 'admin') . '" node'), | ||
new Given('I expand "' . get_string('administrationsite') . '" node'), | ||
new Given('I expand "' . get_string('users', 'admin') . '" node'), | ||
new Given('I expand "' . get_string('accounts', 'admin') . '" node'), | ||
new Given('I follow "' . get_string('cohorts', 'cohort') . '"') | ||
), | ||
$steps | ||
); | ||
|
||
// With JS enabled we should expand a few tree nodes. | ||
if ($this->running_javascript()) { | ||
$steps = array_merge( | ||
array( | ||
new Given('I am on homepage'), | ||
new Given('I collapse "' . get_string('frontpagesettings', 'admin') . '" node'), | ||
new Given('I expand "' . get_string('administrationsite') . '" node'), | ||
new Given('I expand "' . get_string('users', 'admin') . '" node'), | ||
new Given('I expand "' . get_string('accounts', 'admin') . '" node'), | ||
new Given('I follow "' . get_string('cohorts', 'cohort') . '"') | ||
), | ||
$steps | ||
); | ||
|
||
} else { | ||
// JS disabled. | ||
$steps = array_merge( | ||
array( | ||
new Given('I am on homepage'), | ||
new Given('I follow "' . get_string('administrationsite') . '" node'), | ||
new Given('I follow "' . get_string('cohorts', 'cohort') . '"') | ||
), | ||
$steps | ||
); | ||
} | ||
} | ||
|
||
return $steps; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,18 +40,16 @@ | |
class behat_groups extends behat_base { | ||
|
||
/** | ||
* Add the specified user to the group. You should be in the groups page when running this step. | ||
* Add the specified user to the group. You should be in the groups page when running this step. The user should be specified like "Firstname Lastname ([email protected])". | ||
* | ||
* @Given /^I add "(?P<username_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group$/ | ||
* @Given /^I add "(?P<user_fullname_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group members$/ | ||
* @throws ElementNotFoundException Thrown by behat_base::find | ||
* @param string $username | ||
* @param string $groupname | ||
*/ | ||
public function i_add_user_to_group($username, $groupname) { | ||
global $DB; | ||
public function i_add_user_to_group_members($userfullname, $groupname) { | ||
|
||
$user = $DB->get_record('user', array('username' => $username)); | ||
$userfullname = $this->getSession()->getSelectorsHandler()->xpathLiteral(fullname($user)); | ||
$userfullname = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname); | ||
|
||
// Using a xpath liternal to avoid problems with quotes and double quotes. | ||
$groupname = $this->getSession()->getSelectorsHandler()->xpathLiteral($groupname); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters