Page MenuHomePhabricator

ApiFormatRaw doesn't have tests
Closed, ResolvedPublic

Description

In MediaWiki core, the ApiFormatRaw class is a bit special, it isn't exposed directly to users and basically spits out exactly whatever is passed to it. Regardless, we should still have tests for this functionality.

If you're not already familiar with PHPUnit tests, https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/Writing_unit_tests has links to some good material on the basics of testing.

I would suggest creating something similar to ApiFormatNoneTest (instead of verifying there is no output, you'd verify the output is exactly the same...).

I'll mentor this for Google-Code-in-2017

Event Timeline

nikitavbv subscribed.

I will add tests for this!

Change 401405 had a related patch set uploaded (by Phantom42; owner: Phantom42):
[mediawiki/core@master] Add tests for ApiFormatRaw

https://gerrit.wikimedia.org/r/401405

I added tests to check that basic types are correctly encoded (ApiFormatRaw does not work with arrays or objects). I also added test case to check that exception is thrown if mime type or text are not given.

Please note that I didn't use parent encodeData function, but overrode it. That is because ApiFormatRaw can't be created using module manager and requires some custom ApiResult structure.

If anything needs fixing / improving, please tell and I will do it!

Change 401405 merged by jenkins-bot:
[mediawiki/core@master] Add tests for ApiFormatRaw

https://gerrit.wikimedia.org/r/401405