The function is entirely unnecessary.
Change-Id: I805520e5355119e872e602d0bfc93be26f227128
protected function setUp() {
parent::setUp();
- $this->doLogin();
$this->mUser = $this->getMutableTestUser()->getUser();
}
* @covers ApiDelete
*/
class ApiDeleteTest extends ApiTestCase {
-
- protected function setUp() {
- parent::setUp();
-
- $this->doLogin();
- }
-
public function testDelete() {
$name = 'Help:' . ucfirst( __FUNCTION__ );
MWNamespace::clearCaches();
$wgContLang->resetNamespaces(); # reset namespace cache
-
- $this->doLogin();
}
protected function tearDown() {
*/
class ApiPurgeTest extends ApiTestCase {
- protected function setUp() {
- parent::setUp();
- $this->doLogin();
- }
-
/**
* @group Broken
*/
* @covers ApiQueryAllPages
*/
class ApiQueryAllPagesTest extends ApiTestCase {
-
- protected function setUp() {
- parent::setUp();
- $this->doLogin();
- }
-
/**
- *Test T27702
- *Prefixes of API search requests are not handled with case sensitivity and may result
- *in wrong search results
+ * Test T27702
+ * Prefixes of API search requests are not handled with case sensitivity and may result
+ * in wrong search results
*/
public function testPrefixNormalizationSearchBug() {
$title = Title::newFromText( 'Category:Template:xyz' );
parent::setUp();
self::$users['ApiQueryRecentChangesIntegrationTestUser'] = $this->getMutableTestUser();
- $this->doLogin( 'ApiQueryRecentChangesIntegrationTestUser' );
wfGetDB( DB_MASTER )->delete( 'recentchanges', '*', __METHOD__ );
}
$params
),
null,
- false
+ false,
+ $this->getLoggedInTestUser()
);
}
array_merge(
[ 'action' => 'query', 'generator' => 'recentchanges' ],
$params
- )
+ ),
+ null,
+ false,
+ $this->getLoggedInTestUser()
);
}
parent::setUp();
self::$users['ApiQueryWatchlistIntegrationTestUser'] = $this->getMutableTestUser();
self::$users['ApiQueryWatchlistIntegrationTestUser2'] = $this->getMutableTestUser();
- $this->doLogin( 'ApiQueryWatchlistIntegrationTestUser' );
}
private function getLoggedInTestUser() {
}
private function doListWatchlistRequest( array $params = [], $user = null ) {
+ if ( $user === null ) {
+ $user = $this->getLoggedInTestUser();
+ }
return $this->doApiRequest(
array_merge(
[ 'action' => 'query', 'list' => 'watchlist' ],
array_merge(
[ 'action' => 'query', 'generator' => 'watchlist' ],
$params
- )
+ ), null, false, $this->getLoggedInTestUser()
);
}
= $this->getMutableTestUser();
self::$users['ApiQueryWatchlistRawIntegrationTestUser2']
= $this->getMutableTestUser();
- $this->doLogin( 'ApiQueryWatchlistRawIntegrationTestUser' );
}
private function getLoggedInTestUser() {
return $this->doApiRequest( array_merge(
[ 'action' => 'query', 'list' => 'watchlistraw' ],
$params
- ) );
+ ), null, false, $this->getLoggedInTestUser() );
}
private function doGeneratorWatchlistRawRequest( array $params = [] ) {
return $this->doApiRequest( array_merge(
[ 'action' => 'query', 'generator' => 'watchlistraw' ],
$params
- ) );
+ ), null, false, $this->getLoggedInTestUser() );
}
private function getItemsFromApiResponse( array $response ) {
protected function setUp() {
parent::setUp();
self::$users[__CLASS__] = new TestUser( __CLASS__ );
- $this->doLogin( __CLASS__ );
}
public function testStuff() {
class ApiStashEditTest extends ApiTestCase {
public function testBasicEdit() {
- $this->doLogin();
$apiResult = $this->doApiRequestWithToken(
[
'action' => 'stashedit',
return $this->doApiRequest( $params, $session, false, $user, $tokenType );
}
- protected function doLogin( $testUser = 'sysop' ) {
+ /**
+ * Previously this would do API requests to log in, as well as setting $wgUser and the request
+ * context's user. The API requests are unnecessary, and the global-setting is unwanted, so
+ * this method should not be called. Instead, pass appropriate User values directly to
+ * functions that need them. For functions that still rely on $wgUser, set that directly. If
+ * you just want to log in the test sysop user, don't do anything -- that's the default.
+ *
+ * @param TestUser|string $testUser Object, or key to self::$users such as 'sysop' or 'uploader'
+ * @deprecated since 1.31
+ */
+ protected function doLogin( $testUser = null ) {
+ global $wgUser;
+
if ( $testUser === null ) {
$testUser = static::getTestSysop();
} elseif ( is_string( $testUser ) && array_key_exists( $testUser, self::$users ) ) {
- $testUser = self::$users[ $testUser ];
+ $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' => $testUser->getUser()->getName(),
- 'lgpassword' => $testUser->getPassword() ] );
-
- $token = $data[0]['login']['token'];
-
- $data = $this->doApiRequest(
- [
- 'action' => 'login',
- 'lgtoken' => $token,
- 'lgname' => $testUser->getUser()->getName(),
- 'lgpassword' => $testUser->getPassword(),
- ],
- $data[2]
- );
-
- if ( $data[0]['login']['result'] === 'Success' ) {
- // DWIM
- global $wgUser;
- $wgUser = $testUser->getUser();
- RequestContext::getMain()->setUser( $wgUser );
+ throw new MWException( "Can't log in to undefined user $testUser" );
}
- return $data;
+ $wgUser = $testUser->getUser();
+ RequestContext::getMain()->setUser( $wgUser );
}
protected function getTokenList( TestUser $user, $session = null ) {
* @covers ApiUnblock
*/
class ApiUnblockTest extends ApiTestCase {
- protected function setUp() {
- parent::setUp();
- $this->doLogin();
- }
-
/**
* @expectedException ApiUsageException
*/
'action' => 'unblock',
'user' => 'UTApiBlockee',
'reason' => 'Some reason',
- ],
- null,
- false,
- self::$users['sysop']->getUser()
+ ]
);
}
}
* @covers ApiWatch
*/
class ApiWatchTest extends ApiTestCase {
- protected function setUp() {
- parent::setUp();
- $this->doLogin();
- }
-
function getTokens() {
return $this->getTokenList( self::$users['sysop'] );
}
class ApiQueryTest extends ApiTestCase {
protected function setUp() {
parent::setUp();
- $this->doLogin();
// Setup apiquerytestiw: as interwiki prefix
$this->setMwGlobals( 'wgHooks', [