Merge "Add some translations for Western Punjabi (pnb)"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiTestCase.php
index ac4d2c9..abef1c9 100644 (file)
@@ -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,8 +198,28 @@ 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 ) );
+               $groups = PHPUnit_Util_Test::getGroups( static::class );
                $constraint = PHPUnit_Framework_Assert::logicalOr(
                        $this->contains( 'medium' ),
                        $this->contains( 'large' )