ApiTokensTest.php
Go to the documentation of this file.00001 <?php
00014 class ApiTokensTest extends MediaWikiTestCase {
00016 public function testTokenRetrieval( $id, $class ) {
00017
00018 global $wgGroupPermissions;
00019 $wgGroupPermissions['*'][$class::getRight()] = true;
00020 RequestContext::getMain()->getUser()->clearInstanceCache();
00021
00022
00023 $expected = $class::getToken();
00024 $this->assertNotSame( false, $expected, 'We did not get a valid token' );
00025
00026 $actionString = TranslateUtils::getTokenAction( $id );
00027 $params = wfCgiToArray( $actionString );
00028
00029 $req = new FauxRequest( $params );
00030 $api = new ApiMain( $req );
00031 $api->execute();
00032
00033 $data = $api->getResultData();
00034 if ( isset( $data['query'] ) ) {
00035 foreach ( $data['query']['pages'] as $page ) {
00036 $this->assertSame( $expected, $page[$id . 'token'] );
00037 }
00038 } else {
00039 $this->assertArrayHasKey( 'tokens', $data, 'Result has tokens' );
00040 $this->assertSame( $expected, $data['tokens'][$id . 'token'] );
00041 }
00042 }
00043
00044 public static function provideTokenClasses() {
00045 return array(
00046 array( 'groupreview', 'ApiGroupReview' ),
00047 array( 'translationreview', 'ApiTranslationReview' ),
00048 array( 'aggregategroups', 'ApiAggregateGroups' ),
00049 );
00050 }
00051 }