Extension:MWUnit/Contexts

Tests can be run in a number of different contexts. By default, tests are run in a canonical context. This means the parser is initialized with an anonymous user and the content language. This is done to make the output of the test consistent across users and languages.

However, sometimes it is easier or necessary to run a test in the context of an existing user. For instance, because the template makes use of the MyVariables extension and the output of the template is dependent on who is viewing it. For this reason, tests can be run in a "user" context. This can achieved by using the "@context" annotation:

 ...

When this annotation is present, the test is run as the current user. This means the parser is initialized with the User object of the current user.

Running a test as another user
It is also possible to run a test as if another is logged in. This can be achieved through the "@user" annotation:

 ...

The above snippet would run the test case as if the user  were running it in "user" context. When running a test as another user, the  global is temporarily replaced, the RequestContext is altered and the Parser is initialized with the mocked user's User object.