wiki.techinc.nl/tests/phpunit/includes/AutopromoteTest.php

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
use MediaWiki\User\UserEditTracker;
/**
* @covers Autopromote
*/
class AutopromoteTest extends MediaWikiIntegrationTestCase {
/**
UserEditTracker: Minor code clean up and follow-ups * Remove ILoadBalancer from UserEditCountInitJob constructor, since it is not a parameter and not a Job property. It is not needed during Job construction. * Use ConvertibleTimestamp instead of MWTimestamp since no MW-specific methods or behaviours are needed here. * I don't know if UserEditCountInitJob is always safe to de-duplicate, but this should be decided in the Job class, and is not the responsibility of calling code that creates/queues a job. I don't know for sure why this is publicly part of JobSpecification, but I guess it is there for internal use when serialising jobs, not for external use in the way it was used here. I'm assuming for now that its use means it is safe and I moved it to the UserEditCountInitJob class. If this is not the case and de-dupability is actually dependent on the parameters, then that logic should reside in the UserEditCountInitJob constructor. * Document for which internal use clearUserEditCache() is public. This way during refactoring the method can be easily found and made private if that caller is no longer needed. * Remove needless Job::factory() indirection in the UserEditCountInitJob test suite. This added overhead that is not part of the test's purpose, and also risks making the test break because Job::factory() allows types to be mapped to different implementations. But, this test suite is meant to cover the UserEditCountInitJob class implementation specifically. Change-Id: I6fef4d297b1c0169f95906822e30b4addab7eaf4
2020-08-12 01:35:55 +00:00
* Autopromote must not perform edit count lookup if requirement is 0 or invalid (T157718).
*
* @see Autopromote::getAutopromoteGroups()
* @dataProvider provideEditCountsAndRequirements
* @param int $editCount edit count of user to be checked by Autopromote
* @param int $requirement edit count required to autopromote user
*/
public function testEditCountLookupIsSkippedIfRequirementIsZero( $editCount, $requirement ) {
$this->hideDeprecated( 'Autopromote::getAutopromoteGroups' );
$this->setMwGlobals( [
'wgAutopromote' => [
'autoconfirmed' => [ APCOND_EDITCOUNT, $requirement ]
]
] );
$user = $this->getTestUser()->getUser();
$userEditTrackerMock = $this->createNoOpMock(
UserEditTracker::class,
[ 'getUserEditCount' ]
);
if ( $requirement > 0 ) {
$userEditTrackerMock->expects( $this->once() )
->method( 'getUserEditCount' )
->with( $user )
->willReturn( $editCount );
} else {
$userEditTrackerMock->expects( $this->never() )
->method( 'getUserEditCount' );
}
$this->setService( 'UserEditTracker', $userEditTrackerMock );
$result = Autopromote::getAutopromoteGroups( $user );
if ( $editCount >= $requirement ) {
$this->assertContains(
'autoconfirmed',
$result,
'User must be promoted if they meet edit count requirement'
);
} else {
$this->assertNotContains(
'autoconfirmed',
$result,
'User must not be promoted if they fail edit count requirement'
);
}
}
public static function provideEditCountsAndRequirements() {
return [
'user with sufficient editcount' => [ 100, 10 ],
'user with insufficient editcount' => [ 4, 10 ],
'edit count requirement set to 0' => [ 1, 0 ],
];
}
}