Consider the following step in a scenario:
Given I log in as "student1"Supposed I create a custom behat test that depends on the user role.
**The problem is $USER always points to admin. (This is more evident if you do print_object($USER)). Anyway, is there a reliable way of getting the user role of the current logged in user.
* @Given /^I register iclicker id "(?P<iclickerid>(?:[^"]|\\")*)" at course "(?P<course>(?:[^"]|\\")*)" and activity "(?P<activity>(?:[^"]|\\")*)"$/
*/
public function register_iclicker_to_current_user($iclicker, $course, $activity) {
global $USER;
// Have something like, as a student.
if ($USER->username === "admin") {
return array(
new Given("I am on homepage"),
new Given("I follow \"$course\""),
new Given("I follow \"$activity\""),
new Given('I press "iclickerregistration/registrationbuttontext" lang string'),
new Given("I set the field \"clicker-id\" to \"$iclicker\""),
new Given('I press "iclickerregistration/registrationbuttontext" lang string'),
new Given('I should see "iclickerregistration/registrationsuccess" lang string'),
new Given('I wait to be redirected'),
new Given("I am on homepage")
);
} else {
return array(
new Given("I am on homepage"),
new Given("I follow \"$course\""),
new Given("I follow \"$activity\""),
new Given("I set the field \"clicker-id\" to \"$iclicker\""),
new Given('I press "iclickerregistration/registrationbuttontext" lang string'),
new Given('I should see "iclickerregistration/registrationsuccess." lang string'),
new Given('I wait to be redirected'),
new Given("I am on homepage")
);
}
}