Merge "ApiMain: Always create a new printer in getPrinterByName()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 20 Jul 2018 00:06:10 +0000 (00:06 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 20 Jul 2018 00:06:10 +0000 (00:06 +0000)
includes/api/ApiMain.php
tests/phpunit/includes/api/ApiMainTest.php

index 610ecf5..b398ecd 100644 (file)
@@ -486,7 +486,7 @@ class ApiMain extends ApiBase {
         * @return ApiFormatBase
         */
        public function createPrinterByName( $format ) {
-               $printer = $this->mModuleMgr->getModule( $format, 'format' );
+               $printer = $this->mModuleMgr->getModule( $format, 'format', /* $ignoreCache */ true );
                if ( $printer === null ) {
                        $this->dieWithError(
                                [ 'apierror-unknownformat', wfEscapeWikiText( $format ) ], 'unknown_format'
index f06d97e..b7869e6 100644 (file)
@@ -1098,4 +1098,21 @@ class ApiMainTest extends ApiTestCase {
                        ],
                ];
        }
+
+       public function testPrinterParameterValidationError() {
+               $api = $this->getNonInternalApiMain( [
+                       'action' => 'query', 'meta' => 'siteinfo', 'format' => 'json', 'formatversion' => 'bogus',
+               ] );
+
+               ob_start();
+               $api->execute();
+               $txt = ob_get_clean();
+
+               // Test that the actual output is valid JSON, not just the format of the ApiResult.
+               $data = FormatJson::decode( $txt, true );
+               $this->assertInternalType( 'array', $data );
+               $this->assertArrayHasKey( 'error', $data );
+               $this->assertArrayHasKey( 'code', $data['error'] );
+               $this->assertSame( 'unknown_formatversion', $data['error']['code'] );
+       }
 }