/** * @covers ApiErrorFormatter * @dataProvider provideErrorFormatter */ public function testErrorFormatter($format, $lang, $useDB, $expect1, $expect2, $expect3) { $result = new ApiResult(8388608); $formatter = new ApiErrorFormatter($result, Language::factory($lang), $format, $useDB); // Add default type $expect1[ApiResult::META_TYPE] = 'assoc'; $expect2[ApiResult::META_TYPE] = 'assoc'; $expect3[ApiResult::META_TYPE] = 'assoc'; $formatter->addWarning('string', 'mainpage'); $formatter->addError('err', 'mainpage'); $this->assertSame($expect1, $result->getResultData(), 'Simple test'); $result->reset(); $formatter->addWarning('foo', 'mainpage'); $formatter->addWarning('foo', 'mainpage'); $formatter->addWarning('foo', array('parentheses', 'foobar')); $msg1 = wfMessage('mainpage'); $formatter->addWarning('message', $msg1); $msg2 = new ApiMessage('mainpage', 'overriddenCode', array('overriddenData' => true)); $formatter->addWarning('messageWithData', $msg2); $formatter->addError('errWithData', $msg2); $this->assertSame($expect2, $result->getResultData(), 'Complex test'); $result->reset(); $status = Status::newGood(); $status->warning('mainpage'); $status->warning('parentheses', 'foobar'); $status->warning($msg1); $status->warning($msg2); $status->error('mainpage'); $status->error('parentheses', 'foobar'); $formatter->addMessagesFromStatus('status', $status); $this->assertSame($expect3, $result->getResultData(), 'Status test'); $this->assertSame($expect3['errors']['status'], $formatter->arrayFromStatus($status, 'error'), 'arrayFromStatus test for error'); $this->assertSame($expect3['warnings']['status'], $formatter->arrayFromStatus($status, 'warning'), 'arrayFromStatus test for warning'); }
/** * @param ApiResult $result Into which data will be added */ public function __construct(ApiResult $result) { parent::__construct($result, Language::factory('en'), 'none', false); }