*/
protected $apiContext;
- /**
- * @var array
- */
- protected $tablesUsed = [ 'user', 'user_groups', 'user_properties' ];
-
protected function setUp() {
global $wgServer, $wgDisableAuthManager;
ApiQueryInfo::resetTokenCache(); // tokens are invalid because we cleared the session
self::$users = [
- 'sysop' => new TestUser(
- 'Apitestsysop',
- 'Api Test Sysop',
- 'api_test_sysop@example.com',
- [ 'sysop' ]
- ),
- 'uploader' => new TestUser(
- 'Apitestuser',
- 'Api Test User',
- 'api_test_user@example.com',
- []
- )
+ 'sysop' => static::getTestSysop(),
+ 'uploader' => static::getTestUser(),
];
$this->setMwGlobals( [
}
}
- protected function doLogin( $user = 'sysop' ) {
- if ( !array_key_exists( $user, self::$users ) ) {
- throw new MWException( "Can not log in to undefined user $user" );
+ protected function doLogin( $testUser = 'sysop' ) {
+ if ( $testUser === null ) {
+ $testUser = static::getTestSysop();
+ } elseif ( is_string( $testUser ) && array_key_exists( $testUser, self::$users ) ) {
+ $testUser = self::$users[ $testUser ];
+ } elseif ( !$testUser instanceof TestUser ) {
+ throw new MWException( "Can not log in to undefined user $testUser" );
}
$data = $this->doApiRequest( [
'action' => 'login',
- 'lgname' => self::$users[$user]->username,
- 'lgpassword' => self::$users[$user]->password ] );
+ 'lgname' => $testUser->username,
+ 'lgpassword' => $testUser->password ] );
$token = $data[0]['login']['token'];
[
'action' => 'login',
'lgtoken' => $token,
- 'lgname' => self::$users[$user]->username,
- 'lgpassword' => self::$users[$user]->password,
+ 'lgname' => $testUser->username,
+ 'lgpassword' => $testUser->password,
],
$data[2]
);
if ( $data[0]['login']['result'] === 'Success' ) {
// DWIM
global $wgUser;
- $wgUser = self::$users[$user]->getUser();
+ $wgUser = $testUser->getUser();
RequestContext::getMain()->setUser( $wgUser );
}