Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/77812


Change subject: Use action=tokens for api test tokens
......................................................................

Use action=tokens for api test tokens

Change-Id: I5d517eca7529dd57e14629a1ea5dd4d50110f39f
---
M tests/phpunit/includes/api/ApiBlockTest.php
M tests/phpunit/includes/api/ApiTest.php
M tests/phpunit/includes/api/ApiTestCase.php
M tests/phpunit/includes/api/ApiWatchTest.php
4 files changed, 28 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/12/77812/2

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

-- 
To view, visit https://gerrit.wikimedia.org/r/77812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d517eca7529dd57e14629a1ea5dd4d50110f39f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to