Page MenuHomePhabricator

Improve unit testing for CheckUser
Open, LowPublic


Issues like what was found and fixed in T175898 should be caught by unit testing; ideally, we should have a unit test that should run checks on some fake data and compare the results with the expected results.

It will be a bit hard though, because of the "fake data" part, and due to the fact that CU functions only accept DB tables as the input and cannot be run on, say, an arbitrary data source (otherwise we could package with the CU unit tests a sqlite DB with some fake data in it). Do we have other unit tests that use alternative data sources?

Event Timeline

Huji created this task.Sep 14 2017, 1:44 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 14 2017, 1:44 PM
Huji triaged this task as Low priority.Sep 14 2017, 1:44 PM
Huji added a project: User-Huji.

I'm experimenting with this right now, and trying to go off of other extensions that do db stuff. It might be closer to an integration test, but if it works...

I'll let you know if I figure anything out!

MusikAnimal added a comment.EditedSep 14 2017, 3:49 PM

So I was just going to do it like I did in PageArchiveTest.php (create revisions with new Revision() which in turn would populate cuc_changes). There's some magic somewhere in core that creates all the default.unittest_whatever tables, and you specify which ones should be truncated with $this->tablesUsed. default.unittest_cuc_changes however does not exist. Do we know how to make it create this table?

hashar added a subscriber: hashar.Sep 16 2017, 6:52 AM

CI does:

  • clone mediawiki
  • maintenance/install.php
  • tweak LocalSettings.php to enable extensions
  • maintenance/update.php (which creates the extension database tables)
  • run phpunit

The magic is in tests/phpunit/MediaWikiTestCase.php. When your test class as a @databases it clones database tables with a unittest_ prefix so your tests run against a copy of the installed DB.

To inject data to the database, in your test class you can use one of:


You can look at tests/phpunit/includes/BlockTest.php which inserts some user/IP blocks which are then used to test the code logic.

@hashar Splendid!!! Thank you :)

hashar removed a subscriber: hashar.Oct 16 2017, 11:45 AM

Change 394918 had a related patch set uploaded (by MusikAnimal; owner: MusikAnimal):
[mediawiki/extensions/CheckUser@master] Start on basic unit tests for CheckUser extension

Change 394918 merged by jenkins-bot:
[mediawiki/extensions/CheckUser@master] Start on basic unit tests for CheckUser extension

Huji moved this task from Backlog to Patches in review on the CheckUser board.Feb 24 2018, 8:08 PM