I'm trying to test a custom block, relationships, and I want to ensure students cannot access it, even if they go to the direct URL. To do this, I implemented a behat step:
/**
* Goes to specified URL
* @Given /^I go to "([^"]*)"$/
*/
public function iGoTo($url) {
try{
$session = $this->getSession();
$session->visit($url);
} catch(\Exception $e){
echo "Exceção: " . $e;
}
}
This is the scenario so far:
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | stundent1@example.com |
And the following "courses" exist:
| fullname | shortname | id |
| Course1 | c1 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | c1 | student |
@javascript @wip
Scenario: Students cannot access the relationship page
When I log in as "student1"
And I am on homepage
And I go to "http://150.162.242.121/mariana/unasus-cp/local/relationship/index.php?contextid=1"
Then I should see "Usar relacionamentos e ver membros"
When I run this scenario, I get a moodle exception which interrupts the test:
Moodle exception: Sorry, but you do not currently have permissions to do that (Usar relacionamentos e ver membros) More information about this error
Debug info:
Error code: nopermissions
Stack trace:
line 786 of /lib/accesslib.php: required_capability_exception thrown
line 32 of /local/relationship/index.php: call to require_capability()
which is expected, but I don't want my test to stop, I want to verify that the message is being displayed on the browser. Is there a way for me to do this?
EDIT: When I made the step definition, I didn't implement the try/catch block, and the error already existed.