* previously always considered valid (bug 34212).
*/
function testMakeNormalBlock() {
- $data = $this->getTokens();
+ $tokens = $this->getTokens();
$user = User::newFromName( 'UTApiBlockee' );
$this->markTestIncomplete( "The user UTApiBlockee does not exist" );
}
- if ( !isset( $data[0]['query']['pages'] ) ) {
+ if ( !array_key_exists( 'blocktoken', $tokens ) ) {
$this->markTestIncomplete( "No block token found" );
}
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
- $pageinfo = $data[0]['query']['pages'][$key];
-
$this->doApiRequest( array(
'action' => 'block',
'user' => 'UTApiBlockee',
'reason' => 'Some reason',
- 'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user );
+ 'token' => $tokens['blocktoken'] ), null, false, self::$users['sysop']->user );
$block = Block::newFromTarget( 'UTApiBlockee' );
}
function runTokenTest( $user ) {
- $data = $this->getTokenList( $user );
-
- $this->assertArrayHasKey( 'query', $data[0] );
- $this->assertArrayHasKey( 'pages', $data[0]['query'] );
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
+ $tokens = $this->getTokenList( $user );
$rights = $user->user->getRights();
- $this->assertArrayHasKey( $key, $data[0]['query']['pages'] );
- $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] );
- $this->assertArrayHasKey( 'movetoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'edittoken', $tokens );
+ $this->assertArrayHasKey( 'movetoken', $tokens );
if ( isset( $rights['delete'] ) ) {
- $this->assertArrayHasKey( 'deletetoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'deletetoken', $tokens );
}
if ( isset( $rights['block'] ) ) {
- $this->assertArrayHasKey( 'blocktoken', $data[0]['query']['pages'][$key] );
- $this->assertArrayHasKey( 'unblocktoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'blocktoken', $tokens );
+ $this->assertArrayHasKey( 'unblocktoken', $tokens );
}
if ( isset( $rights['protect'] ) ) {
- $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
+ $this->assertArrayHasKey( 'protecttoken', $tokens );
}
- return $data;
+ return $tokens;
}
}
protected function getTokenList( $user, $session = null ) {
$data = $this->doApiRequest( array(
- 'action' => 'query',
- 'titles' => 'Main Page',
- 'intoken' => 'edit|delete|protect|move|block|unblock|watch',
- 'prop' => 'info' ), $session, false, $user->user );
+ 'action' => 'tokens',
+ 'type' => 'edit|delete|protect|move|block|unblock|watch'
+ ), $session, false, $user->user );
- return $data;
+ if( !array_key_exists( 'tokens', $data[0] ) ){
+ throw new MWException( 'Api failed to return a token list' );
+ }
+
+ return $data[0]['tokens'];
}
public function testApiTestGroup() {
}
function getTokens() {
- $data = $this->getTokenList( self::$users['sysop'] );
-
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
- $pageinfo = $data[0]['query']['pages'][$key];
-
- return $pageinfo;
+ return $this->getTokenList( self::$users['sysop'] );
}
/**
*/
function testWatchEdit() {
- $pageinfo = $this->getTokens();
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'edit',
'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
'text' => 'new text',
- 'token' => $pageinfo['edittoken'],
+ 'token' => $tokens['edittoken'],
'watchlist' => 'watch' ) );
$this->assertArrayHasKey( 'edit', $data[0] );
$this->assertArrayHasKey( 'result', $data[0]['edit'] );
* @depends testWatchEdit
*/
function testWatchClear() {
-
- $pageinfo = $this->getTokens();
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'query',
'action' => 'watch',
'title' => $page['title'],
'unwatch' => true,
- 'token' => $pageinfo['watchtoken'] ) );
+ 'token' => $tokens['watchtoken'] ) );
}
}
$data = $this->doApiRequest( array(
/**
*/
function testWatchProtect() {
-
- $pageinfo = $this->getTokens();
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'protect',
- 'token' => $pageinfo['protecttoken'],
+ 'token' => $tokens['protecttoken'],
'title' => 'Help:UTPage',
'protections' => 'edit=sysop',
'watchlist' => 'unwatch' ) );
/**
*/
function testWatchDelete() {
- $pageinfo = $this->getTokens();
+ $tokens = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'delete',
- 'token' => $pageinfo['deletetoken'],
+ 'token' => $tokens['deletetoken'],
'title' => 'Help:UTPage' ) );
$this->assertArrayHasKey( 'delete', $data[0] );
$this->assertArrayHasKey( 'title', $data[0]['delete'] );