AutopromoteTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @covers Autopromote
  4. */
  5. class AutopromoteTest extends MediaWikiTestCase {
  6. /**
  7. * T157718: Verify Autopromote does not perform edit count lookup if requirement is 0 or invalid
  8. *
  9. * @see Autopromote::getAutopromoteGroups()
  10. * @dataProvider provideEditCountsAndRequirements
  11. * @param int $editCount edit count of user to be checked by Autopromote
  12. * @param int $requirement edit count required to autopromote user
  13. */
  14. public function testEditCountLookupIsSkippedIfRequirementIsZero( $editCount, $requirement ) {
  15. $this->setMwGlobals( [
  16. 'wgAutopromote' => [
  17. 'autoconfirmed' => [ APCOND_EDITCOUNT, $requirement ]
  18. ]
  19. ] );
  20. /** @var PHPUnit_Framework_MockObject_MockObject|User $userMock */
  21. $userMock = $this->getMock( User::class, [ 'getEditCount' ] );
  22. if ( $requirement > 0 ) {
  23. $userMock->expects( $this->once() )
  24. ->method( 'getEditCount' )
  25. ->willReturn( $editCount );
  26. } else {
  27. $userMock->expects( $this->never() )
  28. ->method( 'getEditCount' );
  29. }
  30. $result = Autopromote::getAutopromoteGroups( $userMock );
  31. if ( $editCount >= $requirement ) {
  32. $this->assertContains(
  33. 'autoconfirmed',
  34. $result,
  35. 'User must be promoted if they meet edit count requirement'
  36. );
  37. } else {
  38. $this->assertNotContains(
  39. 'autoconfirmed',
  40. $result,
  41. 'User must not be promoted if they fail edit count requirement'
  42. );
  43. }
  44. }
  45. public static function provideEditCountsAndRequirements() {
  46. return [
  47. 'user with sufficient editcount' => [ 100, 10 ],
  48. 'user with insufficient editcount' => [ 4, 10 ],
  49. 'edit count requirement set to 0' => [ 1, 0 ],
  50. ];
  51. }
  52. }