Page MenuHomePhabricator

Improve unit testing for CheckUser
Open, LowPublic

Description

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 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!

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?

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:

MediaWikiTestCase::addDBDataOnce()
MediaWikiTestCase::addDBData()

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

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

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

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

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

Change 799015 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Replace deprecated calls and add some tests

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

Change 799015 abandoned by Dreamy Jazz:

[mediawiki/extensions/CheckUser@master] Replace deprecated calls and add some tests

Reason:

Splitting into smaller patches to make merge conflicts easier.

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

Change 800803 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Add tests for Special:CheckUser

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

Change 800977 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Add tests for Special:CheckUserLog

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

Change 800803 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Add tests for Special:CheckUser

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

Change 800977 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Add tests for SpecialCheckUserLog and LogPager

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

Change 805863 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Start on tests for CheckUser and CheckUserLog API

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

Change 806171 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Add required right tests for SpecialCheckUser and SpecialCheckUserLog

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

Change 806171 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Add required right tests for SpecialCheckUser and SpecialCheckUserLog

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

Change 805863 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Start on tests for CheckUser and CheckUserLog API

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

Change 815328 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Test Hooks::getAgent and Hooks::insertIntoCuChangesTable

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

Change 815328 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Test getAgent, insertIntoCuChangesTable and updateCheckUserData

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

Change 816045 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Fix isValidRange and getIpConds tests and document test data

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

Change 816296 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Further tests for Hooks.php

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

Change 816045 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Fix isValidRange and getIpConds tests and document test data

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

Change 816296 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Further tests for Hooks.php

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

Change 819764 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Add tests for the CheckUser pagers and CheckUserLogService

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

Change 820156 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] Add tests for the APIs and a test for SpecialCheckUser.php

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

Change 820156 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Add tests for the APIs and a test for SpecialCheckUser.php

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

Change 819764 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Add tests for the CheckUser pagers and CheckUserLogService

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