Use action=tokens for api test tokens
authoraddshore <addshorewiki@gmail.com>
Mon, 5 Aug 2013 19:31:45 +0000 (21:31 +0200)
committerAddshore <addshorewiki@gmail.com>
Mon, 5 Aug 2013 20:08:21 +0000 (20:08 +0000)
Change-Id: I5d517eca7529dd57e14629a1ea5dd4d50110f39f

tests/phpunit/includes/api/ApiBlockTest.php
tests/phpunit/includes/api/ApiTest.php
tests/phpunit/includes/api/ApiTestCase.php
tests/phpunit/includes/api/ApiWatchTest.php

index a3d39dd..3c18968 100644 (file)
@@ -35,7 +35,7 @@ class ApiBlockTest extends ApiTestCase {
         * previously always considered valid (bug 34212).
         */
        function testMakeNormalBlock() {
-               $data = $this->getTokens();
+               $tokens = $this->getTokens();
 
                $user = User::newFromName( 'UTApiBlockee' );
 
@@ -43,19 +43,15 @@ class ApiBlockTest extends ApiTestCase {
                        $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' );
 
index e278fd0..21c6247 100644 (file)
@@ -234,32 +234,26 @@ class ApiTest extends ApiTestCase {
        }
 
        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;
        }
 }
index bf970da..374eded 100644 (file)
@@ -166,12 +166,15 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
        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() {
index a9bc43a..78bb151 100644 (file)
@@ -13,25 +13,19 @@ class ApiWatchTest extends ApiTestCase {
        }
 
        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'] );
@@ -44,8 +38,7 @@ class ApiWatchTest extends ApiTestCase {
         * @depends testWatchEdit
         */
        function testWatchClear() {
-
-               $pageinfo = $this->getTokens();
+               $tokens = $this->getTokens();
 
                $data = $this->doApiRequest( array(
                        'action' => 'query',
@@ -59,7 +52,7 @@ class ApiWatchTest extends ApiTestCase {
                                        'action' => 'watch',
                                        'title' => $page['title'],
                                        'unwatch' => true,
-                                       'token' => $pageinfo['watchtoken'] ) );
+                                       'token' => $tokens['watchtoken'] ) );
                        }
                }
                $data = $this->doApiRequest( array(
@@ -75,12 +68,11 @@ class ApiWatchTest extends ApiTestCase {
        /**
         */
        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' ) );
@@ -157,11 +149,11 @@ class ApiWatchTest extends ApiTestCase {
        /**
         */
        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'] );