The default user id for $USER in the phpunit test is 0. I need it to be a privileged user such as admin so as to test certain privileged actions. In the test I've set $USER->id = 2 which seems to work. Is there a better/recommended way for achieving the same effect?
Hi,
you can use $this->setAdminUser(), $this->setGuestUser() or general $this->setUser($user). If you need to create new user try $this->getDataGenerator()->create_user($userrecord).
Petr
you can use $this->setAdminUser(), $this->setGuestUser() or general $this->setUser($user). If you need to create new user try $this->getDataGenerator()->create_user($userrecord).
Petr
Excellent. Thanks!
Do we have any convenience methods for enrolling a user in a course?
I'm thinking of tests for a module:
* Create 5 users
* Enrol into test course
* Do tests in mod_mymod using those test users.
I'm thinking of tests for a module:
* Create 5 users
* Enrol into test course
* Do tests in mod_mymod using those test users.