Page MenuHomePhabricator

Add basic unit tests for classes that extend Ballot [M]
Closed, ResolvedPublic

Description

See also T282010: Add basic unit tests for the Ballot class [M].

Subclasses of ballot are:

  • ApprovalBallot
  • ChooseBallot
  • PreferentialBallot
  • RadioRangeBallot

We should implement a new test class for each ballot class, and each one should extend MediaWikiUnitTestCase.

This will require some judgement of what is worth testing, and what is possible to test with a unit test (as opposed to an integration test).

Event Timeline

ARamirez_WMF renamed this task from Add basic unit tests for classes that extend Ballot to Add basic unit tests for classes that extend Ballot [M].May 26 2021, 4:21 PM

Change 698891 had a related patch set uploaded (by STran; author: STran):

[mediawiki/extensions/SecurePoll@master] Add ballot tests

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

Change 698891 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] Add ballot tests

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

dom_walden subscribed.

I have briefly reviewed the unit tests, and they seem fine to me.

I paid most attention to the unit tests of the STVBallot class, as this is new. The other classes we are testing have been around for a while, so I assume they work.

Out of interest, I want to see what happened when I submitted duplicate options (e.g. a voter trying to select two different candidates as first preference). I think this could only happen if they modified the HTML or used a REST client, so it seems unlikely. Nevertheless, it appears to ignore all but the last duplicate option, which seems reasonable. My unit test is below.