}
}
+ /**
+ * Test that 'assert' is processed before module errors
+ */
+ public function testAssertBeforeModule() {
+ // Sanity check that the query without assert throws too-many-titles
+ try {
+ $this->doApiRequest( [
+ 'action' => 'query',
+ 'titles' => implode( '|', range( 1, ApiBase::LIMIT_SML1 + 1 ) ),
+ ], null, null, new User );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e, 'too-many-titles' ), 'sanity check' );
+ }
+
+ // Now test that the assert happens first
+ try {
+ $this->doApiRequest( [
+ 'action' => 'query',
+ 'titles' => implode( '|', range( 1, ApiBase::LIMIT_SML1 + 1 ) ),
+ 'assert' => 'user',
+ ], null, null, new User );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e, 'assertuserfailed' ),
+ "Error '{$e->getMessage()}' matched expected 'assertuserfailed'" );
+ }
+ }
+
/**
* Test if all classes in the main module manager exists
*/
$context->setLanguage( 'en' );
$context->setConfig( new MultiConfig( [
new HashConfig( [
- 'ShowHostnames' => true, 'ShowSQLErrors' => false,
- 'ShowExceptionDetails' => true, 'ShowDBErrorBacktrace' => true,
+ 'ShowHostnames' => true, 'ShowExceptionDetails' => true,
] ),
$context->getConfig()
] ) );
[ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
[
'code' => 'internal_api_error_DBQueryError',
- 'text' => "[$reqId] Database query error.",
+ 'text' => "[$reqId] Exception caught: A database query error has occurred. " .
+ "This may indicate a bug in the software.",
]
],
'trace' => $dbtrace,
],
];
}
+
+ 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'] );
+ }
}