API: Allow prop=info intestactions to return reasons
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiErrorFormatterTest.php
index d47481c..d11e314 100644 (file)
@@ -14,6 +14,7 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
                $result = new ApiResult( 8388608 );
                $formatter = new ApiErrorFormatter( $result, Language::factory( 'de' ), 'wikitext', false );
                $this->assertSame( 'de', $formatter->getLanguage()->getCode() );
+               $this->assertSame( 'wikitext', $formatter->getFormat() );
 
                $formatter->addMessagesFromStatus( null, Status::newGood() );
                $this->assertSame(
@@ -31,6 +32,25 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
                );
        }
 
+       /**
+        * @covers ApiErrorFormatter
+        * @covers ApiErrorFormatter_BackCompat
+        */
+       public function testNewWithFormat() {
+               $result = new ApiResult( 8388608 );
+               $formatter = new ApiErrorFormatter( $result, Language::factory( 'de' ), 'wikitext', false );
+               $formatter2 = $formatter->newWithFormat( 'html' );
+
+               $this->assertSame( $formatter->getLanguage(), $formatter2->getLanguage() );
+               $this->assertSame( 'html', $formatter2->getFormat() );
+
+               $formatter3 = new ApiErrorFormatter_BackCompat( $result );
+               $formatter4 = $formatter3->newWithFormat( 'html' );
+               $this->assertNotInstanceOf( ApiErrorFormatter_BackCompat::class, $formatter4 );
+               $this->assertSame( $formatter3->getLanguage(), $formatter4->getLanguage() );
+               $this->assertSame( 'html', $formatter4->getFormat() );
+       }
+
        /**
         * @covers ApiErrorFormatter
         * @dataProvider provideErrorFormatter
@@ -351,6 +371,7 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
                $formatter = new ApiErrorFormatter_BackCompat( $result );
 
                $this->assertSame( 'en', $formatter->getLanguage()->getCode() );
+               $this->assertSame( 'bc', $formatter->getFormat() );
 
                $this->assertSame( [], $formatter->arrayFromStatus( Status::newGood() ) );
 
@@ -526,10 +547,6 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
         * @param array $expect
         */
        public function testGetMessageFromException( $exception, $options, $expect ) {
-               if ( $exception instanceof UsageException ) {
-                       $this->hideDeprecated( 'UsageException::getMessageArray' );
-               }
-
                $result = new ApiResult( 8388608 );
                $formatter = new ApiErrorFormatter( $result, Language::factory( 'en' ), 'html', false );
 
@@ -575,12 +592,6 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
        }
 
        public static function provideGetMessageFromException() {
-               MediaWiki\suppressWarnings();
-               $usageException = new UsageException(
-                       '<b>Something broke!</b>', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ]
-               );
-               MediaWiki\restoreWarnings();
-
                return [
                        'Normal exception' => [
                                new RuntimeException( '<b>Something broke!</b>' ),
@@ -600,24 +611,6 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
                                        'data' => [ 'foo' => 'bar', 'baz' => 42 ],
                                ]
                        ],
-                       'UsageException' => [
-                               $usageException,
-                               [],
-                               [
-                                       'text' => '&#60;b&#62;Something broke!&#60;/b&#62;',
-                                       'code' => 'ue-code',
-                                       'data' => [ 'xxx' => 'yyy', 'baz' => 23 ],
-                               ]
-                       ],
-                       'UsageException, wrapped' => [
-                               $usageException,
-                               [ 'wrap' => 'parentheses', 'code' => 'some-code', 'data' => [ 'foo' => 'bar', 'baz' => 42 ] ],
-                               [
-                                       'text' => '(&#60;b&#62;Something broke!&#60;/b&#62;)',
-                                       'code' => 'some-code',
-                                       'data' => [ 'xxx' => 'yyy', 'baz' => 42, 'foo' => 'bar' ],
-                               ]
-                       ],
                        'LocalizedException' => [
                                new LocalizedException( [ 'returnto', '<b>FooBar</b>' ] ),
                                [],