[
'text' => '<b>Something broke!</b>',
'code' => 'internal_api_error_RuntimeException',
- 'data' => [],
+ 'data' => [
+ 'errorclass' => 'RuntimeException',
+ ],
]
],
'Normal exception, wrapped' => [
];
}
+ /**
+ * @covers ApiErrorFormatter::addMessagesFromStatus
+ * @covers ApiErrorFormatter::addWarningOrError
+ * @covers ApiErrorFormatter::formatMessageInternal
+ */
+ public function testAddMessagesFromStatus_filter() {
+ $result = new ApiResult( 8388608 );
+ $formatter = new ApiErrorFormatter( $result, Language::factory( 'qqx' ), 'plaintext', false );
+
+ $status = Status::newGood();
+ $status->warning( 'mainpage' );
+ $status->warning( 'parentheses', 'foobar' );
+ $status->warning( wfMessage( 'mainpage' ) );
+ $status->error( 'mainpage' );
+ $status->error( 'parentheses', 'foobaz' );
+ $formatter->addMessagesFromStatus( 'status', $status, [ 'warning', 'error' ], [ 'mainpage' ] );
+ $this->assertSame( [
+ 'errors' => [
+ [
+ 'code' => 'parentheses',
+ 'text' => '(parentheses: foobaz)',
+ 'module' => 'status',
+ ApiResult::META_CONTENT => 'text',
+ ],
+ ApiResult::META_INDEXED_TAG_NAME => 'error',
+ ],
+ 'warnings' => [
+ [
+ 'code' => 'parentheses',
+ 'text' => '(parentheses: foobar)',
+ 'module' => 'status',
+ ApiResult::META_CONTENT => 'text',
+ ],
+ ApiResult::META_INDEXED_TAG_NAME => 'warning',
+ ],
+ ApiResult::META_TYPE => 'assoc',
+ ], $result->getResultData() );
+ }
+
+ /**
+ * @dataProvider provideIsValidApiCode
+ * @covers ApiErrorFormatter::isValidApiCode
+ * @param string $code
+ * @param bool $expect
+ */
+ public function testIsValidApiCode( $code, $expect ) {
+ $this->assertSame( $expect, ApiErrorFormatter::isValidApiCode( $code ) );
+ }
+
+ public static function provideIsValidApiCode() {
+ return [
+ [ 'foo-bar_Baz123', true ],
+ [ 'foo bar', false ],
+ [ 'foo\\bar', false ],
+ [ 'internal_api_error_foo\\bar baz', true ],
+ ];
+ }
+
}