X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiTestCase.php;h=6b299c98c80fbece7198931a74b3bb599353f222;hb=4e6810e4a2c1d821d8d108c7974ac16917561764;hp=ac4d2c92cafd138f9fe346982f5cfab5bc971725;hpb=7160234ab2976d9ef7c36cb16f2101059388f2f2;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index ac4d2c92ca..6b299c98c8 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -3,13 +3,15 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { protected static $apiUrl; + protected static $errorFormatter = null; + /** * @var ApiTestContext */ protected $apiContext; protected function setUp() { - global $wgServer, $wgDisableAuthManager; + global $wgServer; parent::setUp(); self::$apiUrl = $wgServer . wfScript( 'api' ); @@ -22,7 +24,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { ]; $this->setMwGlobals( [ - 'wgAuth' => $wgDisableAuthManager ? new AuthPlugin : new MediaWiki\Auth\AuthManagerAuthPlugin, + 'wgAuth' => new MediaWiki\Auth\AuthManagerAuthPlugin, 'wgRequest' => new FauxRequest( [] ), 'wgUser' => self::$users['sysop']->getUser(), ] ); @@ -196,6 +198,26 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { return $data[0]['tokens']; } + protected static function getErrorFormatter() { + if ( self::$errorFormatter === null ) { + self::$errorFormatter = new ApiErrorFormatter( + new ApiResult( false ), + Language::factory( 'en' ), + 'none' + ); + } + return self::$errorFormatter; + } + + public static function apiExceptionHasCode( ApiUsageException $ex, $code ) { + return (bool)array_filter( + self::getErrorFormatter()->arrayFromStatus( $ex->getStatusValue() ), + function ( $e ) use ( $code ) { + return is_array( $e ) && $e['code'] === $code; + } + ); + } + public function testApiTestGroup() { $groups = PHPUnit_Util_Test::getGroups( get_class( $this ) ); $constraint = PHPUnit_Framework_Assert::logicalOr(